Skip to content

api.c: move out tests into other files#10547

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:api_c_split_4
Open

api.c: move out tests into other files#10547
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:api_c_split_4

Conversation

@SparkiDev
Copy link
Copy Markdown
Contributor

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

@SparkiDev SparkiDev self-assigned this May 28, 2026
@SparkiDev SparkiDev force-pushed the api_c_split_4 branch 5 times, most recently from 4151c88 to 58da590 Compare May 28, 2026 09:19
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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and test_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.c and registers them via test_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.

Comment thread tests/api/test_lms_xmss.c
/* LMS tests */
/*----------------------------------------------------------------------------*/

#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
Comment thread tests/api/test_lms_xmss.c
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 thread tests/api/test_session.c
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 thread tests/api/test_session.c
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants