@@ -35,7 +35,12 @@ static char *concat_path(const char* a, const char* b)
static void init_local_test_path(void)
{
char *pwd = g_get_current_dir();
- local_test_path = concat_path(pwd, "qtest-9p-local");
+ char *template = concat_path(pwd, "qtest-9p-local-XXXXXX");
+ local_test_path = mkdtemp(template);
+ if (!local_test_path) {
+ g_test_message("mkdtemp('%s') failed: %s", template, strerror(errno));
+ }
+ g_assert(local_test_path);
g_free(pwd);
}
@@ -246,11 +251,6 @@ static void virtio_9p_register_nodes(void)
const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG;
const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG;
- /* make sure test dir for the 'local' tests exists and is clean */
- init_local_test_path();
- remove_local_test_dir();
- create_local_test_dir();
-
QPCIAddress addr = {
.devfn = QPCI_DEVFN(4, 0),
};
@@ -278,3 +278,16 @@ static void virtio_9p_register_nodes(void)
}
libqos_init(virtio_9p_register_nodes);
+
+static void __attribute__((constructor)) construct_virtio_9p(void)
+{
+ /* make sure test dir for the 'local' tests exists */
+ init_local_test_path();
+ create_local_test_dir();
+}
+
+static void __attribute__((destructor)) destruct_virtio_9p(void)
+{
+ /* remove previously created test dir when test suite completed */
+ remove_local_test_dir();
+}