@@ -532,15 +532,6 @@ int tmpDirNameSet = 0;
532532 | Constants
533533 *----------------------------------------------------------------------------*/
534534
535- /* Test result constants and macros. */
536-
537- /* Test succeeded. */
538- #define TEST_SUCCESS (1)
539- /* Test failed. */
540- #define TEST_FAIL (0)
541- /* Test skipped - not run. */
542- #define TEST_SKIPPED (-7777)
543-
544535/* Returns the result based on whether check is true.
545536 *
546537 * @param [in] check Condition for success.
@@ -7291,7 +7282,7 @@ static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
72917282
72927283static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
72937284{
7294- EXPECT_DECLS ;
7285+ EXPECT_DECLS_NO_MSGS(-2000) ;
72957286#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
72967287 int c_sharedCtx = 0;
72977288 int s_sharedCtx = 0;
@@ -7564,7 +7555,7 @@ static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
75647555
75657556static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
75667557{
7567- EXPECT_DECLS ;
7558+ EXPECT_DECLS_NO_MSGS(-3000) ;
75687559 char input[1024];
75697560 int idx = 0;
75707561 const char* msg_c = "hello wolfssl!";
@@ -7653,7 +7644,14 @@ static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
76537644int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
76547645 test_ssl_cbf* server_cb, cbType client_on_handshake)
76557646{
7656- EXPECT_DECLS;
7647+ /* We use EXPECT_DECLS_NO_MSGS() here because this helper routine is used
7648+ * for numerous but varied expected-to-fail scenarios that should not emit
7649+ * error messages on the expected failures. Instead, we return a distinct
7650+ * code for each failure point, allowing the caller to assert on a
7651+ * particular mode of expected failure. On success, the usual TEST_SUCCESS
7652+ * is returned.
7653+ */
7654+ EXPECT_DECLS_NO_MSGS(-1000);
76577655 struct test_ssl_memio_ctx test_ctx;
76587656#ifdef WOLFSSL_HAVE_TLS_UNIQUE
76597657 size_t msg_len;
@@ -7665,8 +7663,8 @@ int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
76657663
76667664 test_ctx.c_ctx = client_cb->ctx;
76677665 test_ctx.s_ctx = server_cb->ctx;
7668- test_ctx.c_cb.return_code = TEST_FAIL ;
7669- test_ctx.s_cb.return_code = TEST_FAIL ;
7666+ test_ctx.c_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID ;
7667+ test_ctx.s_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID ;
76707668
76717669 ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
76727670 ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
@@ -9575,10 +9573,10 @@ static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
95759573 * therefore, handshake becomes failure.
95769574 */
95779575 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
9578- &server_cbf, NULL), TEST_FAIL );
9576+ &server_cbf, NULL), -1001 );
95799577
9580- ExpectIntEQ(client_cbf.return_code, TEST_FAIL );
9581- ExpectIntEQ(server_cbf.return_code, TEST_FAIL );
9578+ ExpectIntEQ(client_cbf.return_code, -1000 );
9579+ ExpectIntEQ(server_cbf.return_code, -1000 );
95829580 ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
95839581 ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
95849582#endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
@@ -14120,7 +14118,7 @@ static int test_wolfSSL_X509_TLS_version_test_1(void)
1412014118
1412114119#ifndef OPENSSL_COMPATIBLE_DEFAULTS
1412214120 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
14123- &func_cb_server, NULL), TEST_FAIL );
14121+ &func_cb_server, NULL), -1001 );
1412414122#else
1412514123 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
1412614124 &func_cb_server, NULL), TEST_SUCCESS);
@@ -15009,14 +15007,20 @@ static int test_Sha512_Family_Final(int type, int isRaw)
1500915007 hash_test[2] = hash3;
1501015008 times = sizeof(hash_test) / sizeof(byte *);
1501115009
15012- /* Good test args. */
15013- for (i = 0; i < times; i++) {
15014- ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
15010+ #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \
15011+ defined(WOLFSSL_NO_HASH_RAW)
15012+ if (finalFp != NULL)
15013+ #endif
15014+ {
15015+ /* Good test args. */
15016+ for (i = 0; i < times; i++) {
15017+ ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
15018+ }
15019+ /* Test bad args. */
15020+ ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
15021+ ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
15022+ ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
1501515023 }
15016- /* Test bad args. */
15017- ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
15018- ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
15019- ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
1502015024
1502115025 freeFp(&sha512);
1502215026
@@ -61861,7 +61865,7 @@ static int test_wolfSSL_curves_mismatch(void)
6186161865 func_cb_server.method = test_params[i].server_meth;
6186261866
6186361867 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
61864- &func_cb_server, NULL), TEST_FAIL );
61868+ &func_cb_server, NULL), -1001 );
6186561869 ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
6186661870 ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
6186761871
@@ -69656,10 +69660,16 @@ static int test_wolfSSL_SESSION_expire_downgrade(void)
6965669660
6965769661#if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
6965869662 defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
69659- static int clientSessRemCountMalloc = 0;
69660- static int serverSessRemCountMalloc = 0;
69661- static int clientSessRemCountFree = 0;
69662- static int serverSessRemCountFree = 0;
69663+ #ifdef WOLFSSL_ATOMIC_OPS
69664+ typedef wolfSSL_Atomic_Int SessRemCounter_t;
69665+ #else
69666+ typedef int SessRemCounter_t;
69667+ #endif
69668+ static SessRemCounter_t clientSessRemCountMalloc;
69669+ static SessRemCounter_t serverSessRemCountMalloc;
69670+ static SessRemCounter_t clientSessRemCountFree;
69671+ static SessRemCounter_t serverSessRemCountFree;
69672+
6966369673static WOLFSSL_CTX* serverSessCtx = NULL;
6966469674static WOLFSSL_SESSION* serverSess = NULL;
6966569675#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
@@ -69680,9 +69690,9 @@ static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
6968069690 side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
6968169691 if (side != NULL) {
6968269692 if (*side == WOLFSSL_CLIENT_END)
69683- clientSessRemCountFree++ ;
69693+ (void)wolfSSL_Atomic_Int_FetchAdd(& clientSessRemCountFree, 1) ;
6968469694 else
69685- serverSessRemCountFree++ ;
69695+ (void)wolfSSL_Atomic_Int_FetchAdd(& serverSessRemCountFree, 1) ;
6968669696
6968769697 SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
6968869698 }
@@ -69719,14 +69729,14 @@ static int SessRemSslSetupCb(WOLFSSL* ssl)
6971969729
6972069730 if (SSL_is_server(ssl)) {
6972169731 side = &sessRemCtx_Server;
69722- serverSessRemCountMalloc++ ;
69732+ (void)wolfSSL_Atomic_Int_FetchAdd(& serverSessRemCountMalloc, 1) ;
6972369733 ExpectNotNull(serverSess = SSL_get1_session(ssl));
6972469734 ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
6972569735 SSL_SUCCESS);
6972669736 }
6972769737 else {
6972869738 side = &sessRemCtx_Client;
69729- clientSessRemCountMalloc++ ;
69739+ (void)wolfSSL_Atomic_Int_FetchAdd(& clientSessRemCountMalloc, 1) ;
6973069740 #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
6973169741 !defined(NO_SESSION_CACHE_REF)
6973269742 ExpectNotNull(clientSess = SSL_get1_session(ssl));
@@ -69750,6 +69760,11 @@ static int test_wolfSSL_CTX_sess_set_remove_cb(void)
6975069760 * session object */
6975169761 test_ssl_cbf func_cb;
6975269762
69763+ wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0);
69764+ wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0);
69765+ wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0);
69766+ wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0);
69767+
6975369768 XMEMSET(&func_cb, 0, sizeof(func_cb));
6975469769 func_cb.ctx_ready = SessRemCtxSetupCb;
6975569770 func_cb.on_result = SessRemSslSetupCb;
@@ -78615,7 +78630,7 @@ static int test_DhCallbacks(void)
7861578630 func_cb_server.method = wolfTLSv1_2_server_method;
7861678631
7861778632 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
78618- &func_cb_server, NULL), TEST_FAIL );
78633+ &func_cb_server, NULL), -1001 );
7861978634#endif
7862078635 return EXPECT_RESULT();
7862178636}
@@ -85792,7 +85807,7 @@ static int test_multiple_crls_same_issuer(void)
8579285807 client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
8579385808
8579485809 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
85795- &server_cbs, NULL), TEST_FAIL );
85810+ &server_cbs, NULL), -1001 );
8579685811 }
8579785812#endif
8579885813 return EXPECT_RESULT();
@@ -90339,7 +90354,7 @@ static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
9033990354 server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
9034090355
9034190356 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
90342- &server_cbs, NULL), TEST_FAIL );
90357+ &server_cbs, NULL), -1001 );
9034390358
9034490359 return EXPECT_RESULT();
9034590360}
@@ -91146,7 +91161,7 @@ static int test_override_alt_cert_chain(void)
9114691161 {test_override_alt_cert_chain_client_ctx_ready,
9114791162 test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
9114891163 {test_override_alt_cert_chain_client_ctx_ready2,
91149- test_override_alt_cert_chain_server_ctx_ready, TEST_FAIL },
91164+ test_override_alt_cert_chain_server_ctx_ready, -1001 },
9115091165 };
9115191166
9115291167 for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
@@ -91162,8 +91177,10 @@ static int test_override_alt_cert_chain(void)
9116291177 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
9116391178 &server_cbs, NULL), params[i].result);
9116491179
91165- ExpectIntEQ(client_cbs.return_code, params[i].result);
91166- ExpectIntEQ(server_cbs.return_code, params[i].result);
91180+ ExpectIntEQ(client_cbs.return_code,
91181+ params[i].result <= 0 ? -1000 : TEST_SUCCESS);
91182+ ExpectIntEQ(server_cbs.return_code,
91183+ params[i].result <= 0 ? -1000 : TEST_SUCCESS);
9116791184 }
9116891185
9116991186 return EXPECT_RESULT();
@@ -93766,7 +93783,7 @@ static int test_revoked_loaded_int_cert(void)
9376693783 client_cbf.ctx_ready = test_params[i].client_ctx_ready;
9376793784
9376893785 ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
93769- &server_cbf, NULL), TEST_FAIL );
93786+ &server_cbf, NULL), -1001 );
9377093787 ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
9377193788 ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
9377293789
0 commit comments