1#!/bin/sh 2 3# Shell script used to test MINIX. 4 5# Helper function 6bomb() { 7 echo $* 8 cd .. 9 rm -rf $TESTDIR 10 exit 1 11} 12 13 14PATH=:/bin:/usr/bin 15export PATH 16 17TESTDIR=DIR_SH1 18export TESTDIR 19 20OLDPWD=`pwd` 21export OLDPWD 22 23echo -n "Shell test 1 " 24rm -rf $TESTDIR 25mkdir $TESTDIR 26cd $TESTDIR 27 28f=$OLDPWD/test1.c 29if test -r $f; then : ; else echo sh1 cannot read $f; exit 1; fi 30 31#Initial setup 32echo "abcdefghijklmnopqrstuvwxyz" >alpha 33echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ" >ALPHA 34echo "0123456789" >num 35echo "!@#$%^&*()_+=-{}[]:;<>?/.," >special 36cp /etc/rc rc 37cp /etc/passwd passwd 38cat alpha ALPHA num rc passwd special >tmp 39cat tmp tmp tmp >f1 40 41 42#Test cp 43mkdir foo 44cp /etc/rc /etc/passwd foo 45if cmp -s foo/rc /etc/rc ; then : ; else bomb "Error on cp test 1"; fi 46if cmp -s foo/passwd /etc/passwd ; then : ; else bomb "Error on cp test 2"; fi 47rm -rf foo 48 49#Test cat 50cat num num num num num >y 51wc -c y >x1 52echo " 55 y" >x2 53if cmp -s x1 x2; then : ; else bomb "Error on cat test 1"; fi 54cat <y >z 55if cmp -s y z; then : ; else bomb "Error on cat test 2"; fi 56 57#Test basename 58if test `basename /usr/ast/foo.c .c` != 'foo' 59 then bomb "Error on basename test 1" 60fi 61 62if test `basename a/b/c/d` != 'd'; then bomb "Error on basename test 2"; fi 63 64#Test cdiff, sed, and patch 65cp $f x.c # x.c is a copy $f 66echo "/a/s//#####/g" >s # create sed script 67sed -f s <x.c >y.c # y.c is new version of x.c 68diff -c x.c y.c >y # y is cdiff listing 69patch x.c y 2>/dev/null # z should be y.c 70if cmp -s x.c y.c; then : ; else bomb "Error in cdiff test"; fi 71rm x.c* y.c s y 72 73#Test comm, grep -v 74ls /etc >x # x = list of /etc 75grep -v "passwd" x >y # y = x except for /etc/passwd 76comm -3 x y >z # should only be 1 line, /etc/passwd 77echo "passwd" >w 78if cmp -s w z; then : else bomb "Error on comm test 1"; fi 79 80comm -13 x y >z # should be empty 81if test -s z; then bomb "Error on comm test 2"; fi 82rm -rf w x y z 83 84#Test compress 85compress -fc $f >x.c.Z # compress the test file 86compress -cd x.c.Z >y # uncompress it 87if cmp -s $f y; then : else bomb "Error in compress test 1"; fi 88rm -rf x.c.Z y 89 90#Test ed 91cp $f x # copy $f to x 92cat >y <<END 93g/a/s//#####/g 94g/b/s//@@@@@/g 95g/c/s//!!!!!/g 96w 97q 98END 99ed 2>/dev/null x <y >/dev/null 100cat >y <<END 101g/#####/s//a/g 102g/@@@@@/s//b/g 103g/!!!!!/s//c/g 104w 105q 106END 107ed 2>/dev/null x <y >/dev/null 108if cmp -s x $f; then : ; else bomb "Error in ed test 1"; fi 109rm x y 110 111#Test expr 112if test `expr 1 + 1` != 2; then bomb "Error on expr test 1"; fi 113if test `expr 10000 - 1` != 9999; then bomb "Error on expr test 2"; fi 114if test `expr 100 '*' 50` != 5000; then bomb "Error on expr test 3"; fi 115if test `expr 120 / 5` != 24; then bomb "Error on expr test 4"; fi 116if test `expr 143 % 7` != 3; then bomb "Error on expr test 5"; fi 117a=100 118a=`expr $a + 1` 119if test $a != '101'; then bomb "Error on expr test 6"; fi 120 121#Test fgrep 122fgrep "abc" alpha >z 123if cmp -s alpha z ; then : else bomb "Error on fgrep test 1"; fi 124fgrep "abc" num >z 125if test -s z; then bomb "Error on fgrep test 2"; fi 126cat alpha num >z 127fgrep "012" z >w 128if cmp -s w num; then : ; else bomb "Error fgrep test 3"; fi 129 130 131#Test find 132date >Rabbit 133echo "Rabbit" >y 134find . -name Rabbit -print >z 135if cmp -s y z; then : else bomb "Error on find test 1"; fi 136find . -name Bunny -print >z 137if test -s z; then bomb "Error on find test 2"; fi 138rm Rabbit y z 139 140#Test grep 141grep "a" alpha >x 142if cmp -s x alpha; then : ; else bomb "Error on grep test 1"; fi 143grep "a" ALPHA >x 144if test -s x; then bomb "Error on grep test 2"; fi 145grep -v "0" alpha >x 146if cmp -s x alpha; then : ; else bomb "Error on grep test 3"; fi 147grep -s "a" XXX_nonexistent_file_XXX >x 148if test -s x; then echo "Error on grep test 4"; fi 149if grep -s "a" alpha >x; then : else bomb "Error on grep test 5"; fi 150if grep -s "a" ALPHA >x; then bomb "Error on grep test 6"; fi 151 152#Test head 153head -1 f1 >x 154if cmp -s x alpha; then : else bomb "Error on head test 1"; fi 155head -2 f1 >x 156cat alpha ALPHA >y 157if cmp -s x y; then : else bomb "Error on head test 2"; fi 158 159#Test ls 160mkdir FOO 161cp passwd FOO/z 162cp alpha FOO/x 163cp ALPHA FOO/y 164cd FOO 165ls >w 166cat >w1 <<END 167w 168x 169y 170z 171END 172if cmp -s w w1; then : ; else bomb "Error on ls test 1"; fi 173rm * 174cd .. 175rmdir FOO 176 177#Test mkdir/rmdir 178mkdir Foo Bar 179if test -d Foo; then : ; else bomb "Error on mkdir test 1"; fi 180if test -d Bar; then : ; else bomb "Error on mkdir test 2"; fi 181rmdir Foo Bar 182if test -d Foo; then bomb "Error on mkdir test 3"; fi 183if test -d Foo; then bomb "Error on rmdir test 4"; fi 184 185#Test mv 186mkdir MVDIR 187cp $f x 188mv x y 189mv y z 190if cmp -s $f z; then : ; else bomb "Error on mv test 1"; fi 191cp $f x 192mv x MVDIR/y 193if cmp -s $f MVDIR/y; then : ; else bomb "Error on mv test 2"; fi 194 195#Test rev 196rev <f1 | head -1 >ahpla 197echo "zyxwvutsrqponmlkjihgfedcba" >x 198if cmp -s x ahpla; then : ; else bomb "Error on rev test 1"; fi 199rev <$f >x 200rev <x >y 201if cmp -s $f x; then bomb "Error on rev test 2"; fi 202if cmp -s $f y; then : ; else bomb "Error on rev test 3"; fi 203 204#Test shar 205cp $f w 206cp alpha x 207cp ALPHA y 208cp num z 209shar w x y z >x1 210rm w x y z 211sh <x1 >/dev/null 212if cmp -s w $f; then : ; else bomb "Error on shar test 1"; fi 213if cmp -s x alpha; then : ; else bomb "Error on shar test 2"; fi 214if cmp -s y ALPHA; then : ; else bomb "Error on shar test 3"; fi 215if cmp -s z num; then : ; else bomb "Error on shar test 4"; fi 216 217#Test sort 218sort <$f >x 219wc <$f >x1 220wc <x >x2 221if cmp -s x1 x2; then : ; else bomb "Error on sort test 1"; fi 222cat >x <<END 223demit 10 224epitonic 40 225apoop 20 226bibelot 3 227comate 4 228END 229cat >y <<END 230apoop 20 231bibelot 3 232comate 4 233demit 10 234epitonic 40 235END 236cat >z <<END 237epitonic 40 238demit 10 239comate 4 240bibelot 3 241apoop 20 242END 243sort <x >x1 244if cmp -s y x1; then : ; else bomb "Error on sort test 2"; fi 245sort -r <x1 >x2 246if cmp -s x2 z; then : ; else bomb "Error on sort test 3"; fi 247sort -k 2n <x |head -1 >y 248echo "bibelot 3" >z 249if cmp -s y z; then : ; else bomb "Error on sort test 4"; fi 250 251#Test tail 252tail -1 f1 >x 253if cmp -s x special; then : ; else bomb "Error on tail test 1"; fi 254 255#Test tsort 256cat >x <<END 257a d 258b e 259c f 260a c 261p z 262k p 263a k 264a b 265b c 266c d 267d e 268e f 269f k 270END 271cat >answer <<END 272a 273b 274c 275d 276e 277f 278k 279p 280z 281END 282tsort <x >y 283if cmp -s y answer; then : ; else bomb "Error on tsort test 1"; fi 284 285#Test uuencode/uudecode 286cp $f x 287uuencode x x > x.uue 288if test -s x.uue; then : ; else bomb "Error on uuencode/uudecode test 1"; fi 289rm x 290uudecode x.uue 291if cmp -s x $f; then : ; else bomb "Error on uuencode/uudecode test 2"; fi 292 293compress -fc x >x.Z 2>/dev/null 294uuencode x.Z x.Z > x.Z.uue 295rm x x.Z 296uudecode x.Z.uue 297compress -cd x.Z >x 298if cmp -s x $f; then : ; else bomb "Error on uuencode/uudecode test 3"; fi 299 300cd .. 301rm -rf $TESTDIR 302 303echo ok 304