Files
wolfssl/wolfcrypt/test/test.h

109 lines
3.0 KiB
C
Raw Permalink Normal View History

/* wolfcrypt/test/test.h
2014-12-17 15:33:22 -07:00
*
2025-01-21 09:55:03 -07:00
* Copyright (C) 2006-2025 wolfSSL Inc.
2014-12-17 15:33:22 -07:00
*
2016-03-17 16:02:13 -06:00
* This file is part of wolfSSL.
2014-12-17 15:33:22 -07:00
*
2015-01-06 12:14:15 -07:00
* wolfSSL is free software; you can redistribute it and/or modify
2014-12-17 15:33:22 -07:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
2015-01-06 12:14:15 -07:00
* wolfSSL is distributed in the hope that it will be useful,
2014-12-17 15:33:22 -07:00
* 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
2014-12-17 15:33:22 -07:00
*/
2016-03-17 16:02:13 -06:00
#ifndef WOLFCRYPT_TEST_H
#define WOLFCRYPT_TEST_H
#include <wolfssl/wolfcrypt/types.h>
2014-12-17 15:33:22 -07:00
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WC_TEST_RET_CUSTOM_TYPE
typedef WC_TEST_RET_CUSTOM_TYPE wc_test_ret_t;
#else
typedef sword32 wc_test_ret_t;
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#ifdef HAVE_STACK_SIZE
THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args);
#else
wc_test_ret_t wolfcrypt_test(void* args);
#endif
#ifndef NO_MAIN_DRIVER
wc_test_ret_t wolfcrypt_test_main(int argc, char** argv);
#endif
2014-12-17 15:33:22 -07:00
#if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
int wolf_test_task(void);
#endif
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
#ifndef WC_TEST_RET_HAVE_CUSTOM_MACROS
#define WC_TEST_RET_TAG_NC 0L
#define WC_TEST_RET_TAG_EC 1L
#define WC_TEST_RET_TAG_ERRNO 2L
#define WC_TEST_RET_TAG_I 3L
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
wc_static_assert(-(long)MIN_CODE_E < 0x7ffL);
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
#define WC_TEST_RET_ENC(line, i, tag) \
((wc_test_ret_t)(-((wc_test_ret_t)(line) + ((wc_test_ret_t)((word32)(i) & 0x7ffL) * 100000L) + ((wc_test_ret_t)(tag) << 29L))))
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
#ifndef WC_TEST_RET_LN
#define WC_TEST_RET_LN __LINE__
#endif
/* encode no code */
#define WC_TEST_RET_ENC_NC WC_TEST_RET_ENC(WC_TEST_RET_LN, 0, WC_TEST_RET_TAG_NC)
/* encode positive integer */
#define WC_TEST_RET_ENC_I(i) WC_TEST_RET_ENC(WC_TEST_RET_LN, i, WC_TEST_RET_TAG_I)
/* encode error code (negative integer) */
#define WC_TEST_RET_ENC_EC(ec) WC_TEST_RET_ENC(WC_TEST_RET_LN, -(ec), WC_TEST_RET_TAG_EC)
/* encode system/libc error code */
#if defined(HAVE_ERRNO_H) && !defined(NO_FILESYSTEM) && \
!defined(NO_STDIO_FILESYSTEM) && !defined(WOLFSSL_USER_IO)
#include <errno.h>
#define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC(WC_TEST_RET_LN, errno, WC_TEST_RET_TAG_ERRNO)
#else
#define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC_NC
#endif
#define WC_TEST_RET_DEC_TAG(x) ((-(x)) >> 29L)
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
/* decode line number */
#define WC_TEST_RET_DEC_LN(x) ((int)(((-(x)) & ~(3L << 29L)) % 100000L))
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
/* decode integer or errno */
#define WC_TEST_RET_DEC_I(x) ((int)((((-(x)) & ~(3L << 29L)) / 100000L)))
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
/* decode error code */
#define WC_TEST_RET_DEC_EC(x) ((int)(-WC_TEST_RET_DEC_I(x)))
20230223-refactor-test-c-error-codes (#6135) * wolfcrypt/test/test.{c,h}: refactor to capture and encode error retvals using WC_TEST_RET_*() macros (based on line numbers), and print line and return code in err_sys(). * wolfcrypt/test/test.h: cast back to int in WC_TEST_RET_ENC(), to fix MSVC warning. * configure.ac: add shake128 and shake256 to enable-all and enable-all-crypto; * wolfcrypt/benchmark/benchmark.c: fix gating for bench_shake128() from !defined(WOLFSSL_NO_SHAKE128) to defined(WOLFSSL_SHAKE128). * wolfcrypt/test/test.h: add WC_TEST_RET_TAG_* and WC_TEST_RET_DEC_TAG(), and refactor WC_TEST_RET_{ENC,DEC}_*() macros to implement the tag mechanism; * add render_error_message() with tag-specific rendering of error strings; * wolfcrypt/test/test.c: smallstack refactor of shake128_test() and shake128_absorb_test(); * wolfcrypt/test/test.c: change gating around mp_test() and related routines from defined(HAVE_VALGRIND) to defined(WOLFSSL_PUBLIC_MP); * smallstack refactor of mp_test(); * refactor a slew of WC_TEST_RET_ENC_NC associated with XFOPEN/XFREAD to be WC_TEST_RET_ENC_ERRNO, and add error detection for XFREAD (previously silently tolerating zero retvals). * wolfcrypt/test/test.c: build mp_test() only if WOLFSSL_SP_MATH_ALL or USE_FAST_MATH (in addition to WOLFSSL_PUBLIC_MP), because many general purpose functions such as sp_mulmod() are gated out in SP builds without WOLFSSL_SP_MATH_ALL. * wolfcrypt/test/test.c: fix array bounds flubs in shake128_test(); * don't print_fiducials() in wolfcrypt_test() header, but rather, after render_error_message() in err_sys(). * wolfcrypt/test/test.{c,h}: wrap some overlong lines, and fix an unused-variable warning in mp_test_set_is_bit(). * wolfcrypt/test/test.c: fixes for several misplaced and several missing WC_TEST_RET_ENC_EC()s.
2023-02-28 15:02:37 -06:00
#endif /* !WC_TEST_RET_HAVE_CUSTOM_MACROS */
2014-12-17 15:33:22 -07:00
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WOLFCRYPT_TEST_H */