1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2014 Michihiro NAKAJIMA 5 * All rights reserved. 6 */ 7 #include "test.h" 8 9 DEFINE_TEST(test_option_lz4) 10 { 11 char *p; 12 int r; 13 size_t s; 14 15 /* Create a file. */ 16 assertMakeFile("f", 0644, "a"); 17 18 /* Archive it with lz4 compression. */ 19 r = systemf("%s -cf - --lz4 f >archive.out 2>archive.err", 20 testprog); 21 p = slurpfile(&s, "archive.err"); 22 p[s] = '\0'; 23 if (r != 0) { 24 if (strstr(p, "Unsupported compression") != NULL) { 25 skipping("This version of bsdtar was compiled " 26 "without lz4 support"); 27 goto done; 28 } 29 /* POSIX permits different handling of the spawnp 30 * system call used to launch the subsidiary 31 * program: */ 32 /* Some systems fail immediately to spawn the new process. */ 33 if (strstr(p, "Can't launch") != NULL && !canLz4()) { 34 skipping("This version of bsdtar uses an external lz4 program " 35 "but no such program is available on this system."); 36 goto done; 37 } 38 /* Some systems successfully spawn the new process, 39 * but fail to exec a program within that process. 40 * This results in failure at the first attempt to 41 * write. */ 42 if (strstr(p, "Can't write") != NULL && !canLz4()) { 43 skipping("This version of bsdtar uses an external lz4 program " 44 "but no such program is available on this system."); 45 goto done; 46 } 47 /* On some systems the error won't be detected until closing 48 time, by a 127 exit error returned by waitpid. */ 49 if (strstr(p, "Error closing") != NULL && !canLz4()) { 50 skipping("This version of bsdcpio uses an external lz4 program " 51 "but no such program is available on this system."); 52 return; 53 } 54 failure("--lz4 option is broken: %s", p); 55 assertEqualInt(r, 0); 56 goto done; 57 } 58 free(p); 59 /* Check that the archive file has an lz4 signature. */ 60 p = slurpfile(&s, "archive.out"); 61 assert(s > 2); 62 assertEqualMem(p, "\x04\x22\x4d\x18", 4); 63 64 done: 65 free(p); 66 } 67