1caf54c4fSMartin Matuska /*-
2*bd66c1b4SMartin Matuska * SPDX-License-Identifier: BSD-2-Clause
3*bd66c1b4SMartin Matuska *
4caf54c4fSMartin Matuska * Copyright (c) 2003-2007 Tim Kientzle
5caf54c4fSMartin Matuska * All rights reserved.
6caf54c4fSMartin Matuska */
7caf54c4fSMartin Matuska #include "test.h"
8caf54c4fSMartin Matuska
9caf54c4fSMartin Matuska static void
unpack_test(const char * from,const char * options,const char * se)10caf54c4fSMartin Matuska unpack_test(const char *from, const char *options, const char *se)
11caf54c4fSMartin Matuska {
12caf54c4fSMartin Matuska int r;
13caf54c4fSMartin Matuska
14caf54c4fSMartin Matuska /* Create a work dir named after the file we're unpacking. */
15caf54c4fSMartin Matuska assertMakeDir(from, 0775);
16caf54c4fSMartin Matuska assertChdir(from);
17caf54c4fSMartin Matuska
18caf54c4fSMartin Matuska /*
19caf54c4fSMartin Matuska * Use cpio to unpack the sample archive
20caf54c4fSMartin Matuska */
21caf54c4fSMartin Matuska extract_reference_file(from);
22caf54c4fSMartin Matuska r = systemf("%s -i %s < %s >unpack.out 2>unpack.err",
23caf54c4fSMartin Matuska testprog, options, from);
24caf54c4fSMartin Matuska failure("Error invoking %s -i %s < %s",
25caf54c4fSMartin Matuska testprog, options, from);
26caf54c4fSMartin Matuska assertEqualInt(r, 0);
27caf54c4fSMartin Matuska
28caf54c4fSMartin Matuska /* Verify that nothing went to stderr. */
29caf54c4fSMartin Matuska if (canSymlink()) {
30caf54c4fSMartin Matuska failure("Error invoking %s -i %s < %s",
31caf54c4fSMartin Matuska testprog, options, from);
32caf54c4fSMartin Matuska assertTextFileContents(se, "unpack.err");
33caf54c4fSMartin Matuska }
34caf54c4fSMartin Matuska
35caf54c4fSMartin Matuska /*
36caf54c4fSMartin Matuska * Verify unpacked files.
37caf54c4fSMartin Matuska */
38caf54c4fSMartin Matuska
39caf54c4fSMartin Matuska /* Regular file with 2 links. */
40caf54c4fSMartin Matuska assertIsReg("file", 0644);
41caf54c4fSMartin Matuska failure("%s", from);
42caf54c4fSMartin Matuska assertFileSize("file", 10);
43caf54c4fSMartin Matuska assertFileSize("linkfile", 10);
44caf54c4fSMartin Matuska failure("%s", from);
45caf54c4fSMartin Matuska assertFileNLinks("file", 2);
46caf54c4fSMartin Matuska
47caf54c4fSMartin Matuska /* Another name for the same file. */
48caf54c4fSMartin Matuska failure("%s", from);
49caf54c4fSMartin Matuska assertIsHardlink("linkfile", "file");
50caf54c4fSMartin Matuska assertFileSize("file", 10);
51caf54c4fSMartin Matuska assertFileSize("linkfile", 10);
52caf54c4fSMartin Matuska
53caf54c4fSMartin Matuska /* Symlink */
54caf54c4fSMartin Matuska if (canSymlink())
5552c2bb75SMartin Matuska assertIsSymlink("symlink", "file", 0);
56caf54c4fSMartin Matuska
57caf54c4fSMartin Matuska /* dir */
58caf54c4fSMartin Matuska assertIsDir("dir", 0775);
59caf54c4fSMartin Matuska
60caf54c4fSMartin Matuska assertChdir("..");
61caf54c4fSMartin Matuska }
62caf54c4fSMartin Matuska
DEFINE_TEST(test_gcpio_compat)63caf54c4fSMartin Matuska DEFINE_TEST(test_gcpio_compat)
64caf54c4fSMartin Matuska {
65caf54c4fSMartin Matuska assertUmask(0);
66caf54c4fSMartin Matuska
67caf54c4fSMartin Matuska /* Dearchive sample files with a variety of options. */
68caf54c4fSMartin Matuska if (canSymlink()) {
69caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref.bin",
70caf54c4fSMartin Matuska "--no-preserve-owner", "1 block\n");
71caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref.crc",
72caf54c4fSMartin Matuska "--no-preserve-owner", "2 blocks\n");
73caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref.newc",
74caf54c4fSMartin Matuska "--no-preserve-owner", "2 blocks\n");
75caf54c4fSMartin Matuska /* gcpio-2.9 only reads 6 blocks here */
76caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref.ustar",
77caf54c4fSMartin Matuska "--no-preserve-owner", "7 blocks\n");
78caf54c4fSMartin Matuska } else {
79caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref_nosym.bin",
80caf54c4fSMartin Matuska "--no-preserve-owner", "1 block\n");
81caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref_nosym.crc",
82caf54c4fSMartin Matuska "--no-preserve-owner", "2 blocks\n");
83caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref_nosym.newc",
84caf54c4fSMartin Matuska "--no-preserve-owner", "2 blocks\n");
85caf54c4fSMartin Matuska /* gcpio-2.9 only reads 6 blocks here */
86caf54c4fSMartin Matuska unpack_test("test_gcpio_compat_ref_nosym.ustar",
87caf54c4fSMartin Matuska "--no-preserve-owner", "7 blocks\n");
88caf54c4fSMartin Matuska }
89caf54c4fSMartin Matuska }
90