X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fdisk_writer_test.cc;h=553adcae7188693f8c330a0b7018e6c0f1894a43;hb=182b9d2e2feb6545592868606aaf0f0146095481;hp=32cd76bc3c8f2209d16d67038cbaa254253fec85;hpb=46b0a3c2c8fa25b9881c4ae64a42682959464217;p=dcpomatic.git diff --git a/test/disk_writer_test.cc b/test/disk_writer_test.cc index 32cd76bc3..553adcae7 100644 --- a/test/disk_writer_test.cc +++ b/test/disk_writer_test.cc @@ -40,18 +40,6 @@ using std::string; using std::vector; -static -void -create_empty (boost::filesystem::path file, int size) -{ - auto fd = open (file.string().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); - BOOST_REQUIRE (fd != -1); - auto const r = posix_fallocate (fd, 0, size); - BOOST_REQUIRE_EQUAL (r, 0); - close (fd); -} - - vector ext2_ls (vector arguments) { @@ -70,6 +58,18 @@ ext2_ls (vector arguments) } +static +void +make_empty_file(boost::filesystem::path file, off_t size) +{ + auto fd = open (file.string().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + BOOST_REQUIRE (fd != -1); + auto const r = posix_fallocate (fd, 0, size); + BOOST_REQUIRE_EQUAL (r, 0); + close (fd); +} + + /** Use the writer code to make a disk and partition and copy a file (in a directory) * to it, then check that: * - the partition has inode size 128 @@ -81,25 +81,26 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1) using namespace boost::filesystem; using namespace boost::process; - remove_all ("build/test/disk_writer_test1.disk"); - remove_all ("build/test/disk_writer_test1.partition"); - remove_all ("build/test/disk_writer_test1"); + Cleanup cl; path disk = "build/test/disk_writer_test1.disk"; path partition = "build/test/disk_writer_test1.partition"; + cl.add(disk); + cl.add(partition); + /* lwext4 has a lower limit of correct ext2 partition sizes it can make; 32Mb * does not work here: fsck gives errors about an incorrect free blocks count. */ - create_empty (disk, 256 * 1024 * 1024); - create_empty (partition, 256 * 1024 * 1024); + make_random_file(disk, 256 * 1024 * 1024); + make_random_file(partition, 256 * 1024 * 1024); path dcp = "build/test/disk_writer_test1"; create_directory (dcp); /* Some arbitrary file size here */ make_random_file (dcp / "foo", 1024 * 1024 * 32 - 6128); - dcpomatic::write (dcp, disk.string(), partition.string(), 0); + dcpomatic::write ({dcp}, disk.string(), partition.string(), nullptr); BOOST_CHECK_EQUAL (system("/sbin/e2fsck -fn build/test/disk_writer_test1.partition"), 0); @@ -136,6 +137,96 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1) system ("e2cp " + partition.string() + ":disk_writer_test1/foo build/test/disk_writer_test1_foo_back"); check_file ("build/test/disk_writer_test1/foo", "build/test/disk_writer_test1_foo_back"); + + cl.run(); +} + + +BOOST_AUTO_TEST_CASE (disk_writer_test2) +{ + using namespace boost::filesystem; + using namespace boost::process; + + remove_all("build/test/disk_writer_test2.disk"); + remove_all("build/test/disk_writer_test2.partition"); + remove_all("build/test/disk_writer_test2"); + + Cleanup cl; + + path const disk = "build/test/disk_writer_test2.disk"; + path const partition = "build/test/disk_writer_test2.partition"; + + cl.add(disk); + cl.add(partition); + + /* Using empty files here still triggers the bug and is much quicker than using random data */ + make_empty_file(disk, 31043616768LL); + make_empty_file(partition, 31043571712LL); + + auto const dcp = TestPaths::private_data() / "xm"; + dcpomatic::write({dcp}, disk.string(), partition.string(), nullptr); + + BOOST_CHECK_EQUAL(system("/sbin/e2fsck -fn build/test/disk_writer_test2.partition"), 0); + + path const check = "build/test/disk_writer_test2"; + create_directory(check); + cl.add(check); + + for (auto original: directory_iterator(dcp)) { + auto path_in_copy = path("xm") / original.path().filename(); + auto path_in_check = check / original.path().filename(); + system("e2cp " + partition.string() + ":" + path_in_copy.string() + " " + path_in_check.string()); + check_file(original.path(), path_in_check); + } + + cl.run(); +} + + + +BOOST_AUTO_TEST_CASE (disk_writer_test3) +{ + using namespace boost::filesystem; + using namespace boost::process; + + remove_all("build/test/disk_writer_test3.disk"); + remove_all("build/test/disk_writer_test3.partition"); + remove_all("build/test/disk_writer_test3"); + + Cleanup cl; + + path const disk = "build/test/disk_writer_test3.disk"; + path const partition = "build/test/disk_writer_test3.partition"; + + cl.add(disk); + cl.add(partition); + + /* Using empty files here still triggers the bug and is much quicker than using random data */ + make_empty_file(disk, 31043616768LL); + make_empty_file(partition, 31043571712LL); + + vector const dcps = { + TestPaths::private_data() / "xm", + TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" + }; + dcpomatic::write(dcps, disk.string(), partition.string(), nullptr); + + BOOST_CHECK_EQUAL(system("/sbin/e2fsck -fn build/test/disk_writer_test3.partition"), 0); + + path const check = "build/test/disk_writer_test3"; + create_directory(check); + cl.add(check); + + for (auto dcp: dcps) { + for (auto original: directory_iterator(dcp)) { + auto path_in_copy = dcp.filename() / original.path().filename(); + auto path_in_check = check / original.path().filename(); + system("e2cp " + partition.string() + ":" + path_in_copy.string() + " " + path_in_check.string()); + check_file(original.path(), path_in_check); + } + } + + cl.run(); }