[dev][ftl]: Port BadBlock Test.
Technically they are testing the FTL behavior after successive failures.
From a single, two, three,... up to six.
We just do it once, with 100 consecutive failures and then Check
that the FTL stored the data correctly.
TEST=ftl-test -f *FtlBadBlock*
Change-Id: I7e9093281e74f218e53d0282f24b802d57be1e7d
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/372950
Commit-Queue: Gianfranco Valentino <gevalentino@google.com>
Reviewed-by: Ricardo Vargas <rvargas@google.com>
Testability-Review: Ricardo Vargas <rvargas@google.com>
diff --git a/src/devices/block/drivers/ftl/test/ftl-test.cc b/src/devices/block/drivers/ftl/test/ftl-test.cc
index 93491f7..e8128fdb 100644
--- a/src/devices/block/drivers/ftl/test/ftl-test.cc
+++ b/src/devices/block/drivers/ftl/test/ftl-test.cc
@@ -677,4 +677,28 @@
ASSERT_NO_FAILURES(CheckNdmHeaderVersion(driver, kControlPage1, 2, 0, buffer.data()));
}
+using FtlBadBlockTest = FtlTestWithDriverAccess;
+
+TEST_F(FtlBadBlockTest, FtlSucceedsAfterContinousFailures) {
+ auto options = kDefaultOptions;
+ options.max_bad_blocks = 10;
+ TestOptions driver_options = kDefaultTestOptions;
+ driver_options.bad_block_interval = 5;
+ driver_options.bad_block_burst = 10;
+
+ auto driver_to_pass = std::make_unique<NdmRamDriver>(options, driver_options);
+ // Retain a pointer. The driver's lifetime is tied to ftl_.
+ NdmRamDriver* driver = driver_to_pass.get();
+ ASSERT_NULL(driver->Init());
+ ASSERT_TRUE(ftl_.InitWithDriver(std::move(driver_to_pass)));
+ SetUpBaseTest();
+
+ // One page at a time.
+ SingleLoop(1);
+
+ ASSERT_NO_FATAL_FAILURES(CheckVolume(1, ftl_.num_pages()));
+ ASSERT_TRUE(ftl_.ReAttach());
+ ASSERT_NO_FATAL_FAILURES(CheckVolume(1, ftl_.num_pages()));
+}
+
} // namespace