}
if (outcome == OK) {
- ++n_ok;
if (opt_verbosity>0 && !opt_forked)
puts(opt_verbosity==1?"OK":"");
} else if (outcome == SKIP) {
- ++n_skipped;
if (opt_verbosity>0 && !opt_forked)
puts("SKIPPED");
} else {
- ++n_bad;
if (!opt_forked)
printf("\n [%s FAILED]\n", testcase->name);
}
#endif
++in_tinytest_main;
- for (i=0; groups[i].prefix; ++i)
- for (j=0; groups[i].cases[j].name; ++j)
- if (groups[i].cases[j].flags & TT_ENABLED_)
- testcase_run_one(&groups[i],
- &groups[i].cases[j]);
+ for (i = 0; groups[i].prefix; ++i) {
+ struct testgroup_t *group = &groups[i];
+ for (j = 0; group->cases[j].name; ++j) {
+ struct testcase_t *testcase = &group->cases[j];
+ int test_attempts = 3;
+ int test_ret_err;
+
+ if (!(testcase->flags & TT_ENABLED_))
+ continue;
+
+ for (;;) {
+ test_ret_err = testcase_run_one(group, testcase);
+
+ if (test_ret_err == OK)
+ break;
+ if (!(testcase->flags & TT_RETRIABLE))
+ break;
+ printf("\n [RETRYING %s (%i)]\n", testcase->name, test_attempts);
+ if (!test_attempts--)
+ break;
+ }
+
+ switch (test_ret_err) {
+ case OK: ++n_ok; break;
+ case SKIP: ++n_skipped; break;
+ default: ++n_bad; break;
+ }
+ }
+ }
--in_tinytest_main;
#define TT_ENABLED_ (1<<2)
/** Flag for a test that's off by default. */
#define TT_OFF_BY_DEFAULT (1<<3)
+/** Flag for a test that should be runned again in case of failure (but not
+ * more then 3 times). */
+#define TT_RETRIABLE (1<<4)
/** If you add your own flags, make them start at this point. */
-#define TT_FIRST_USER_FLAG (1<<4)
+#define TT_FIRST_USER_FLAG (1<<5)
typedef void (*testcase_fn)(void *);
;
}
+void
+test_timeout_retry(void *ptr)
+{
+ static int i = 0;
+
+ ++i;
+ tt_int_op(i, !=, 1);
+
+ time_t t1, t2;
+ (void)ptr;
+ t1 = time(NULL);
+#ifdef _WIN32
+ Sleep(5000);
+#else
+ sleep(5);
+#endif
+ t2 = time(NULL);
+
+ tt_int_op(t2-t1, >=, 4);
+
+ tt_int_op(t2-t1, <=, 6);
+
+ end:
+ ;
+}
+
/* ============================================================ */
/* Now we need to make sure that our tests get invoked. First, you take
* can enable it manually by passing +demo/timeout at the command line.*/
{ "timeout", test_timeout, TT_OFF_BY_DEFAULT },
+ /* This test will be retried. (and it will not pass from the first
+ * time) */
+ { "timeout_retry", test_timeout_retry, TT_RETRIABLE },
+
/* The array has to end with END_OF_TESTCASES. */
END_OF_TESTCASES
};