1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) International Business Machines Corp., 2001 4# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 5# Author: Manoj Iyer <manjo@mail.utexas.edu> 6# 7# Tests basic cp functionality 8 9TST_CNT=5 10TST_TESTFUNC=do_test 11TST_SETUP=setup 12TST_NEEDS_TMPDIR=1 13. tst_test.sh 14 15create_tree() 16{ 17 local dirname=$1 18 local dircnt=$2 19 local filecnt=$3 20 21 tst_res TINFO "Creating $dircnt directories." 22 tst_res TINFO "Filling each dir with $filecnt files". 23 while [ $dircnt -gt 0 ]; do 24 dirname=$dirname/dir$dircnt 25 ROD mkdir -p $dirname 26 27 local fcnt=0 28 while [ $fcnt -lt $filecnt ]; do 29 ROD touch $dirname/file$fcnt 30 fcnt=$((fcnt+1)) 31 done 32 dircnt=$((dircnt-1)) 33 done 34} 35 36setup() 37{ 38 create_tree "dir" 10 10 39 ROD echo LTP > file 40} 41 42compare_dirs() 43{ 44 local src="$1" 45 local dst="$2" 46 47 if diff -r $src $dst; then 48 tst_res TPASS "Directories $src and $dst are equal" 49 else 50 tst_res TFAIL "Directories $src and $dst differs" 51 ls -R $src 52 echo 53 ls -R $dst 54 fi 55} 56 57compare_files() 58{ 59 local src="$1" 60 local dst="$2" 61 62 if diff $src $dst; then 63 tst_res TPASS "Files $src and $dst are equal" 64 else 65 tst_res TFAIL "Files $src and $dst differs" 66 fi 67} 68 69cp_test() 70{ 71 local args="$1" 72 local src="$2" 73 local dst="$3" 74 EXPECT_PASS cp $args $src $dst 75 if [ -f $src ]; then 76 compare_files $src $dst 77 else 78 compare_dirs $src $dst 79 fi 80 ROD rm -r $dst 81} 82 83do_test() 84{ 85 case $1 in 86 1) cp_test "" "file" "file_copy";; 87 2) cp_test -l "file" "file_copy";; 88 3) cp_test -s "file" "file_copy";; 89 4) cp_test -R "dir" "dir_copy";; 90 5) cp_test -lR "dir" "dir_copy";; 91 esac 92} 93 94tst_run 95