aboutsummaryrefslogtreecommitdiff
path: root/src/test/testing_common.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-11-07 16:31:40 -0500
committerNick Mathewson <nickm@torproject.org>2016-11-07 16:31:40 -0500
commit3e3040a5d911e6c4ae59114a0f98daf09ee299bc (patch)
tree74ef382fdecab05746d0fb8ccbd81dd0a2c29878 /src/test/testing_common.c
parent7236e42684de017d66b38bac13c4f7ff8dac428c (diff)
parent9994404238e6b87907f811cab2a5126d030ff55d (diff)
downloadtor-3e3040a5d911e6c4ae59114a0f98daf09ee299bc.tar.gz
tor-3e3040a5d911e6c4ae59114a0f98daf09ee299bc.zip
Merge branch 'maint-0.2.9'
Conflicts: src/or/rendservice.c
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 deb11d0112..caeae13a38 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)
@@ -158,6 +181,9 @@ remove_directory(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