Skip to content

Commit cf37704

Browse files
authored
Merge pull request simdjson#737 from simdjson/jkeiser/sanitize-gcc-9
Run sanitize using gcc 9
2 parents 38289fe + 6d059b4 commit cf37704

11 files changed

Lines changed: 301 additions & 322 deletions

File tree

.circleci/config.yml

Lines changed: 106 additions & 214 deletions
Large diffs are not rendered by default.

.drone.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ steps:
231231
- mkdir build && cd build
232232
- cmake $CMAKE_FLAGS ..
233233
- make -j
234-
- ctest --output-on-failure
234+
- ctest -j --output-on-failure
235235
---
236236
kind: pipeline
237237
name: amd64_clang_cmake_no_exceptions
@@ -254,7 +254,7 @@ steps:
254254
- mkdir build && cd build
255255
- cmake $CMAKE_FLAGS ..
256256
- make -j
257-
- ctest --output-on-failure
257+
- ctest -j --output-on-failure
258258
---
259259
kind: pipeline
260260
name: amd64_clang_cmake_static
@@ -277,7 +277,7 @@ steps:
277277
- mkdir build && cd build
278278
- cmake $CMAKE_FLAGS ..
279279
- make -j
280-
- ctest --output-on-failure
280+
- ctest -j --output-on-failure
281281
---
282282
kind: pipeline
283283
name: amd64_gcc_cmake_static
@@ -300,7 +300,7 @@ steps:
300300
- mkdir build && cd build
301301
- cmake $CMAKE_FLAGS ..
302302
- make -j
303-
- ctest --output-on-failure
303+
- ctest -j --output-on-failure
304304
---
305305
kind: pipeline
306306
name: amd64_gcc_cmake_dynamic
@@ -323,7 +323,7 @@ steps:
323323
- mkdir build && cd build
324324
- cmake $CMAKE_FLAGS ..
325325
- make -j
326-
- ctest --output-on-failure
326+
- ctest -j --output-on-failure
327327
---
328328
kind: pipeline
329329
name: arm64_clang_cmake_dynamic
@@ -346,7 +346,7 @@ steps:
346346
- mkdir build && cd build
347347
- cmake $CMAKE_FLAGS ..
348348
- make -j
349-
- ctest --output-on-failure
349+
- ctest -j --output-on-failure
350350
---
351351
kind: pipeline
352352
name: arm64_gcc_cmake_dynamic
@@ -369,7 +369,7 @@ steps:
369369
- mkdir build && cd build
370370
- cmake $CMAKE_FLAGS ..
371371
- make -j
372-
- ctest --output-on-failure
372+
- ctest -j --output-on-failure
373373
---
374374
kind: pipeline
375375
name: arm64_clang_cmake_static
@@ -392,7 +392,7 @@ steps:
392392
- mkdir build && cd build
393393
- cmake $CMAKE_FLAGS ..
394394
- make -j
395-
- ctest --output-on-failure
395+
- ctest -j --output-on-failure
396396
---
397397
kind: pipeline
398398
name: arm64_gcc_cmake_static
@@ -415,7 +415,7 @@ steps:
415415
- mkdir build && cd build
416416
- cmake $CMAKE_FLAGS ..
417417
- make -j
418-
- ctest --output-on-failure
418+
- ctest -j --output-on-failure
419419

420420
---
421421
kind: pipeline
@@ -439,7 +439,7 @@ steps:
439439
- mkdir build && cd build
440440
- cmake $CMAKE_FLAGS ..
441441
- make -j
442-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
442+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure
443443
---
444444
kind: pipeline
445445
name: arm64_gcc_cmake_sanitize
@@ -462,7 +462,7 @@ steps:
462462
- mkdir build && cd build
463463
- cmake $CMAKE_FLAGS ..
464464
- make -j
465-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
465+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure
466466

467467
---
468468
kind: pipeline
@@ -486,7 +486,7 @@ steps:
486486
- mkdir build && cd build
487487
- cmake $CMAKE_FLAGS ..
488488
- make -j
489-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
489+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure
490490
---
491491
kind: pipeline
492492
name: amd64_gcc_cmake_sanitize
@@ -509,7 +509,7 @@ steps:
509509
- mkdir build && cd build
510510
- cmake $CMAKE_FLAGS ..
511511
- make -j
512-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
512+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure
513513

514514
---
515515
kind: pipeline
@@ -533,7 +533,7 @@ steps:
533533
- mkdir build && cd build
534534
- cmake $CMAKE_FLAGS ..
535535
- make -j
536-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
536+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure
537537
---
538538
kind: pipeline
539539
name: amd64_gcc_cmake_sanitize_noavx
@@ -556,4 +556,4 @@ steps:
556556
- mkdir build && cd build
557557
- cmake $CMAKE_FLAGS ..
558558
- make -j
559-
- ASAN_OPTIONS="detect_leaks=0" ctest --output-on-failure
559+
- ASAN_OPTIONS="detect_leaks=0" ctest -j --output-on-failure

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ objs
130130
/singleheader/demo
131131
/tests/allparserscheckfile
132132
/tests/basictests
133+
/tests/checkimplementation
133134
/tests/errortests
134135
/tests/extracting_values_example
135136
/tests/integer_tests

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ export_private_library(simdjson-flags)
122122

123123
#
124124
# Create the top level simdjson library (must be done at this level to use both src/ and include/
125-
# directories)
125+
# directories) and tools
126126
#
127127
add_subdirectory(include)
128128
add_subdirectory(src)
129+
add_subdirectory(windows)
130+
add_subdirectory(tools)
129131

130132
#
131133
# Compile tools / tests / benchmarks
@@ -135,12 +137,11 @@ enable_testing()
135137
add_library(test-data INTERFACE)
136138
target_compile_definitions(test-data INTERFACE SIMDJSON_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")
137139
target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
140+
set(EXAMPLE_JSON ${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/twitter.json)
138141

139-
add_subdirectory(windows)
140142
add_subdirectory(dependencies)
141143
add_subdirectory(tests)
142144
add_subdirectory(examples)
143-
add_subdirectory(tools)
144145
add_subdirectory(benchmark)
145146

146147
# for fuzzing, read the comments in the fuzz/CMakeLists.txt file

examples/quickstart/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ if (NOT MSVC)
4545
add_quickstart_test(quickstart quickstart.cpp)
4646
add_quickstart_test(quickstart11 quickstart.cpp c++11)
4747
add_quickstart_test(quickstart14 quickstart.cpp c++14)
48-
set_property( TEST quickstart quickstart11 APPEND PROPERTY LABELS quicktests )
49-
set_property( TEST quickstart14 APPEND PROPERTY LABELS slowtests )
48+
set_property( TEST quickstart quickstart11 APPEND PROPERTY LABELS acceptance compiletests )
5049
endif()
5150

5251
add_quickstart_test(quickstart_noexceptions quickstart_noexceptions.cpp "" true)
5352
add_quickstart_test(quickstart_noexceptions11 quickstart_noexceptions.cpp c++11 true)
54-
set_property( TEST quickstart_noexceptions APPEND PROPERTY LABELS quicktests )
55-
set_property( TEST quickstart_noexceptions11 APPEND PROPERTY LABELS slowtests )
53+
set_property( TEST quickstart_noexceptions APPEND PROPERTY LABELS acceptance compile )
5654
endif()

src/implementation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ const implementation *available_implementation_list::detect_best_supported() con
122122
}
123123

124124
const implementation *detect_best_supported_implementation_on_first_use::set_best() const noexcept {
125+
char *force_implementation_name = getenv("SIMDJSON_FORCE_IMPLEMENTATION");
126+
if (force_implementation_name) {
127+
auto force_implementation = available_implementations[force_implementation_name];
128+
if (!force_implementation) {
129+
fprintf(stderr, "SIMDJSON_FORCE_IMPLEMENTATION environment variable set to '%s', which is not a supported implementation name!\n", force_implementation_name);
130+
abort();
131+
}
132+
return active_implementation = force_implementation;
133+
}
125134
return active_implementation = available_implementations.detect_best_supported();
126135
}
127136

tests/CMakeLists.txt

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
11
# Helper so we don't have to repeat ourselves so much
2-
function(add_cpp_test TEST_NAME TEST_FILE)
3-
# If a source file is passed, add an executable
4-
add_executable(${TEST_NAME} ${TEST_FILE})
5-
add_test(${TEST_NAME} ${TEST_NAME})
6-
if ($ARGN)
7-
set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN})
8-
else()
9-
set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests)
2+
# Usage: add_cpp_test(testname [COMPILE_ONLY] [SOURCES a.cpp b.cpp ...] [LABELS acceptance per_implementation ...])
3+
# SOURCES defaults to testname.cpp if not specified.
4+
function(add_cpp_test TEST_NAME)
5+
# Parse arguments
6+
cmake_parse_arguments(PARSE_ARGV 1 ARGS "COMPILE_ONLY;WILL_FAIL" "" "SOURCES;LABELS")
7+
if (NOT ARGS_SOURCES)
8+
list(APPEND ARGS_SOURCES ${TEST_NAME}.cpp)
9+
endif()
10+
if (COMPILE_ONLY)
11+
list(APPEND ${ARGS_LABELS} compile)
1012
endif()
11-
endfunction()
1213

13-
function(add_compile_test TEST_NAME TEST_FILE)
14-
add_executable(${TEST_NAME} ${TEST_FILE})
15-
set_target_properties(${TEST_NAME} PROPERTIES
16-
EXCLUDE_FROM_ALL TRUE
17-
EXCLUDE_FROM_DEFAULT_BUILD TRUE)
18-
add_test(
19-
NAME ${TEST_NAME}
20-
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
21-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
22-
)
23-
if (${ARGN}) # Labels
24-
set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN})
14+
# Add executable
15+
add_executable(${TEST_NAME} ${ARGS_SOURCES})
16+
17+
# Add test
18+
if (ARGS_COMPILE_ONLY)
19+
add_test(
20+
NAME ${TEST_NAME}
21+
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
22+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
23+
)
24+
set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE)
2525
else()
26-
set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests)
26+
add_test(${TEST_NAME} ${TEST_NAME})
2727
endif()
28-
endfunction(add_compile_test)
2928

29+
if (ARGS_LABELS)
30+
set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGS_LABELS})
31+
endif()
32+
33+
if (ARGS_WILL_FAIL)
34+
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
35+
endif()
36+
endfunction()
3037
# Most tests need test data, and many need windows headers.
3138
link_libraries(simdjson-flags test-data simdjson-windows-headers)
3239

40+
include(${PROJECT_SOURCE_DIR}/tests/add_cpp_test.cmake)
41+
3342
#
3443
# These tests explicitly do #include "simdjson.cpp" so they can override stuff
3544
#
3645
if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason.
37-
add_cpp_test(numberparsingcheck numberparsingcheck.cpp quicktests)
46+
add_cpp_test(numberparsingcheck LABELS acceptance per_implementation)
3847
target_link_libraries(numberparsingcheck simdjson-include-source)
39-
add_cpp_test(stringparsingcheck stringparsingcheck.cpp quicktests)
48+
add_cpp_test(stringparsingcheck LABELS acceptance per_implementation)
4049
target_link_libraries(stringparsingcheck simdjson-include-source)
4150
endif()
4251

4352
# All remaining tests link with simdjson proper
4453
link_libraries(simdjson)
45-
add_cpp_test(basictests basictests.cpp quicktests)
46-
add_cpp_test(errortests errortests.cpp quicktests)
47-
add_cpp_test(integer_tests integer_tests.cpp quicktests)
48-
add_cpp_test(jsoncheck jsoncheck.cpp quicktests)
49-
add_cpp_test(parse_many_test parse_many_test.cpp quicktests)
50-
add_cpp_test(pointercheck pointercheck.cpp quicktests)
51-
add_cpp_test(extracting_values_example extracting_values_example.cpp quicktests)
54+
add_cpp_test(basictests LABELS acceptance per_implementation)
55+
add_cpp_test(errortests LABELS acceptance per_implementation)
56+
add_cpp_test(integer_tests LABELS acceptance per_implementation)
57+
add_cpp_test(jsoncheck LABELS acceptance per_implementation)
58+
add_cpp_test(parse_many_test LABELS acceptance per_implementation)
59+
add_cpp_test(pointercheck LABELS acceptance per_implementation)
60+
add_cpp_test(extracting_values_example LABELS acceptance per_implementation)
5261

5362
# Script tests
5463
if (NOT MSVC) # Can't run .sh on windows
@@ -61,7 +70,7 @@ if (NOT MSVC) # Can't run .sh on windows
6170
WORKING_DIRECTORY $<TARGET_FILE_DIR:minify>
6271
)
6372
set_property(TEST testjson2json APPEND PROPERTY DEPENDS minify json2json)
64-
set_property(TEST testjson2json APPEND PROPERTY LABELS slowtests)
73+
set_property(TEST testjson2json APPEND PROPERTY LABELS per_implementation)
6574

6675
#
6776
# Competition parse test
@@ -72,46 +81,64 @@ if (NOT MSVC) # Can't run .sh on windows
7281

7382
add_test(issue150 ${CMAKE_CURRENT_SOURCE_DIR}/issue150.sh)
7483
set_property(TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile)
75-
set_property(TEST issue150 APPEND PROPERTY LABELS slowtests)
84+
set_property(TEST issue150 APPEND PROPERTY LABELS per_implementation)
7685
endif()
7786
endif()
7887

88+
if (NOT MSVC)
89+
#
90+
# json2json tool test: check that json2json can parse twitter.json
91+
#
92+
93+
# This tests validates that the implementation is what we think it is if we get passed
94+
# SIMDJSON_FORCE_IMPLEMENTATION, so we know we're testing what we think we're testing
95+
add_cpp_test(checkimplementation LABELS per_implementation)
96+
97+
add_test(NAME json2json COMMAND $<TARGET_FILE:json2json> ${EXAMPLE_JSON})
98+
set_property(TEST issue150 APPEND PROPERTY LABELS acceptance per_implementation)
99+
100+
#
101+
# SIMDJSON_FORCE_IMPLEMENTATION tests: run json2json with SIMDJSON
102+
#
103+
if (SIMDJSON_IMPLEMENTATION_FALLBACK)
104+
add_test(
105+
NAME simdjson_force_implementation
106+
COMMAND
107+
${CMAKE_COMMAND} -E env
108+
SIMDJSON_FORCE_IMPLEMENTATION=fallback
109+
$<TARGET_FILE:checkimplementation>
110+
)
111+
endif()
112+
add_test(
113+
NAME simdjson_force_implementation_error
114+
COMMAND
115+
${CMAKE_COMMAND} -E env
116+
SIMDJSON_FORCE_IMPLEMENTATION=doesnotexist
117+
$<TARGET_FILE:json2json> ${EXAMPLE_JSON}
118+
)
119+
set_tests_properties(simdjson_force_implementation_error PROPERTIES WILL_FAIL TRUE)
120+
endif()
121+
79122
#
80123
# Compile-only tests with simdjson flags on
81124
#
82125

83126
# Don't add the tests if we're on VS2017 or older; they don't succeed.
84127
if(NOT (MSVC AND MSVC_VERSION LESS 1920))
85128
if(SIMDJSON_EXCEPTIONS)
86-
add_compile_test(readme_examples readme_examples.cpp quicktests)
87-
set_property(
88-
TEST readme_examples
89-
APPEND PROPERTY LABELS quicktests
90-
)
91-
92-
add_compile_test(readme_examples11 readme_examples.cpp quicktests)
129+
add_cpp_test(readme_examples COMPILE_ONLY LABELS acceptance)
130+
add_cpp_test(readme_examples11 COMPILE_ONLY LABELS acceptance SOURCES readme_examples.cpp)
93131
set_target_properties(readme_examples11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
94-
if (!MSVC)
95-
target_compile_options(readme_examples11 PRIVATE -Werror)
96-
endif()
97132
endif()
98133

99-
add_compile_test(readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests)
134+
add_cpp_test(readme_examples_noexceptions COMPILE_ONLY LABELS acceptance)
100135

101-
add_compile_test(readme_examples_noexceptions11 readme_examples_noexceptions.cpp quicktests)
136+
add_cpp_test(readme_examples_noexceptions11 COMPILE_ONLY LABELS acceptance SOURCES readme_examples_noexceptions.cpp)
102137
set_target_properties(readme_examples_noexceptions11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
103-
if (!MSVC)
104-
target_compile_options(readme_examples_noexceptions11 PRIVATE -Werror)
105-
endif()
106138

107139
# Compile tests that *should fail*
108-
add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp quicktests)
140+
add_cpp_test(readme_examples_will_fail_with_exceptions_off WILL_FAIL COMPILE_ONLY LABELS acceptance SOURCES readme_examples.cpp)
109141
target_compile_definitions(readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0)
110-
set_tests_properties(readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE)
111-
set_property(
112-
TEST readme_examples_noexceptions readme_examples_will_fail_with_exceptions_off
113-
APPEND PROPERTY LABELS quicktests
114-
)
115142

116143
endif()
117144

0 commit comments

Comments
 (0)