diff options
| author | 2026-06-28 01:27:46 -0500 | |
|---|---|---|
| committer | 2026-06-28 01:27:46 -0500 | |
| commit | bc8d6da2c1cb659b406cbd59b7eac80bba51033f (patch) | |
| tree | dd6605c84129ed43c528eb4a98ccfc0f653987cf /source/tests/basic.c | |
| parent | initial commit (diff) | |
Diffstat (limited to 'source/tests/basic.c')
| -rw-r--r-- | source/tests/basic.c | 97 |
1 files changed, 55 insertions, 42 deletions
diff --git a/source/tests/basic.c b/source/tests/basic.c index 8645b19..4f34ba4 100644 --- a/source/tests/basic.c +++ b/source/tests/basic.c @@ -1,66 +1,79 @@ #define ET_TEST_IMPL #include "../test.h" #include <inttypes.h> +#include <stdio.h> -et_test_status test_exi_readwrite(struct et_test_plan *plan, void *data, size_t data_sz, et_test_error base, struct et_next_state *next_state) { - struct et_test_plan_entry *cur = test_current(plan); - int chan = plan->exi_channel; - et_test_status status = TEST_PASS; - s32 exi_res; +#define TEST_ITERATIONS 16 - if ((exi_res = EXI_Lock(chan, EXI_DEVICE_0, NULL)) <= 0) { - status = TEST_ERROR(base); - test_plan_entry_set_error(cur, "failed to lock EXI channel: %" PRId32, exi_res); - goto fail_lock; - } +struct test_with_iterations { + struct et_test_state_private_base base; + int iteration; +}; - if ((exi_res = EXI_Select(chan, EXI_DEVICE_0, EXI_SPEED32MHZ)) <= 0) { - status = TEST_ERROR(base + 1); - test_plan_entry_set_error(cur, "failed to select EXI channel: %" PRId32, exi_res); - goto fail_select; - } +static int init_test_with_iterations(const struct et_state *state, void *data, et_state_init_data init_data) { + struct test_with_iterations *priv = data; + priv->iteration = 0; + return 0; +} - if ((exi_res = EXI_Imm(chan, data, data_sz, EXI_READWRITE, NULL)) <= 0) { - status = TEST_ERROR(base + 2); - test_plan_entry_set_error(cur, "failed to send EXI data: %" PRId32, exi_res); - goto fail_data; +static int check_id_tick(const struct et_state *state, void *data, struct et_next_state *next_state) { + struct test_with_iterations *priv = data; + struct et_test_plan *test_plan = priv->base.plan; + struct et_test_plan_entry *cur = test_current(test_plan); + et_test_status status = TEST_PASS; + u16 command = 0x9000; + + if ((status = test_exi_readwrite(test_plan, &command, sizeof(command), TEST_EPRIV_BASE)) != TEST_PASS) { + cur->status = status; + return test_next(test_plan, next_state); } - if ((exi_res = EXI_Sync(chan)) <= 0) { - status = TEST_ERROR(base + 3); - test_plan_entry_set_error(cur, "failed to complete transfer: %" PRId32, exi_res); - goto fail_data; + if (command != 0x0470) { + test_plan_entry_set_error(cur, "bad identifier from gecko: expected 0x0470, got 0x%04" PRIx16, command); + status = TEST_FAIL; } -fail_data: - EXI_Deselect(chan); + cur->status = status; -fail_select: - EXI_Unlock(chan); + if (status != TEST_PASS || ++priv->iteration >= TEST_ITERATIONS) { + return test_next(test_plan, next_state); + } -fail_lock: - cur->status = status; - return status; + return 0; } -static int check_id_tick(const struct et_state *state, void *data, struct et_next_state *next_state) { - struct et_test_state_private_base *priv = data; - struct et_test_plan *test_plan = priv->plan; +TEST_DEF(check_id, "Identify Gecko (0x09)", TEST_PAUSE_ON_ERROR, init_test_with_iterations, check_id_tick, NULL, struct test_with_iterations); + +static int bad_commands_tick(const struct et_state *state, void *data, struct et_next_state *next_state) { + struct test_with_iterations *priv = data; + struct et_test_plan *test_plan = priv->base.plan; struct et_test_plan_entry *cur = test_current(test_plan); et_test_status status = TEST_PASS; - u16 command = 0x9000; - if ((status = test_exi_readwrite(test_plan, &command, sizeof(command), TEST_EPRIV_BASE, next_state)) != TEST_PASS) { - return test_next(test_plan, next_state); + static const u16 bad_commands[] = { 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0xe000, 0xf000 }; + + for (int i = 0; i < ARRLEN(bad_commands); ++i) { + u16 orig_cmd = bad_commands[i]; + u16 cmd = orig_cmd; + if ((status = test_exi_readwrite(test_plan, &cmd, sizeof(cmd), TEST_EPRIV_BASE)) != TEST_PASS) { + goto test_fail; + } + + if (cmd != 0x0000) { + test_plan_entry_set_error(cur, "got bogus response from invalid command 0x%04" PRIx16 ": 0x%04" PRIx16, orig_cmd, cmd); + status = TEST_FAIL; + break; + } } - if (command != 0x0470) { - test_plan_entry_set_error(cur, "bad identifier from gecko: expected 0x0470, got 0x%04" PRIx16, command); - status = TEST_FAIL; +test_fail: + cur->status = status; + + if (status != TEST_PASS || ++priv->iteration >= TEST_ITERATIONS) { + return test_next(test_plan, next_state); } - cur->status = TEST_PASS; - return test_next(test_plan, next_state); + return 0; } -TEST_DEF(check_id, "Identify Gecko (0x09)", TEST_PAUSE_ON_ERROR, NULL, check_id_tick, NULL, struct et_test_state_private_base); +TEST_DEF(bad_commands, "Bad commands", 0, init_test_with_iterations, bad_commands_tick, NULL, struct test_with_iterations); |
