summaryrefslogtreecommitdiff
path: root/src/test/testing_common.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-11-07 16:12:13 -0500
committerNick Mathewson <nickm@torproject.org>2016-11-07 16:12:13 -0500
commitc2fc0941a53884c63c477f68c74a26627bb35db8 (patch)
tree58b30f597f9e7e10a0cfe7806e9c028fc19d9560 /src/test/testing_common.c
parente482541cfb0bd85cab8a7fed86e31e0b18912730 (diff)
parenta77187a52c9594c0c168596eec856ee11c447fe0 (diff)
downloadtor-c2fc0941a53884c63c477f68c74a26627bb35db8.tar.gz
tor-c2fc0941a53884c63c477f68c74a26627bb35db8.zip
Merge remote-tracking branch 'teor/bug20484_029_v2' into maint-0.2.9
Diffstat (limited to 'src/test/testing_common.c')
-rw-r--r--src/test/testing_common.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index fd7c4e7074..9c6580f788 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -102,18 +102,41 @@ setup_directory(void)
temp_dir_setup_in_pid = getpid();
}
-/** Return a filename relative to our testing temporary directory */
-const char *
-get_fname(const char *name)
+/** Return a filename relative to our testing temporary directory, based on
+ * name and suffix. If name is NULL, return the name of the testing temporary
+ * directory. */
+static const char *
+get_fname_suffix(const char *name, const char *suffix)
{
static char buf[1024];
setup_directory();
if (!name)
return temp_dir;
- tor_snprintf(buf,sizeof(buf),"%s/%s",temp_dir,name);
+ tor_snprintf(buf,sizeof(buf),"%s/%s%s%s",temp_dir,name,suffix ? "_" : "",
+ suffix ? suffix : "");
return buf;
}
+/** Return a filename relative to our testing temporary directory. If name is
+ * NULL, return the name of the testing temporary directory. */
+const char *
+get_fname(const char *name)
+{
+ return get_fname_suffix(name, NULL);
+}
+
+/** Return a filename with a random suffix, relative to our testing temporary
+ * directory. If name is NULL, return the name of the testing temporary
+ * directory, without any suffix. */
+const char *
+get_fname_rnd(const char *name)
+{
+ char rnd[256], rnd32[256];
+ crypto_rand(rnd, RAND_PATH_BYTES);
+ base32_encode(rnd32, sizeof(rnd32), rnd, RAND_PATH_BYTES);
+ return get_fname_suffix(name, rnd32);
+}
+
/* Remove a directory and all of its subdirectories */
static void
rm_rf(const char *dir)
@@ -217,6 +240,9 @@ free_pregenerated_keys(void)
static void *
passthrough_test_setup(const struct testcase_t *testcase)
{
+ /* Make sure the passthrough doesn't unintentionally fail or skip tests */
+ tor_assert(testcase->setup_data);
+ tor_assert(testcase->setup_data != (void*)TT_SKIP);
return testcase->setup_data;
}
static int