From: Tim Kientzle Date: Sun, 2 Jan 2011 19:16:59 +0000 (-0500) Subject: Extend the test of bsdtar -r to exercise larger file contents. X-Git-Tag: v3.0.0a~794 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9df97121a3bf0b685164cbf0c444a504c19e9d63;p=thirdparty%2Flibarchive.git Extend the test of bsdtar -r to exercise larger file contents. This does not reproduce the problem that Michihiro recently found, but it's an improvement in the test, so it's worth checking in. SVN-Revision: 2852 --- diff --git a/tar/test/test_option_r.c b/tar/test/test_option_r.c index 2bfcacea5..bfbdf795a 100644 --- a/tar/test/test_option_r.c +++ b/tar/test/test_option_r.c @@ -30,23 +30,19 @@ __FBSDID("$FreeBSD$"); */ DEFINE_TEST(test_option_r) { + char buff[7500]; char *p0, *p1; - size_t s; - int r; + size_t s, buff_size_rounded; + int r, i; - /* Create a file */ + /* Create an archive with one file. */ assertMakeFile("f1", 0644, "abc"); - - /* Archive that one file. */ r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog); failure("Error invoking %s cf archive.tar f1", testprog); assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("step1.out"); assertEmptyFile("step1.err"); - /* Do some basic validation of the constructed archive. */ p0 = slurpfile(&s, "archive.tar"); if (!assert(p0 != NULL)) @@ -60,43 +56,72 @@ DEFINE_TEST(test_option_r) assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); - /* Edit that file */ - assertMakeFile("f1", 0644, "123"); - - /* Update the archive. */ + /* Edit that file with a lot more data and update the archive with a new copy. */ + for (i = 0; i < sizeof(buff); ++i) + buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26]; + buff[sizeof(buff) - 1] = '\0'; + assertMakeFile("f1", 0644, buff); r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog); failure("Error invoking %s rf archive.tar f1", testprog); assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("step2.out"); assertEmptyFile("step2.err"); - /* Do some basic validation of the constructed archive. */ + /* The constructed archive should just have the new entry appended. */ p1 = slurpfile(&s, "archive.tar"); if (!assert(p1 != NULL)) { free(p0); return; } - assert(s >= 3072); + buff_size_rounded = ((sizeof(buff) + 511) / 512) * 512; + assert(s >= 2560 + buff_size_rounded); /* Verify first entry is unchanged. */ assertEqualMem(p0, p1, 1024); /* Verify that second entry is correct. */ assertEqualMem(p1 + 1024, "f1", 3); - assertEqualMem(p1 + 1536, "123", 3); + assertEqualMem(p1 + 1536, buff, sizeof(buff)); + /* Verify end-of-archive marker. */ + assertEqualMem(p1 + 1536 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 2048 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + + free(p0); + p0 = p1; + + /* Update the archive by adding a different file. */ + assertMakeFile("f2", 0644, "f2"); + r = systemf("%s rf archive.tar --format=ustar f2 >step3.out 2>step3.err", testprog); + failure("Error invoking %s rf archive.tar f2", testprog); + assertEqualInt(r, 0); + assertEmptyFile("step3.out"); + assertEmptyFile("step3.err"); + + /* Validate the constructed archive. */ + p1 = slurpfile(&s, "archive.tar"); + if (!assert(p1 != NULL)) { + free(p0); + return; + } + assert(s >= 3584 + buff_size_rounded); + /* Verify first two entries are unchanged. */ + assertEqualMem(p0, p1, 1536 + buff_size_rounded); + /* Verify that new entry is correct. */ + assertEqualMem(p1 + 1536 + buff_size_rounded, "f2", 3); + assertEqualMem(p1 + 2048 + buff_size_rounded, "f2", 3); /* Verify end-of-archive marker. */ - assertEqualMem(p1 + 2048, "\0\0\0\0\0\0\0\0", 8); - assertEqualMem(p1 + 2560, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 2560 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 3072 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); free(p0); free(p1); - /* Unpack both items */ - assertMakeDir("step3", 0775); - assertChdir("step3"); - r = systemf("%s xf ../archive.tar", testprog); + /* Unpack everything */ + assertMakeDir("extract", 0775); + assertChdir("extract"); + r = systemf("%s xf ../archive.tar >extract.out 2>extract.err", testprog); failure("Error invoking %s xf archive.tar", testprog); assertEqualInt(r, 0); + assertEmptyFile("extract.out"); + assertEmptyFile("extract.err"); - /* Verify that the second one overwrote the first. */ - assertFileContents("123", 3, "f1"); + /* Verify that the second copy of f1 overwrote the first. */ + assertFileContents(buff, strlen(buff), "f1"); }