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# Tests basic cp functionality 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ciTST_CNT=5 10f08c3bdfSopenharmony_ciTST_TESTFUNC=do_test 11f08c3bdfSopenharmony_ciTST_SETUP=setup 12f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_cicreate_tree() 15f08c3bdfSopenharmony_ci{ 16f08c3bdfSopenharmony_ci local dirname=$1 17f08c3bdfSopenharmony_ci local dircnt=$2 18f08c3bdfSopenharmony_ci local filecnt=$3 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci tst_res TINFO "Creating $dircnt directories." 21f08c3bdfSopenharmony_ci tst_res TINFO "Filling each dir with $filecnt files". 22f08c3bdfSopenharmony_ci while [ $dircnt -gt 0 ]; do 23f08c3bdfSopenharmony_ci dirname=$dirname/dir$dircnt 24f08c3bdfSopenharmony_ci ROD mkdir -p $dirname 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci local fcnt=0 27f08c3bdfSopenharmony_ci while [ $fcnt -lt $filecnt ]; do 28f08c3bdfSopenharmony_ci ROD touch $dirname/file$fcnt 29f08c3bdfSopenharmony_ci fcnt=$((fcnt+1)) 30f08c3bdfSopenharmony_ci done 31f08c3bdfSopenharmony_ci dircnt=$((dircnt-1)) 32f08c3bdfSopenharmony_ci done 33f08c3bdfSopenharmony_ci} 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_cisetup() 36f08c3bdfSopenharmony_ci{ 37f08c3bdfSopenharmony_ci create_tree "dir" 10 10 38f08c3bdfSopenharmony_ci ROD echo LTP > file 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cicompare_dirs() 42f08c3bdfSopenharmony_ci{ 43f08c3bdfSopenharmony_ci local src="$1" 44f08c3bdfSopenharmony_ci local dst="$2" 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci if diff -r $src $dst; then 47f08c3bdfSopenharmony_ci tst_res TPASS "Directories $src and $dst are equal" 48f08c3bdfSopenharmony_ci else 49f08c3bdfSopenharmony_ci tst_res TFAIL "Directories $src and $dst differs" 50f08c3bdfSopenharmony_ci ls -R $src 51f08c3bdfSopenharmony_ci echo 52f08c3bdfSopenharmony_ci ls -R $dst 53f08c3bdfSopenharmony_ci fi 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cicompare_files() 57f08c3bdfSopenharmony_ci{ 58f08c3bdfSopenharmony_ci local src="$1" 59f08c3bdfSopenharmony_ci local dst="$2" 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci if diff $src $dst; then 62f08c3bdfSopenharmony_ci tst_res TPASS "Files $src and $dst are equal" 63f08c3bdfSopenharmony_ci else 64f08c3bdfSopenharmony_ci tst_res TFAIL "Files $src and $dst differs" 65f08c3bdfSopenharmony_ci fi 66f08c3bdfSopenharmony_ci} 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_cicp_test() 69f08c3bdfSopenharmony_ci{ 70f08c3bdfSopenharmony_ci local args="$1" 71f08c3bdfSopenharmony_ci local src="$2" 72f08c3bdfSopenharmony_ci local dst="$3" 73f08c3bdfSopenharmony_ci EXPECT_PASS cp $args $src $dst 74f08c3bdfSopenharmony_ci if [ -f $src ]; then 75f08c3bdfSopenharmony_ci compare_files $src $dst 76f08c3bdfSopenharmony_ci else 77f08c3bdfSopenharmony_ci compare_dirs $src $dst 78f08c3bdfSopenharmony_ci fi 79f08c3bdfSopenharmony_ci ROD rm -r $dst 80f08c3bdfSopenharmony_ci} 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_cido_test() 83f08c3bdfSopenharmony_ci{ 84f08c3bdfSopenharmony_ci case $1 in 85f08c3bdfSopenharmony_ci 1) cp_test "" "file" "file_copy";; 86f08c3bdfSopenharmony_ci 2) cp_test -l "file" "file_copy";; 87f08c3bdfSopenharmony_ci 3) cp_test -s "file" "file_copy";; 88f08c3bdfSopenharmony_ci 4) cp_test -R "dir" "dir_copy";; 89f08c3bdfSopenharmony_ci 5) cp_test -lR "dir" "dir_copy";; 90f08c3bdfSopenharmony_ci esac 91f08c3bdfSopenharmony_ci} 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ci. tst_test.sh 94f08c3bdfSopenharmony_citst_run 95