Skip to content

Commit 38ec859

Browse files
committed
test(support): add SimulatedEnvironment for deterministic testing
Introduces a new testing support library 'testing/support' that provides a clean, modular, and fully deterministic environment for testing toxcore components.
1 parent f34fcb1 commit 38ec859

File tree

82 files changed

+3591
-2059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3591
-2059
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if(MSVC AND MSVC_TOOLSET_VERSION LESS 143)
8787
else()
8888
set(CMAKE_C_STANDARD 11)
8989
endif()
90-
set(CMAKE_CXX_STANDARD 17)
90+
set(CMAKE_CXX_STANDARD 20)
9191
set(CMAKE_C_EXTENSIONS OFF)
9292
set(CMAKE_CXX_EXTENSIONS OFF)
9393

@@ -533,6 +533,8 @@ make_version_script(toxcore ${toxcore_API_HEADERS})
533533
# "${CMAKE_INSTALL_INCLUDEDIR}/tox".
534534
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
535535

536+
add_subdirectory(testing)
537+
536538
################################################################################
537539
#
538540
# :: Unit tests: no networking, just pure function calls.
@@ -545,8 +547,8 @@ if(UNITTEST)
545547
toxcore/DHT_test_util.hh
546548
toxcore/crypto_core_test_util.cc
547549
toxcore/crypto_core_test_util.hh
548-
toxcore/mem_test_util.cc
549-
toxcore/mem_test_util.hh
550+
toxcore/mono_time_test_util.cc
551+
toxcore/mono_time_test_util.hh
550552
toxcore/network_test_util.cc
551553
toxcore/network_test_util.hh
552554
toxcore/test_util.cc
@@ -555,7 +557,7 @@ endif()
555557

556558
function(unit_test subdir target)
557559
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
558-
target_link_libraries(unit_${target}_test PRIVATE test_util)
560+
target_link_libraries(unit_${target}_test PRIVATE test_util support)
559561
if(TARGET toxcore_static)
560562
target_link_libraries(unit_${target}_test PRIVATE toxcore_static)
561563
else()
@@ -570,7 +572,7 @@ function(unit_test subdir target)
570572
endif()
571573
target_link_libraries(unit_${target}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock)
572574
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
573-
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
575+
add_test(NAME ${target} COMMAND unit_${target}_test)
574576
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
575577
endfunction()
576578

@@ -612,8 +614,6 @@ if(UNITTEST AND TARGET GTest::gtest AND TARGET GTest::gmock)
612614
unit_test(toxcore util)
613615
endif()
614616

615-
add_subdirectory(testing)
616-
617617
################################################################################
618618
#
619619
# :: Automated regression tests: create a tox network and run integration tests

auto_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function(auto_test target)
3232
elseif(TARGET Threads::Threads)
3333
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
3434
endif()
35-
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
35+
add_test(NAME ${target} COMMAND auto_${target}_test)
3636
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
3737
# add the source dir as environment variable, so the testdata can be found
3838
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")

auto_tests/scenarios/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif()
1818
function(scenario_test target)
1919
add_executable(auto_${target}_test ${target}_test.c)
2020
target_link_libraries(auto_${target}_test PRIVATE misc_tools scenario_framework)
21-
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
21+
add_test(NAME ${target} COMMAND auto_${target}_test)
2222
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
2323
# add the source dir as environment variable, so the testdata can be found
2424
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}/..")

other/analysis/gen-file.sh

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CPPFLAGS+=("-Iother/bootstrap_daemon/src")
1111
CPPFLAGS+=("-Iother/fun")
1212
CPPFLAGS+=("-Itesting")
1313
CPPFLAGS+=("-Itesting/fuzzing")
14+
CPPFLAGS+=("-Itesting/support/doubles")
15+
CPPFLAGS+=("-Itesting/support/public")
1416
CPPFLAGS+=("-Itoxcore")
1517
CPPFLAGS+=("-Itoxcore/events")
1618
CPPFLAGS+=("-Itoxav")
@@ -51,33 +53,44 @@ callmain() {
5153

5254
# Include all C and C++ code
5355
FIND_QUERY="find . '-(' -name '*.c' -or -name '*.cc' '-)'"
54-
# Excludes
55-
FIND_QUERY="$FIND_QUERY -and -not -wholename './_build/*'"
56-
FIND_QUERY="$FIND_QUERY -and -not -wholename './other/docker/*'"
57-
FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'"
58-
FIND_QUERY="$FIND_QUERY -and -not -name amalgamation.cc"
59-
FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
60-
FIND_QUERY="$FIND_QUERY -and -not -name cracker.c"
61-
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
62-
FIND_QUERY="$FIND_QUERY -and -not -name '*_fuzz_test.cc'"
63-
FIND_QUERY="$FIND_QUERY -and -not -wholename './testing/fuzzing/*'"
64-
FIND_QUERY="$FIND_QUERY -and -not -wholename './third_party/cmp/examples/*'"
65-
FIND_QUERY="$FIND_QUERY -and -not -wholename './third_party/cmp/test/*'"
56+
HEADER_QUERY="find . '-(' -name '*.h' -or -name '*.hh' '-)'"
57+
58+
COMMON_EXCLUDES=""
59+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './_build/*'"
60+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './other/docker/*'"
61+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './super_donators/*'"
62+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './testing/fuzzing/*'"
63+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './third_party/cmp/examples/*'"
64+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -wholename './third_party/cmp/test/*'"
65+
66+
# File name excludes
67+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name amalgamation.cc"
68+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name av_test.c"
69+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name cracker.c"
70+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name version_test.c"
71+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name '*_fuzz_test.cc'"
6672

6773
if [ "$SKIP_BENCHMARK" == 1 ]; then
68-
FIND_QUERY="$FIND_QUERY -and -not -name '*_bench.cc'"
74+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name '*_bench.cc'"
6975
fi
7076

7177
if [ "$SKIP_GTEST" == 1 ]; then
72-
FIND_QUERY="$FIND_QUERY -and -not -name '*_test.cc'"
78+
COMMON_EXCLUDES="$COMMON_EXCLUDES -and -not -name '*_test.cc'"
7379
fi
7480

81+
FIND_QUERY="$FIND_QUERY $COMMON_EXCLUDES"
82+
HEADER_QUERY="$HEADER_QUERY $COMMON_EXCLUDES"
83+
7584
readarray -t FILES <<<"$(eval "$FIND_QUERY")"
85+
readarray -t HEADERS <<<"$(eval "$HEADER_QUERY")"
7686

77-
(for i in "${FILES[@]}"; do
87+
INCLUDES=$(for i in "${FILES[@]}" "${HEADERS[@]}"; do
7888
grep -o '#include <[^>]*>' "$i" |
7989
grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<stropts.h>|<linux'
80-
done) | sort -u >>amalgamation.cc
90+
done | sort -u)
91+
92+
echo "$INCLUDES" | grep "<memory>" >>amalgamation.cc
93+
echo "$INCLUDES" | grep -v "<memory>" >>amalgamation.cc
8194

8295
put auto_tests/check_compat.h
8396

other/analysis/run-clang

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ run() {
3636
-Wno-unreachable-code-return \
3737
-Wno-unsafe-buffer-usage \
3838
-Wno-unused-parameter \
39-
-Wno-used-but-marked-unused
39+
-Wno-used-but-marked-unused \
40+
-Wno-unneeded-member-function \
41+
-Wno-unused-function \
42+
-Wno-unused-member-function \
43+
-Wno-unused-parameter \
44+
-Wno-unused-template
45+
# TODO(iphydf): Remove these last 5 when the test framework matures.
4046
}
4147

4248
. other/analysis/variants.sh

other/analysis/run-gcc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ run() {
6565
-Wunused-value \
6666
-Wunused-but-set-parameter \
6767
-Wunused-but-set-variable \
68-
-fopenmp
68+
-fopenmp \
69+
-Wno-unused-function
70+
# TODO(iphydf): Remove this last 1 when the test framework matures.
6971
}
7072

7173
. other/analysis/variants.sh

0 commit comments

Comments
 (0)