aboutsummaryrefslogtreecommitdiff
path: root/src/test/testing_common.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2020-08-19 13:56:34 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2020-08-19 13:56:34 +0300
commit4e3f55fba1690a63942c0415953cbc1eaf30b360 (patch)
treefad01a621189f06caee6b34d2da8ad5d045f4ea8 /src/test/testing_common.c
parent1089ac6f2275e5d6b62debb5dd05a936fdbad6a7 (diff)
parentb1b007967599ccac2de91aa36d3a11a9bcb4ffdb (diff)
downloadtor-4e3f55fba1690a63942c0415953cbc1eaf30b360.tar.gz
tor-4e3f55fba1690a63942c0415953cbc1eaf30b360.zip
Merge branch 'maint-0.4.4'
Diffstat (limited to 'src/test/testing_common.c')
-rw-r--r--src/test/testing_common.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index cd93055dfb..9b50de07a8 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -287,6 +287,8 @@ main(int c, const char **v)
/* Don't add default logs; the tests manage their own. */
quiet_level = QUIET_SILENT;
+ unsigned num=1, den=1;
+
for (i_out = i = 1; i < c; ++i) {
if (!strcmp(v[i], "--warn")) {
loglevel = LOG_WARN;
@@ -298,6 +300,19 @@ main(int c, const char **v)
loglevel = LOG_DEBUG;
} else if (!strcmp(v[i], "--accel")) {
accel_crypto = 1;
+ } else if (!strcmp(v[i], "--fraction")) {
+ if (i+1 == c) {
+ printf("--fraction needs an argument.\n");
+ return 1;
+ }
+ const char *fracstr = v[++i];
+ char ch;
+ if (sscanf(fracstr, "%u/%u%c", &num, &den, &ch) != 2) {
+ printf("--fraction expects a fraction as an input.\n");
+ }
+ if (den == 0 || num == 0 || num > den) {
+ printf("--fraction expects a valid fraction as an input.\n");
+ }
} else {
v[i_out++] = v[i];
}
@@ -375,6 +390,33 @@ main(int c, const char **v)
smartlist_free(skip);
}
+ if (den != 1) {
+ // count the tests. Linear but fast.
+ unsigned n_tests = 0;
+ struct testgroup_t *tg;
+ struct testcase_t *tc;
+ for (tg = testgroups; tg->prefix != NULL; ++tg) {
+ for (tc = tg->cases; tc->name != NULL; ++tc) {
+ ++n_tests;
+ }
+ }
+ // Which tests should we run? This can give iffy results if den is huge
+ // but it doesn't actually matter in practice.
+ unsigned tests_per_chunk = CEIL_DIV(n_tests, den);
+ unsigned start_at = (num-1) * tests_per_chunk;
+
+ // Skip the tests that are outside of the range.
+ unsigned idx = 0;
+ for (tg = testgroups; tg->prefix != NULL; ++tg) {
+ for (tc = tg->cases; tc->name != NULL; ++tc) {
+ if (idx < start_at || idx >= start_at + tests_per_chunk) {
+ tc->flags |= TT_SKIP;
+ }
+ ++idx;
+ }
+ }
+ }
+
int have_failed = (tinytest_main(c, v, testgroups) != 0);
free_pregenerated_keys();