Changeset 6a174c02 in rtems


Ignore:
Timestamp:
Jul 25, 2016, 1:34:43 PM (4 years ago)
Author:
Alexander Krutwig <alexander.krutwig@…>
Branches:
master
Children:
84008f9e
Parents:
1a8fe67a
git-author:
Alexander Krutwig <alexander.krutwig@…> (07/25/16 13:34:43)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/26/16 08:00:04)
Message:

Add Untar_FromGzChunk_Print() + Test

Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/Makefile.am

    r1a8fe67a r6a174c02  
    156156## libuntar
    157157noinst_LIBRARIES += libuntar.a
    158 libuntar_a_SOURCES = untar/untar.c untar/untar.h
     158libuntar_a_SOURCES = untar/untar.c untar/untar_tgz.c untar/untar.h
    159159
    160160EXTRA_DIST += untar/README
  • cpukit/libmisc/untar/untar.h

    r1a8fe67a r6a174c02  
    2121#include <stddef.h>
    2222#include <tar.h>
     23#include <zlib.h>
    2324
    2425#include <rtems/print.h>
     
    3940#define UNTAR_INVALID_HEADER     3
    4041
     42#define UNTAR_GZ_INFLATE_FAILED 4
     43#define UNTAR_GZ_INFLATE_END_FAILED 5
    4144
    4245int Untar_FromMemory(void *tar_buf, size_t size);
     
    138141);
    139142
     143/**
     144 * @brief Initializes the Untar_ChunkGzContext.
     145 *
     146 * @param Untar_ChunkGzContext *context [in] Pointer to a context structure.
     147 * @param void *inflateBuffer [in] Pointer to a context structure.
     148 * @param size_t inflateBufferSize [in] Size of inflateBuffer.
     149 */
     150int Untar_GzChunkContext_Init(
     151  Untar_GzChunkContext *ctx,
     152  void *inflateBuffer,
     153  size_t inflateBufferSize
     154);
     155
     156/*
     157 * @brief Untars a GZ compressed POSIX TAR file.
     158 *
     159 * This is a subroutine used to rip links, directories, and
     160 * files out of a tar.gz/tgz file.
     161 *
     162 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
     163 * @param ssize buflen [in] Size of valid bytes in input buffer.
     164 * @param z_stream *strm [in] Pointer to the current zlib context.
     165 */
     166int Untar_FromGzChunk_Print(
     167  Untar_GzChunkContext *ctx,
     168  void *chunk,
     169  size_t chunk_size,
     170  const rtems_printer* printer
     171);
     172
    140173/**************************************************************************
    141174 * This converts octal ASCII number representations into an
  • testsuites/libtests/configure.ac

    r1a8fe67a r6a174c02  
    3232AC_PROG_LN_S
    3333AC_PATH_PROG([PAX],[pax],no)
     34AC_PATH_PROG([GZIP],[gzip],no)
    3435
    3536AS_IF([test "x$PAX" = "xno"],[
     
    3940AC_CHECK_HEADERS([complex.h])
    4041
    41 AM_CONDITIONAL(TARTESTS,test "$as_ln_s" = "ln -s" && test -n "$PAX")
     42AM_CONDITIONAL(TARTESTS,test "$as_ln_s" = "ln -s" && test -n "$PAX" && test -n "$GZIP")
    4243
    4344AM_CONDITIONAL(HAS_CXX,test "$rtems_cv_HAS_CPLUSPLUS" = "yes")
  • testsuites/libtests/tar01/Makefile.am

    r1a8fe67a r6a174c02  
    11if TARTESTS
    22rtems_tests_PROGRAMS = tar01
    3 tar01_SOURCES = init.c ../../psxtests/psxfile01/test_cat.c \
    4   initial_filesystem_tar.c initial_filesystem_tar.h
     3tar01_SOURCES =
     4tar01_SOURCES += init.c
     5tar01_SOURCES += ../../psxtests/psxfile01/test_cat.c
     6tar01_SOURCES += initial_filesystem_tar.c
     7tar01_SOURCES += initial_filesystem_tar.h
     8tar01_SOURCES += initial_filesystem_tar_gz.c
     9tar01_SOURCES += initial_filesystem_tar_gz.h
     10
     11tar01_LDADD = -lrtemscpu -lz
    512 
    6 BUILT_SOURCES = initial_filesystem_tar.c initial_filesystem_tar.h
     13BUILT_SOURCES =
     14BUILT_SOURCES += initial_filesystem_tar.c
     15BUILT_SOURCES += initial_filesystem_tar.h
     16BUILT_SOURCES += initial_filesystem_tar_gz.c
     17BUILT_SOURCES += initial_filesystem_tar_gz.h
    718
    819dist_rtems_tests_DATA = tar01.scn
     
    1930AM_CPPFLAGS += -I$(top_srcdir)/../psxtests/include
    2031
    21 LINK_OBJS = $(tar01_OBJECTS)
     32LINK_OBJS = $(tar01_OBJECTS) $(tar01_LDADD)
    2233LINK_LIBS = $(tar01_LDLIBS)
    2334
     
    3445CLEANFILES += initial_filesystem_tar.h
    3546
     47initial_filesystem_tar_gz.c: initial_filesystem.tar.gz
     48        $(BIN2C) -C initial_filesystem.tar.gz initial_filesystem_tar_gz
     49CLEANFILES += initial_filesystem_tar_gz.h
     50
     51initial_filesystem_tar_gz.h: initial_filesystem.tar.gz
     52        $(BIN2C) -H initial_filesystem.tar.gz initial_filesystem_tar_gz
     53CLEANFILES += initial_filesystem_tar_gz.h
     54
    3655initial_filesystem.tar:
    3756        rm -rf initial_fs
     
    4362        $(PAX) -w -f ../initial_filesystem.tar home symlink)
    4463CLEANFILES += initial_filesystem.tar
     64
     65initial_filesystem.tar.gz: initial_filesystem.tar
     66        $(GZIP) < initial_filesystem.tar > initial_filesystem.tar.gz
     67CLEANFILES += initial_filesystem.tar.gz
     68
    4569endif TARTESTS
    4670
  • testsuites/libtests/tar01/init.c

    r1a8fe67a r6a174c02  
    2525
    2626#include "initial_filesystem_tar.h"
     27#include "initial_filesystem_tar_gz.h"
    2728
    2829const char rtems_test_name[] = "TAR 1";
     
    3334void test_untar_from_file(void);
    3435void test_untar_chunks_from_memory(void);
     36void test_untar_unzip_tgz(void);
    3537
    3638#define TARFILE_START initial_filesystem_tar
    3739#define TARFILE_SIZE  initial_filesystem_tar_size
     40#define TARFILE_GZ_START initial_filesystem_tar_gz
     41#define TARFILE_GZ_SIZE  initial_filesystem_tar_gz_size
    3842
    3943void test_cat(
     
    146150}
    147151
     152void test_untar_unzip_tgz(void)
     153{
     154  int status;
     155  rtems_printer     printer;
     156  int rv;
     157  Untar_GzChunkContext ctx;
     158  size_t i = 0;
     159  char *buffer = (char *)TARFILE_GZ_START;
     160  size_t buflen = TARFILE_GZ_SIZE;
     161  char inflate_buffer;
     162
     163  rtems_print_printer_printf(&printer);
     164
     165  /* make a directory to untar it into */
     166  rv = mkdir( "/dest3", 0777 );
     167  rtems_test_assert( rv == 0 );
     168
     169  rv = chdir( "/dest3" );
     170  rtems_test_assert( rv == 0 );
     171
     172  printf( "Untaring chunks from tgz - " );
     173
     174  status = Untar_GzChunkContext_Init(&ctx, &inflate_buffer, 1);
     175  rtems_test_assert(status == UNTAR_SUCCESSFUL);
     176  for(i = 0; i < buflen; i++) {
     177    status = Untar_FromGzChunk_Print(&ctx, &buffer[i], 1, &printer);
     178    rtems_test_assert(status == UNTAR_SUCCESSFUL);
     179  }
     180  printf( "successful\n" );
     181
     182  /******************/
     183  printf( "========= /dest3/home/test_file =========\n" );
     184  test_cat( "/dest3/home/test_file", 0, 0 );
     185
     186  /******************/
     187  printf( "========= /dest3/symlink =========\n" );
     188  test_cat( "/dest3/symlink", 0, 0 );
     189}
     190
    148191rtems_task Init(
    149192  rtems_task_argument ignored
     
    157200  puts( "" );
    158201  test_untar_chunks_from_memory();
     202  puts( "" );
     203  test_untar_unzip_tgz();
    159204
    160205  TEST_END();
  • testsuites/libtests/tar01/tar01.scn

    r1a8fe67a r6a174c02  
    3232initial tar image.
    3333
     34
     35Untaring chunks from tgz- untar: dir: home
     36untar: file: home/test_file (73)
     37successful
     38========= /dest3/home/test_file =========
     39(0)This is a test of loading an RTEMS filesystem from an
     40initial tar image.
     41
     42========= /dest3/symlink =========
     43(0)This is a test of loading an RTEMS filesystem from an
     44initial tar image.
    3445*** END OF TAR01 TEST ***
Note: See TracChangeset for help on using the changeset viewer.