Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ ForEachMacros:
- mlib_foreach_urange
- mlib_foreach
- mlib_foreach_arr
- mlib_vec_foreach
IfMacros:
- mlib_assert_aborts
- KJ_IF_MAYBE
Expand Down
1 change: 1 addition & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ PREP_CMAKE:
FUNCTION
# Run all CMake commands using uvx:
RUN __alias cmake uvx cmake
RUN __alias ctest uvx --from=cmake ctest
# Executing any CMake command will warm the cache:
RUN cmake --version | head -n 1

Expand Down
111 changes: 73 additions & 38 deletions build/cmake/LoadTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,92 @@
# allowing CTest to control the execution, parallelization, and collection of
# test results.

if (NOT EXISTS "${TEST_LIBMONGOC_EXE}")
if(NOT EXISTS "${TEST_LIBMONGOC_EXE}")
# This will fail if 'test-libmongoc' is not compiled yet.
message (WARNING "The test executable ${TEST_LIBMONGOC_EXE} is not present. "
"Its tests will not be registered")
add_test (mongoc/not-found NOT_FOUND)
return ()
endif ()

# Get the list of tests
execute_process (
COMMAND "${TEST_LIBMONGOC_EXE}" --list-tests --no-fork
OUTPUT_VARIABLE tests_out
message(WARNING "The test executable ${TEST_LIBMONGOC_EXE} is not present. "
"Its tests will not be registered")
add_test(mongoc/not-found NOT_FOUND)
return()
endif()

# Get the list of tests. This command emits CMake code that defines variables for
# all test cases defined in the suite
execute_process(
COMMAND "${TEST_LIBMONGOC_EXE}" --tests-cmake --no-fork
OUTPUT_VARIABLE tests_cmake
WORKING_DIRECTORY "${SRC_ROOT}"
RESULT_VARIABLE retc
)
if (retc)
if(retc)
# Failed to list the tests. That's bad.
message (FATAL_ERROR "Failed to run test-libmongoc to discover tests [${retc}]:\n${tests_out}")
endif ()
message(FATAL_ERROR "Failed to run test-libmongoc to discover tests [${retc}]:\n${tests_out}")
endif()

# Split lines on newlines
string (REPLACE "\n" ";" lines "${tests_out}")
# Execute the code that defines the test case information
cmake_language(EVAL CODE "${tests_cmake}")

# TODO: Allow individual test cases to specify the fixtures they want.
set (all_fixtures "mongoc/fixtures/fake_kms_provider_server")
set (all_env
# Define environment variables that are common to all test cases
set(all_env
TEST_KMS_PROVIDER_HOST=localhost:14987 # Refer: Fixtures.cmake
)

# Generate the test definitions
foreach (line IN LISTS lines)
if (NOT line MATCHES "^/")
# Only generate if the line begins with `/`, which all tests should.
continue ()
endif ()
# The new test name is prefixed with 'mongoc'
set (test "mongoc${line}")
# Define the test. Use `--ctest-run` to tell it that CTest is in control.
add_test ("${test}" "${TEST_LIBMONGOC_EXE}" --ctest-run "${line}")
set_tests_properties ("${test}" PROPERTIES
function(list_select list_var)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SELECT;REPLACE;OUT" "")
set(seq "${${list_var}}")
list(FILTER seq INCLUDE REGEX "${arg_SELECT}")
list(TRANSFORM seq REPLACE "${arg_SELECT}" "${arg_REPLACE}")
set("${arg_OUT}" "${seq}" PARENT_SCOPE)
endfunction()

# The emitted code defines a list MONGOC_TESTS with the name of every test case
# in the suite.
foreach(casename IN LISTS MONGOC_TESTS)
set(name "mongoc${casename}")
# Run the program with --ctest-run to select only this one test case
add_test("${name}" "${TEST_LIBMONGOC_EXE}" --ctest-run "${casename}")
# The emitted code defines a TAGS list for every test case that it emits. We use
# these as the LABELS for the test case
unset(labels)
set(labels "${MONGOC_TEST_${casename}_TAGS}")

# Find what test fixtures the test wants by inspecting labels. Each "uses:"
# label defines the names of the test fixtures that a particular case requires
list_select(labels SELECT "^uses:(.*)$" REPLACE "mongoc/fixtures/\\1" OUT fixtures)

# For any "lock:..." labels, add a resource lock with the corresponding name
list_select(labels SELECT "^lock:(.*)$" REPLACE "\\1" OUT lock)

# Tests can set a timeout with a tag:
list_select(labels SELECT "^timeout:(.*)$" REPLACE "\\1" OUT timeout)
if(NOT timeout)
# Default timeout of 5 seconds
set(timeout 5)
endif()

# If a test declares that it is "live", lock exclusive access to the live server
if("live" IN_LIST labels)
list(APPEND lock live-server)
endif()

# Add a label for all test cases generated via this script so that they
# can be (de)selected separately:
list(APPEND labels test-libmongoc-generated)
# Set up the test:
set_tests_properties("${name}" PROPERTIES
# test-libmongoc expects to execute in the root of the source directory
WORKING_DIRECTORY "${SRC_ROOT}"
# If a test emits '@@ctest-skipped@@', this tells us that the test is
# skipped.
SKIP_REGULAR_EXPRESSION "@@ctest-skipped@@"
# 45 seconds of timeout on each test.
TIMEOUT 45
FIXTURES_REQUIRED "${all_fixtures}"
# Apply a timeout to each test, either the default or one from test tags
TIMEOUT "${timeout}"
# Common environment variables:
ENVIRONMENT "${all_env}"
# Mark all tests generated from the executable, so they can be (de)selected
# for execution separately.
LABELS "test-libmongoc-generated"
)
endforeach ()
# Apply the labels
LABELS "${labels}"
# Fixture requirements:
FIXTURES_REQUIRED "${fixtures}"
# Test may lock resources:
RESOURCE_LOCK "${lock}"
)
endforeach()
5 changes: 4 additions & 1 deletion build/cmake/MongoC-Warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ mongoc_add_warning_options (

# Aside: Disable CRT insecurity warnings
msvc:/D_CRT_SECURE_NO_WARNINGS
)

# Old Clang has an over-aggressive missing-braces warning that warns on the `foo = {0}` idiom
clang:clang-lt10:-Wno-missing-braces
)
Loading