Reload Partition object after FS creation in read tests (!49)
Here are the errors reported in the deliberately broken CreateAndReadLabel test from the previous commit message: [ RUN ] ext2Test.CreateAndReadLabel test_ext2.cc:311: Failure Value of: m_partition.get_messages().empty() Actual: false Expected: true Partition messages: e2label: No such file or directory while trying to open /does_not_exist/test_ext2.img Couldn't find valid filesystem superblock. [ FAILED ] ext2Test.CreateAndReadLabel (77 ms) Even though the test was deliberately broken by setting the wrong path for the file system image and the e2label command failed, apparently testing for the expected label still passed. What happened was that the desired "TEST_LABEL" has to be in the Partition object and then the file system was created. Then reading the file system label failed, however "TEST_LABEL" was already set in the Partition object so it matched. Reading the label is unique among the read actions of usage, label and UUID as the others don't need to be set before the file system is created. GParted doesn't encounter this issue because when refreshing devices it creates new blank Partition objects and then performs the read actions to populate them. Fix by resetting the Partition object back to only containing basic information before all the reading file system information tests, even though it is only needed in the read label case. This also better reflects how GParted works. Now with the same deliberate brokenness the test also reports the label does not match it's expected value: $ ./test_ext2 --gtest_filter='ext2Test.CreateAndReadLabel' Running main() from test_ext2.cc Note: Google Test filter = ext2Test.CreateAndReadLabel [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from ext2Test [ RUN ] ext2Test.CreateAndReadLabel test_ext2.cc:322: Failure Expected equality of these values: fs_label Which is: "TEST_LABEL" m_partition.get_filesystem_label().c_str() Which is: "" test_ext2.cc:272: Failure Value of: m_partition.get_messages().empty() Actual: false Expected: true Partition messages: e2label: No such file or directory while trying to open /does_not_exist/test_ext2.img Couldn't find valid filesystem superblock. [ FAILED ] ext2Test.CreateAndReadLabel (70 ms) [----------] 1 test from ext2Test (70 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (75 ms total) [ PASSED ] 0 tests. [ FAILED ] 1 test, listed below: [ FAILED ] ext2Test.CreateAndReadLabel 1 FAILED TEST Closes !49 - Add file system interface tests
This commit is contained in:
parent
e4a479214d
commit
571525084b
|
@ -190,6 +190,8 @@ protected:
|
|||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
|
||||
virtual void reload_partition();
|
||||
|
||||
static FileSystem* s_ext2_obj;
|
||||
static FS s_ext2_support;
|
||||
static const char* s_image_name;
|
||||
|
@ -217,20 +219,7 @@ void ext2Test::extra_setup()
|
|||
<< ImageSize << ". errno=" << errno << "," << strerror(errno);
|
||||
close(fd);
|
||||
|
||||
// Use libparted to get the sector size etc. of the image file.
|
||||
PedDevice* lp_device = ped_device_get(s_image_name);
|
||||
ASSERT_TRUE(lp_device != NULL);
|
||||
|
||||
// Prepare partition object spanning whole of the image file.
|
||||
m_partition.set_unpartitioned(s_image_name,
|
||||
lp_device->path,
|
||||
FS_EXT2,
|
||||
lp_device->length,
|
||||
lp_device->sector_size,
|
||||
false);
|
||||
|
||||
ped_device_destroy(lp_device);
|
||||
lp_device = NULL;
|
||||
reload_partition();
|
||||
}
|
||||
|
||||
|
||||
|
@ -257,6 +246,29 @@ void ext2Test::TearDownTestCase()
|
|||
}
|
||||
|
||||
|
||||
// (Re)initialise m_partition as a Partition object spanning the whole of the image file
|
||||
// with file system type only. No file system usage, label or UUID.
|
||||
void ext2Test::reload_partition()
|
||||
{
|
||||
m_partition.Reset();
|
||||
|
||||
// Use libparted to get the sector size etc. of the image file.
|
||||
PedDevice* lp_device = ped_device_get(s_image_name);
|
||||
ASSERT_TRUE(lp_device != NULL);
|
||||
|
||||
// Prepare partition object spanning whole of the image file.
|
||||
m_partition.set_unpartitioned(s_image_name,
|
||||
lp_device->path,
|
||||
FS_EXT2,
|
||||
lp_device->length,
|
||||
lp_device->sector_size,
|
||||
false);
|
||||
|
||||
ped_device_destroy(lp_device);
|
||||
lp_device = NULL;
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ext2Test, Create)
|
||||
{
|
||||
SKIP_IF_FS_DOESNT_SUPPORT(create);
|
||||
|
@ -274,6 +286,7 @@ TEST_F(ext2Test, CreateAndReadUsage)
|
|||
extra_setup();
|
||||
ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
|
||||
|
||||
reload_partition();
|
||||
s_ext2_obj->set_used_sectors(m_partition);
|
||||
// Test file system usage is reported correctly.
|
||||
// Used is between 0 and length.
|
||||
|
@ -303,6 +316,7 @@ TEST_F(ext2Test, CreateAndReadLabel)
|
|||
ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
|
||||
|
||||
// Test reading the label is successful.
|
||||
reload_partition();
|
||||
s_ext2_obj->read_label(m_partition);
|
||||
EXPECT_STREQ(fs_label, m_partition.get_filesystem_label().c_str());
|
||||
|
||||
|
@ -320,6 +334,7 @@ TEST_F(ext2Test, CreateAndReadUUID)
|
|||
ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
|
||||
|
||||
// Test reading the UUID is successful.
|
||||
reload_partition();
|
||||
s_ext2_obj->read_uuid(m_partition);
|
||||
EXPECT_EQ(m_partition.uuid.size(), 36U);
|
||||
|
||||
|
|
Loading…
Reference in New Issue