[blobfs] Port QueryInfoTest.

This CL also makes sure that the base fixture of FVM tests operate over
an FVM volume (otherwise this test fails).

ZX-4203 #comment Port BlobfsTestWithFvm.QueryInfo

Change-Id: I50b0616d127bc140ae65d71142922cae2f97311a
diff --git a/zircon/system/ulib/blobfs/test/integration/blobfs_integration_test.cpp b/zircon/system/ulib/blobfs/test/integration/blobfs_integration_test.cpp
index 22cadb9..9aab6eb 100644
--- a/zircon/system/ulib/blobfs/test/integration/blobfs_integration_test.cpp
+++ b/zircon/system/ulib/blobfs/test/integration/blobfs_integration_test.cpp
@@ -5,6 +5,9 @@
 #include <errno.h>
 #include <fcntl.h>
 
+#include <fuchsia/io/c/fidl.h>
+#include <lib/fzl/fdio.h>
+#include <zircon/device/vfs.h>
 #include <zxtest/zxtest.h>
 
 #include "blobfs_test.h"
@@ -65,37 +68,6 @@
     return true;
 }
 
-bool QueryInfo(size_t expected_nodes, size_t expected_bytes) {
-    fbl::unique_fd fd(open(MOUNT_PATH, O_RDONLY | O_DIRECTORY));
-    ASSERT_TRUE(fd);
-
-    zx_status_t status;
-    fuchsia_io_FilesystemInfo info;
-    fzl::FdioCaller caller(std::move(fd));
-    ASSERT_EQ(fuchsia_io_DirectoryAdminQueryFilesystem(caller.borrow_channel(), &status, &info),
-              ZX_OK);
-    ASSERT_EQ(status, ZX_OK);
-    const char* kFsName = "blobfs";
-    const char* name = reinterpret_cast<const char*>(info.name);
-    ASSERT_EQ(close(caller.release().release()), 0);
-    ASSERT_EQ(strncmp(name, kFsName, strlen(kFsName)), 0, "Unexpected filesystem mounted");
-    ASSERT_EQ(info.block_size, blobfs::kBlobfsBlockSize);
-    ASSERT_EQ(info.max_filename_size, Digest::kLength * 2);
-    ASSERT_EQ(info.fs_type, VFS_TYPE_BLOBFS);
-    ASSERT_NE(info.fs_id, 0);
-
-    // Check that used_bytes are within a reasonable range
-    ASSERT_GE(info.used_bytes, expected_bytes);
-    ASSERT_LE(info.used_bytes, info.total_bytes);
-
-    // Check that total_bytes are a multiple of slice_size
-    ASSERT_GE(info.total_bytes, kTestFvmSliceSize);
-    ASSERT_EQ(info.total_bytes % kTestFvmSliceSize, 0);
-    ASSERT_EQ(info.total_nodes, kTestFvmSliceSize / blobfs::kBlobfsInodeSize);
-    ASSERT_EQ(info.used_nodes, expected_nodes);
-    return true;
-}
-
 */
 
 // Go over the parent device logic and test fixture.
@@ -107,7 +79,7 @@
 
 void RunBasicsTest() {
     for (unsigned int i = 10; i < 16; i++) {
-        fbl::unique_ptr<fs_test_utils::BlobInfo> info;
+        std::unique_ptr<fs_test_utils::BlobInfo> info;
         ASSERT_TRUE(fs_test_utils::GenerateRandomBlob(kMountPath, 1 << i, &info));
 
         fbl::unique_fd fd;
@@ -141,7 +113,7 @@
 }
 
 void RunUnallocatedBlobTest() {
-    fbl::unique_ptr<fs_test_utils::BlobInfo> info;
+    std::unique_ptr<fs_test_utils::BlobInfo> info;
     ASSERT_TRUE(fs_test_utils::GenerateRandomBlob(kMountPath, 1 << 10, &info));
 
     // We can create a blob with a name.
@@ -166,7 +138,7 @@
 }
 
 void RunNullBlobTest() {
-    fbl::unique_ptr<fs_test_utils::BlobInfo> info;
+    std::unique_ptr<fs_test_utils::BlobInfo> info;
     ASSERT_TRUE(fs_test_utils::GenerateRandomBlob(kMountPath, 0, &info));
 
     fbl::unique_fd fd(open(info->path, O_CREAT | O_EXCL | O_RDWR));
@@ -443,27 +415,55 @@
     END_TEST;
 }
 
-static bool TestQueryInfo(BlobfsTest* blobfsTest) {
-    BEGIN_HELPER;
-    ASSERT_EQ(blobfsTest->GetType(), FsTestType::kFvm);
+*/
 
+void QueryInfo(size_t expected_nodes, size_t expected_bytes) {
+    fbl::unique_fd fd(open(kMountPath, O_RDONLY | O_DIRECTORY));
+    ASSERT_TRUE(fd);
+
+    zx_status_t status;
+    fuchsia_io_FilesystemInfo info;
+    fzl::FdioCaller caller(std::move(fd));
+    ASSERT_OK(fuchsia_io_DirectoryAdminQueryFilesystem(caller.borrow_channel(), &status, &info));
+    ASSERT_OK(status);
+
+    const char kFsName[] = "blobfs";
+    const char* name = reinterpret_cast<const char*>(info.name);
+    ASSERT_STR_EQ(kFsName, name, "Unexpected filesystem mounted");
+    EXPECT_EQ(info.block_size, blobfs::kBlobfsBlockSize);
+    EXPECT_EQ(info.max_filename_size, digest::Digest::kLength * 2);
+    EXPECT_EQ(info.fs_type, VFS_TYPE_BLOBFS);
+    EXPECT_NE(info.fs_id, 0);
+
+    // Check that used_bytes are within a reasonable range
+    EXPECT_GE(info.used_bytes, expected_bytes);
+    EXPECT_LE(info.used_bytes, info.total_bytes);
+
+    // Check that total_bytes are a multiple of slice_size
+    EXPECT_GE(info.total_bytes, kTestFvmSliceSize);
+    EXPECT_EQ(info.total_bytes % kTestFvmSliceSize, 0);
+    EXPECT_EQ(info.total_nodes, kTestFvmSliceSize / blobfs::kBlobfsInodeSize);
+    EXPECT_EQ(info.used_nodes, expected_nodes);
+}
+
+TEST_F(BlobfsTestWithFvm, QueryInfo) {
     size_t total_bytes = 0;
-    ASSERT_TRUE(QueryInfo(0, 0));
+    ASSERT_NO_FAILURES(QueryInfo(0, 0));
     for (size_t i = 10; i < 16; i++) {
-        fbl::unique_ptr<fs_test_utils::BlobInfo> info;
-        ASSERT_TRUE(fs_test_utils::GenerateRandomBlob(MOUNT_PATH, 1 << i, &info));
+        std::unique_ptr<fs_test_utils::BlobInfo> info;
+        ASSERT_TRUE(fs_test_utils::GenerateRandomBlob(kMountPath, 1 << i, &info));
 
         fbl::unique_fd fd;
-        ASSERT_TRUE(MakeBlob(info.get(), &fd));
-        ASSERT_EQ(close(fd.release()), 0);
+        ASSERT_NO_FAILURES(MakeBlob(info.get(), &fd));
         total_bytes += fbl::round_up(info->size_merkle + info->size_data,
-                       blobfs::kBlobfsBlockSize);
+                                     blobfs::kBlobfsBlockSize);
     }
 
-    ASSERT_TRUE(QueryInfo(6, total_bytes));
-    END_HELPER;
+    ASSERT_NO_FAILURES(QueryInfo(6, total_bytes));
 }
 
+/*
+
 bool GetAllocations(zx::vmo* out_vmo, uint64_t* out_count) {
     BEGIN_HELPER;
     fbl::unique_fd fd(open(MOUNT_PATH, O_RDONLY | O_DIRECTORY));
@@ -2046,7 +2046,6 @@
 RUN_TESTS(MEDIUM, TestMmapUseAfterClose)
 RUN_TESTS(MEDIUM, TestReaddir)
 RUN_TESTS(MEDIUM, TestDiskTooSmall)
-RUN_TEST_FVM(MEDIUM, TestQueryInfo)
 RUN_TESTS(MEDIUM, TestGetAllocatedRegions)
 RUN_TESTS(MEDIUM, UseAfterUnlink)
 RUN_TESTS(MEDIUM, WriteAfterRead)
diff --git a/zircon/system/ulib/blobfs/test/integration/blobfs_test.cpp b/zircon/system/ulib/blobfs/test/integration/blobfs_test.cpp
index bb8a7e1..e0d904f 100644
--- a/zircon/system/ulib/blobfs/test/integration/blobfs_test.cpp
+++ b/zircon/system/ulib/blobfs/test/integration/blobfs_test.cpp
@@ -51,7 +51,7 @@
 
 void BlobfsTest::SetUp() {
     ASSERT_TRUE(mkdir(kMountPath, 0755) == 0 || errno == EEXIST, "Could not create mount point");
-    ASSERT_OK(mkfs(device_path_, DISK_FORMAT_BLOBFS, launch_stdio_sync, &default_mkfs_options));
+    ASSERT_OK(mkfs(device_path_.c_str(), DISK_FORMAT_BLOBFS, launch_stdio_sync, &default_mkfs_options));
     Mount();
 }
 
@@ -71,7 +71,7 @@
     ASSERT_FALSE(mounted_);
     int flags = read_only_ ? O_RDONLY : O_RDWR;
 
-    fbl::unique_fd fd(open(device_path_, flags));
+    fbl::unique_fd fd(open(device_path_.c_str(), flags));
     ASSERT_TRUE(fd, "Could not open ramdisk");
 
     mount_options_t options = default_mount_options;
@@ -103,16 +103,16 @@
         .force = true,
         .apply_journal = true,
     };
-    return fsck(device_path_, DISK_FORMAT_BLOBFS, &test_fsck_options, launch_stdio_sync);
+    return fsck(device_path_.c_str(), DISK_FORMAT_BLOBFS, &test_fsck_options, launch_stdio_sync);
 }
 
 void BlobfsTest::CheckInfo() {
     fuchsia_io_FilesystemInfo info;
     ASSERT_TRUE(GetFsInfo(&info));
 
-    const char* kFsName = "blobfs";
+    const char kFsName[] = "blobfs";
     const char* name = reinterpret_cast<const char*>(info.name);
-    ASSERT_EQ(strncmp(name, kFsName, strlen(kFsName)), 0, "Unexpected filesystem mounted");
+    ASSERT_STR_EQ(kFsName, name);
     ASSERT_LE(info.used_nodes, info.total_nodes, "Used nodes greater than free nodes");
     ASSERT_LE(info.used_bytes, info.total_bytes, "Used bytes greater than free bytes");
 }
@@ -133,11 +133,11 @@
 
 void BlobfsTestWithFvm::TearDown() {
     BlobfsTest::TearDown();
-    ASSERT_OK(fvm_destroy(device_path_));
+    ASSERT_OK(fvm_destroy(partition_path_.c_str()));
 }
 
 void BlobfsTestWithFvm::BindFvm() {
-    fbl::unique_fd fd(open(device_path_, O_RDWR));
+    fbl::unique_fd fd(open(device_path_.c_str(), O_RDWR));
     ASSERT_TRUE(fd, "Could not open test disk");
     ASSERT_OK(fvm_init(fd.get(), kTestFvmSliceSize));
 
@@ -170,6 +170,10 @@
     char path[PATH_MAX];
     fd.reset(open_partition(kTestUniqueGUID, kTestPartGUID, 0, path));
     ASSERT_TRUE(fd, "Could not locate FVM partition");
+
+    // The base test must see the FVM volume as the device to work with.
+    partition_path_.swap(device_path_);
+    device_path_.assign(path);
 }
 
 void MakeBlob(const fs_test_utils::BlobInfo* info, fbl::unique_fd* fd) {
diff --git a/zircon/system/ulib/blobfs/test/integration/blobfs_test.h b/zircon/system/ulib/blobfs/test/integration/blobfs_test.h
index 24f64fe..4c612db 100644
--- a/zircon/system/ulib/blobfs/test/integration/blobfs_test.h
+++ b/zircon/system/ulib/blobfs/test/integration/blobfs_test.h
@@ -55,7 +55,7 @@
 
     FsTestType type_;
     Environment* environment_;
-    const char* device_path_;
+    std::string device_path_;
     bool read_only_ = false;
     bool mounted_ = false;
 };
@@ -75,6 +75,7 @@
     void CreatePartition();
 
     std::string fvm_path_;
+    std::string partition_path_;
 };
 
 // Creates an open blob with the provided Merkle tree + Data, and reads back to