1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 5f08c3bdfSopenharmony_ci# Author: Manoj Iyer <manjo@mail.utexas.edu> 6f08c3bdfSopenharmony_ci# 7f08c3bdfSopenharmony_ci# Creates, lists and extracts an plain, gzip and bzip tar archive. 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ciTST_CNT=6 10f08c3bdfSopenharmony_ciTST_TESTFUNC=do_test 11f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1 12f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="gzip bzip2" 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ciTAR_FILES="file1 file2 file3" 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_cicheck_listing() 17f08c3bdfSopenharmony_ci{ 18f08c3bdfSopenharmony_ci local i 19f08c3bdfSopenharmony_ci local verbose=$1 20f08c3bdfSopenharmony_ci shift 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci if [ -z "$verbose" ]; then 23f08c3bdfSopenharmony_ci if [ -s tar.out ]; then 24f08c3bdfSopenharmony_ci tst_res TFAIL "Tar produced unexpected output" 25f08c3bdfSopenharmony_ci cat tar.out 26f08c3bdfSopenharmony_ci else 27f08c3bdfSopenharmony_ci tst_res TPASS "Tar produced no output" 28f08c3bdfSopenharmony_ci fi 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci return 31f08c3bdfSopenharmony_ci fi 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci if [ $(wc -l < tar.out) != $# ]; then 34f08c3bdfSopenharmony_ci tst_res TFAIL "Unexpected number of lines in tar.out" 35f08c3bdfSopenharmony_ci cat tar.out 36f08c3bdfSopenharmony_ci return 37f08c3bdfSopenharmony_ci fi 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci for i in $@; do 40f08c3bdfSopenharmony_ci if ! grep -q $i tar.out; then 41f08c3bdfSopenharmony_ci tst_res TFAIL "File $i missing in listing" 42f08c3bdfSopenharmony_ci return 43f08c3bdfSopenharmony_ci fi 44f08c3bdfSopenharmony_ci done 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci tst_res TPASS "Listing in tar.out is correct" 47f08c3bdfSopenharmony_ci} 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_cicheck_content() 50f08c3bdfSopenharmony_ci{ 51f08c3bdfSopenharmony_ci local fname="$1" 52f08c3bdfSopenharmony_ci local verbose="$2" 53f08c3bdfSopenharmony_ci shift 2 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci EXPECT_PASS tar t${verbose}f "$fname" \> tar.out 56f08c3bdfSopenharmony_ci check_listing v $@ 57f08c3bdfSopenharmony_ci} 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_cicheck_files() 60f08c3bdfSopenharmony_ci{ 61f08c3bdfSopenharmony_ci for i in $@; do 62f08c3bdfSopenharmony_ci if ! [ -f $i ]; then 63f08c3bdfSopenharmony_ci tst_res TFAIL "Missing file $i in extracted archive" 64f08c3bdfSopenharmony_ci cat tar.out 65f08c3bdfSopenharmony_ci return 66f08c3bdfSopenharmony_ci fi 67f08c3bdfSopenharmony_ci done 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ci tst_res TPASS "Files were uncompressed correctly" 70f08c3bdfSopenharmony_ci} 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_cicheck_extraction() 73f08c3bdfSopenharmony_ci{ 74f08c3bdfSopenharmony_ci local fname="$1" 75f08c3bdfSopenharmony_ci local verbose="$2" 76f08c3bdfSopenharmony_ci shift 2 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci EXPECT_PASS tar x${verbose}f $fname \> tar.out 79f08c3bdfSopenharmony_ci check_listing "${verbose}" $@ 80f08c3bdfSopenharmony_ci check_files $@ 81f08c3bdfSopenharmony_ci ROD rm $@ 82f08c3bdfSopenharmony_ci} 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_citest_tar() 85f08c3bdfSopenharmony_ci{ 86f08c3bdfSopenharmony_ci local comp="$1" 87f08c3bdfSopenharmony_ci local verbose="$2" 88f08c3bdfSopenharmony_ci local fname="$3" 89f08c3bdfSopenharmony_ci local i 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci # Create archive 92f08c3bdfSopenharmony_ci ROD touch $TAR_FILES 93f08c3bdfSopenharmony_ci EXPECT_PASS tar c${verbose}f$comp $fname $TAR_FILES \> tar.out 94f08c3bdfSopenharmony_ci check_listing "$verbose" $TAR_FILES 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci # Diff filesystem against the archive, should be the same at this point 97f08c3bdfSopenharmony_ci EXPECT_PASS tar d${verbose}f $fname \> tar.out 98f08c3bdfSopenharmony_ci check_listing "$verbose" $TAR_FILES 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci ROD rm $TAR_FILES 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ci # Check content listing 103f08c3bdfSopenharmony_ci check_content $fname "$verbose" $TAR_FILES 104f08c3bdfSopenharmony_ci 105f08c3bdfSopenharmony_ci # Check decompression 106f08c3bdfSopenharmony_ci check_extraction $fname "$verbose" $TAR_FILES 107f08c3bdfSopenharmony_ci 108f08c3bdfSopenharmony_ci # Append to an archive, only possible for uncompressed archive 109f08c3bdfSopenharmony_ci if [ -z "$comp" ]; then 110f08c3bdfSopenharmony_ci ROD touch file4 111f08c3bdfSopenharmony_ci EXPECT_PASS tar r${verbose}f $fname file4 \> tar.out 112f08c3bdfSopenharmony_ci check_listing "$verbose" file4 113f08c3bdfSopenharmony_ci check_content $fname "$verbose" $TAR_FILES file4 114f08c3bdfSopenharmony_ci ROD rm file4 115f08c3bdfSopenharmony_ci 116f08c3bdfSopenharmony_ci check_extraction $fname "$verbose" $TAR_FILES file4 117f08c3bdfSopenharmony_ci fi 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci ROD rm $fname 120f08c3bdfSopenharmony_ci} 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_cido_test() 123f08c3bdfSopenharmony_ci{ 124f08c3bdfSopenharmony_ci case $1 in 125f08c3bdfSopenharmony_ci 1) test_tar "" "v" "test.tar";; 126f08c3bdfSopenharmony_ci 2) test_tar "z" "v" "test.tar.gz";; 127f08c3bdfSopenharmony_ci 3) test_tar "j" "v" "test.tar.bz2";; 128f08c3bdfSopenharmony_ci 4) test_tar "" "" "test.tar";; 129f08c3bdfSopenharmony_ci 5) test_tar "z" "" "test.tar.gz";; 130f08c3bdfSopenharmony_ci 6) test_tar "j" "" "test.tar.bz2";; 131f08c3bdfSopenharmony_ci esac 132f08c3bdfSopenharmony_ci} 133f08c3bdfSopenharmony_ci 134f08c3bdfSopenharmony_ci. tst_test.sh 135f08c3bdfSopenharmony_citst_run 136