api.c: move out tests into other files#10547
Open
SparkiDev wants to merge 1 commit into
Open
Conversation
4151c88 to
58da590
Compare
Move out DTLS 1.3 specific tests into test_dtls13.c. (Also move out from test_dtls.c) Move out DTLS tests into test_dtls.c. Move out LMS and XMSS tests into test_lms_xmss.c. Move out SSL session tests into test_session.c. Move out remaining ML-DSA/Dilithium tests in api.c into test_mldsa.c.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the API unit test suite by splitting large chunks of tests/api.c into focused translation units (DTLS 1.3, DTLS, sessions, LMS/XMSS, and remaining ML-DSA/Dilithium tests), and updates build metadata so the new files are compiled in both Autotools and CMake builds.
Changes:
- Introduces new test modules:
test_dtls13.c,test_session.c, andtest_lms_xmss.c(+ corresponding headers) and wires them into the unit-test build. - Moves/extends ML-DSA/Dilithium negative length-validation regression tests into
test_mldsa.cand registers them viatest_mldsa.h. - Updates shared test utilities (
tests/utils.h) and build lists (tests/api/include.am,CMakeLists.txt) to accommodate the split.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils.h | Adds shared thread-body prototypes used across API tests. |
| tests/api/test_session.h | New header declaring session-related tests and registration macro. |
| tests/api/test_session.c | New translation unit containing session resumption/cache tests. |
| tests/api/test_mldsa.h | Registers additional ML-DSA/Dilithium negative/regression tests. |
| tests/api/test_mldsa.c | Adds ML-DSA/Dilithium negative length-validation regression tests. |
| tests/api/test_lms_xmss.h | New header declaring LMS/XMSS tests and registration macro. |
| tests/api/test_lms_xmss.c | New translation unit containing LMS signing/reload tests + RFC 9802 fixtures. |
| tests/api/test_dtls13.h | New header declaring DTLS 1.3-only tests and registration macro. |
| tests/api/test_dtls13.c | New translation unit containing DTLS 1.3-only tests. |
| tests/api/test_dtls.h | Removes DTLS 1.3 tests from DTLS group and adds DTLS tests moved from tests/api.c. |
| tests/api/include.am | Adds new test sources/headers to Autotools unit-test build and dist. |
| CMakeLists.txt | Adds new test sources to CMake unit_test target source list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* LMS tests */ | ||
| /*----------------------------------------------------------------------------*/ | ||
|
|
||
| #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) |
Comment on lines
+59
to
+70
| static int test_lms_read_key(byte* priv, word32 privSz, void* context) | ||
| { | ||
| FILE* f = fopen((const char*)context, "rb"); | ||
| if (f == NULL) | ||
| return -1; | ||
| if (fread(priv, 1, privSz, f) == 0) { | ||
| fclose(f); | ||
| return -1; | ||
| } | ||
| fclose(f); | ||
| return WC_LMS_RC_READ_TO_MEMORY; | ||
| } |
Comment on lines
+350
to
+360
| for (i = 0; i < SESSION_CACHE_SIZE; i++) { | ||
| if (server_sessionCache.entries[i].key != NULL && | ||
| XMEMCMP(server_sessionCache.entries[i].key, | ||
| sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { | ||
| wolfSSL_SESSION_free(server_sessionCache.entries[i].value); | ||
| server_sessionCache.entries[i].value = NULL; | ||
| server_sessionCache.entries[i].key = NULL; | ||
| server_sessionCache.length--; | ||
| break; | ||
| } | ||
| } |
Comment on lines
+367
to
+398
| static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl, | ||
| const unsigned char *id, int len, int *ref) | ||
| { | ||
| int i; | ||
| (void)ssl; | ||
| (void)id; | ||
| (void)len; | ||
|
|
||
| /* | ||
| * This example uses a hash table. | ||
| * Steps you should take for a non-demo code: | ||
| * - acquire a lock for the file named according to the session id in the | ||
| * 2nd arg | ||
| * - read and decrypt contents of file and create a new SSL_SESSION | ||
| * - object release the lock | ||
| * - return the new session object | ||
| */ | ||
| fprintf(stderr, "\t\ttwcase_get_session_called %d\n", | ||
| ++twcase_get_session_called); | ||
| /* This callback want to retain a copy of the object. If we want wolfSSL to | ||
| * be responsible for the pointer then set to 0. */ | ||
| *ref = 1; | ||
|
|
||
| for (i = 0; i < SESSION_CACHE_SIZE; i++) { | ||
| if (server_sessionCache.entries[i].key != NULL && | ||
| XMEMCMP(server_sessionCache.entries[i].key, id, | ||
| SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { | ||
| return server_sessionCache.entries[i].value; | ||
| } | ||
| } | ||
| return NULL; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Move out DTLS 1.3 specific tests into test_dtls13.c. (Also move out from test_dtls.c)
Move out DTLS tests into test_dtls.c.
Move out LMS and XMSS tests into test_lms_xmss.c.
Move out SSL session tests into test_session.c.
Move out remaining ML-DSA/Dilithium tests in api.c into test_mldsa.c.
Testing
./configure --disable-shared --enable-all --enable-opensslall