Skip to content

Commit 9257ac8

Browse files
committed
test: introduce (mini) unit test framework
Lightweight unit testing framework, providing a structured way to define, execute, and report tests. It includes a central test registry, a flexible command-line argument parser of the form "--key=value" / "-k=value" / "-key=value" (facilitating future framework extensions), ability to run tests in parallel and accumulated test time logging reports. So far the supported command-line args are: - "--jobs=<num>" or "-j=<num>" to specify the number of parallel workers. - "--seed=<hex>" to specify the RNG seed (random if not set). - "--iterations=<num>" or "-i=<num>" to specify the number of iterations. Compatibility Note: To stay compatible with previous versions, the framework also supports the two original positional arguments: the iterations count and the RNG seed (in that order).
1 parent 9cce703 commit 9257ac8

File tree

6 files changed

+682
-142
lines changed

6 files changed

+682
-142
lines changed

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ noinst_HEADERS += src/assumptions.h
4747
noinst_HEADERS += src/checkmem.h
4848
noinst_HEADERS += src/tests_common.h
4949
noinst_HEADERS += src/testutil.h
50+
noinst_HEADERS += src/unit_test.h
51+
noinst_HEADERS += src/unit_test.c
5052
noinst_HEADERS += src/util.h
5153
noinst_HEADERS += src/util_local_visibility.h
5254
noinst_HEADERS += src/int128.h
@@ -121,7 +123,7 @@ if USE_TESTS
121123
TESTS += noverify_tests
122124
noinst_PROGRAMS += noverify_tests
123125
noverify_tests_SOURCES = src/tests.c
124-
noverify_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES)
126+
noverify_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DSUPPORTS_CONCURRENCY=$(SUPPORTS_CONCURRENCY)
125127
noverify_tests_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB)
126128
noverify_tests_LDFLAGS = -static
127129
if !ENABLE_COVERAGE

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ if test x"$enable_experimental" = x"no"; then
443443
fi
444444
fi
445445

446+
# Check for concurrency support (tests only)
447+
if test "x$enable_tests" != x"no"; then
448+
AC_CHECK_HEADERS([sys/types.h sys/wait.h unistd.h])
449+
AS_IF([test "x$ac_cv_header_sys_types_h" = xyes && test "x$ac_cv_header_sys_wait_h" = xyes &&
450+
test "x$ac_cv_header_unistd_h" = xyes], [SUPPORTS_CONCURRENCY=1])
451+
AC_SUBST(SUPPORTS_CONCURRENCY)
452+
fi
453+
446454
###
447455
### Generate output
448456
###

src/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,23 @@ if(SECP256K1_BUILD_BENCHMARK)
134134
endif()
135135

136136
if(SECP256K1_BUILD_TESTS)
137+
include(CheckIncludeFile)
138+
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
139+
check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
140+
check_include_file(unistd.h HAVE_UNISTD_H)
141+
142+
set(TEST_DEFINITIONS)
143+
if(HAVE_SYS_TYPES_H AND HAVE_SYS_WAIT_H AND HAVE_UNISTD_H)
144+
list(APPEND TEST_DEFINITIONS SUPPORTS_CONCURRENCY=1)
145+
endif()
146+
137147
add_executable(noverify_tests tests.c)
138148
target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm)
149+
target_compile_definitions(noverify_tests PRIVATE ${TEST_DEFINITIONS})
139150
add_test(NAME secp256k1_noverify_tests COMMAND noverify_tests)
140151
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
141152
add_executable(tests tests.c)
142-
target_compile_definitions(tests PRIVATE VERIFY)
153+
target_compile_definitions(tests PRIVATE VERIFY ${TEST_DEFINITIONS})
143154
target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
144155
add_test(NAME secp256k1_tests COMMAND tests)
145156
endif()

0 commit comments

Comments
 (0)