From fde76a949fbd9ba7bff30579626a6ff812b555ff Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Fri, 1 Jul 2022 09:09:52 +0100 Subject: [PATCH] Add CreateAndWriteUUIDAndReadLabel unit test (!104) During review and testing of this patchset it was discovered that using GParted to set a new UUID on a FAT16 or FAT32 file system that there was a new unwanted side effect of clearing the label. Add unit test to cover this error scenario. It does the following: 1. Creates a file system with a known label; 2. Writes a new UUID; 3. Reads the label and confirms it matches the initial label. This new unit test captures the fault like this: $ ./test_SupportedFileSystems --gtest_filter='*CreateAndWriteUUIDAndReadLabel*' ... [ RUN ] My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/fat16 test_SupportedFileSystems.cc:645: Failure Expected equality of these values: fs_label Which is: "TEST_LABEL" m_partition.get_filesystem_label().c_str() Which is: "" [ FAILED ] My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/fat16, where GetParam() = 13 (21 ms) [ RUN ] My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/fat32 test_SupportedFileSystems.cc:645: Failure Expected equality of these values: fs_label Which is: "TEST_LABEL" m_partition.get_filesystem_label().c_str() Which is: "" [ FAILED ] My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/fat32, where GetParam() = 14 (22 ms) Don't forget to exclude this unit test for file systems which need a loop device but which fails to be created inside the docker CI image. Reference: 39fdfe51da4bddecb2c99a9b544b270130423e72 Exclude unit tests needing losetup in Docker CI image (!59) Closes !104 - Add Alpine Linux CI jobs and resolve label and UUID issues with FAT16/32 --- .gitlab-ci.yml | 3 +++ tests/test_SupportedFileSystems.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a01535b..63f9cb6e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -92,6 +92,9 @@ stages: - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteLabel/nilfs2" - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteUUID/lvm2pv" - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteUUID/nilfs2" + - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/btrfs" + - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/lvm2pv" + - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndWriteUUIDAndReadLabel/nilfs2" - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndCheck/lvm2pv" - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndRemove/lvm2pv" - GTEST_FILTER="$GTEST_FILTER:My/SupportedFileSystemsTest.CreateAndGrow/btrfs" diff --git a/tests/test_SupportedFileSystems.cc b/tests/test_SupportedFileSystems.cc index f38c2407..f08b29b8 100644 --- a/tests/test_SupportedFileSystems.cc +++ b/tests/test_SupportedFileSystems.cc @@ -617,6 +617,33 @@ TEST_P(SupportedFileSystemsTest, CreateAndWriteUUID) } +TEST_P(SupportedFileSystemsTest, CreateAndWriteUUIDAndReadLabel) +{ + SKIP_IF_FS_DOESNT_SUPPORT(create); + SKIP_IF_FS_DOESNT_SUPPORT(write_uuid); + SKIP_IF_FS_DOESNT_SUPPORT(read_label); + SKIP_IF_NOT_ROOT_FOR_REQUIRED_LOOPDEV_FOR_FS(FS_BTRFS); + SKIP_IF_NOT_ROOT_FOR_REQUIRED_LOOPDEV_FOR_FS(FS_LVM2_PV); + SKIP_IF_NOT_ROOT_FOR_REQUIRED_LOOPDEV_FOR_FS(FS_NILFS2); + + const char* fs_label = "TEST_LABEL"; + create_image_file(); + m_partition.set_filesystem_label(fs_label); + ASSERT_TRUE(m_fs_object->create(m_partition, m_operation_detail)) << m_operation_detail; + + // Test writing a new random UUID is successful. + ASSERT_TRUE(m_fs_object->write_uuid(m_partition, m_operation_detail)) << m_operation_detail; + + // Test reading the label is successful and it hasn't changed. + reload_partition(); + m_fs_object->read_label(m_partition); + EXPECT_STREQ(fs_label, m_partition.get_filesystem_label().c_str()); + + // Test messages from read operation are empty or print them. + EXPECT_TRUE(m_partition.get_messages().empty()) << m_partition; +} + + TEST_P(SupportedFileSystemsTest, CreateAndCheck) { SKIP_IF_FS_DOESNT_SUPPORT(create);