aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-08-15 21:20:19 -0400
committerNick Mathewson <nickm@torproject.org>2010-08-15 21:20:19 -0400
commit5757f47fc34235675d67b71c68b207582b245ca8 (patch)
treef1ac945d5970ef7dd124fd11ae08123e712ed507 /src/test
parent8394c7020470ffd300b237c4759c4813205a1899 (diff)
downloadtor-5757f47fc34235675d67b71c68b207582b245ca8.tar
tor-5757f47fc34235675d67b71c68b207582b245ca8.tar.gz
Make unit tests work when tests get run in subprocesses.
Apparently the way we handled cleaning up temporary directories with atexit() meant that when the child process exited, it would remove the temporary directory, thus making other tests in the main process fail.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/test/test.c b/src/test/test.c
index f0f86cdb5..2d396b581 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -70,6 +70,7 @@ int have_failed = 0;
/** Temporary directory (set up by setup_directory) under which we store all
* our files during testing. */
static char temp_dir[256];
+static pid_t temp_dir_setup_in_pid = 0;
/** Select and create the temporary directory we'll use to run our unit tests.
* Store it in <b>temp_dir</b>. Exit immediately if we can't create it.
@@ -96,6 +97,7 @@ setup_directory(void)
exit(1);
}
is_setup = 1;
+ temp_dir_setup_in_pid = getpid();
}
/** Return a filename relative to our testing temporary directory */
@@ -109,11 +111,16 @@ get_fname(const char *name)
}
/** Remove all files stored under the temporary directory, and the directory
- * itself. */
+ * itself. Called by atexit(). */
static void
remove_directory(void)
{
- smartlist_t *elements = tor_listdir(temp_dir);
+ smartlist_t *elements;
+ if (getpid() != temp_dir_setup_in_pid) {
+ /* Only clean out the tempdir when the main process is exiting. */
+ return;
+ }
+ elements = tor_listdir(temp_dir);
if (elements) {
SMARTLIST_FOREACH(elements, const char *, cp,
{