From owner-svn-src-head@FreeBSD.ORG Fri Apr 17 01:06:32 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A5F4810656C5; Fri, 17 Apr 2009 01:06:32 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 914128FC17; Fri, 17 Apr 2009 01:06:32 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n3H16Wn6000147; Fri, 17 Apr 2009 01:06:32 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n3H16W29000134; Fri, 17 Apr 2009 01:06:32 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200904170106.n3H16W29000134@svn.freebsd.org> From: Tim Kientzle Date: Fri, 17 Apr 2009 01:06:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r191183 - head/lib/libarchive/test X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Apr 2009 01:06:33 -0000 Author: kientzle Date: Fri Apr 17 01:06:31 2009 New Revision: 191183 URL: http://svn.freebsd.org/changeset/base/191183 Log: Merge lots of test suite updates from libarchive.googlecode.com. Added: head/lib/libarchive/test/test_compat_xz.c (contents, props changed) head/lib/libarchive/test/test_compat_xz_1.txz.uu (contents, props changed) head/lib/libarchive/test/test_open_fd.c (contents, props changed) head/lib/libarchive/test/test_open_file.c (contents, props changed) head/lib/libarchive/test/test_open_filename.c (contents, props changed) head/lib/libarchive/test/test_read_disk_entry_from_file.c (contents, props changed) head/lib/libarchive/test/test_read_format_cpio_bin_xz.c (contents, props changed) head/lib/libarchive/test/test_read_format_gtar_lzma.c (contents, props changed) head/lib/libarchive/test/test_read_format_iso_gz.iso.gz.uu (contents, props changed) head/lib/libarchive/test/test_read_format_txz.c (contents, props changed) head/lib/libarchive/test/test_write_compress_bzip2.c (contents, props changed) head/lib/libarchive/test/test_write_compress_gzip.c (contents, props changed) head/lib/libarchive/test/test_write_compress_lzma.c (contents, props changed) head/lib/libarchive/test/test_write_compress_xz.c (contents, props changed) head/lib/libarchive/test/test_write_format_mtree.c (contents, props changed) Modified: head/lib/libarchive/test/Makefile head/lib/libarchive/test/main.c head/lib/libarchive/test/read_open_memory.c head/lib/libarchive/test/test_compat_bzip2.c head/lib/libarchive/test/test_compat_gzip.c head/lib/libarchive/test/test_entry.c head/lib/libarchive/test/test_entry_strmode.c head/lib/libarchive/test/test_extattr_freebsd.c head/lib/libarchive/test/test_pax_filename_encoding.c head/lib/libarchive/test/test_pax_filename_encoding.tar.uu head/lib/libarchive/test/test_read_compress_program.c head/lib/libarchive/test/test_read_disk.c head/lib/libarchive/test/test_read_format_cpio_bin_bz2.c head/lib/libarchive/test/test_read_format_cpio_bin_gz.c head/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c head/lib/libarchive/test/test_read_format_gtar_gz.c head/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu head/lib/libarchive/test/test_read_format_iso_gz.c head/lib/libarchive/test/test_read_format_isojoliet_bz2.c head/lib/libarchive/test/test_read_format_isorr_bz2.c head/lib/libarchive/test/test_read_format_mtree.c head/lib/libarchive/test/test_read_format_pax_bz2.c head/lib/libarchive/test/test_read_format_tbz.c head/lib/libarchive/test/test_read_format_tgz.c head/lib/libarchive/test/test_write_compress_program.c head/lib/libarchive/test/test_write_disk_failures.c head/lib/libarchive/test/test_write_disk_sparse.c Modified: head/lib/libarchive/test/Makefile ============================================================================== --- head/lib/libarchive/test/Makefile Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/Makefile Fri Apr 17 01:06:31 2009 (r191183) @@ -17,6 +17,7 @@ TESTS= \ test_compat_gtar.c \ test_compat_gzip.c \ test_compat_tar_hardlink.c \ + test_compat_xz.c \ test_compat_zip.c \ test_empty_write.c \ test_entry.c \ @@ -24,10 +25,14 @@ TESTS= \ test_extattr_freebsd.c \ test_fuzz.c \ test_link_resolver.c \ + test_open_fd.c \ + test_open_file.c \ + test_open_filename.c \ test_pax_filename_encoding.c \ test_read_compress_program.c \ test_read_data_large.c \ test_read_disk.c \ + test_read_disk_entry_from_file.c \ test_read_extract.c \ test_read_file_nonexistent.c \ test_read_format_ar.c \ @@ -35,13 +40,16 @@ TESTS= \ test_read_format_cpio_bin_Z.c \ test_read_format_cpio_bin_bz2.c \ test_read_format_cpio_bin_gz.c \ + test_read_format_cpio_bin_xz.c \ test_read_format_cpio_odc.c \ test_read_format_cpio_svr4_gzip.c \ test_read_format_cpio_svr4c_Z.c \ test_read_format_empty.c \ test_read_format_gtar_gz.c \ + test_read_format_gtar_lzma.c \ test_read_format_gtar_sparse.c \ test_read_format_iso_gz.c \ + test_read_format_isojoliet_bz2.c \ test_read_format_isorr_bz2.c \ test_read_format_mtree.c \ test_read_format_pax_bz2.c \ @@ -49,6 +57,7 @@ TESTS= \ test_read_format_tar_empty_filename.c \ test_read_format_tbz.c \ test_read_format_tgz.c \ + test_read_format_txz.c \ test_read_format_tz.c \ test_read_format_zip.c \ test_read_large.c \ @@ -59,7 +68,11 @@ TESTS= \ test_tar_large.c \ test_ustar_filenames.c \ test_write_compress.c \ + test_write_compress_bzip2.c \ + test_write_compress_gzip.c \ + test_write_compress_lzma.c \ test_write_compress_program.c \ + test_write_compress_xz.c \ test_write_disk.c \ test_write_disk_failures.c \ test_write_disk_hardlink.c \ @@ -72,6 +85,7 @@ TESTS= \ test_write_format_cpio_empty.c \ test_write_format_cpio_newc.c \ test_write_format_cpio_odc.c \ + test_write_format_mtree.c \ test_write_format_pax.c \ test_write_format_shar_empty.c \ test_write_format_tar.c \ @@ -93,10 +107,18 @@ PROG=libarchive_test INTERNALPROG=yes # Don't install this; it's just for testing DPADD=${LIBBZ2} ${LIBZ} CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" -LDADD= -lz -lbz2 -CFLAGS+= -static -g +LDADD= -lz -lbz2 -lmd -lcrypto +CFLAGS+= -g CFLAGS+= -I${LA_SRCDIR} -I. +# Uncomment to build and test lzma support via liblzmadec +#CFLAGS+= -I/usr/local/include -DHAVE_LIBLZMADEC=1 -DHAVE_LZMADEC_H=1 +#LDADD+= -L/usr/local/lib -llzmadec + +# Uncomment to build and test lzma and xz support via liblzma +CFLAGS+= -I/usr/local/include -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 +LDADD+= -L/usr/local/lib -llzma + # Uncomment to link against dmalloc #LDADD+= -L/usr/local/lib -ldmalloc #CFLAGS+= -I/usr/local/include -DUSE_DMALLOC @@ -108,9 +130,10 @@ check test: libarchive_test # list.h is just a list of all tests, as indicated by DEFINE_TEST macro lines list.h: ${TESTS} Makefile - (cd ${.CURDIR}; cat ${TESTS}) | grep DEFINE_TEST > list.h + (cd ${.CURDIR}; cat test_*.c) | grep DEFINE_TEST > list.h -CLEANFILES += *.out *.o *.core *~ list.h +CLEANFILES += *.out *.o *.core *~ list.h .dirstamp .depend +CLEANDIRS += .deps .libs cleantest: -chmod -R +w /tmp/libarchive_test.* Modified: head/lib/libarchive/test/main.c ============================================================================== --- head/lib/libarchive/test/main.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/main.c Fri Apr 17 01:06:31 2009 (r191183) @@ -62,11 +62,7 @@ __FBSDID("$FreeBSD$"); */ #undef DEFINE_TEST #define DEFINE_TEST(name) void name(void); -#ifdef LIST_H -#include LIST_H -#else #include "list.h" -#endif /* Interix doesn't define these in a standard header. */ #if __INTERIX__ @@ -128,13 +124,28 @@ static const char *failed_filename = NUL static struct line { int line; int count; + int critical; } failed_lines[1000]; /* + * Called at the beginning of each assert() function. + */ +static void +count_assertion(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + +/* * Count this failure; return the number of previous failures. */ static int -previous_failures(const char *filename, int line) +previous_failures(const char *filename, int line, int critical) { unsigned int i; int count; @@ -152,6 +163,7 @@ previous_failures(const char *filename, if (failed_lines[i].line == 0) { failed_lines[i].line = line; failed_lines[i].count = 1; + failed_lines[i].critical = critical; return (0); } } @@ -178,7 +190,7 @@ test_skipping(const char *fmt, ...) { va_list ap; - if (previous_failures(test_filename, test_line)) + if (previous_failures(test_filename, test_line, 0)) return; va_start(ap, fmt); @@ -241,7 +253,7 @@ summarize(void) for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { if (failed_lines[i].line == 0) break; - if (failed_lines[i].count > 1) + if (failed_lines[i].count > 1 && failed_lines[i].critical) fprintf(stderr, "%s:%d: Failed %d times\n", failed_filename, failed_lines[i].line, failed_lines[i].count); @@ -264,13 +276,13 @@ failure(const char *fmt, ...) int test_assert(const char *file, int line, int value, const char *condition, void *extra) { - ++assertions; + count_assertion(file, line); if (value) { msg[0] = '\0'; return (value); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (value); fprintf(stderr, "%s:%d: Assertion failed\n", file, line); fprintf(stderr, " Condition: %s\n", condition); @@ -283,13 +295,13 @@ int test_assert_equal_int(const char *file, int line, int v1, const char *e1, int v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == v2) { msg[0] = '\0'; return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n", file, line); @@ -330,7 +342,7 @@ test_assert_equal_string(const char *fil const char *v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL || v2 == NULL) { if (v1 == v2) { msg[0] = '\0'; @@ -341,7 +353,7 @@ test_assert_equal_string(const char *fil return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n", file, line); @@ -383,7 +395,7 @@ test_assert_equal_wstring(const char *fi const wchar_t *v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL) { if (v2 == NULL) { msg[0] = '\0'; @@ -399,7 +411,7 @@ test_assert_equal_wstring(const char *fi return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n", file, line); @@ -458,7 +470,7 @@ test_assert_equal_mem(const char *file, const char *v2, const char *e2, size_t l, const char *ld, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL || v2 == NULL) { if (v1 == v2) { msg[0] = '\0'; @@ -469,7 +481,7 @@ test_assert_equal_mem(const char *file, return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n", file, line); @@ -507,7 +519,7 @@ test_assert_empty_file(const char *f1fmt return (1); failures ++; - if (!verbose && previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line, 1)) return (0); fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1); @@ -554,7 +566,7 @@ test_assert_equal_file(const char *f1, c break; } failures ++; - if (!verbose && previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line, 1)) return (0); fprintf(stderr, "%s:%d: Files are not identical\n", test_filename, test_line); @@ -576,7 +588,7 @@ test_assert_file_exists(const char *fpat if (!access(f, F_OK)) return (1); - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File doesn't exist\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -597,7 +609,7 @@ test_assert_file_not_exists(const char * if (access(f, F_OK)) return (1); - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File exists and shouldn't\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -628,7 +640,7 @@ test_assert_file_contents(const void *bu return (1); } failures ++; - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File contents don't match\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -722,13 +734,19 @@ slurpfile(size_t * sizep, const char *fm #undef DEFINE_TEST #define DEFINE_TEST(n) { n, #n }, struct { void (*func)(void); const char *name; } tests[] = { -#ifdef LIST_H - #include LIST_H -#else #include "list.h" -#endif }; +/* + * This is well-intentioned, but sometimes the standard libraries + * leave open file descriptors and expect to be able to come back to + * them (e.g., for username lookups or logging). Closing these + * descriptors out from under those libraries creates havoc. + * + * Maybe there's some reasonably portable way to tell if a descriptor + * is open without using close()? + */ +#if 0 static void close_descriptors(int warn) { @@ -745,6 +763,7 @@ close_descriptors(int warn) report_failure(NULL); } } +#endif /* * Each test is run in a private work dir. Those work dirs @@ -788,11 +807,12 @@ static int test_run(int i, const char *t /* Explicitly reset the locale before each test. */ setlocale(LC_ALL, "C"); /* Make sure there are no stray descriptors going into the test. */ - close_descriptors(0); + /* TODO: Find a better way to identify file descriptor leaks. */ + //close_descriptors(0); /* Run the actual test. */ (*tests[i].func)(); /* Close stray descriptors, record as errors against this test. */ - close_descriptors(1); + //close_descriptors(1); /* Summarize the results of this test. */ summarize(); /* If there were no failures, we can remove the work dir. */ @@ -894,30 +914,34 @@ extract_reference_file(const char *name) fclose(in); } -#if defined(_WIN32) && !defined(__CYGWIN__) -#define DEV_NULL "NUL" -#else -#define DEV_NULL "/dev/null" -#endif +/* Since gzip is by far the most popular external compression program + * available, we try to use it in the read_program and write_program + * tests. But if it's not available, then we can't use it. This + * function just tries to run gzip/gunzip to see if they're available. + * If not, some of the external compression program tests will be + * skipped. */ const char * external_gzip_program(int un) { - const char *extprog; + static int tested = 0; + static const char *compress_prog = NULL; + static const char *decompress_prog = NULL; + /* Args vary depending on the command interpreter we're using. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + static const char *args = "-V >NUL 2>NUL"; /* Win32 cmd.exe */ +#else + static const char *args = "-V >/dev/null 2>/dev/null"; /* POSIX 'sh' */ +#endif - if (un) { - extprog = "gunzip"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); - extprog = "gzip -d"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); - } else { - extprog = "gzip"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); + if (!tested) { + if (systemf("gunzip %s", args) == 0) + decompress_prog = "gunzip"; + if (systemf("gzip %s", args) == 0) + compress_prog = "gzip"; + tested = 1; } - return (NULL); + return (un ? decompress_prog : compress_prog); } static char * @@ -1144,16 +1168,30 @@ int main(int argc, char **argv) } } else { while (*(argv) != NULL) { - i = atoi(*argv); - if (**argv < '0' || **argv > '9' || i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); + if (**argv >= '0' && **argv <= '9') { + i = atoi(*argv); + if (i < 0 || i >= limit) { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } } else { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; + for (i = 0; i < limit; ++i) { + if (strcmp(*argv, tests[i].name) == 0) + break; + } + if (i >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } } + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; argv++; } } Modified: head/lib/libarchive/test/read_open_memory.c ============================================================================== --- head/lib/libarchive/test/read_open_memory.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/read_open_memory.c Fri Apr 17 01:06:31 2009 (r191183) @@ -96,7 +96,7 @@ read_open_memory_internal(struct archive memory_read, memory_read_skip, memory_read_close)); else return (archive_read_open2(a, mine, NULL, - memory_read, NULL, NULL)); + memory_read, NULL, memory_read_close)); } /* Modified: head/lib/libarchive/test/test_compat_bzip2.c ============================================================================== --- head/lib/libarchive/test/test_compat_bzip2.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/test_compat_bzip2.c Fri Apr 17 01:06:31 2009 (r191183) @@ -44,7 +44,7 @@ compat_bzip2(const char *name) const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; struct archive_entry *ae; struct archive *a; - int i,r; + int i; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); @@ -54,19 +54,9 @@ compat_bzip2(const char *name) /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, r); - if (r != ARCHIVE_OK) { - archive_read_finish(a); - return; - } + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); assertEqualString(n[i], archive_entry_pathname(ae)); } @@ -79,12 +69,7 @@ compat_bzip2(const char *name) assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif } Modified: head/lib/libarchive/test/test_compat_gzip.c ============================================================================== --- head/lib/libarchive/test/test_compat_gzip.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/test_compat_gzip.c Fri Apr 17 01:06:31 2009 (r191183) @@ -47,22 +47,22 @@ verify(const char *name) int i,r; assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, r); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 200)); /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); if (r != ARCHIVE_OK) { archive_read_finish(a); return; @@ -79,12 +79,7 @@ verify(const char *name) assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif } Added: head/lib/libarchive/test/test_compat_xz.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_compat_xz.c Fri Apr 17 01:06:31 2009 (r191183) @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Verify our ability to read sample files compatibly with unxz. + * + * In particular: + * * unxz will read multiple xz streams, concatenating the output + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_xz(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i, r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualString(archive_compression_name(a), "xz"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + +DEFINE_TEST(test_compat_xz) +{ + compat_xz("test_compat_xz_1.txz"); +} Added: head/lib/libarchive/test/test_compat_xz_1.txz.uu ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_compat_xz_1.txz.uu Fri Apr 17 01:06:31 2009 (r191183) @@ -0,0 +1,13 @@ +$FreeBSD$ +begin 644 test_compat_gzip_1.txz +M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2 +M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B +MHS@=K]7@K1-9FOIP#PU!I?E5&IHH&Q=N>_C&G +M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P`` +MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I +M70``;IBIKOMK%/A?-TZV0266G?2,[/?\,JE6` +M__C/SA[W1?*2= 1009000 /* ino */ archive_entry_set_ino(e, 8593); @@ -233,6 +239,10 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_size(e), 0); assert(!archive_entry_size_is_set(e)); + /* sourcepath */ + archive_entry_copy_sourcepath(e, "path1"); + assertEqualString(archive_entry_sourcepath(e), "path1"); + /* symlink */ archive_entry_set_symlink(e, "symlinkname"); assertEqualString(archive_entry_symlink(e), "symlinkname"); @@ -243,8 +253,14 @@ DEFINE_TEST(test_entry) memset(buff, 0, sizeof(buff)); assertEqualString(archive_entry_symlink(e), "symlinkname2"); #endif + archive_entry_copy_symlink_w(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); archive_entry_copy_symlink_w(e, L"wsymlink"); assertEqualWString(archive_entry_symlink_w(e), L"wsymlink"); + archive_entry_copy_symlink(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); /* uid */ archive_entry_set_uid(e, 83); @@ -271,9 +287,13 @@ DEFINE_TEST(test_entry) /* TODO: Make this system-independent. */ assertEqualString(archive_entry_fflags_text(e), "uappnd,nouchg,nodump,noopaque,uunlnk"); - /* TODO: Test archive_entry_copy_fflags_text_w() */ + /* Test archive_entry_copy_fflags_text_w() */ + archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk"); + archive_entry_fflags(e, &set, &clear); + assertEqualInt(16, set); + assertEqualInt(7, clear); /* Test archive_entry_copy_fflags_text() */ - archive_entry_copy_fflags_text(e, "nouappnd, nouchg, dump,uunlnk"); + archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk"); archive_entry_fflags(e, &set, &clear); assertEqualInt(16, set); assertEqualInt(7, clear); @@ -343,6 +363,7 @@ DEFINE_TEST(test_entry) archive_entry_set_rdev(e, 532); #endif archive_entry_set_size(e, 987654321); + archive_entry_copy_sourcepath(e, "source"); archive_entry_set_symlink(e, "symlinkname"); archive_entry_set_uid(e, 83); archive_entry_set_uname(e, "user"); @@ -385,6 +406,7 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_rdev(e2), 532); #endif assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); assertEqualString(archive_entry_symlink(e2), "symlinkname"); assertEqualInt(archive_entry_uid(e2), 83); assertEqualString(archive_entry_uname(e2), "user"); @@ -472,6 +494,7 @@ DEFINE_TEST(test_entry) archive_entry_set_rdev(e, 132); #endif archive_entry_set_size(e, 987456321); + archive_entry_copy_sourcepath(e, "source2"); archive_entry_set_symlink(e, "symlinkpath"); archive_entry_set_uid(e, 93); archive_entry_set_uname(e, "username"); @@ -508,6 +531,7 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_rdev(e2), 532); #endif assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); assertEqualString(archive_entry_symlink(e2), "symlinkname"); assertEqualInt(archive_entry_uid(e2), 83); assertEqualString(archive_entry_uname(e2), "user"); Modified: head/lib/libarchive/test/test_entry_strmode.c ============================================================================== --- head/lib/libarchive/test/test_entry_strmode.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/test_entry_strmode.c Fri Apr 17 01:06:31 2009 (r191183) @@ -34,15 +34,38 @@ DEFINE_TEST(test_entry_strmode) archive_entry_set_mode(entry, S_IFREG | 0642); assertEqualString(archive_entry_strmode(entry), "-rw-r---w- "); + /* Regular file + hardlink still shows as regular file. */ + archive_entry_set_mode(entry, S_IFREG | 0644); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- "); + + archive_entry_set_mode(entry, 0640); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "hrw-r----- "); + archive_entry_set_hardlink(entry, NULL); + + archive_entry_set_mode(entry, S_IFDIR | 0777); + assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx "); + archive_entry_set_mode(entry, S_IFBLK | 03642); assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT "); archive_entry_set_mode(entry, S_IFCHR | 05777); assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt "); + archive_entry_set_mode(entry, S_IFSOCK | 0222); + assertEqualString(archive_entry_strmode(entry), "s-w--w--w- "); + + archive_entry_set_mode(entry, S_IFIFO | 0444); + assertEqualString(archive_entry_strmode(entry), "pr--r--r-- "); + archive_entry_set_mode(entry, S_IFLNK | 04000); assertEqualString(archive_entry_strmode(entry), "l--S------ "); + archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + 0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78"); + assertEqualString(archive_entry_strmode(entry), "l--S------+"); + /* Release the experimental entry. */ archive_entry_free(entry); } Modified: head/lib/libarchive/test/test_extattr_freebsd.c ============================================================================== --- head/lib/libarchive/test/test_extattr_freebsd.c Fri Apr 17 01:04:23 2009 (r191182) +++ head/lib/libarchive/test/test_extattr_freebsd.c Fri Apr 17 01:06:31 2009 (r191183) @@ -169,5 +169,6 @@ DEFINE_TEST(test_extattr_freebsd) assertEqualMem(xval, "12345", xsize); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + archive_entry_free(ae); #endif } Added: head/lib/libarchive/test/test_open_fd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_open_fd.c Fri Apr 17 01:06:31 2009 (r191183) @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + + +DEFINE_TEST(test_open_fd) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + int fd; + + fd = open("test.tar", O_RDWR | O_CREAT, 0777); + assert(fd >= 0); + if (fd < 0) + return; + + /* Write an archive through this fd. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_fd(a, fd)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + assert(lseek(fd, 0, SEEK_SET) == 0); + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_fd(a, fd, 512)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + close(fd); + + + /* + * Verify some of the error handling. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + /* FD 100 shouldn't be open. */ + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_open_fd(a, 100, 512)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} Added: head/lib/libarchive/test/test_open_file.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_open_file.c Fri Apr 17 01:06:31 2009 (r191183) @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_open_file) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + FILE *f; + + f = fopen("test.tar", "w"); + assert(f != NULL); + if (f == NULL) + return; + + /* Write an archive through this FILE *. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_FILE(a, f)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + fclose(f); + + /* + * Now, read the data back. + */ + f = fopen("test.tar", "r"); + assert(f != NULL); + if (f == NULL) + return; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***