Skip to content

Commit 1f5c959

Browse files
committed
testing: cv_wait_example: relax max waiting time
1 parent 30efbe0 commit 1f5c959

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_POSITION_INDEPENDENT_CODE ON)
1919

2020
# Allow nsync users to turn the tests on or off.
2121
option (NSYNC_ENABLE_TESTS "Enable for building tests" ON)
22+
option (NSYNC_TESTING_SLOW_MACHINE "Allow relax waiting time for very slow machine" OFF)
2223

2324
# -----------------------------------------------------------------
2425
# Functions to set common options on targets and files.
@@ -291,6 +292,10 @@ set_cpp_target (nsync_cpp "${NSYNC_CPP_SRC_COPY}")
291292

292293

293294
if (NSYNC_ENABLE_TESTS)
295+
if (NSYNC_TESTING_SLOW_MACHINE)
296+
add_compile_options ("-DNSYNC_TESTING_SLOW_MACHINE")
297+
endif()
298+
294299
set (NSYNC_TEST_SRC
295300
"testing/array.c"
296301
"testing/atm_log.c"

testing/cv_wait_example_test.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ static void example_cv_wait (testing t) {
136136
static const char *input[] = { "one", "two", "three", "four", "five" };
137137
string_priority_queue_cv q;
138138
a_char output;
139+
#ifdef NSYNC_TESTING_SLOW_MACHINE
140+
static const uint waiting_factor = 5;
141+
static const char *expected =
142+
"one\n"
143+
"three\n"
144+
"two\n"
145+
"timeout 0.5s\n"
146+
"four\n"
147+
"timeout 0.5s\n"
148+
"five\n"
149+
"timeout 5s\n";
150+
#else
151+
static const uint waiting_factor = 1;
139152
static const char *expected =
140153
"one\n"
141154
"three\n"
@@ -145,24 +158,25 @@ static void example_cv_wait (testing t) {
145158
"timeout 0.1s\n"
146159
"five\n"
147160
"timeout 1s\n";
161+
#endif
148162

149163
memset ((void *) &q, 0, sizeof (q));
150164
memset (&output, 0, sizeof (output));
151165

152166
closure_fork (closure_add_and_wait_cv (&add_and_wait_cv, &q,
153-
nsync_time_ms (500), NELEM (input), input));
167+
nsync_time_ms (waiting_factor * 500), NELEM (input), input));
154168

155169
/* delay: "one", "two", "three" are queued; not "four" */
156-
nsync_time_sleep (nsync_time_ms (1200));
157-
158-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* "one" */
159-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* "three" (less than "two") */
160-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* "two" */
161-
remove_and_print_cv (&q, nsync_time_ms (100), &output); /* time out because 1.3 < 0.5*3 */
162-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* "four" */
163-
remove_and_print_cv (&q, nsync_time_ms (100), &output); /* time out because 0.1 < 0.5 */
164-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* "five" */
165-
remove_and_print_cv (&q, nsync_time_ms (1000), &output); /* time out: no more to fetch */
170+
nsync_time_sleep (nsync_time_ms (waiting_factor * 1200));
171+
172+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* "one" */
173+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* "three" (less than "two") */
174+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* "two" */
175+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 100), &output); /* time out because 1.3 < 0.5*3 */
176+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* "four" */
177+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 100), &output); /* time out because 0.1 < 0.5 */
178+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* "five" */
179+
remove_and_print_cv (&q, nsync_time_ms (waiting_factor * 1000), &output); /* time out: no more to fetch */
166180

167181
A_PUSH (&output) = 0;
168182
if (strcmp (&A (&output, 0), expected) != 0) {

0 commit comments

Comments
 (0)