Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / disk_writer_test.cc
index 32cd76bc3c8f2209d16d67038cbaa254253fec85..7b3778b671c7b9b9a930d18d3cf222df3e017147 100644 (file)
@@ -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<string>
 ext2_ls (vector<string> arguments)
 {
@@ -91,8 +79,8 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1)
        /* 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);
@@ -139,6 +127,46 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1)
 }
 
 
+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);
+
+       make_random_file(disk, 4LL * 1024LL * 1024LL * 1024LL);
+       make_random_file(partition, 4LL * 1024LL * 1024LL * 1024LL);
+
+       auto const dcp = TestPaths::private_data() / "xm";
+       dcpomatic::write(dcp, disk.string(), partition.string(), 0);
+
+       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 (osx_drive_identification_test)
 {
        vector<OSXDisk> disks;