2015-07-01 11:12:54 -07:00
|
|
|
/* unit.c API unit tests driver
|
|
|
|
|
*
|
2025-01-21 09:55:03 -07:00
|
|
|
* Copyright (C) 2006-2025 wolfSSL Inc.
|
2015-07-01 11:12:54 -07:00
|
|
|
*
|
2016-03-17 16:02:13 -06:00
|
|
|
* This file is part of wolfSSL.
|
2015-07-01 11:12:54 -07:00
|
|
|
*
|
|
|
|
|
* wolfSSL is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2025-07-10 16:01:52 -06:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2015-07-01 11:12:54 -07:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* wolfSSL is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2016-03-17 16:02:13 -06:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
2015-07-01 11:12:54 -07:00
|
|
|
*/
|
2011-12-14 09:31:54 -08:00
|
|
|
|
2016-03-17 16:02:13 -06:00
|
|
|
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#ifndef TESTS_UNIT_H
|
|
|
|
|
#define TESTS_UNIT_H
|
2012-08-06 17:14:31 -07:00
|
|
|
|
2025-04-03 19:29:17 -05:00
|
|
|
#define WOLFSSL_VIS_FOR_TESTS
|
2025-04-02 18:04:18 -05:00
|
|
|
|
2024-10-30 19:28:39 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef WOLFSSL_USER_SETTINGS
|
|
|
|
|
#include <wolfssl/options.h>
|
|
|
|
|
#endif
|
2024-11-06 15:23:49 +10:00
|
|
|
#include <wolfssl/wolfcrypt/settings.h>
|
2024-10-30 19:28:39 -05:00
|
|
|
|
|
|
|
|
#undef TEST_OPENSSL_COEXIST /* can't use this option with unit tests */
|
2024-10-31 13:42:04 -05:00
|
|
|
#undef OPENSSL_COEXIST /* can't use this option with unit tests */
|
2024-10-30 19:28:39 -05:00
|
|
|
|
2015-02-25 13:34:29 -08:00
|
|
|
#include <wolfssl/ssl.h>
|
|
|
|
|
#include <wolfssl/test.h> /* thread and tcp stuff */
|
2012-08-06 17:14:31 -07:00
|
|
|
|
2018-07-27 10:16:14 -07:00
|
|
|
#ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST
|
2023-07-14 09:50:01 -05:00
|
|
|
#define XABORT() WC_DO_NOTHING
|
2018-07-27 10:16:14 -07:00
|
|
|
#else
|
2018-07-27 11:16:23 -07:00
|
|
|
#define XABORT() abort()
|
2018-07-27 10:16:14 -07:00
|
|
|
#endif
|
|
|
|
|
|
2018-09-08 10:19:31 +09:00
|
|
|
#ifndef WOLFSSL_PASSTHRU_ERR
|
2013-05-21 14:37:50 -07:00
|
|
|
#define Fail(description, result) do { \
|
|
|
|
|
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
2022-07-11 22:27:43 -05:00
|
|
|
fputs("\n expected: ", stdout); printf description; \
|
|
|
|
|
fputs("\n result: ", stdout); printf result; fputs("\n\n", stdout); \
|
|
|
|
|
fflush(stdout); \
|
2018-09-08 10:19:31 +09:00
|
|
|
XABORT(); \
|
2013-05-21 14:37:50 -07:00
|
|
|
} while(0)
|
2018-09-08 10:19:31 +09:00
|
|
|
#else
|
2022-07-11 22:27:43 -05:00
|
|
|
#define Fail(description, result) do { \
|
|
|
|
|
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
|
|
|
|
fputs("\n expected: ", stdout); printf description; \
|
|
|
|
|
fputs("\n result: ", stdout); printf result; fputs("\n\n", stdout); \
|
|
|
|
|
fflush(stdout); \
|
2018-09-08 10:19:31 +09:00
|
|
|
} while (0)
|
|
|
|
|
#endif
|
2013-05-21 14:37:50 -07:00
|
|
|
|
|
|
|
|
#define Assert(test, description, result) if (!(test)) Fail(description, result)
|
|
|
|
|
|
|
|
|
|
#define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE"))
|
|
|
|
|
#define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE"))
|
|
|
|
|
#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
|
|
|
|
|
|
2022-10-25 11:42:51 -07:00
|
|
|
#define AssertNull(x) do { \
|
|
|
|
|
PEDANTIC_EXTENSION void* _x = (void*)(x); \
|
|
|
|
|
Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
2013-05-21 14:37:50 -07:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define AssertInt(x, y, op, er) do { \
|
2022-01-26 02:06:37 -06:00
|
|
|
int _x = (int)(x); \
|
|
|
|
|
int _y = (int)(y); \
|
2013-05-21 14:37:50 -07:00
|
|
|
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
|
|
|
|
|
#define AssertIntNE(x, y) AssertInt(x, y, !=, ==)
|
|
|
|
|
#define AssertIntGT(x, y) AssertInt(x, y, >, <=)
|
|
|
|
|
#define AssertIntLT(x, y) AssertInt(x, y, <, >=)
|
|
|
|
|
#define AssertIntGE(x, y) AssertInt(x, y, >=, <)
|
|
|
|
|
#define AssertIntLE(x, y) AssertInt(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define AssertStr(x, y, op, er) do { \
|
2022-10-25 11:42:51 -07:00
|
|
|
const char* _x = (const char*)(x); \
|
|
|
|
|
const char* _y = (const char*)(y); \
|
|
|
|
|
int _z = (_x && _y) ? strcmp(_x, _y) : -1; \
|
2013-05-21 14:37:50 -07:00
|
|
|
Assert(_z op 0, ("%s " #op " %s", #x, #y), \
|
|
|
|
|
("\"%s\" " #er " \"%s\"", _x, _y));\
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define AssertStrEQ(x, y) AssertStr(x, y, ==, !=)
|
|
|
|
|
#define AssertStrNE(x, y) AssertStr(x, y, !=, ==)
|
|
|
|
|
#define AssertStrGT(x, y) AssertStr(x, y, >, <=)
|
|
|
|
|
#define AssertStrLT(x, y) AssertStr(x, y, <, >=)
|
|
|
|
|
#define AssertStrGE(x, y) AssertStr(x, y, >=, <)
|
|
|
|
|
#define AssertStrLE(x, y) AssertStr(x, y, <=, >)
|
|
|
|
|
|
2023-04-15 00:36:22 -05:00
|
|
|
#ifdef WOLF_C89
|
|
|
|
|
|
|
|
|
|
#define AssertPtr(x, y, op, er) do { \
|
|
|
|
|
void* _x = (void*)(x); \
|
|
|
|
|
void* _y = (void*)(y); \
|
|
|
|
|
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y)); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2019-10-15 11:17:51 -07:00
|
|
|
#define AssertPtr(x, y, op, er) do { \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_GCC_DIAG_PUSH \
|
2022-07-11 22:27:43 -05:00
|
|
|
/* remarkably, without this inhibition, */ \
|
|
|
|
|
/* the _Pragma()s make the declarations warn. */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_GCC("GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
|
2022-07-11 22:27:43 -05:00
|
|
|
/* inhibit "ISO C forbids conversion of function pointer */ \
|
|
|
|
|
/* to object pointer type [-Werror=pedantic]" */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_GCC("GCC diagnostic ignored \"-Wpedantic\"") \
|
2022-01-26 02:06:37 -06:00
|
|
|
void* _x = (void*)(x); \
|
|
|
|
|
void* _y = (void*)(y); \
|
2019-10-15 11:17:51 -07:00
|
|
|
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y)); \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_GCC_DIAG_POP \
|
2019-10-15 11:17:51 -07:00
|
|
|
} while(0)
|
|
|
|
|
|
2023-04-15 00:36:22 -05:00
|
|
|
#endif
|
|
|
|
|
|
2019-10-15 11:17:51 -07:00
|
|
|
#define AssertPtrEq(x, y) AssertPtr(x, y, ==, !=)
|
2019-11-19 15:05:49 +01:00
|
|
|
#define AssertPtrNE(x, y) AssertPtr(x, y, !=, ==)
|
|
|
|
|
#define AssertPtrGT(x, y) AssertPtr(x, y, >, <=)
|
|
|
|
|
#define AssertPtrLT(x, y) AssertPtr(x, y, <, >=)
|
|
|
|
|
#define AssertPtrGE(x, y) AssertPtr(x, y, >=, <)
|
|
|
|
|
#define AssertPtrLE(x, y) AssertPtr(x, y, <=, >)
|
2019-10-15 11:17:51 -07:00
|
|
|
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#define TEST_FAIL 0
|
|
|
|
|
#define TEST_SUCCESS 1
|
|
|
|
|
#define TEST_SUCCESS_NO_MSGS 2
|
|
|
|
|
#define TEST_SKIPPED 3 /* Test skipped - not run. */
|
|
|
|
|
#define TEST_SKIPPED_NO_MSGS 4 /* Test skipped - not run. */
|
2013-05-21 14:37:50 -07:00
|
|
|
|
2023-05-26 15:49:14 +10:00
|
|
|
#define EXPECT_DECLS \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
int _ret = TEST_SKIPPED, _fail_codepoint_id = TEST_FAIL
|
2025-03-04 16:55:05 +10:00
|
|
|
#define EXPECT_SUCCESS_DECLS \
|
|
|
|
|
int _ret = TEST_SUCCESS, _fail_codepoint_id = TEST_SUCCESS
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#define EXPECT_DECLS_NO_MSGS(fail_codepoint_offset) \
|
|
|
|
|
int _ret = TEST_SKIPPED_NO_MSGS, \
|
|
|
|
|
_fail_codepoint_id = (fail_codepoint_offset)
|
|
|
|
|
#define EXPECT_FAILURE_CODEPOINT_ID _fail_codepoint_id
|
2023-05-26 15:49:14 +10:00
|
|
|
#define EXPECT_RESULT() \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
((void)_fail_codepoint_id, \
|
|
|
|
|
_ret == TEST_SUCCESS_NO_MSGS ? TEST_SUCCESS : \
|
|
|
|
|
_ret == TEST_SKIPPED_NO_MSGS ? TEST_SKIPPED : \
|
|
|
|
|
_ret)
|
2023-05-26 15:49:14 +10:00
|
|
|
#define EXPECT_SUCCESS() \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
((_ret == TEST_SUCCESS) || \
|
|
|
|
|
(_ret == TEST_SKIPPED) || \
|
|
|
|
|
(_ret == TEST_SUCCESS_NO_MSGS) || \
|
|
|
|
|
(_ret == TEST_SKIPPED_NO_MSGS))
|
2023-05-26 15:49:14 +10:00
|
|
|
#define EXPECT_FAIL() \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
(! EXPECT_SUCCESS())
|
|
|
|
|
|
2024-10-28 11:25:52 +10:00
|
|
|
#define EXPECT_TEST(ret) do { \
|
|
|
|
|
if (EXPECT_SUCCESS()) { \
|
|
|
|
|
_ret = (ret); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#define ExpFail(description, result) do { \
|
|
|
|
|
if ((_ret == TEST_SUCCESS_NO_MSGS) || (_ret == TEST_SKIPPED_NO_MSGS)) \
|
|
|
|
|
_ret = _fail_codepoint_id; \
|
|
|
|
|
else { \
|
|
|
|
|
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
|
|
|
|
fputs("\n expected: ", stdout); printf description; \
|
|
|
|
|
fputs("\n result: ", stdout); printf result; \
|
|
|
|
|
fputs("\n\n", stdout); \
|
|
|
|
|
fflush(stdout); \
|
|
|
|
|
_ret = TEST_FAIL; \
|
|
|
|
|
} \
|
2023-05-26 15:49:14 +10:00
|
|
|
} while (0)
|
|
|
|
|
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#define Expect(test, description, result) do { \
|
|
|
|
|
if (EXPECT_SUCCESS()) { \
|
|
|
|
|
if (!(test)) \
|
|
|
|
|
ExpFail(description, result); \
|
|
|
|
|
else if (_ret == TEST_SKIPPED_NO_MSGS) \
|
|
|
|
|
_ret = TEST_SUCCESS_NO_MSGS; \
|
|
|
|
|
else \
|
|
|
|
|
_ret = TEST_SUCCESS; \
|
|
|
|
|
} \
|
|
|
|
|
if (_ret == TEST_SUCCESS_NO_MSGS) \
|
|
|
|
|
--_fail_codepoint_id; \
|
2023-06-13 16:36:10 +10:00
|
|
|
} while (0)
|
2023-05-26 15:49:14 +10:00
|
|
|
|
|
|
|
|
#define ExpectTrue(x) Expect( (x), ("%s is true", #x), (#x " => FALSE"))
|
|
|
|
|
#define ExpectFalse(x) Expect(!(x), ("%s is false", #x), (#x " => TRUE"))
|
|
|
|
|
#define ExpectNotNull(x) Expect( (x), ("%s is not null", #x), (#x " => NULL"))
|
|
|
|
|
|
|
|
|
|
#define ExpectNull(x) do { \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
if (EXPECT_SUCCESS()) { \
|
2023-05-26 15:49:14 +10:00
|
|
|
PEDANTIC_EXTENSION void* _x = (void*)(x); \
|
|
|
|
|
Expect(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define ExpectInt(x, y, op, er) do { \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
if (EXPECT_SUCCESS()) { \
|
2023-05-26 15:49:14 +10:00
|
|
|
int _x = (int)(x); \
|
|
|
|
|
int _y = (int)(y); \
|
|
|
|
|
Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y));\
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define ExpectIntEQ(x, y) ExpectInt(x, y, ==, !=)
|
|
|
|
|
#define ExpectIntNE(x, y) ExpectInt(x, y, !=, ==)
|
|
|
|
|
#define ExpectIntGT(x, y) ExpectInt(x, y, >, <=)
|
|
|
|
|
#define ExpectIntLT(x, y) ExpectInt(x, y, <, >=)
|
|
|
|
|
#define ExpectIntGE(x, y) ExpectInt(x, y, >=, <)
|
|
|
|
|
#define ExpectIntLE(x, y) ExpectInt(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define ExpectStr(x, y, op, er) do { \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
if (EXPECT_SUCCESS()) { \
|
2023-05-26 15:49:14 +10:00
|
|
|
const char* _x = (const char*)(x); \
|
|
|
|
|
const char* _y = (const char*)(y); \
|
2023-09-08 14:51:49 +02:00
|
|
|
int _z = (_x && _y) ? XSTRCMP(_x, _y) : -1; \
|
2023-05-26 15:49:14 +10:00
|
|
|
Expect(_z op 0, ("%s " #op " %s", #x, #y), \
|
|
|
|
|
("\"%s\" " #er " \"%s\"", _x, _y));\
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define ExpectStrEQ(x, y) ExpectStr(x, y, ==, !=)
|
|
|
|
|
#define ExpectStrNE(x, y) ExpectStr(x, y, !=, ==)
|
|
|
|
|
#define ExpectStrGT(x, y) ExpectStr(x, y, >, <=)
|
|
|
|
|
#define ExpectStrLT(x, y) ExpectStr(x, y, <, >=)
|
|
|
|
|
#define ExpectStrGE(x, y) ExpectStr(x, y, >=, <)
|
|
|
|
|
#define ExpectStrLE(x, y) ExpectStr(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define ExpectPtr(x, y, op, er) do { \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
if (EXPECT_SUCCESS()) { \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_DIAG_PUSH \
|
2023-05-26 15:49:14 +10:00
|
|
|
/* remarkably, without this inhibition, */ \
|
|
|
|
|
/* the _Pragma()s make the declarations warn. */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA("GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
|
2023-05-26 15:49:14 +10:00
|
|
|
/* inhibit "ISO C forbids conversion of function pointer */ \
|
|
|
|
|
/* to object pointer type [-Werror=pedantic]" */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA("GCC diagnostic ignored \"-Wpedantic\"") \
|
2023-05-26 15:49:14 +10:00
|
|
|
void* _x = (void*)(x); \
|
|
|
|
|
void* _y = (void*)(y); \
|
|
|
|
|
Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y));\
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_DIAG_POP \
|
2023-05-26 15:49:14 +10:00
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define ExpectPtrEq(x, y) ExpectPtr(x, y, ==, !=)
|
|
|
|
|
#define ExpectPtrNE(x, y) ExpectPtr(x, y, !=, ==)
|
|
|
|
|
#define ExpectPtrGT(x, y) ExpectPtr(x, y, >, <=)
|
|
|
|
|
#define ExpectPtrLT(x, y) ExpectPtr(x, y, <, >=)
|
|
|
|
|
#define ExpectPtrGE(x, y) ExpectPtr(x, y, >=, <)
|
|
|
|
|
#define ExpectPtrLE(x, y) ExpectPtr(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define ExpectBuf(x, y, z, op, er) do { \
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
if (EXPECT_SUCCESS()) { \
|
2023-05-26 15:49:14 +10:00
|
|
|
const byte* _x = (const byte*)(x); \
|
|
|
|
|
const byte* _y = (const byte*)(y); \
|
|
|
|
|
int _z = (int)(z); \
|
2024-09-18 16:53:39 +02:00
|
|
|
int _w = ((_x) && (_y)) ? XMEMCMP(_x, _y, (unsigned long)_z) : -1; \
|
2023-05-26 15:49:14 +10:00
|
|
|
Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \
|
2024-01-24 12:40:35 +01:00
|
|
|
("\"%p\" " #er " \"%p\" for \"%d\"", \
|
|
|
|
|
(const void *)_x, (const void *)_y, _z)); \
|
2023-05-26 15:49:14 +10:00
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define ExpectBufEQ(x, y, z) ExpectBuf(x, y, z, ==, !=)
|
|
|
|
|
#define ExpectBufNE(x, y, z) ExpectBuf(x, y, z, !=, ==)
|
|
|
|
|
|
2023-06-22 08:11:50 +10:00
|
|
|
#define ExpectFail() ExpectTrue(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DoExpectNull(x) do { \
|
|
|
|
|
PEDANTIC_EXTENSION void* _x = (void*)(x); \
|
|
|
|
|
Expect(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define DoExpectInt(x, y, op, er) do { \
|
|
|
|
|
int _x = (int)(x); \
|
|
|
|
|
int _y = (int)(y); \
|
|
|
|
|
Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define DoExpectIntEQ(x, y) DoExpectInt(x, y, ==, !=)
|
|
|
|
|
#define DoExpectIntNE(x, y) DoExpectInt(x, y, !=, ==)
|
|
|
|
|
#define DoExpectIntGT(x, y) DoExpectInt(x, y, >, <=)
|
|
|
|
|
#define DoExpectIntLT(x, y) DoExpectInt(x, y, <, >=)
|
|
|
|
|
#define DoExpectIntGE(x, y) DoExpectInt(x, y, >=, <)
|
|
|
|
|
#define DoExpectIntLE(x, y) DoExpectInt(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define DoExpectStr(x, y, op, er) do { \
|
|
|
|
|
const char* _x = (const char*)(x); \
|
|
|
|
|
const char* _y = (const char*)(y); \
|
|
|
|
|
int _z = (_x && _y) ? strcmp(_x, _y) : -1; \
|
|
|
|
|
Expect(_z op 0, ("%s " #op " %s", #x, #y), \
|
|
|
|
|
("\"%s\" " #er " \"%s\"", _x, _y));\
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define DoExpectStrEQ(x, y) DoExpectStr(x, y, ==, !=)
|
|
|
|
|
#define DoExpectStrNE(x, y) DoExpectStr(x, y, !=, ==)
|
|
|
|
|
#define DoExpectStrGT(x, y) DoExpectStr(x, y, >, <=)
|
|
|
|
|
#define DoExpectStrLT(x, y) DoExpectStr(x, y, <, >=)
|
|
|
|
|
#define DoExpectStrGE(x, y) DoExpectStr(x, y, >=, <)
|
|
|
|
|
#define DoExpectStrLE(x, y) DoExpectStr(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define DoExpectPtr(x, y, op, er) do { \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_DIAG_PUSH \
|
2023-06-22 08:11:50 +10:00
|
|
|
/* remarkably, without this inhibition, */ \
|
|
|
|
|
/* the _Pragma()s make the declarations warn. */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA("GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
|
2023-06-22 08:11:50 +10:00
|
|
|
/* inhibit "ISO C forbids conversion of function pointer */ \
|
|
|
|
|
/* to object pointer type [-Werror=pedantic]" */ \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA("GCC diagnostic ignored \"-Wpedantic\"") \
|
2023-06-22 08:11:50 +10:00
|
|
|
void* _x = (void*)(x); \
|
|
|
|
|
void* _y = (void*)(y); \
|
|
|
|
|
Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y)); \
|
2023-07-14 09:50:01 -05:00
|
|
|
PRAGMA_DIAG_POP \
|
2023-06-22 08:11:50 +10:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define DoExpectPtrEq(x, y) DoExpectPtr(x, y, ==, !=)
|
|
|
|
|
#define DoExpectPtrNE(x, y) DoExpectPtr(x, y, !=, ==)
|
|
|
|
|
#define DoExpectPtrGT(x, y) DoExpectPtr(x, y, >, <=)
|
|
|
|
|
#define DoExpectPtrLT(x, y) DoExpectPtr(x, y, <, >=)
|
|
|
|
|
#define DoExpectPtrGE(x, y) DoExpectPtr(x, y, >=, <)
|
|
|
|
|
#define DoExpectPtrLE(x, y) DoExpectPtr(x, y, <=, >)
|
|
|
|
|
|
|
|
|
|
#define DoExpectBuf(x, y, z, op, er) do { \
|
|
|
|
|
const byte* _x = (const byte*)(x); \
|
|
|
|
|
const byte* _y = (const byte*)(y); \
|
|
|
|
|
int _z = (int)(z); \
|
|
|
|
|
int _w = ((_x) && (_y)) ? XMEMCMP(_x, _y, _z) : -1; \
|
|
|
|
|
Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \
|
|
|
|
|
("\"%p\" " #er " \"%p\" for \"%d\"", _x, _y, _z));\
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define DoExpectBufEQ(x, y, z) DoExpectBuf(x, y, z, ==, !=)
|
|
|
|
|
#define DoExpectBufNE(x, y, z) DoExpectBuf(x, y, z, !=, ==)
|
2023-05-26 15:49:14 +10:00
|
|
|
|
2025-10-17 07:22:37 +10:00
|
|
|
|
|
|
|
|
#define ApiDumpData(name, data, len) do { \
|
|
|
|
|
int _i; \
|
|
|
|
|
fprintf(stderr, "%s: %d bytes\n", name, (int)(len)); \
|
|
|
|
|
for (_i = 0; _i < (int)(len); _i++) { \
|
|
|
|
|
fprintf(stderr, "0x%02x,", ((byte*)(data))[_i]); \
|
|
|
|
|
if ((_i & 7) == 7) fprintf(stderr, "\n"); \
|
|
|
|
|
else fprintf(stderr, " "); \
|
|
|
|
|
} \
|
|
|
|
|
if ((_i & 7) != 0) fprintf(stderr, "\n"); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
2025-02-04 22:44:26 +00:00
|
|
|
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) && \
|
|
|
|
|
!defined(NO_RSA) && \
|
|
|
|
|
!defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
|
|
|
|
|
!defined(WOLFSSL_TIRTOS)
|
|
|
|
|
#define HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
|
|
|
|
|
|
|
|
|
|
typedef int (*ctx_cb)(WOLFSSL_CTX* ctx);
|
|
|
|
|
typedef int (*ssl_cb)(WOLFSSL* ssl);
|
|
|
|
|
typedef int (*test_cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
|
|
|
|
|
typedef int (*hs_cb)(WOLFSSL_CTX **ctx, WOLFSSL **ssl);
|
|
|
|
|
|
|
|
|
|
typedef struct test_ssl_cbf {
|
|
|
|
|
method_provider method;
|
|
|
|
|
ctx_cb ctx_ready;
|
|
|
|
|
ssl_cb ssl_ready;
|
|
|
|
|
ssl_cb on_result;
|
|
|
|
|
ctx_cb on_ctx_cleanup;
|
|
|
|
|
ssl_cb on_cleanup;
|
|
|
|
|
hs_cb on_handshake;
|
|
|
|
|
WOLFSSL_CTX* ctx;
|
|
|
|
|
const char* caPemFile;
|
|
|
|
|
const char* certPemFile;
|
|
|
|
|
const char* keyPemFile;
|
|
|
|
|
const char* crlPemFile;
|
|
|
|
|
#ifdef WOLFSSL_STATIC_MEMORY
|
|
|
|
|
byte* mem;
|
|
|
|
|
word32 memSz;
|
|
|
|
|
wolfSSL_method_func method_ex;
|
|
|
|
|
#endif
|
|
|
|
|
int devId;
|
|
|
|
|
int return_code;
|
|
|
|
|
int last_err;
|
|
|
|
|
unsigned char isSharedCtx:1;
|
|
|
|
|
unsigned char loadToSSL:1;
|
|
|
|
|
unsigned char ticNoInit:1;
|
|
|
|
|
unsigned char doUdp:1;
|
|
|
|
|
} test_ssl_cbf;
|
|
|
|
|
|
|
|
|
|
#define TEST_SSL_MEMIO_BUF_SZ (64 * 1024)
|
2025-05-13 16:40:56 +02:00
|
|
|
#define TEST_MEMIO_MAX_MSGS 32
|
|
|
|
|
|
2025-02-04 22:44:26 +00:00
|
|
|
typedef struct test_ssl_memio_ctx {
|
|
|
|
|
WOLFSSL_CTX* s_ctx;
|
|
|
|
|
WOLFSSL_CTX* c_ctx;
|
|
|
|
|
WOLFSSL* s_ssl;
|
|
|
|
|
WOLFSSL* c_ssl;
|
|
|
|
|
|
|
|
|
|
const char* c_ciphers;
|
|
|
|
|
const char* s_ciphers;
|
|
|
|
|
|
|
|
|
|
char* c_msg;
|
|
|
|
|
int c_msglen;
|
|
|
|
|
char* s_msg;
|
|
|
|
|
int s_msglen;
|
|
|
|
|
|
|
|
|
|
test_ssl_cbf s_cb;
|
|
|
|
|
test_ssl_cbf c_cb;
|
|
|
|
|
|
|
|
|
|
byte c_buff[TEST_SSL_MEMIO_BUF_SZ];
|
|
|
|
|
int c_len;
|
|
|
|
|
byte s_buff[TEST_SSL_MEMIO_BUF_SZ];
|
|
|
|
|
int s_len;
|
2025-05-13 16:40:56 +02:00
|
|
|
|
|
|
|
|
int c_msg_sizes[TEST_MEMIO_MAX_MSGS];
|
|
|
|
|
int c_msg_count;
|
|
|
|
|
int c_msg_pos;
|
|
|
|
|
int c_msg_offset;
|
|
|
|
|
|
|
|
|
|
int s_msg_sizes[TEST_MEMIO_MAX_MSGS];
|
|
|
|
|
int s_msg_count;
|
|
|
|
|
int s_msg_pos;
|
|
|
|
|
int s_msg_offset;
|
2025-02-04 22:44:26 +00:00
|
|
|
} test_ssl_memio_ctx;
|
|
|
|
|
|
|
|
|
|
int test_ssl_memio_setup(test_ssl_memio_ctx *ctx);
|
|
|
|
|
int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
|
|
|
|
|
int* rounds);
|
|
|
|
|
void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx);
|
2025-02-04 23:34:53 +00:00
|
|
|
int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
|
|
|
|
|
test_ssl_cbf* server_cb, test_cbType client_on_handshake);
|
|
|
|
|
#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
|
2025-02-04 22:44:26 +00:00
|
|
|
|
2025-08-05 11:50:08 +10:00
|
|
|
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) && \
|
|
|
|
|
!defined(NO_RSA) && !defined(SINGLE_THREADED) && \
|
|
|
|
|
!defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
|
|
|
|
|
#define HAVE_IO_TESTS_DEPENDENCIES
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_IO_TESTS_DEPENDENCIES
|
|
|
|
|
THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args);
|
|
|
|
|
int test_client_nofail(void* args, cbType cb);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
|
|
|
|
|
WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
|
|
|
|
|
int CreatePKCS7SignedData(unsigned char* output, int outputSz,
|
|
|
|
|
byte* data, word32 dataSz,
|
|
|
|
|
int withAttribs, int detachedSig,
|
|
|
|
|
int useIntermediateCertChain,
|
|
|
|
|
int pkAlgoType);
|
|
|
|
|
#endif
|
|
|
|
|
|
Split out tests: random, wolfmath, public key
Improved testing of random APIs.
wolfmath tests moved out.
Public key algorithm testing moved out: RSA, DSA, DH, ECC, SM2,
Curve25519, Ed25519, Curve448, Ed448, ML-DSA.
Signature API tests moved out.
Fix for OCSP testing to ensure RSA is available.
Added group names to API test cases.
Can select groups to run with --group <name>. --groups lists all known
group names.
Added option to stop API testing on first failure: --stopOnFail.
2025-03-14 08:36:27 +10:00
|
|
|
void ApiTest_StopOnFail(void);
|
2022-11-29 11:11:59 +10:00
|
|
|
void ApiTest_PrintTestCases(void);
|
Split out tests: random, wolfmath, public key
Improved testing of random APIs.
wolfmath tests moved out.
Public key algorithm testing moved out: RSA, DSA, DH, ECC, SM2,
Curve25519, Ed25519, Curve448, Ed448, ML-DSA.
Signature API tests moved out.
Fix for OCSP testing to ensure RSA is available.
Added group names to API test cases.
Can select groups to run with --group <name>. --groups lists all known
group names.
Added option to stop API testing on first failure: --stopOnFail.
2025-03-14 08:36:27 +10:00
|
|
|
void ApiTest_PrintGroups(void);
|
|
|
|
|
int ApiTest_RunGroup(char* name);
|
2022-11-29 11:11:59 +10:00
|
|
|
int ApiTest_RunIdx(int idx);
|
2025-02-18 18:51:14 +10:00
|
|
|
int ApiTest_RunPartName(char* name);
|
2022-11-29 11:11:59 +10:00
|
|
|
int ApiTest_RunName(char* name);
|
2023-05-26 15:49:14 +10:00
|
|
|
int ApiTest(void);
|
2022-11-29 11:11:59 +10:00
|
|
|
|
2018-12-21 09:33:54 -08:00
|
|
|
int SuiteTest(int argc, char** argv);
|
2015-07-07 12:01:47 -03:00
|
|
|
void SrpTest(void);
|
2022-05-30 11:17:03 +02:00
|
|
|
int w64wrapper_test(void);
|
2022-08-08 13:24:00 +02:00
|
|
|
int QuicTest(void);
|
2011-12-14 09:31:54 -08:00
|
|
|
|
2012-08-06 17:14:31 -07:00
|
|
|
|
m4/ax_atomic.m4: fixes for C++ compatibility.
wolfssl/wolfcrypt/wc_port.h: add WOLFSSL_API attribute to wolfSSL_Atomic_Int_Init, wolfSSL_Atomic_Int_FetchAdd, and wolfSSL_Atomic_Int_FetchAdd, and add fallback definitions for them, allowing elimination of SINGLE_THREADED implementations of wolfSSL_Ref*(), and allowing ungated use of wolfSSL_Atomic_* calls in api.c.
wolfcrypt/src/dh.c: in wc_DhAgree_ct(), remove frivolous XMEMSET() and stray semicolon.
wolfcrypt/benchmark/benchmark.c: fix bench_rsaKeyGen() to skip tests of key sizes below RSA_MIN_SIZE, and add 4096 bit benchmark if RSA_MAX_SIZE is big enough.
tests/unit.h:
* adopt definitions of TEST_FAIL, TEST_SUCCESS, and TEST_SKIPPED from unit.c, remap TEST_SKIPPED from -7777 to 3, and add TEST_SUCCESS_NO_MSGS, TEST_SKIPPED_NO_MSGS, EXPECT_DECLS_NO_MSGS(), and EXPECT_FAILURE_CODEPOINT_ID, to support existing and future expected-particular-failure test cases without log noise.
* rename outer gate from CyaSSL_UNIT_H to TESTS_UNIT_H.
tests/api.c:
* use EXPECT_DECLS_NO_MSGS() in test_ssl_memio_setup(), test_ssl_memio_read_write(), and test_wolfSSL_client_server_nofail_memio(), and globally update affected expected error codes to correspond.
* use atomics for {client,server}SessRemCount{Malloc,free} to fix races in SessRemCtxCb() and SessRemSslSetupCb().
2024-09-18 16:24:55 -05:00
|
|
|
#endif /* TESTS_UNIT_H */
|