1#!/bin/sh 2 3# Shell script #2 used to test MINIX. 4 5# Helper function 6bomb() { 7 echo $* 8 cd .. 9 rm -rf $TESTDIR 10 exit 1 11} 12 13PATH=:/bin:/usr/bin:/usr/pkg/bin 14export PATH 15 16TESTDIR=DIR_SH2 17export TESTDIR 18 19OLDPWD=`pwd` 20export OLDPWD 21 22# CC="exec cc -wo -F" # nonstandard flags for ACK :-( 23if which clang 2>/dev/null >/dev/null 24then CC=clang 25elif which gcc 2>/dev/null >/dev/null 26then CC=gcc 27else echo "Can't find a compiler, skipping test" 28 exit 0 29fi 30 31ARCH=`uname -p` 32 33echo -n "Shell test 2 " 34rm -rf $TESTDIR 35mkdir $TESTDIR # all files are created here 36cd $TESTDIR 37 38cat >file <<END 39The time has come the walrus said to talk of many things 40Of shoes and ships and sealing wax of cabbages and kings 41Of why the sea is boiling hot and whether pigs have wings 42END 43f=file # scratch file 44 45cat >makefile <<END # create a makefile 46all: x.c 47 @$CC x.c >/dev/null 2>&1 48END 49cat >x.c <<END # create a C program 50#include <stdio.h> 51char s[] = {"MS-DOS: Just say no"}; /* used by strings later */ 52main() 53{ 54 int i; 55 for (i = 15; i < 18; i++) printf("%d\\n",i*i); 56} 57END 58 59cat >answer <<END # C program should produce these results 60225 61256 62289 63END 64 65make 66if test -f a.out; then : ; else bomb "Compilation failed"; fi 67a.out >x 68if test -f x; then : ; else bomb "No compiler output"; fi 69if cmp -s x answer; then : ; else bomb "Error in cc test 1"; fi 70 71#Test chmod 72echo "Hi there folks" >x 73if test -r x; then : ; else bomb "Error on chmod test 1"; fi 74chmod 377 x 75if test -r x; then test -w / || bomb "Error on chmod test 2"; fi 76chmod 700 x 77if test -r x; then : ; else bomb "Error on chmod test 3"; fi 78 79#Test cut 80cat >x <<END # x is a test file with 3 columns 811 white bunny 822 gray rabbits 833 brown hares 844 black conies 85END 86 87cat >answer <<END # after cutting out cols 3-7, we get this 88white 89gray 90brown 91black 92END 93 94cut -c 3-7 x >y # extract columns 3-7 95if cmp -s y answer; then : ; else bomb "Error in cut test 1"; fi 96 97#Test dd 98dd if=$f of=x bs=12 count=1 2>/dev/null # x = bytes 0-11 99dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null # y = bytes 11-35 100cat x y >z # z = bytes 0-35 101dd if=$f of=answer bs=9 count=4 2>/dev/null # answer = bytes 0-35 102if cmp -s z answer; then : ; else bomb "Error in dd test 1"; fi 103 104#Test df # hard to make a sensible Test here 105rm ? 106df >x 107if test -r x; then : ; else bomb "Error in df Test 1"; fi 108 109#Test du # see df 110rm ? 111du >x 112if test -r x; then : ; else bomb "Error in du Test 1"; fi 113 114#Test od 115head -1 $f |od >x # see if od converts ascii to octal ok 116if [ $ARCH = i86 -o $ARCH = i386 -o $ARCH = arm ] 117then 118cat >answer <<END 1190000000 064124 020145 064564 062555 064040 071541 061440 066557 1200000020 020145 064164 020145 060567 071154 071565 071440 064541 1210000040 020144 067564 072040 066141 020153 063157 066440 067141 1220000060 020171 064164 067151 071547 000012 1230000071 124END 125else 126cat >answer <<END 1270000000 052150 062440 072151 066545 020150 060563 020143 067555 1280000020 062440 072150 062440 073541 066162 072563 020163 060551 1290000040 062040 072157 020164 060554 065440 067546 020155 060556 1300000060 074440 072150 064556 063563 005000 1310000071 132END 133fi 134 135if cmp -s x answer; then : ; else bomb "Error in od test 1"; fi 136 137head -1 $f |od -d >x # see if od converts ascii to decimal ok 138if [ $ARCH = i86 -o $ARCH = i386 -o $ARCH = arm ] 139then 140cat >answer <<END 1410000000 26708 08293 26996 25965 26656 29537 25376 28015 1420000020 08293 26740 08293 24951 29292 29557 29472 26977 1430000040 08292 28532 29728 27745 08299 26223 27936 28257 1440000060 08313 26740 28265 29543 00010 1450000071 146END 147else 148cat >answer <<END 1490000000 21608 25888 29801 28005 08296 24947 08291 28525 1500000020 25888 29800 25888 30561 27762 30067 08307 24937 1510000040 25632 29807 08308 24940 27424 28518 08301 24942 1520000060 31008 29800 26990 26483 02560 1530000071 154END 155fi 156 157if cmp -s x answer; then : ; else bomb "Error in od test 2"; fi 158 159#Test paste 160cat >x <<END 161red 162green 163blue 164END 165 166cat >y <<END 167rood 168groen 169blauw 170END 171cat >answer <<END 172red rood 173green groen 174blue blauw 175END 176 177paste x y >z 178if cmp -s z answer; then : ; else bomb "Error in paste test 1"; fi 179 180#Test prep 181prep >x <<END 182"Hi," said Carol, laughing, "How's life?" 183END 184 185cat >answer <<END 186hi 187said 188carol 189laughing 190how's 191life 192END 193 194if cmp -s x answer; then : ; else bomb "Error in prep test 1"; fi 195 196#Test printenv 197printenv >x 198if grep HOME x >/dev/null; then : ; else bomb "Error in printenv test 1"; fi 199if grep PATH x >/dev/null; then : ; else bomb "Error in printenv test 2"; fi 200if grep SHELL x >/dev/null; then : ; else bomb "Error in printenv test 3"; fi 201if grep USER x >/dev/null; then : ; else bomb "Error in printenv test 4"; fi 202 203#Test pwd 204pwd >Pwd_file 205cd `pwd` 206pwd >x 207if test -s Pwd_file; then : ; else bomb "Error in pwd test 1"; fi 208if cmp -s Pwd_file x; then : ; else bomb "Error in pwd test 2"; fi 209 210#Test strings 211strings a.out | grep "MS-DOS" >x 212cat >answer <<END 213MS-DOS: Just say no 214END 215 216if cmp -s x answer; then : ; else bomb "Error in strings test 1"; fi 217 218#Test sum 219sum $f >x 220cat >answer <<END 22129904 1 $f 222END 223 224if cmp -s x answer; then : ; else bomb "Error in sum test 1"; fi 225 226#Test tee 227cat $f | tee x >/dev/null 228if cmp -s x $f; then : ; else bomb "Error in tee test 1"; fi 229 230#Test true 231if true ; then : ; else bomb "Error in true test 1"; fi 232 233#Test uniq 234cat >x <<END 235100 236200 237200 238300 239END 240 241cat >answer <<END 242100 243200 244300 245END 246 247uniq <x >y 248if cmp -s y answer; then : ; else bomb "Error in uniq test 1"; fi 249 250#Test pipelines 251cat >x <<END 252the big black dog 253the little white cat 254the big white sheep 255the little black cat 256END 257 258cat >answer <<END 259 1 dog 260 1 sheep 261 2 big 262 2 black 263 2 cat 264 2 little 265 2 white 266 4 the 267END 268 269prep x | sort | uniq -c >y1 270sort <y1 >y 271if cmp -s y answer; then : ; else bomb "Error in pipeline test 1"; fi 272 273cat $f $f $f | sort | uniq >x 274sort <$f >y 275if cmp -s x y; then : ; else bomb "Error in pipeline test 2"; fi 276 277cd .. 278rm -rf $TESTDIR 279 280echo ok 281