Skip to content

Commit b4c7214

Browse files
committed
tests/9pfs: fix creator of 'local' test dir
The test dir for the 9pfs 'local' tests should not be created by a constructor in libqos, rather use a constructor on test unit side. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
1 parent df1e80d commit b4c7214

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

tests/qtest/libqos/virtio-9p.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ static void init_local_test_path(void)
5959
g_free(pwd);
6060
}
6161

62-
/* Creates the directory for the 9pfs 'local' filesystem driver to access. */
63-
static void create_local_test_dir(void)
62+
void virtio_9p_create_local_test_dir(void)
6463
{
6564
struct stat st;
6665
int res;
6766

67+
if (local_test_path) {
68+
return;
69+
}
70+
71+
init_local_test_path();
72+
6873
g_assert(local_test_path != NULL);
6974
res = mkdir(local_test_path, 0777);
7075
if (res < 0) {
@@ -78,8 +83,7 @@ static void create_local_test_dir(void)
7883
g_assert((st.st_mode & S_IFMT) == S_IFDIR);
7984
}
8085

81-
/* Deletes directory previously created by create_local_test_dir(). */
82-
static void remove_local_test_dir(void)
86+
void virtio_9p_remove_local_test_dir(void)
8387
{
8488
g_assert(local_test_path != NULL);
8589
char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path);
@@ -298,19 +302,3 @@ static void virtio_9p_register_nodes(void)
298302
}
299303

300304
libqos_init(virtio_9p_register_nodes);
301-
302-
static void __attribute__((constructor)) construct_virtio_9p(void)
303-
{
304-
/* make sure test dir for the 'local' tests exists */
305-
if (local_test_path) {
306-
return;
307-
}
308-
init_local_test_path();
309-
create_local_test_dir();
310-
}
311-
312-
static void __attribute__((destructor)) destruct_virtio_9p(void)
313-
{
314-
/* remove previously created test dir when test suite completed */
315-
remove_local_test_dir();
316-
}

tests/qtest/libqos/virtio-9p.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ struct QVirtio9PDevice {
4444
QVirtio9P v9p;
4545
};
4646

47+
/**
48+
* Creates the directory for the 9pfs 'local' filesystem driver to access.
49+
*/
50+
void virtio_9p_create_local_test_dir(void);
51+
52+
/**
53+
* Deletes directory previously created by virtio_9p_create_local_test_dir().
54+
*/
55+
void virtio_9p_remove_local_test_dir(void);
56+
4757
/**
4858
* Prepares QEMU command line for 9pfs tests using the 'local' fs driver.
4959
*/

tests/qtest/virtio-9p-test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,15 @@ static void register_virtio_9p_test(void)
14711471
}
14721472

14731473
libqos_init(register_virtio_9p_test);
1474+
1475+
static void __attribute__((constructor)) construct_9p_test(void)
1476+
{
1477+
/* make sure test dir for the 'local' tests exists */
1478+
virtio_9p_create_local_test_dir();
1479+
}
1480+
1481+
static void __attribute__((destructor)) destruct_9p_test(void)
1482+
{
1483+
/* remove previously created test dir when test suite completed */
1484+
virtio_9p_remove_local_test_dir();
1485+
}

0 commit comments

Comments
 (0)