Skip to content

Commit 1bc7a46

Browse files
When running with CTest, don't register all tests. (#883)
* When running with CTest, don't register all tests. Only register tests that match the name of the expression. This logic is still somewhat fuzzy, but provides significant speedup in the common case. * Fix duplicated test names
1 parent d1dd248 commit 1bc7a46

26 files changed

+152
-182
lines changed

src/libbson/tests/test-bson-corpus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,6 @@ void
325325
test_bson_corpus_install (TestSuite *suite)
326326
{
327327
install_json_test_suite_with_check (
328-
suite, BSON_JSON_DIR "/bson_corpus", test_bson_corpus_cb);
328+
suite, BSON_JSON_DIR, "bson_corpus", test_bson_corpus_cb);
329329
TestSuite_Add (suite, "/bson_corpus/prose_1", test_bson_corpus_prose_1);
330330
}

src/libmongoc/tests/TestSuite.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ _V_TestSuite_AddFull (TestSuite *suite,
353353
Test *test;
354354
Test *iter;
355355

356+
if (suite->ctest_run && (0 != strcmp (suite->ctest_run, name))) {
357+
return NULL;
358+
}
359+
356360
test = (Test *) calloc (1, sizeof *test);
357361
test->name = bson_strdup (name);
358362
test->func = func;
@@ -393,7 +397,9 @@ _TestSuite_AddMockServerTest (TestSuite *suite,
393397
test = _V_TestSuite_AddFull (suite, name, (TestFuncWC) func, NULL, NULL, ap);
394398
va_end (ap);
395399

396-
_TestSuite_AddCheck (test, TestSuite_CheckMockServerAllowed, name);
400+
if (test) {
401+
_TestSuite_AddCheck (test, TestSuite_CheckMockServerAllowed, name);
402+
}
397403
}
398404

399405

src/libmongoc/tests/json-test.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,8 @@ _skip_if_unsupported (const char *test_name, bson_t *original)
19151915
*/
19161916
void
19171917
_install_json_test_suite_with_check (TestSuite *suite,
1918-
const char *dir_path,
1918+
const char *base,
1919+
const char *subdir,
19191920
test_hook callback,
19201921
...)
19211922
{
@@ -1926,9 +1927,21 @@ _install_json_test_suite_with_check (TestSuite *suite,
19261927
char *skip_json;
19271928
char *ext;
19281929
va_list ap;
1930+
char joined[PATH_MAX];
1931+
char resolved[PATH_MAX];
1932+
1933+
snprintf (joined, PATH_MAX, "%s/%s", base, subdir);
1934+
ASSERT (realpath (joined, resolved));
1935+
1936+
if (suite->ctest_run) {
1937+
const char *found = strstr (suite->ctest_run, subdir);
1938+
if (found != suite->ctest_run && found != suite->ctest_run + 1) {
1939+
return;
1940+
}
1941+
}
19291942

19301943
num_tests =
1931-
collect_tests_from_dir (&test_paths[0], dir_path, 0, MAX_NUM_TESTS);
1944+
collect_tests_from_dir (&test_paths[0], resolved, 0, MAX_NUM_TESTS);
19321945

19331946
for (i = 0; i < num_tests; i++) {
19341947
test = get_bson_from_json_file (test_paths[i]);
@@ -1971,9 +1984,10 @@ _install_json_test_suite_with_check (TestSuite *suite,
19711984
*/
19721985
void
19731986
install_json_test_suite (TestSuite *suite,
1974-
const char *dir_path,
1987+
const char *base,
1988+
const char *subdir,
19751989
test_hook callback)
19761990
{
19771991
install_json_test_suite_with_check (
1978-
suite, dir_path, callback, TestSuite_CheckLive);
1992+
suite, base, subdir, callback, TestSuite_CheckLive);
19791993
}

src/libmongoc/tests/json-test.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ json_test_config_cleanup (json_test_config_t *config);
102102

103103
void
104104
_install_json_test_suite_with_check (TestSuite *suite,
105-
const char *dir_path,
105+
const char *base,
106+
const char *subdir,
106107
test_hook callback,
107108
...);
108109

109110
void
110111
install_json_test_suite (TestSuite *suite,
111-
const char *dir_path,
112+
const char *base,
113+
const char *subdir,
112114
test_hook callback);
113115

114-
#define install_json_test_suite_with_check(_suite, _dir_path, ...) \
115-
_install_json_test_suite_with_check (_suite, _dir_path, __VA_ARGS__, NULL)
116+
#define install_json_test_suite_with_check(_suite, _base, _subdir, ...) \
117+
_install_json_test_suite_with_check ( \
118+
_suite, _base, _subdir, __VA_ARGS__, NULL)
116119

117120
void
118121
set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts);

src/libmongoc/tests/test-libmongoc.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,16 +2682,6 @@ test_framework_skip_if_no_setenv (void)
26822682
return 1;
26832683
}
26842684

2685-
void
2686-
test_framework_resolve_path (const char *path, char *resolved)
2687-
{
2688-
if (!realpath (path, resolved)) {
2689-
MONGOC_ERROR ("Cannot resolve path %s\n", path);
2690-
MONGOC_ERROR ("Run test-libmongoc in repository root directory.\n");
2691-
ASSERT (false);
2692-
}
2693-
}
2694-
26952685
bool
26962686
test_framework_is_serverless (void)
26972687
{

src/libmongoc/tests/test-libmongoc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ test_framework_skip_if_no_client_side_encryption (void);
239239
int
240240
test_framework_skip_if_time_sensitive (void);
241241

242-
void
243-
test_framework_resolve_path (const char *path, char *resolved);
244-
245242
int
246243
test_framework_skip_if_no_aws (void);
247244

src/libmongoc/tests/test-mongoc-change-stream.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
request_t *_request = mock_server_receives_command ( \
3434
server, \
3535
"db", \
36-
MONGOC_QUERY_SECONDARY_OK, \
36+
MONGOC_QUERY_SECONDARY_OK, \
3737
"{ 'killCursors' : 'coll', 'cursors' : [ " #cursor_id " ] }"); \
3838
mock_server_replies_simple (_request, \
3939
"{ 'cursorsKilled': [ " #cursor_id " ] }"); \
@@ -1766,7 +1766,7 @@ change_stream_spec_after_test_cb (json_test_ctx_t *test_ctx, const bson_t *test)
17661766
}
17671767

17681768
/* iterate over the change stream, and verify that the document exists.
1769-
*/
1769+
*/
17701770
for (i = 0; i < num_iterations; i++) {
17711771
char *key = bson_strdup_printf ("%d", i);
17721772
ret = _iterate_until_error_or_event (
@@ -1782,7 +1782,7 @@ change_stream_spec_after_test_cb (json_test_ctx_t *test_ctx, const bson_t *test)
17821782
}
17831783

17841784
/* check that everything in the "result.success" array is contained in
1785-
* our captured changes. */
1785+
* our captured changes. */
17861786
while (bson_iter_next (&expected_iter)) {
17871787
bson_t expected_doc;
17881788
match_ctx_t match_ctx = {{0}};
@@ -2610,7 +2610,6 @@ prose_test_18 (void)
26102610
void
26112611
test_change_stream_install (TestSuite *suite)
26122612
{
2613-
char resolved[PATH_MAX];
26142613
TestSuite_AddMockServerTest (
26152614
suite, "/change_stream/pipeline", test_change_stream_pipeline);
26162615

@@ -2774,6 +2773,6 @@ test_change_stream_install (TestSuite *suite)
27742773
TestSuite_AddMockServerTest (
27752774
suite, "/change_streams/prose_test_18", prose_test_18);
27762775

2777-
test_framework_resolve_path (JSON_DIR "/change_streams/legacy", resolved);
2778-
install_json_test_suite (suite, resolved, &test_change_stream_spec_cb);
2776+
install_json_test_suite (
2777+
suite, JSON_DIR, "change_streams/legacy", &test_change_stream_spec_cb);
27792778
}

src/libmongoc/tests/test-mongoc-client-session.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,8 +2795,6 @@ test_sessions_snapshot_prose_test_1 (void *ctx)
27952795
void
27962796
test_session_install (TestSuite *suite)
27972797
{
2798-
char resolved[PATH_MAX];
2799-
28002798
TestSuite_Add (suite, "/Session/opts/clone", test_session_opts_clone);
28012799
TestSuite_Add (suite,
28022800
"/Session/opts/causal_consistency_and_snapshot",
@@ -3151,9 +3149,9 @@ test_session_install (TestSuite *suite)
31513149
false,
31523150
false);
31533151

3154-
ASSERT (realpath (JSON_DIR "/sessions/legacy", resolved));
31553152
install_json_test_suite_with_check (suite,
3156-
resolved,
3153+
JSON_DIR,
3154+
"sessions/legacy",
31573155
test_sessions_spec_cb,
31583156
test_framework_skip_if_no_sessions);
31593157

src/libmongoc/tests/test-mongoc-client-side-encryption.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,12 +3148,10 @@ test_kms_tls_options_extra_rejected (void *unused)
31483148
void
31493149
test_client_side_encryption_install (TestSuite *suite)
31503150
{
3151-
char resolved[PATH_MAX];
3152-
3153-
ASSERT (realpath (JSON_DIR "/client_side_encryption", resolved));
31543151
install_json_test_suite_with_check (
31553152
suite,
3156-
resolved,
3153+
JSON_DIR,
3154+
"client_side_encryption",
31573155
test_client_side_encryption_cb,
31583156
test_framework_skip_if_no_client_side_encryption);
31593157
/* Prose tests from the spec. */

src/libmongoc/tests/test-mongoc-command-monitoring.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ test_command_monitoring_cb (bson_t *scenario)
104104
static void
105105
test_all_spec_tests (TestSuite *suite)
106106
{
107-
char resolved[PATH_MAX];
108-
109-
run_unified_tests (suite, JSON_DIR "/command_monitoring/unified");
110-
111-
test_framework_resolve_path (JSON_DIR "/command_monitoring/legacy",
112-
resolved);
113-
install_json_test_suite (suite, resolved, &test_command_monitoring_cb);
107+
run_unified_tests (suite, JSON_DIR, "command_monitoring/unified");
108+
install_json_test_suite (suite,
109+
JSON_DIR,
110+
"command_monitoring/legacy",
111+
&test_command_monitoring_cb);
114112
}
115113

116114

src/libmongoc/tests/test-mongoc-connection-uri.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,11 @@ test_connection_uri_cb (bson_t *scenario)
357357
static void
358358
test_all_spec_tests (TestSuite *suite)
359359
{
360-
char resolved[PATH_MAX];
361-
362-
test_framework_resolve_path (JSON_DIR "/uri-options", resolved);
363-
install_json_test_suite (suite, resolved, &test_connection_uri_cb);
364-
365-
test_framework_resolve_path (JSON_DIR "/connection_uri", resolved);
366-
install_json_test_suite (suite, resolved, &test_connection_uri_cb);
367-
368-
test_framework_resolve_path (JSON_DIR "/auth", resolved);
369-
install_json_test_suite (suite, resolved, &test_connection_uri_cb);
360+
install_json_test_suite (
361+
suite, JSON_DIR, "uri-options", &test_connection_uri_cb);
362+
install_json_test_suite (
363+
suite, JSON_DIR, "connection_uri", &test_connection_uri_cb);
364+
install_json_test_suite (suite, JSON_DIR, "auth", &test_connection_uri_cb);
370365
}
371366

372367

src/libmongoc/tests/test-mongoc-crud.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,19 @@ test_crud_cb (bson_t *scenario)
3333
static void
3434
test_all_spec_tests (TestSuite *suite)
3535
{
36-
char resolved[PATH_MAX];
37-
38-
test_framework_resolve_path (JSON_DIR "/crud/legacy", resolved);
39-
4036
install_json_test_suite_with_check (suite,
41-
resolved,
37+
JSON_DIR,
38+
"crud/legacy",
4239
&test_crud_cb,
4340
test_framework_skip_if_no_crypto,
4441
TestSuite_CheckLive);
4542

4643
/* Read/write concern spec tests use the same format. */
47-
test_framework_resolve_path (JSON_DIR "/read_write_concern/operation",
48-
resolved);
49-
50-
install_json_test_suite_with_check (
51-
suite, resolved, &test_crud_cb, TestSuite_CheckLive);
44+
install_json_test_suite_with_check (suite,
45+
JSON_DIR,
46+
"read_write_concern/operation",
47+
&test_crud_cb,
48+
TestSuite_CheckLive);
5249
}
5350

5451
static void

src/libmongoc/tests/test-mongoc-dns.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -420,29 +420,26 @@ test_null_error_pointer (void *ctx)
420420
static void
421421
test_all_spec_tests (TestSuite *suite)
422422
{
423-
char resolved[PATH_MAX];
424-
425-
test_framework_resolve_path (
426-
JSON_DIR "/initial_dns_seedlist_discovery/replica-set", resolved);
427-
install_json_test_suite_with_check (suite,
428-
resolved,
429-
test_dns,
430-
test_dns_check_replset,
431-
test_framework_skip_if_no_crypto);
432-
433-
test_framework_resolve_path (
434-
JSON_DIR "/initial_dns_seedlist_discovery/load-balanced", resolved);
435-
install_json_test_suite_with_check (suite,
436-
resolved,
437-
test_dns,
438-
test_dns_check_loadbalanced,
439-
test_framework_skip_if_no_crypto);
440-
441-
test_framework_resolve_path (
442-
JSON_DIR "/initial_dns_seedlist_discovery/sharded", resolved);
443423
install_json_test_suite_with_check (
444424
suite,
445-
resolved,
425+
JSON_DIR,
426+
"initial_dns_seedlist_discovery/replica-set",
427+
test_dns,
428+
test_dns_check_replset,
429+
test_framework_skip_if_no_crypto);
430+
431+
install_json_test_suite_with_check (
432+
suite,
433+
JSON_DIR,
434+
"initial_dns_seedlist_discovery/load-balanced",
435+
test_dns,
436+
test_dns_check_loadbalanced,
437+
test_framework_skip_if_no_crypto);
438+
439+
install_json_test_suite_with_check (
440+
suite,
441+
JSON_DIR,
442+
"/initial_dns_seedlist_discovery/sharded",
446443
test_dns,
447444
/* Topology of load-balancer tests satisfy topology requirements of
448445
* sharded tests, even though a load balancer is not required. */

src/libmongoc/tests/test-mongoc-gridfs-bucket.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,7 @@ test_gridfs_cb (bson_t *scenario)
877877
static void
878878
test_all_spec_tests (TestSuite *suite)
879879
{
880-
char resolved[PATH_MAX];
881-
882-
test_framework_resolve_path (JSON_DIR "/gridfs", resolved);
883-
install_json_test_suite (suite, resolved, &test_gridfs_cb);
880+
install_json_test_suite (suite, JSON_DIR, "gridfs", &test_gridfs_cb);
884881
}
885882

886883
static void

src/libmongoc/tests/test-mongoc-max-staleness.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,8 @@ test_last_write_date_absent_pooled (void *ctx)
346346
static void
347347
test_all_spec_tests (TestSuite *suite)
348348
{
349-
char resolved[PATH_MAX];
350-
351-
test_framework_resolve_path (JSON_DIR "/max_staleness", resolved);
352-
install_json_test_suite (suite, resolved, &test_server_selection_logic_cb);
349+
install_json_test_suite (
350+
suite, JSON_DIR, "max_staleness", &test_server_selection_logic_cb);
353351
}
354352

355353
void

src/libmongoc/tests/test-mongoc-mongohouse.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,9 @@ test_mongohouse_no_auth (void *ctx_unused)
294294
void
295295
test_mongohouse_install (TestSuite *suite)
296296
{
297-
char resolved[PATH_MAX];
298-
299-
test_framework_resolve_path (JSON_DIR "/mongohouse", resolved);
300-
301297
install_json_test_suite_with_check (suite,
302-
resolved,
298+
JSON_DIR,
299+
"mongohouse",
303300
&test_mongohouse_cb,
304301
test_framework_skip_if_no_mongohouse);
305302

src/libmongoc/tests/test-mongoc-read-write-concern.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,12 @@ test_rw_concern_document (bson_t *scenario)
233233
void
234234
test_read_write_concern_install (TestSuite *suite)
235235
{
236-
char resolved[PATH_MAX];
237-
238-
ASSERT (
239-
realpath (JSON_DIR "/read_write_concern/connection-string", resolved));
240-
install_json_test_suite (suite, resolved, &test_rw_concern_uri);
241-
242-
test_framework_resolve_path (JSON_DIR "/read_write_concern/document",
243-
resolved);
244-
install_json_test_suite (suite, resolved, &test_rw_concern_document);
236+
install_json_test_suite (suite,
237+
JSON_DIR,
238+
"read_write_concern/connection-string",
239+
&test_rw_concern_uri);
240+
install_json_test_suite (suite,
241+
JSON_DIR,
242+
"read_write_concern/document",
243+
&test_rw_concern_document);
245244
}

0 commit comments

Comments
 (0)