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# Author: Manoj Iyer <manjo@mail.utexas.edu> 5f08c3bdfSopenharmony_ci# 6f08c3bdfSopenharmony_ci# Test basic functionality of mv command 7f08c3bdfSopenharmony_ci# Test #1: mv <dir1> <dir2> 8f08c3bdfSopenharmony_ci# move dir1 to dir2 and all its contents. 9f08c3bdfSopenharmony_ci# Test #2: mv -b <file1> <file2> 10f08c3bdfSopenharmony_ci# move file1 to file2 and backup the file2. 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_ciTST_CNT=2 13f08c3bdfSopenharmony_ciTST_SETUP=setup 14f08c3bdfSopenharmony_ciTST_TESTFUNC=test 15f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_cisetup() 18f08c3bdfSopenharmony_ci{ 19f08c3bdfSopenharmony_ci ROD_SILENT mkdir -p tst_mv.old 20f08c3bdfSopenharmony_ci} 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cicreat_dirnfiles() 23f08c3bdfSopenharmony_ci{ 24f08c3bdfSopenharmony_ci local numdirs=$2 25f08c3bdfSopenharmony_ci local numfiles=$3 26f08c3bdfSopenharmony_ci local dirname=$4 27f08c3bdfSopenharmony_ci local dircnt=0 28f08c3bdfSopenharmony_ci local fcnt=0 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci tst_res TINFO "Test #$1: Creating $numdirs directories." 31f08c3bdfSopenharmony_ci tst_res TINFO "Test #$1: filling each dir with $numfiles files." 32f08c3bdfSopenharmony_ci while [ $dircnt -lt $numdirs ] 33f08c3bdfSopenharmony_ci do 34f08c3bdfSopenharmony_ci dirname=$dirname/d.$dircnt 35f08c3bdfSopenharmony_ci ROD_SILENT mkdir -p $dirname 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci fcnt=0 38f08c3bdfSopenharmony_ci while [ $fcnt -lt $numfiles ] 39f08c3bdfSopenharmony_ci do 40f08c3bdfSopenharmony_ci ROD_SILENT touch $dirname/f.$fcnt 41f08c3bdfSopenharmony_ci fcnt=$(($fcnt+1)) 42f08c3bdfSopenharmony_ci done 43f08c3bdfSopenharmony_ci dircnt=$(($dircnt+1)) 44f08c3bdfSopenharmony_ci done 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cicreat_expout() 48f08c3bdfSopenharmony_ci{ 49f08c3bdfSopenharmony_ci local numdir=$1 50f08c3bdfSopenharmony_ci local numfile=$2 51f08c3bdfSopenharmony_ci local dirname=$3 52f08c3bdfSopenharmony_ci local dircnt=0 53f08c3bdfSopenharmony_ci local fcnt=0 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci echo "$dirname:" 1>>tst_mv.exp 56f08c3bdfSopenharmony_ci echo "d.$dircnt" 1>>tst_mv.exp 57f08c3bdfSopenharmony_ci while [ $dircnt -lt $numdirs ] 58f08c3bdfSopenharmony_ci do 59f08c3bdfSopenharmony_ci dirname=$dirname/d.$dircnt 60f08c3bdfSopenharmony_ci dircnt=$(($dircnt+1)) 61f08c3bdfSopenharmony_ci echo "$dirname:" 1>>tst_mv.exp 62f08c3bdfSopenharmony_ci if [ $dircnt -lt $numdirs ]; then 63f08c3bdfSopenharmony_ci echo "d.$dircnt" 1>>tst_mv.exp 64f08c3bdfSopenharmony_ci fi 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ci fcnt=0 67f08c3bdfSopenharmony_ci while [ $fcnt -lt $numfiles ] 68f08c3bdfSopenharmony_ci do 69f08c3bdfSopenharmony_ci echo "f.$fcnt " 1>>tst_mv.exp 70f08c3bdfSopenharmony_ci fcnt=$(($fcnt+1)) 71f08c3bdfSopenharmony_ci done 72f08c3bdfSopenharmony_ci printf "\n\n" 1>>tst_mv.exp 73f08c3bdfSopenharmony_ci done 74f08c3bdfSopenharmony_ci} 75f08c3bdfSopenharmony_ci 76f08c3bdfSopenharmony_citest1() 77f08c3bdfSopenharmony_ci{ 78f08c3bdfSopenharmony_ci numdirs=10 79f08c3bdfSopenharmony_ci numfiles=10 80f08c3bdfSopenharmony_ci dircnt=0 81f08c3bdfSopenharmony_ci fcnt=0 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_ci tst_res TINFO "Test #1: mv <dir1> <dir2> will move dir1 to dir2 and" \ 84f08c3bdfSopenharmony_ci "all its contents" 85f08c3bdfSopenharmony_ci 86f08c3bdfSopenharmony_ci creat_dirnfiles 1 $numdirs $numfiles tst_mv.old 87f08c3bdfSopenharmony_ci 88f08c3bdfSopenharmony_ci mv tst_mv.old tst_mv.new > tst_mv.err 2>&1 89f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 90f08c3bdfSopenharmony_ci cat tst_mv.err 91f08c3bdfSopenharmony_ci tst_brk TFAIL "Test #1: 'mv tst_mv.old tst_mv.new' failed" 92f08c3bdfSopenharmony_ci fi 93f08c3bdfSopenharmony_ci 94f08c3bdfSopenharmony_ci tst_res TINFO "Test #1: creating output file" 95f08c3bdfSopenharmony_ci ls -R tst_mv.new > tst_mv.out 2>&1 96f08c3bdfSopenharmony_ci 97f08c3bdfSopenharmony_ci tst_res TINFO "Test #1: creating expected output file" 98f08c3bdfSopenharmony_ci creat_expout $numdirs $numfiles tst_mv.new 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci tst_res TINFO "Test #1: comparing expected out and actual output file" 101f08c3bdfSopenharmony_ci diff -w -B -q tst_mv.out tst_mv.exp > tst_mv.err 2>&1 102f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 103f08c3bdfSopenharmony_ci cat tst_mv.err 104f08c3bdfSopenharmony_ci tst_res TFAIL "Test #1: mv failed." 105f08c3bdfSopenharmony_ci else 106f08c3bdfSopenharmony_ci tst_res TINFO "Test #1: expected same as actual" 107f08c3bdfSopenharmony_ci if [ -f tst_mv.old ]; then 108f08c3bdfSopenharmony_ci tst_res TFAIL "Test #1: mv did not delete old" \ 109f08c3bdfSopenharmony_ci "directory" 110f08c3bdfSopenharmony_ci else 111f08c3bdfSopenharmony_ci tst_res TPASS "Test #1: mv success" 112f08c3bdfSopenharmony_ci fi 113f08c3bdfSopenharmony_ci fi 114f08c3bdfSopenharmony_ci} 115f08c3bdfSopenharmony_ci 116f08c3bdfSopenharmony_citest2() 117f08c3bdfSopenharmony_ci{ 118f08c3bdfSopenharmony_ci tst_res TINFO "Test #2: mv -b <file1> <file2> will move dir1 to dir2" 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci ROD_SILENT touch tmpfile1 tmpfile2 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ci MD5_old=$(md5sum tmpfile2 | awk '{print $1}') 123f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 124f08c3bdfSopenharmony_ci tst_brk TBROK "Test #2: can't get the MD5 message of file2." 125f08c3bdfSopenharmony_ci fi 126f08c3bdfSopenharmony_ci 127f08c3bdfSopenharmony_ci if [ -f "tmpfile2~" ]; then 128f08c3bdfSopenharmony_ci tst_brk TBROK "Test #2: file tmpfile2~ should not exists." 129f08c3bdfSopenharmony_ci fi 130f08c3bdfSopenharmony_ci 131f08c3bdfSopenharmony_ci mv -b tmpfile1 tmpfile2 132f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 133f08c3bdfSopenharmony_ci tst_brk TBROK "Test #2: 'mv -b tmpfile1 tmpfile2' failed." 134f08c3bdfSopenharmony_ci fi 135f08c3bdfSopenharmony_ci 136f08c3bdfSopenharmony_ci # if 'mv -b file1 file2' succeed, there will be "tmpfile2~" file. 137f08c3bdfSopenharmony_ci 138f08c3bdfSopenharmony_ci MD5_backup=$(md5sum tmpfile2 | awk '{print $1}') 139f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 140f08c3bdfSopenharmony_ci tst_brk TBROK "Test #2: can not get the MD5 message of" \ 141f08c3bdfSopenharmony_ci "backup file2." 142f08c3bdfSopenharmony_ci fi 143f08c3bdfSopenharmony_ci 144f08c3bdfSopenharmony_ci if [ "$MD5_old" = "$MD5_backup" -a -f "tmpfile2~" ]; then 145f08c3bdfSopenharmony_ci tst_res TPASS "Test #2: mv -b success" 146f08c3bdfSopenharmony_ci else 147f08c3bdfSopenharmony_ci tst_res TFAIL "Test #2: mv -b failed" 148f08c3bdfSopenharmony_ci fi 149f08c3bdfSopenharmony_ci} 150f08c3bdfSopenharmony_ci 151f08c3bdfSopenharmony_ci. tst_test.sh 152f08c3bdfSopenharmony_citst_run 153