Skip to content

Commit 9ee1bb8

Browse files
bonzinimstsirkin
authored andcommitted
vhost-user-test: small changes to init_hugepagefs
After the conversion to qgraph, the equivalent of "main" will be in a constructor and will run even if the tests are not being requested. Therefore, it should not assert that init_hugepagefs succeeds and will be called when creating the TestServer. This patch changes the prototype of init_hugepagefs, this way the next patch looks nicer. Reviewed-by: Marc-André Lureau <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 7d0ca3e commit 9ee1bb8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/vhost-user-test.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,20 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
465465
g_mutex_unlock(&s->data_mutex);
466466
}
467467

468-
#ifdef CONFIG_LINUX
469-
static const char *init_hugepagefs(const char *path)
468+
static const char *init_hugepagefs(void)
470469
{
470+
#ifdef CONFIG_LINUX
471+
const char *path = getenv("QTEST_HUGETLBFS_PATH");
471472
struct statfs fs;
472473
int ret;
473474

475+
if (!path) {
476+
return NULL;
477+
}
478+
474479
if (access(path, R_OK | W_OK | X_OK)) {
475480
g_test_message("access on path (%s): %s\n", path, strerror(errno));
481+
abort();
476482
return NULL;
477483
}
478484

@@ -482,17 +488,21 @@ static const char *init_hugepagefs(const char *path)
482488

483489
if (ret != 0) {
484490
g_test_message("statfs on path (%s): %s\n", path, strerror(errno));
491+
abort();
485492
return NULL;
486493
}
487494

488495
if (fs.f_type != HUGETLBFS_MAGIC) {
489496
g_test_message("Warning: path not on HugeTLBFS: %s\n", path);
497+
abort();
490498
return NULL;
491499
}
492500

493501
return path;
494-
}
502+
#else
503+
return NULL;
495504
#endif
505+
}
496506

497507
static TestServer *test_server_new(const gchar *name)
498508
{
@@ -986,7 +996,6 @@ static void test_multiqueue(void)
986996

987997
int main(int argc, char **argv)
988998
{
989-
const char *hugefs;
990999
int ret;
9911000
char template[] = "/tmp/vhost-test-XXXXXX";
9921001

@@ -1001,14 +1010,7 @@ int main(int argc, char **argv)
10011010
}
10021011
g_assert(tmpfs);
10031012

1004-
root = tmpfs;
1005-
#ifdef CONFIG_LINUX
1006-
hugefs = getenv("QTEST_HUGETLBFS_PATH");
1007-
if (hugefs) {
1008-
root = init_hugepagefs(hugefs);
1009-
g_assert(root);
1010-
}
1011-
#endif
1013+
root = init_hugepagefs() ? : tmpfs;
10121014

10131015
if (qemu_memfd_check(0)) {
10141016
qtest_add_data_func("/vhost-user/read-guest-mem/memfd",

0 commit comments

Comments
 (0)