diff --git a/firmware/asdf/src/Arch/asdf_arch_test.c b/firmware/asdf/src/Arch/asdf_arch_test.c index 475b769..86acf10 100644 --- a/firmware/asdf/src/Arch/asdf_arch_test.c +++ b/firmware/asdf/src/Arch/asdf_arch_test.c @@ -543,6 +543,23 @@ void asdf_arch_pulse_delay_long(void) asdf_arch_pulse_delay(); } +// PROCEDURE: asdf_arch_delay_ms +// INPUTS: (uint16) delay_ms - the delay in msec. +// OUTPUTS: none +// +// DESCRIPTION: Delays a specified number of milliseconds +// +// SIDE EFFECTS: see above. +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_arch_delay_ms(uint16_t delay_ms) +{ + asdf_arch_pulse_delay(); +} + // PROCEDURE: asdf_arch_pulse_delay_short // INPUTS: none // OUTPUTS: none diff --git a/firmware/asdf/src/Arch/asdf_arch_test.h b/firmware/asdf/src/Arch/asdf_arch_test.h index 6839dbe..500dd35 100644 --- a/firmware/asdf/src/Arch/asdf_arch_test.h +++ b/firmware/asdf/src/Arch/asdf_arch_test.h @@ -197,6 +197,12 @@ asdf_cols_t asdf_arch_read_row(uint8_t row); // be tested. void asdf_arch_send_code(asdf_keycode_t); +// PROCEDURE: asdf_arch_delay_ms +// INPUTS: (uint16) delay_ms - the delay in msec. +// OUTPUTS: none +// DESCRIPTION: Delays a specified number of milliseconds +void asdf_arch_delay_ms(uint16_t delay_ms); + // PROCEDURE: asdf_arch_get_sent_code // INPUTS: none // OUTPUTS: returns type (asdf_keycode_t) in register and zeros the register. diff --git a/firmware/asdf/test/asdf_keymap_table.c b/firmware/asdf/test/asdf_keymap_table.c index 1816b6c..4af7774 100644 --- a/firmware/asdf/test/asdf_keymap_table.c +++ b/firmware/asdf/test/asdf_keymap_table.c @@ -26,29 +26,99 @@ // this program. If not, see . // +#include #include "asdf_keymap_table.h" #include "test_asdf_keymap_defs.h" -asdf_keymap_setup_function_t keymap_setup_function_lookup_table[ASDF_NUM_KEYMAPS] = { - [ASDF_TEST_PLAIN_MAP_INDEX] = setup_test_plain_map, - [ASDF_TEST_CAPS_MAP_INDEX] = setup_test_caps_map, - [ASDF_TEST2_PLAIN_MAP_INDEX] = setup_test2_plain_map, - [ASDF_TEST2_CAPS_MAP_INDEX] = setup_test2_caps_map, - - // keymap assignments for the virtual device tests - [SINGLE_TESTS_KEYMAP] = setup_test_vdevs_single, - [DOUBLE_ASSIGN_TEST_KEYMAP] = setup_test_vdevs_double, - [TRIPLE_TESTS_KEYMAP] = setup_test_vdevs_triple, - [VCAPS_TEST_KEYMAP] = setup_test_vdevs_vcaps, +// PROCEDURE: asdf_keymap_setup +// +// INPUTS: (uint8_t) index - index of the keymap setup function to call +// OUTPUTS: none +//// +// DESCRIPTION: This function calls the keymap setup function specified +// by the index. +// +// SIDE EFFECTS: See Description +// +// NOTES: This function is necessary because functions defined in external +// modules are not considered compile-time constants by the C99 standard, so the +// array cannot be initialized with a compile-time declaration. +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymap_setup(uint8_t index) { + switch(index) { - // keymap assignments for the hook mechanism tests - [ASDF_TEST_DEFAULT_SCANNER_MAP] = setup_test_hooks_alt_scanner, - [ASDF_TEST_ALTERNATE_OUTPUT_MAP] = setup_test_hooks_alt_output, - [ASDF_TEST_EACH_SCAN_MAP] = setup_test_hooks_each_scan, -}; + default: + case ASDF_TEST_PLAIN_MAP_INDEX: setup_test_plain_map(); break; + case ASDF_TEST_CAPS_MAP_INDEX: setup_test_caps_map(); break; + case ASDF_TEST2_PLAIN_MAP_INDEX: setup_test2_plain_map(); break; + case ASDF_TEST2_CAPS_MAP_INDEX: setup_test2_caps_map(); + break; + // keymap assignments for the virtual device tests + case SINGLE_TESTS_KEYMAP: setup_test_vdevs_single(); break; + case DOUBLE_ASSIGN_TEST_KEYMAP: setup_test_vdevs_double(); break; + case TRIPLE_TESTS_KEYMAP: setup_test_vdevs_triple(); break; + case VCAPS_TEST_KEYMAP: setup_test_vdevs_vcaps(); + break; + + // keymap assignments for the hook mechanism tests + case ASDF_TEST_DEFAULT_SCANNER_MAP: setup_test_hooks_alt_scanner(); break; + case ASDF_TEST_ALTERNATE_OUTPUT_MAP: setup_test_hooks_alt_output(); break; + case ASDF_TEST_EACH_SCAN_MAP: setup_test_hooks_each_scan(); break; + } +} + +// PROCEDURE: asdf_keymap_valid +// +// INPUTS: (uint8_t) index - index of the keymap setup function to check +// OUTPUTS: (uintu_t) returns TRUE (nonzero) if valid, FALSE (0) otherwise +// +// DESCRIPTION: This function returns TRUE if the index corresponds to +// a valid keymap. +// +// SIDE EFFECTS: none +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +uint8_t asdf_keymap_valid(uint8_t index) { + uint8_t valid = 0; + + switch(index) { + case ASDF_TEST_PLAIN_MAP_INDEX: + case ASDF_TEST_CAPS_MAP_INDEX: + case ASDF_TEST2_PLAIN_MAP_INDEX: + case ASDF_TEST2_CAPS_MAP_INDEX: + + // keymap assignments for the virtual device tests + case SINGLE_TESTS_KEYMAP: + case DOUBLE_ASSIGN_TEST_KEYMAP: + case TRIPLE_TESTS_KEYMAP: + case VCAPS_TEST_KEYMAP: + + // keymap assignments for the hook mechanism tests + case ASDF_TEST_DEFAULT_SCANNER_MAP: + case ASDF_TEST_ALTERNATE_OUTPUT_MAP: + case ASDF_TEST_EACH_SCAN_MAP: + + valid = 1; + break; + + default: + valid = 0; + break; + } + + return valid; +} -void asdf_keymap_table_init(void) {} //-------|---------|---------+---------+---------+---------+---------+---------+ // Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/test/asdf_keymap_table.h b/firmware/asdf/test/asdf_keymap_table.h index 69d58eb..11df758 100644 --- a/firmware/asdf/test/asdf_keymap_table.h +++ b/firmware/asdf/test/asdf_keymap_table.h @@ -30,9 +30,21 @@ // define the type for a keymap setup function. Keymaps are registerd by storing // a keymap setup function in the keymap setup array. -typedef void (*asdf_keymap_setup_function_t)(void); -void asdf_keymap_table_init(void); +// PROCEDURE: asdf_keymap_setup +// INPUTS: (uint8_t) index - index of the keymap setup function to call +// OUTPUTS: none +// DESCRIPTION: This function calls the keymap setup function specified +// by the index. +// SIDE EFFECTS: See Description +void asdf_keymap_setup(uint8_t index); + +// PROCEDURE: asdf_keymap_valid +// INPUTS: (uint8_t) index - index of the keymap setup function to check +// OUTPUTS: (uintu_t) returns TRUE (nonzero) if valid, FALSE (0) otherwise +// DESCRIPTION: This function returns TRUE if the index corresponds to +// a valid keymap. +uint8_t asdf_keymap_valid(uint8_t index); //-------|---------|---------+---------+---------+---------+---------+---------+ // Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/test/test_asdf_buffer.c b/firmware/asdf/test/test_asdf_buffer.c index 0763336..66a3624 100644 --- a/firmware/asdf/test/test_asdf_buffer.c +++ b/firmware/asdf/test/test_asdf_buffer.c @@ -10,8 +10,8 @@ #define MAX_BUFFER ASDF_BUFFER_POOL_SIZE #define HALF_BUFFER (ASDF_BUFFER_POOL_SIZE / 2) -static const char test_string[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char test_string[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const int test_string_size = sizeof(test_string) - 1; static const char * const more_strings[] = { "abcdefghijkl", @@ -32,6 +32,18 @@ void setUp(void) void tearDown(void) {} + +// function to generate pseudo-random sequence to fill buffer. +asdf_keycode_t random_code(asdf_keycode_t seed) +{ + uint8_t msb = seed & 0x80; + seed <<= 1; + if (msb) { + seed ^= 0x88; + } + return seed; +} + // allocating first buffer returns handle 0 void test_allocating_first_buffer_returns_handle_0(void) { @@ -125,16 +137,16 @@ void test_adding_and_retrieving_string_one_by_one(void) } } -// Filling the buffer first, then retrieving the characters from the buffer + // should return the same string. void test_fill_buffer_then_retrieve_string(void) { for (int sent = 0; sent < MAX_BUFFER; sent++) { - asdf_buffer_put(handle, (asdf_keycode_t) test_string[sent]); + asdf_buffer_put(handle, (asdf_keycode_t) test_string[sent % test_string_size]); } for (int received = 0; received < MAX_BUFFER; received++) { int32_t code = (int32_t) asdf_buffer_get(handle); - TEST_ASSERT_EQUAL_INT32((int32_t) test_string[received],code); + TEST_ASSERT_EQUAL_INT32((int32_t) test_string[received % test_string_size],code); } // assert that next code request returns invalid code: TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_buffer_get(handle)); @@ -145,15 +157,20 @@ void test_fill_buffer_then_retrieve_string(void) // characters back, quietly dropping the overflow. void test_overfilling_buffer_and_retrieve_drops_overflow(void) { + const asdf_keycode_t seed = 0x3b; + asdf_keycode_t next_random_code; + // send the entire test string to overflow the buffer. - for (int i = 0; i < (int) sizeof(test_string); i++) { - asdf_buffer_put(handle, (asdf_keycode_t) test_string[i]); + for (int i = 0, next_rand_code = seed; i < MAX_BUFFER * 2; i++) { + next_rand_code = random_code(next_rand_code); + asdf_buffer_put(handle, next_rand_code); } // read until invalid character is received, testing that each character is // correct. - for (int i = 0; i < MAX_BUFFER; i++) { + for (int i = 0, next_rand_code = seed; i < MAX_BUFFER; i++) { asdf_keycode_t code = asdf_buffer_get(handle); - TEST_ASSERT_EQUAL_INT32((int32_t) test_string[i], (int32_t) code); + next_rand_code = random_code(next_rand_code); + TEST_ASSERT_EQUAL_INT32((int32_t) next_rand_code, (int32_t) code); } // the next code request returns invalid code: diff --git a/firmware/asdf/test/test_keymapdefs.c b/firmware/asdf/test/test_keymapdefs.c index 09eb0c7..4be120a 100644 --- a/firmware/asdf/test/test_keymapdefs.c +++ b/firmware/asdf/test/test_keymapdefs.c @@ -25,8 +25,6 @@ // testing, both must be present to test their functionality. -#include "test_keymapdefs.h" - #define PLAIN_MATRIX_1 RESERVED_1 #define CAPS_MATRIX_1 RESERVED_2 #define SHIFT_MATRIX_1 RESERVED_3