1#!/bin/sh 2################################################################################ 3## ## 4## Copyright (c) International Business Machines Corp., 2001 ## 5## Author: Manoj Iyer, manjo@mail.utexas.edu ## 6## Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> ## 7## ## 8## This program is free software; you can redistribute it and#or modify ## 9## it under the terms of the GNU General Public License as published by ## 10## the Free Software Foundation; either version 2 of the License, or ## 11## (at your option) any later version. ## 12## ## 13## This program is distributed in the hope that it will be useful, but ## 14## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 15## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 16## for more details. ## 17## ## 18## You should have received a copy of the GNU General Public License ## 19## along with this program; if not, write to the Free Software Foundation, ## 20## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 21## ## 22################################################################################ 23# 24# Tests basic cp functionality 25# 26TST_ID="ln01" 27TST_CNT=5 28TST_TESTFUNC=do_test 29TST_SETUP=setup 30TST_NEEDS_TMPDIR=1 31. tst_test.sh 32 33create_tree() 34{ 35 local dirname=$1 36 local dircnt=$2 37 local filecnt=$3 38 39 tst_res TINFO "Creating $dircnt directories." 40 tst_res TINFO "Filling each dir with $filecnt files". 41 while [ $dircnt -gt 0 ]; do 42 dirname=$dirname/dir$dircnt 43 ROD mkdir -p $dirname 44 45 local fcnt=0 46 while [ $fcnt -lt $filecnt ]; do 47 ROD touch $dirname/file$fcnt 48 fcnt=$((fcnt+1)) 49 done 50 dircnt=$((dircnt-1)) 51 done 52} 53 54setup() 55{ 56 create_tree "dir" 10 10 57 ROD echo LTP > file 58} 59 60compare_dirs() 61{ 62 local src="$1" 63 local dst="$2" 64 65 if diff -r $src $dst; then 66 tst_res TPASS "Directories $src and $dst are equal" 67 else 68 tst_res TFAIL "Directories $src and $dst differs" 69 ls -R $src 70 echo 71 ls -R $dst 72 fi 73} 74 75compare_files() 76{ 77 local src="$1" 78 local dst="$2" 79 80 if diff $src $dst; then 81 tst_res TPASS "Files $src and $dst are equal" 82 else 83 tst_res TFAIL "Files $src and $dst differs" 84 fi 85} 86 87cp_test() 88{ 89 local args="$1" 90 local src="$2" 91 local dst="$3" 92 EXPECT_PASS cp $args $src $dst 93 if [ -f $src ]; then 94 compare_files $src $dst 95 else 96 compare_dirs $src $dst 97 fi 98 ROD rm -r $dst 99} 100 101do_test() 102{ 103 case $1 in 104 1) cp_test "" "file" "file_copy";; 105 2) cp_test -l "file" "file_copy";; 106 3) cp_test -s "file" "file_copy";; 107 4) cp_test -R "dir" "dir_copy";; 108 5) cp_test -lR "dir" "dir_copy";; 109 esac 110} 111 112tst_run 113