diff options
| author | Mumtahin Farabi <[email protected]> | 2026-05-12 00:23:26 -0400 |
|---|---|---|
| committer | Mumtahin Farabi <[email protected]> | 2026-05-12 00:23:26 -0400 |
| commit | cdf1db1c4197f76cf2dd876e3c8a27c807acb7fd (patch) | |
| tree | db479c9577f96f84de4c4e10449b22370d0f19fc /firmware/tests/shell.c | |
| parent | 28bf8cb5076f419abcfe912d4ec2e0c5f31819a0 (diff) | |
feat(firmware): scaffold setup
Signed-off-by: Mumtahin Farabi <[email protected]>
Diffstat (limited to 'firmware/tests/shell.c')
| -rw-r--r-- | firmware/tests/shell.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/firmware/tests/shell.c b/firmware/tests/shell.c new file mode 100644 index 0000000..5b52a53 --- /dev/null +++ b/firmware/tests/shell.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2026 Apidae Systems + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <zephyr/kernel.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_dummy.h> +#include <zephyr/sys/atomic.h> +#include <zephyr/ztest.h> + +static atomic_t hello_invocations = ATOMIC_INIT(0); + +static int cmd_hello(const struct shell *sh, size_t argc, char **argv) +{ + atomic_inc(&hello_invocations); + shell_print(sh, "hello from %s", argc > 1 ? argv[1] : "test"); + return 0; +} + +SHELL_CMD_REGISTER(hello, NULL, "test-only command — increments a counter", cmd_hello); + +ZTEST_SUITE(shell, NULL, NULL, NULL, NULL, NULL); + +ZTEST(shell, test_dummy_backend_is_ready) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + + zassert_not_null(sh, "dummy shell backend pointer is NULL"); +} + +ZTEST(shell, test_executes_builtin_help) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + int rc = shell_execute_cmd(sh, "help"); + + zassert_ok(rc, "shell_execute_cmd(\"help\") failed: %d", rc); +} + +ZTEST(shell, test_executes_kernel_uptime) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + int rc = shell_execute_cmd(sh, "kernel uptime"); + + zassert_ok(rc, "shell_execute_cmd(\"kernel uptime\") failed: %d", rc); +} + +ZTEST(shell, test_executes_custom_command_with_side_effect) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + atomic_val_t before = atomic_get(&hello_invocations); + + int rc = shell_execute_cmd(sh, "hello world"); + + zassert_ok(rc, "shell_execute_cmd(\"hello world\") failed: %d", rc); + + atomic_val_t after = atomic_get(&hello_invocations); + zassert_equal(after, before + 1, + "custom command did not run: before=%ld after=%ld", + (long)before, (long)after); +} + +ZTEST(shell, test_unknown_command_does_not_crash) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + int rc = shell_execute_cmd(sh, "definitely_not_a_real_command_xyz"); + + zassert_not_equal(rc, 0, + "unknown command should return non-zero, got %d", rc); +} |
