Skip to content

Commit 506debd

Browse files
committed
tests: Rewrite the test harness to be more robust
While at it, add test SC vectors from SIA and NIST. Also rolled out some custom test cases to excecise the remaining=0 and remaining!=0 code paths in the encryption sequences. These will come in handy for the next change to osdp_compute_mac to drop the 256 byte stack buffer. Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 0422343 commit 506debd

10 files changed

Lines changed: 1644 additions & 52 deletions

File tree

.github/workflows/build-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
./configure.sh
4242
- name: make
4343
run: make V=1
44+
- name: make check
45+
run: make V=1 check
4446

4547
DocBuild:
4648
runs-on: ubuntu-latest
@@ -67,9 +69,7 @@ jobs:
6769
- name: Configure
6870
run: cmake -DCMAKE_BUILD_TYPE=Debug .
6971
- name: Run unit-tests
70-
run: cmake --build . --parallel 7 --target check-ut
71-
- name: Run pytest
72-
run: tests/pytest/run.sh
72+
run: cmake --build . --parallel 7 --target check
7373

7474
CheckPatch:
7575
runs-on: ubuntu-latest

.github/workflows/cross-plaform-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Build
2727
run: cmake --build build --parallel 8
2828
- name: Run unit-tests
29-
run: cmake --build build --parallel 8 --target check-ut
29+
run: cmake --build build --parallel 8 --target check
3030
- name: Pack built binaries
3131
run: cmake --build build --target package
3232
- name: Upload artifacts

configure.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ TEST_SOURCES+=" tests/unit-tests/test-cp-fsm.c"
184184
TEST_SOURCES+=" tests/unit-tests/test-file.c"
185185
TEST_SOURCES+=" tests/unit-tests/test-async-fuzz.c"
186186
TEST_SOURCES+=" tests/unit-tests/test-hotplug.c"
187+
TEST_SOURCES+=" tests/unit-tests/test-sc.c"
188+
TEST_SOURCES+=" tests/unit-tests/test-sc-sia-vectors.c"
187189
TEST_SOURCES+=" ${LIBOSDP_SOURCES} ${UTILS_SOURCES}"
188190

189191
if [[ ! -z "${LIB_ONLY}" ]]; then

src/osdp_sc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,12 @@ void osdp_sc_teardown(struct osdp_pd *pd)
245245
ARG_UNUSED(pd);
246246
osdp_crypt_teardown();
247247
}
248+
249+
#ifdef UNIT_TESTING
250+
int (*test_osdp_compute_mac)(struct osdp_pd *pd, int is_cmd,
251+
const uint8_t *data, int len) = osdp_compute_mac;
252+
int (*test_osdp_encrypt_data)(struct osdp_pd *pd, int is_cmd,
253+
uint8_t *data, int length) = osdp_encrypt_data;
254+
int (*test_osdp_decrypt_data)(struct osdp_pd *pd, int is_cmd,
255+
uint8_t *data, int length) = osdp_decrypt_data;
256+
#endif /* UNIT_TESTING */

tests/unit-tests/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ list(APPEND OSDP_UNIT_TEST_SRC
2525
test-events.c
2626
test-hotplug.c
2727
test-async-fuzz.c
28+
test-sc.c
29+
test-sc-sia-vectors.c
2830
)
2931

3032
add_executable(${OSDP_UNIT_TEST} EXCLUDE_FROM_ALL ${OSDP_UNIT_TEST_SRC})
@@ -45,8 +47,13 @@ include_directories(
4547
${PROJECT_SOURCE_DIR}/utils/include
4648
)
4749

48-
add_custom_target(check-ut
50+
add_custom_target(check
4951
COMMAND ${CMAKE_BINARY_DIR}/bin/${OSDP_UNIT_TEST}
5052
COMMAND rm ${CMAKE_BINARY_DIR}/bin/${OSDP_UNIT_TEST}
5153
DEPENDS ${OSDP_UNIT_TEST}
5254
)
55+
56+
# Backward-compatible alias; prefer `check`.
57+
add_custom_target(check-ut
58+
DEPENDS check
59+
)

0 commit comments

Comments
 (0)