From 826f3afaf3e4682c3ab7110648327217b0cd9e44 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Wed, 12 Oct 2016 09:15:23 +1100 Subject: libmisc/xz: Add xz decompression. Add support to untar XZ compressed files. --- testsuites/libtests/tar01/init.c | 74 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'testsuites/libtests/tar01/init.c') diff --git a/testsuites/libtests/tar01/init.c b/testsuites/libtests/tar01/init.c index 7d4f1b9a2a..f8f26c9a07 100644 --- a/testsuites/libtests/tar01/init.c +++ b/testsuites/libtests/tar01/init.c @@ -25,6 +25,9 @@ #include "initial_filesystem_tar.h" #include "initial_filesystem_tar_gz.h" +#if HAVE_XZ +#include "initial_filesystem_tar_xz.h" +#endif const char rtems_test_name[] = "TAR 1"; @@ -34,11 +37,16 @@ void test_untar_from_memory(void); void test_untar_from_file(void); void test_untar_chunks_from_memory(void); void test_untar_unzip_tgz(void); +void test_untar_unzip_txz(void); #define TARFILE_START initial_filesystem_tar #define TARFILE_SIZE initial_filesystem_tar_size #define TARFILE_GZ_START initial_filesystem_tar_gz #define TARFILE_GZ_SIZE initial_filesystem_tar_gz_size +#if HAVE_XZ +#define TARFILE_XZ_START initial_filesystem_tar_xz +#define TARFILE_XZ_SIZE initial_filesystem_tar_xz_size +#endif void test_cat( char *file, @@ -92,6 +100,8 @@ void test_untar_from_file(void) int rv; ssize_t n; + puts( "" ); + puts( "Copy tar image to test.tar" ); /* Copy tar image from object to file in IMFS */ fd = open( "/test.tar", O_CREAT|O_TRUNC|O_WRONLY, 0777 ); @@ -141,6 +151,8 @@ void test_untar_chunks_from_memory(void) char *buffer = (char *)TARFILE_START; size_t buflen = TARFILE_SIZE; + puts( "" ); + rtems_print_printer_printf(&printer); /* make a directory to untar it into */ @@ -185,6 +197,10 @@ void test_untar_unzip_tgz(void) size_t buflen = TARFILE_GZ_SIZE; char inflate_buffer; + puts( "" ); + + rtems_test_assert( buflen != 0 ); + rtems_print_printer_printf(&printer); /* make a directory to untar it into */ @@ -218,6 +234,60 @@ void test_untar_unzip_tgz(void) test_cat( "/dest3/symlink", 0, 0 ); } +void test_untar_unzip_txz(void) +{ +#if HAVE_XZ + int status; + rtems_printer printer; + int rv; + Untar_XzChunkContext ctx; + size_t i = 0; + char *buffer = (char *)TARFILE_XZ_START; + size_t buflen = TARFILE_XZ_SIZE; + char inflate_buffer; + + puts( "" ); + + rtems_test_assert( buflen != 0 ); + + rtems_print_printer_printf(&printer); + + /* make a directory to untar it into */ + rv = mkdir( "/dest4", 0777 ); + rtems_test_assert( rv == 0 ); + + rv = chdir( "/dest4" ); + rtems_test_assert( rv == 0 ); + + printf( "Untaring chunks from txz - " ); + + /* + * Use 8K dict, this is set on the command line of xz when compressing. + */ + status = Untar_XzChunkContext_Init(&ctx, XZ_DYNALLOC, + 8 * 1024, &inflate_buffer, 1); + rtems_test_assert(status == UNTAR_SUCCESSFUL); + for(i = 0; i < buflen; i++) { + status = Untar_FromXzChunk_Print(&ctx, &buffer[i], 1, &printer); + rtems_test_assert(status == UNTAR_SUCCESSFUL); + } + printf( "successful\n" ); + + /******************/ + printf( "========= /dest4/home/test_file =========\n" ); + test_cat( "/dest4/home/test_file", 0, 0 ); + + /******************/ + printf( "========= /dest4/home/test_script =========\n" ); + test_cat( "/dest4/home/test_script", 0, 0 ); + test_untar_check_mode("/dest4/home/test_script", 0755); + + /******************/ + printf( "========= /dest4/symlink =========\n" ); + test_cat( "/dest4/symlink", 0, 0 ); +#endif +} + rtems_task Init( rtems_task_argument ignored ) @@ -225,12 +295,10 @@ rtems_task Init( TEST_BEGIN(); test_untar_from_memory(); - puts( "" ); test_untar_from_file(); - puts( "" ); test_untar_chunks_from_memory(); - puts( "" ); test_untar_unzip_tgz(); + test_untar_unzip_txz(); TEST_END(); exit( 0 ); -- cgit v1.2.3