[utest][memfs] Convert tests to use zxtest instead of unittest
This was mostly automated, with one manual change:
* change a helper function: return void not bool; calls use ASSERT_NO_FATAL_FAILURES()
Bug: 51652
Test: runs on CQ, but tested locally with:
fx set bringup.x64 --with-base //garnet/packages/tests:zircon --with-base //bundles/bringup:tests
fx build
fx qemu -k -c zircon.autorun.boot=/boot/test/memfs
Change-Id: Iabec5bb97637b46d14ff4f47cf228c9261a97155
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/405385
Reviewed-by: George Kulakowski <kulakowski@google.com>
Testability-Review: George Kulakowski <kulakowski@google.com>
Commit-Queue: Mark Seaborn <mseaborn@google.com>
diff --git a/zircon/system/utest/memfs/BUILD.gn b/zircon/system/utest/memfs/BUILD.gn
index 86b31d1..6167f59 100644
--- a/zircon/system/utest/memfs/BUILD.gn
+++ b/zircon/system/utest/memfs/BUILD.gn
@@ -34,6 +34,7 @@
"//zircon/public/lib/fbl",
"//zircon/public/lib/sync",
"//zircon/public/lib/zx",
+ "//zircon/public/lib/zxtest",
"//zircon/system/ulib/async-default",
"//zircon/system/ulib/async-loop",
"//zircon/system/ulib/async-loop:async-loop-cpp",
@@ -44,6 +45,5 @@
"//zircon/system/ulib/memfs",
"//zircon/system/ulib/memfs:memfs-cpp",
"//zircon/system/ulib/trace-engine",
- "//zircon/system/ulib/unittest",
]
}
diff --git a/zircon/system/utest/memfs/fidl-tests.cc b/zircon/system/utest/memfs/fidl-tests.cc
index 3bf8d49..200d07b 100644
--- a/zircon/system/utest/memfs/fidl-tests.cc
+++ b/zircon/system/utest/memfs/fidl-tests.cc
@@ -25,15 +25,13 @@
#include <utility>
#include <fbl/unique_fd.h>
-#include <unittest/unittest.h>
+#include <zxtest/zxtest.h>
namespace {
namespace fio = ::llcpp::fuchsia::io;
-bool TestFidlBasic() {
- BEGIN_TEST;
-
+TEST(FidlTests, TestFidlBasic) {
memfs_filesystem_t* fs;
{
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
@@ -67,13 +65,9 @@
ASSERT_EQ(memfs_uninstall_unsafe(fs, "/fidltmp"), ZX_OK);
// No way to clean up the namespace entry. See ZX-2013 for more details.
-
- END_TEST;
}
-bool TestFidlOpenReadOnly() {
- BEGIN_TEST;
-
+TEST(FidlTests, TestFidlOpenReadOnly) {
memfs_filesystem_t* fs;
{
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
@@ -104,12 +98,9 @@
memfs_uninstall_unsafe(fs, "/fidltmp-ro");
// No way to clean up the namespace entry. See ZX-2013 for more details.
-
- END_TEST;
}
-bool QueryInfo(const char* path, fio::FilesystemInfo* info) {
- BEGIN_HELPER;
+void QueryInfo(const char* path, fio::FilesystemInfo* info) {
fbl::unique_fd fd(open(path, O_RDONLY | O_DIRECTORY));
ASSERT_TRUE(fd);
fdio_cpp::FdioCaller caller(std::move(fd));
@@ -126,12 +117,9 @@
ASSERT_EQ(info->fs_type, VFS_TYPE_MEMFS);
ASSERT_NE(info->fs_id, 0);
ASSERT_EQ(info->used_bytes % info->block_size, 0);
- END_HELPER;
}
-bool TestFidlQueryFilesystem() {
- BEGIN_TEST;
-
+TEST(FidlTests, TestFidlQueryFilesystem) {
{
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -142,7 +130,7 @@
// Sanity checks
fio::FilesystemInfo info;
- ASSERT_TRUE(QueryInfo("/fidltmp-basic", &info));
+ ASSERT_NO_FATAL_FAILURES(QueryInfo("/fidltmp-basic", &info));
// These values are nonsense, but they're the nonsense we expect memfs to generate.
ASSERT_EQ(info.total_bytes, UINT64_MAX);
@@ -153,14 +141,6 @@
}
// No way to clean up the namespace entry. See ZX-2013 for more details.
-
- END_TEST;
}
} // namespace
-
-BEGIN_TEST_CASE(fidl_tests)
-RUN_TEST(TestFidlBasic)
-RUN_TEST(TestFidlOpenReadOnly)
-RUN_TEST(TestFidlQueryFilesystem)
-END_TEST_CASE(fidl_tests)
diff --git a/zircon/system/utest/memfs/memfs-tests.cc b/zircon/system/utest/memfs/memfs-tests.cc
index cff6646..5d8940f 100644
--- a/zircon/system/utest/memfs/memfs-tests.cc
+++ b/zircon/system/utest/memfs/memfs-tests.cc
@@ -24,13 +24,11 @@
#include <fbl/unique_fd.h>
#include <fbl/vector.h>
-#include <unittest/unittest.h>
+#include <zxtest/zxtest.h>
namespace {
-bool TestMemfsNull() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsNull) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
memfs_filesystem_t* vfs;
@@ -41,13 +39,9 @@
sync_completion_t unmounted;
memfs_free_filesystem(vfs, &unmounted);
ASSERT_EQ(sync_completion_wait(&unmounted, zx::duration::infinite().get()), ZX_OK);
-
- END_TEST;
}
-bool TestMemfsBasic() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsBasic) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -76,9 +70,9 @@
// Readdir the file
struct dirent* de;
- ASSERT_NONNULL((de = readdir(d)));
+ ASSERT_NOT_NULL((de = readdir(d)));
ASSERT_EQ(strcmp(de->d_name, "."), 0);
- ASSERT_NONNULL((de = readdir(d)));
+ ASSERT_NOT_NULL((de = readdir(d)));
ASSERT_EQ(strcmp(de->d_name, filename), 0);
ASSERT_NULL(readdir(d));
@@ -86,13 +80,9 @@
sync_completion_t unmounted;
memfs_free_filesystem(vfs, &unmounted);
ASSERT_EQ(sync_completion_wait(&unmounted, zx::duration::infinite().get()), ZX_OK);
-
- END_TEST;
}
-bool TestMemfsAppend() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsAppend) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -130,13 +120,9 @@
sync_completion_t unmounted;
memfs_free_filesystem(vfs, &unmounted);
ASSERT_EQ(sync_completion_wait(&unmounted, zx::duration::infinite().get()), ZX_OK);
-
- END_TEST;
}
-bool TestMemfsInstall() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsInstall) {
memfs_filesystem_t* fs;
memfs_filesystem_t* fs_2;
{
@@ -165,9 +151,9 @@
// Readdir the file
struct dirent* de;
- ASSERT_NONNULL((de = readdir(d)));
+ ASSERT_NOT_NULL((de = readdir(d)));
ASSERT_EQ(strcmp(de->d_name, "."), 0);
- ASSERT_NONNULL((de = readdir(d)));
+ ASSERT_NOT_NULL((de = readdir(d)));
ASSERT_EQ(strcmp(de->d_name, filename), 0);
ASSERT_NULL(readdir(d));
@@ -184,13 +170,9 @@
memfs_uninstall_unsafe(fs, "/mytmp");
// No way to clean up the namespace entry. See ZX-2013 for more details.
-
- END_TEST;
}
-bool TestMemfsCloseDuringAccess() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsCloseDuringAccess) {
for (int i = 0; i < 100; i++) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -204,7 +186,7 @@
// Access files within the filesystem.
DIR* d = fdopendir(fd);
- ASSERT_NONNULL(d);
+ ASSERT_NOT_NULL(d);
thrd_t worker;
struct thread_args {
@@ -253,13 +235,9 @@
// only close the client side of the connection.
ASSERT_EQ(closedir(d), 0);
}
-
- END_TEST;
}
-bool TestMemfsOverflow() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsOverflow) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -272,7 +250,7 @@
// Access files within the filesystem.
DIR* d = fdopendir(root_fd);
- ASSERT_NONNULL(d);
+ ASSERT_NOT_NULL(d);
// Issue writes to the file in an order that previously would have triggered
// an overflow in the memfs write path.
@@ -290,12 +268,9 @@
sync_completion_t unmounted;
memfs_free_filesystem(vfs, &unmounted);
ASSERT_EQ(sync_completion_wait(&unmounted, zx::duration::infinite().get()), ZX_OK);
- END_TEST;
}
-bool TestMemfsDetachLinkedFilesystem() {
- BEGIN_TEST;
-
+TEST(MemfsTests, TestMemfsDetachLinkedFilesystem) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
@@ -308,7 +283,7 @@
// Access files within the filesystem.
DIR* d = fdopendir(root_fd);
- ASSERT_NONNULL(d);
+ ASSERT_NOT_NULL(d);
// Leave a regular file.
fbl::unique_fd fd(openat(dirfd(d), "file", O_CREAT | O_RDWR));
@@ -326,17 +301,6 @@
sync_completion_t unmounted;
memfs_free_filesystem(vfs, &unmounted);
ASSERT_EQ(sync_completion_wait(&unmounted, zx::duration::infinite().get()), ZX_OK);
- END_TEST;
}
} // namespace
-
-BEGIN_TEST_CASE(memfs_tests)
-RUN_TEST(TestMemfsNull)
-RUN_TEST(TestMemfsBasic)
-RUN_TEST(TestMemfsAppend)
-RUN_TEST(TestMemfsInstall)
-RUN_TEST(TestMemfsCloseDuringAccess)
-RUN_TEST(TestMemfsOverflow)
-RUN_TEST(TestMemfsDetachLinkedFilesystem)
-END_TEST_CASE(memfs_tests)
diff --git a/zircon/system/utest/memfs/vmofile-tests.cc b/zircon/system/utest/memfs/vmofile-tests.cc
index 8ac106f..0d8ab92 100644
--- a/zircon/system/utest/memfs/vmofile-tests.cc
+++ b/zircon/system/utest/memfs/vmofile-tests.cc
@@ -25,7 +25,7 @@
#include <zircon/syscalls.h>
#include <fbl/unique_fd.h>
-#include <unittest/unittest.h>
+#include <zxtest/zxtest.h>
namespace {
@@ -59,9 +59,7 @@
sync_completion_wait(&completion, zx::sec(5).get());
}
-bool test_vmofile_basic() {
- BEGIN_TEST;
-
+TEST(VmofileTests, test_vmofile_basic) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
async_dispatcher_t* dispatcher = loop.dispatcher();
@@ -133,13 +131,9 @@
}
shutdown_vfs(std::move(vfs));
-
- END_TEST;
}
-bool test_vmofile_exec() {
- BEGIN_TEST;
-
+TEST(VmofileTests, test_vmofile_exec) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
ASSERT_EQ(loop.StartThread(), ZX_OK);
async_dispatcher_t* dispatcher = loop.dispatcher();
@@ -207,13 +201,6 @@
}
shutdown_vfs(std::move(vfs));
-
- END_TEST;
}
} // namespace
-
-BEGIN_TEST_CASE(vmofile_tests)
-RUN_TEST(test_vmofile_basic)
-RUN_TEST(test_vmofile_exec)
-END_TEST_CASE(vmofile_tests)