Skip to content

Commit b193dba

Browse files
authored
increase sleep time in cache test and flush test output (#935)
* increase timeout Account for possible coarse resolution of `bson_get_monotonic_time` on Windows * add `TEST_PRINTF` and `TEST_STDERR_PRINTF` macros To flush stderr and stdout to avoid mixed output in logs.
1 parent 0727c32 commit b193dba

28 files changed

+248
-230
lines changed

kms-message/test/test_kmip_reader_writer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ kms_kmip_writer_test_evaluate (kmip_writer_t *writer,
4242
actual_hex = data_to_hex (actual_buf, actual_len);
4343

4444
if (0 != strcmp (expected_hex, actual_hex)) {
45-
fprintf (stderr,
46-
"expected '%s' but got '%s' for test description: %s\n",
47-
expected_hex,
48-
actual_hex,
49-
desc);
45+
TEST_STDERR_PRINTF (
46+
"expected '%s' but got '%s' for test description: %s\n",
47+
expected_hex,
48+
actual_hex,
49+
desc);
5050
abort ();
5151
}
5252

kms-message/test/test_kms_assert.h

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,31 @@
2323
#include <stdio.h>
2424
#include <string.h>
2525

26-
#define TEST_ERROR(...) \
27-
do { \
28-
fprintf ( \
29-
stderr, "test error %s:%d %s(): ", __FILE__, __LINE__, __FUNCTION__); \
30-
fprintf (stderr, __VA_ARGS__); \
31-
fprintf (stderr, "\n"); \
32-
fflush (stderr); \
33-
abort (); \
26+
// TEST_PRINTF ensures stdout and stderr are flushed.
27+
#define TEST_PRINTF(...) \
28+
if (1) { \
29+
fflush (stderr); \
30+
fprintf (stdout, __VA_ARGS__); \
31+
fflush (stdout); \
32+
} else \
33+
((void) 0)
34+
35+
// TEST_STDERR_PRINTF ensures stdout and stderr are flushed.
36+
#define TEST_STDERR_PRINTF(...) \
37+
if (1) { \
38+
fflush (stdout); \
39+
fprintf (stderr, __VA_ARGS__); \
40+
fflush (stderr); \
41+
} else \
42+
((void) 0)
43+
44+
#define TEST_ERROR(...) \
45+
do { \
46+
TEST_STDERR_PRINTF ( \
47+
"test error %s:%d %s(): ", __FILE__, __LINE__, __FUNCTION__); \
48+
TEST_STDERR_PRINTF (__VA_ARGS__); \
49+
TEST_STDERR_PRINTF ("\n"); \
50+
abort (); \
3451
} while (0)
3552

3653
#define ASSERT(stmt) \

kms-message/test/test_kms_azure_online.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ test_getenv (const char *key)
5656
{
5757
char *value = getenv (key);
5858
if (!value) {
59-
fprintf (
60-
stderr, "Environment variable: %s not set (@@ctest-skip@@)", key);
59+
TEST_STDERR_PRINTF ("Environment variable: %s not set (@@ctest-skip@@)\n",
60+
key);
6161
exit (2);
6262
}
6363
TEST_TRACE ("Env: %s = %s", key, value);

kms-message/test/test_kms_gcp_online.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ test_getenv (const char *key)
5656
{
5757
char *value = getenv (key);
5858
if (!value) {
59-
fprintf (
60-
stderr, "Environment variable: %s not set (@@ctest-skip@@)", key);
59+
TEST_STDERR_PRINTF ("Environment variable: %s not set (@@ctest-skip@@)\n",
60+
key);
6161
exit (2);
6262
}
6363
TEST_TRACE ("Env: %s = %s", key, value);
@@ -185,7 +185,7 @@ test_gcp (void)
185185
opt);
186186
ASSERT (req);
187187
if (kms_request_get_error (req)) {
188-
printf ("error: %s\n", kms_request_get_error (req));
188+
TEST_STDERR_PRINTF ("error: %s\n", kms_request_get_error (req));
189189
ASSERT (false);
190190
}
191191
req_str = kms_request_to_string (req);

kms-message/test/test_kms_request.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ all_aws_sig_v4_tests (const char *path, const char *selected)
383383
}
384384

385385
if (skip_aws_test (test_name) && !selected) {
386-
printf ("SKIP: %s\n", test_name);
386+
TEST_PRINTF ("SKIP: %s\n", test_name);
387387
goto done;
388388
}
389389

@@ -407,7 +407,7 @@ all_aws_sig_v4_tests (const char *path, const char *selected)
407407
continue;
408408
}
409409

410-
printf ("%s\n", path);
410+
TEST_PRINTF ("%s\n", path);
411411
aws_sig_v4_test (path);
412412
ran_tests = true;
413413
}
@@ -903,7 +903,7 @@ parser_testcase_run (parser_testcase_t *testcase)
903903
size_t ret = fread (buf, 1, (size_t) bytes_to_read, response_file);
904904

905905
if (!kms_response_parser_feed (parser, buf, (int) ret)) {
906-
printf ("feed error: %s\n", parser->error);
906+
TEST_PRINTF ("feed error: %s\n", parser->error);
907907
ASSERT (false);
908908
}
909909
}
@@ -945,7 +945,7 @@ kms_response_parser_files (void)
945945
size_t i;
946946

947947
for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
948-
printf (" parser testcase: %d\n", (int) i);
948+
TEST_PRINTF (" parser testcase: %d\n", (int) i);
949949
parser_testcase_run (tests + i);
950950
}
951951
}
@@ -1081,8 +1081,8 @@ kms_signature_test (void)
10811081
signature_b64 = kms_message_raw_to_b64 (signature_raw, 256);
10821082

10831083
if (0 != strcmp (signature_b64, expected_signature)) {
1084-
printf ("generated signature: %s\n", signature_b64);
1085-
printf ("but expected signature: %s\n", expected_signature);
1084+
TEST_PRINTF ("generated signature: %s\n", signature_b64);
1085+
TEST_PRINTF ("but expected signature: %s\n", expected_signature);
10861086
abort ();
10871087
}
10881088

@@ -1197,7 +1197,7 @@ test_request_newlines (void)
11971197
#define RUN_TEST(_func) \
11981198
do { \
11991199
if (!selector || 0 == kms_strcasecmp (#_func, selector)) { \
1200-
printf ("%s\n", #_func); \
1200+
TEST_PRINTF ("%s\n", #_func); \
12011201
_func (); \
12021202
ran_tests = true; \
12031203
} \
@@ -1232,15 +1232,15 @@ main (int argc, char *argv[])
12321232
help = "Usage: test_kms_request [TEST_NAME]";
12331233

12341234
if (argc > 2) {
1235-
fprintf (stderr, "%s\n", help);
1235+
TEST_STDERR_PRINTF ("%s\n", help);
12361236
abort ();
12371237
} else if (argc == 2) {
12381238
selector = argv[1];
12391239
}
12401240

12411241
int ret = kms_message_init ();
12421242
if (ret != 0) {
1243-
printf ("kms_message_init failed: 0x%x\n", ret);
1243+
TEST_PRINTF ("kms_message_init failed: 0x%x\n", ret);
12441244
abort ();
12451245
}
12461246

@@ -1292,7 +1292,7 @@ main (int argc, char *argv[])
12921292

12931293
if (!ran_tests) {
12941294
KMS_ASSERT (argc == 2);
1295-
fprintf (stderr, "No such test: \"%s\"\n", argv[1]);
1295+
TEST_STDERR_PRINTF ("No such test: \"%s\"\n", argv[1]);
12961296
abort ();
12971297
}
12981298

test/test-mc-fle2-payload-iev-v2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void _mc_fle2_iev_v2_validate(_mongocrypt_tester_t *tester, _mc_fle2_iev_
379379
}
380380

381381
static void test_fle2_iev_v2_test(_mongocrypt_tester_t *tester, const char *path) {
382-
printf("Loading test from %s...\n", path);
382+
TEST_PRINTF("Loading test from %s...\n", path);
383383

384384
mongocrypt_binary_t *test_bin = TEST_FILE(path);
385385
if (!test_bin) {
@@ -405,7 +405,7 @@ static void test_fle2_iev_v2_test(_mongocrypt_tester_t *tester, const char *path
405405

406406
static void test_fle2_iev_v2(_mongocrypt_tester_t *tester) {
407407
if (!_aes_ctr_is_supported_by_os) {
408-
printf("Common Crypto with no CTR support detected. Skipping.");
408+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
409409
return;
410410
}
411411

test/test-mc-fle2-payload-iev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void test_FLE2IndexedEqualityEncryptedValue_decrypt(_mongocrypt_tester_t
171171
mongocrypt_t *crypt;
172172

173173
if (!_aes_ctr_is_supported_by_os) {
174-
printf("Common Crypto with no CTR support detected. Skipping.");
174+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
175175
return;
176176
}
177177

test/test-mc-fle2-payload-iup-v2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void _test_mc_FLE2InsertUpdatePayloadV2_decrypt(_mongocrypt_tester_t *tes
107107
mongocrypt_t *crypt;
108108

109109
if (!_aes_ctr_is_supported_by_os) {
110-
printf("Common Crypto with no CTR support detected. Skipping.");
110+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
111111
return;
112112
}
113113

test/test-mc-fle2-payload-iup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void test_FLE2InsertUpdatePayload_decrypt(_mongocrypt_tester_t *tester) {
100100
mongocrypt_t *crypt;
101101

102102
if (!_aes_ctr_is_supported_by_os) {
103-
printf("Common Crypto with no CTR support detected. Skipping.");
103+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
104104
return;
105105
}
106106

test/test-mc-fle2-payload-uev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void test_FLE2UnindexedEncryptedValue_decrypt(_mongocrypt_tester_t *teste
125125
mongocrypt_t *crypt;
126126

127127
if (!_aes_ctr_is_supported_by_os) {
128-
printf("Common Crypto with no CTR support detected. Skipping.");
128+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
129129
return;
130130
}
131131

@@ -201,7 +201,7 @@ static void test_FLE2UnindexedEncryptedValue_decrypt(_mongocrypt_tester_t *teste
201201

202202
static void test_FLE2UnindexedEncryptedValue_encrypt(_mongocrypt_tester_t *tester) {
203203
if (!_aes_ctr_is_supported_by_os) {
204-
printf("Common Crypto with no CTR support detected. Skipping.");
204+
TEST_PRINTF("Common Crypto with no CTR support detected. Skipping.");
205205
return;
206206
}
207207

0 commit comments

Comments
 (0)