diff options
author | teor <teor2345@gmail.com> | 2016-11-02 14:14:19 +1100 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2016-11-02 14:14:19 +1100 |
commit | 77e1d660ee5b8e2beae12f3de543d19009aaa8ac (patch) | |
tree | c572af2af2c34dd4dce9080eae092b8a118be049 | |
parent | d7634dc5196801c5a3e6be9eb2167c2c96f48ab4 (diff) | |
download | tor-77e1d660ee5b8e2beae12f3de543d19009aaa8ac.tar.gz tor-77e1d660ee5b8e2beae12f3de543d19009aaa8ac.zip |
Add get_fname_rnd for unit tests that want a unique path every time
-rw-r--r-- | src/test/test.h | 1 | ||||
-rw-r--r-- | src/test/testing_common.c | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/test/test.h b/src/test/test.h index 770f403cee..25336ac83e 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -73,6 +73,7 @@ {print_ = (I64_PRINTF_TYPE) value_;}, {}, TT_EXIT_TEST_FUNCTION) const char *get_fname(const char *name); +const char *get_fname_rnd(const char *name); struct crypto_pk_t *pk_generate(int idx); #define US2_CONCAT_2__(a, b) a ## __ ## b diff --git a/src/test/testing_common.c b/src/test/testing_common.c index e28e3dd457..1eae07e450 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -125,6 +125,18 @@ 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) |