/* * Copyright (c) 2026 Apidae Systems * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include #include #include 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); }