#define LONGEST_TEST_NAME 16384
+#ifndef _WIN32
+#define DEFAULT_TESTCASE_TIMEOUT 30U
+#else
+#define DEFAULT_TESTCASE_TIMEOUT 0U
+#endif
+
static int in_tinytest_main = 0; /**< true if we're in tinytest_main().*/
static int n_ok = 0; /**< Number of tests that have passed */
static int n_bad = 0; /**< Number of tests that have failed. */
static int opt_forked = 0; /**< True iff we're called from inside a win32 fork*/
static int opt_nofork = 0; /**< Suppress calls to fork() for debugging. */
static int opt_verbosity = 1; /**< -==quiet,0==terse,1==normal,2==verbose */
+static unsigned int opt_timeout = DEFAULT_TESTCASE_TIMEOUT; /**< Timeout for every test (using alarm()) */
const char *verbosity_flag = "";
const struct testlist_alias_t *cfg_aliases=NULL;
__attribute__((noreturn));
static int process_test_option(struct testgroup_t *groups, const char *test);
+static unsigned int testcase_set_timeout_(void)
+{
+ if (!opt_timeout)
+ return 0;
+#ifndef _WIN32
+ return alarm(opt_timeout);
+#else
+ /** TODO: win32 support */
+ fprintf(stderr, "You cannot set alarm on windows\n");
+ exit(1);
+#endif
+}
+static unsigned int testcase_reset_timeout_(void)
+{
+#ifndef _WIN32
+ return alarm(0);
+#endif
+}
+
static enum outcome
testcase_run_bare_(const struct testcase_t *testcase)
{
}
cur_test_outcome = OK;
- testcase->fn(env);
+ {
+ testcase_set_timeout_();
+ testcase->fn(env);
+ testcase_reset_timeout_();
+ }
outcome = cur_test_outcome;
if (testcase->setup) {
usage(groups, 0);
} else if (!strcmp(v[i], "--list-tests")) {
usage(groups, 1);
+ } else if (!strcmp(v[i], "--timeout")) {
+ if (i < c) {
+ fprintf(stderr, "--timeout requires argument\n");
+ return -1;
+ }
+ opt_timeout = (unsigned)atoi(v[i]);
} else {
- printf("Unknown option %s. Try --help\n",v[i]);
+ fprintf(stderr, "Unknown option %s. Try --help\n", v[i]);
return -1;
}
} else {