Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6d908aa
`mlib_check` supports an explanatory string with all assertions
vector-of-bool Sep 29, 2025
d636e33
Define a mutable string type
vector-of-bool Sep 29, 2025
9675ae5
Add a "vector" template header
vector-of-bool Sep 29, 2025
8f4ec31
Wrapping indexing for vec
vector-of-bool Sep 30, 2025
f97883e
String functions for trimming whitespace
vector-of-bool Oct 1, 2025
47629d7
Use mlib strings and vec types in TestSuite files
vector-of-bool Oct 1, 2025
b39b795
Add support for test cases to declare tags (labels)
vector-of-bool Oct 3, 2025
4e844f6
Add parens around assignment-as-condition
vector-of-bool Oct 3, 2025
6837d55
Add Earthly alias for CTest with uvx
vector-of-bool Oct 3, 2025
319e351
The GCP test also requires the fake KMS server
vector-of-bool Oct 3, 2025
9de54ab
Windows-only compile error
vector-of-bool Oct 3, 2025
aed388d
No SSIZE_MAX on Windows
vector-of-bool Oct 3, 2025
b4d93bb
uninit-var in MSVC
vector-of-bool Oct 3, 2025
11c9aa8
Fix UBSan issue for null pointer arithmetic
vector-of-bool Oct 3, 2025
91d517b
Fix another nullptr-arith warning
vector-of-bool Oct 6, 2025
6a0c534
Tests can declare resource locks in tags
vector-of-bool Oct 6, 2025
5ac0881
Yet another nullptr-arith
vector-of-bool Oct 7, 2025
5329c7a
Suppress an over-eager Clang warning
vector-of-bool Oct 7, 2025
24225c0
Clean up automatic test properties from tags
vector-of-bool Oct 7, 2025
535b88b
No -Wmissing-braces anywhere
vector-of-bool Oct 7, 2025
a8ea90f
Add an mstr formatting function, change to destroy mstr objects in-place
vector-of-bool Oct 20, 2025
d023131
Define a CTest fixture for our simple HTTP server
vector-of-bool Oct 20, 2025
a044a4c
Tweak default timeout and locking behavior
vector-of-bool Oct 20, 2025
651d7db
Add test tags and properties throughout
vector-of-bool Oct 20, 2025
b9c15bb
Fix OpenSSL test that requires an SSL context
vector-of-bool Oct 20, 2025
40de7d2
Merge branch 'master' into CDRIVER-6107-test-tags
vector-of-bool Oct 20, 2025
4ec209f
Add missing tags following merge
vector-of-bool Oct 20, 2025
a3f1c7e
Conditional content in opeen-private.h
vector-of-bool Oct 20, 2025
0ee0a3e
Fix conditional OpenSSL context in test case
vector-of-bool Oct 21, 2025
c530f98
Fix NRVO warning
vector-of-bool Oct 24, 2025
095c845
Shift conditional inclusion of openssl detail header
vector-of-bool Oct 24, 2025
09d04a6
Tweak error message on invalid test specifier string
vector-of-bool Oct 24, 2025
b258f16
Fix: Wrong argument when invoking exec() with mstr
vector-of-bool Oct 24, 2025
427ccd2
Clarify the purpose of JSON suite name matching
vector-of-bool Oct 24, 2025
d448c7a
Adjust position of lock:live-server for session tests
vector-of-bool Oct 24, 2025
f538f6f
Merge branch 'master' into CDRIVER-6107-test-tags
vector-of-bool Oct 24, 2025
49189ee
Remove extraneous [slow][json] test tags
vector-of-bool Oct 24, 2025
bc96437
Restore accidentally removed inclusion
vector-of-bool Oct 27, 2025
6bdaa7a
Switch extension: `.t.h` -> `.th`
vector-of-bool Oct 27, 2025
3cbeb29
Fix missing extern_c around vec_index_adjust
vector-of-bool Oct 27, 2025
bdc88d4
PR feedback, change behavior of replace() on empty
vector-of-bool Oct 27, 2025
6c58ddc
Add "unlikely" annotations around direct overflow checks
vector-of-bool Oct 27, 2025
ae5bd52
Conditionally select the appropriate printf() attribute
vector-of-bool Oct 27, 2025
6f41703
More PR tweaks
vector-of-bool Oct 27, 2025
efa5055
Fix: Not adjusting elements after erasure
vector-of-bool Oct 27, 2025
ccb2521
Minor tweaks from PR feedback
vector-of-bool Oct 28, 2025
445b8c5
Fix mstr APIs to support self-assign/self-insert
vector-of-bool Oct 31, 2025
ec37524
mstr splice clamps deletion count
vector-of-bool Oct 31, 2025
d561be5
spelling
vector-of-bool Oct 31, 2025
0d9efd4
Plural "locks"
vector-of-bool Oct 31, 2025
3ec45a2
Fix name mstr_vsnprintf -> mstr_vsprintf
vector-of-bool Oct 31, 2025
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ if(ENABLE_MAINTAINER_FLAGS)
gnu-like:-Wuninitialized
# Disabled, for now:
gnu-like:-Wno-strict-aliasing
gnu-like:-Wno-missing-braces
# Sign-comparison-mismatch:
gnu-like:-Wsign-compare
msvc:/we4018
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
107 changes: 69 additions & 38 deletions build/cmake/LoadTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,88 @@
# 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 locks)

# Tests can set a timeout with a tag:
list_select(labels SELECT "^timeout:(.*)$" REPLACE "\\1" OUT timeout)
if(NOT timeout)
# Default timeout of 10 seconds. If a test takes longer than this, it either
# has a bug or it needs to declare a longer timeout.
set(timeout 10)
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 "${locks}"
)
endforeach()
2 changes: 1 addition & 1 deletion build/cmake/MongoC-Warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ mongoc_add_warning_options (

# Aside: Disable CRT insecurity warnings
msvc:/D_CRT_SECURE_NO_WARNINGS
)
)
8 changes: 8 additions & 0 deletions build/cmake/TestFixtures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ mongo_define_subprocess_fixture(
"${_MONGOC_BUILD_SCRIPT_DIR}/bottle.py" fake_kms_provider_server:kms_provider
--bind localhost:14987 # Port 14987 chosen arbitrarily
)

# Run our very simple HTTP server in a fixture process
mongo_define_subprocess_fixture(
mongoc/fixtures/simple-http-server-18000
SPAWN_WAIT 1
COMMAND
$<TARGET_FILE:Python3::Interpreter> -u "${mongo-c-driver_SOURCE_DIR}/.evergreen/scripts/simple_http_server.py"
)
19 changes: 19 additions & 0 deletions src/common/src/mlib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,23 @@
MLIB_IF_GNU_LIKE(mlib_gnu_warning_disable("-Wunused-parameter");) \
MLIB_IF_MSVC(mlib_msvc_warning(disable : 4100);) mlib_static_assert(1, "")

#if mlib_is_clang()
#define mlib_printf_attribute(f, v) __attribute__((format(printf, f, v)))
#elif mlib_is_gcc()
#define mlib_printf_attribute(f, v) __attribute__((format(gnu_printf, f, v)))
#else
#define mlib_printf_attribute(f, v)
#endif

/**
* @brief Annotate a boolean expression as "likely to be true" to guide the optimizer.
* Use this very sparingly.
*/
#define mlib_likely(...) MLIB_IF_ELSE(mlib_is_gnu_like())(__builtin_expect(!!(__VA_ARGS__), 1))((__VA_ARGS__))
/**
* @brief Annotate a boolean expression as "likely to be untrue" to guide the optimizer.
* Use this very sparingly.
*/
#define mlib_unlikely(...) MLIB_IF_ELSE(mlib_is_gnu_like())(__builtin_expect(!!(__VA_ARGS__), 0))((__VA_ARGS__))

#endif // MLIB_CONFIG_H_INCLUDED
Loading