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 31echo -n "Shell test 2 " 32rm -rf $TESTDIR 33mkdir $TESTDIR # all files are created here 34cd $TESTDIR 35 36cat >file <<END 37The time has come the walrus said to talk of many things 38Of shoes and ships and sealing wax of cabbages and kings 39Of why the sea is boiling hot and whether pigs have wings 40END 41f=file # scratch file 42 43cat >makefile <<END # create a makefile 44all: x.c 45 @$CC x.c >/dev/null 2>&1 46END 47cat >x.c <<END # create a C program 48#include <stdio.h> 49char s[] = {"MS-DOS: Just say no"}; /* used by strings later */ 50main() 51{ 52 int i; 53 for (i = 15; i < 18; i++) printf("%d\\n",i*i); 54} 55END 56 57cat >answer <<END # C program should produce these results 58225 59256 60289 61END 62 63make 64if test -f a.out; then : ; else bomb "Compilation failed"; fi 65a.out >x 66if test -f x; then : ; else bomb "No compiler output"; fi 67if cmp -s x answer; then : ; else bomb "Error in cc test 1"; fi 68 69#Test chmod 70echo "Hi there folks" >x 71if test -r x; then : ; else bomb "Error on chmod test 1"; fi 72chmod 377 x 73if test -r x; then test -w / || bomb "Error on chmod test 2"; fi 74chmod 700 x 75if test -r x; then : ; else bomb "Error on chmod test 3"; fi 76 77#Test cut 78cat >x <<END # x is a test file with 3 columns 791 white bunny 802 gray rabbits 813 brown hares 824 black conies 83END 84 85cat >answer <<END # after cutting out cols 3-7, we get this 86white 87gray 88brown 89black 90END 91 92cut -c 3-7 x >y # extract columns 3-7 93if cmp -s y answer; then : ; else bomb "Error in cut test 1"; fi 94 95#Test dd 96dd if=$f of=x bs=12 count=1 2>/dev/null # x = bytes 0-11 97dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null # y = bytes 11-35 98cat x y >z # z = bytes 0-35 99dd if=$f of=answer bs=9 count=4 2>/dev/null # answer = bytes 0-35 100if cmp -s z answer; then : ; else bomb "Error in dd test 1"; fi 101 102#Test df # hard to make a sensible Test here 103rm ? 104df >x 105if test -r x; then : ; else bomb "Error in df Test 1"; fi 106 107#Test du # see df 108rm ? 109du >x 110if test -r x; then : ; else bomb "Error in du Test 1"; fi 111 112#Test od 113head -1 $f |od >x # see if od converts ascii to octal ok 114if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ] 115then 116cat >answer <<END 1170000000 064124 020145 064564 062555 064040 071541 061440 066557 1180000020 020145 064164 020145 060567 071154 071565 071440 064541 1190000040 020144 067564 072040 066141 020153 063157 066440 067141 1200000060 020171 064164 067151 071547 000012 1210000071 122END 123else 124cat >answer <<END 1250000000 052150 062440 072151 066545 020150 060563 020143 067555 1260000020 062440 072150 062440 073541 066162 072563 020163 060551 1270000040 062040 072157 020164 060554 065440 067546 020155 060556 1280000060 074440 072150 064556 063563 005000 1290000071 130END 131fi 132 133if cmp -s x answer; then : ; else bomb "Error in od test 1"; fi 134 135head -1 $f |od -d >x # see if od converts ascii to decimal ok 136if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ] 137then 138cat >answer <<END 1390000000 26708 08293 26996 25965 26656 29537 25376 28015 1400000020 08293 26740 08293 24951 29292 29557 29472 26977 1410000040 08292 28532 29728 27745 08299 26223 27936 28257 1420000060 08313 26740 28265 29543 00010 1430000071 144END 145else 146cat >answer <<END 1470000000 21608 25888 29801 28005 08296 24947 08291 28525 1480000020 25888 29800 25888 30561 27762 30067 08307 24937 1490000040 25632 29807 08308 24940 27424 28518 08301 24942 1500000060 31008 29800 26990 26483 02560 1510000071 152END 153fi 154 155if cmp -s x answer; then : ; else bomb "Error in od test 2"; fi 156 157#Test paste 158cat >x <<END 159red 160green 161blue 162END 163 164cat >y <<END 165rood 166groen 167blauw 168END 169cat >answer <<END 170red rood 171green groen 172blue blauw 173END 174 175paste x y >z 176if cmp -s z answer; then : ; else bomb "Error in paste test 1"; fi 177 178#Test prep 179prep >x <<END 180"Hi," said Carol, laughing, "How's life?" 181END 182 183cat >answer <<END 184hi 185said 186carol 187laughing 188how's 189life 190END 191 192if cmp -s x answer; then : ; else bomb "Error in prep test 1"; fi 193 194#Test printenv 195printenv >x 196if grep HOME x >/dev/null; then : ; else bomb "Error in printenv test 1"; fi 197if grep PATH x >/dev/null; then : ; else bomb "Error in printenv test 2"; fi 198if grep SHELL x >/dev/null; then : ; else bomb "Error in printenv test 3"; fi 199if grep USER x >/dev/null; then : ; else bomb "Error in printenv test 4"; fi 200 201#Test pwd 202pwd >Pwd_file 203cd `pwd` 204pwd >x 205if test -s Pwd_file; then : ; else bomb "Error in pwd test 1"; fi 206if cmp -s Pwd_file x; then : ; else bomb "Error in pwd test 2"; fi 207 208#Test strings 209strings a.out | grep "MS-DOS" >x 210cat >answer <<END 211MS-DOS: Just say no 212END 213 214if cmp -s x answer; then : ; else bomb "Error in strings test 1"; fi 215 216#Test sum 217sum $f >x 218cat >answer <<END 21929904 1 $f 220END 221 222if cmp -s x answer; then : ; else bomb "Error in sum test 1"; fi 223 224#Test tee 225cat $f | tee x >/dev/null 226if cmp -s x $f; then : ; else bomb "Error in tee test 1"; fi 227 228#Test true 229if true ; then : ; else bomb "Error in true test 1"; fi 230 231#Test uniq 232cat >x <<END 233100 234200 235200 236300 237END 238 239cat >answer <<END 240100 241200 242300 243END 244 245uniq <x >y 246if cmp -s y answer; then : ; else bomb "Error in uniq test 1"; fi 247 248#Test pipelines 249cat >x <<END 250the big black dog 251the little white cat 252the big white sheep 253the little black cat 254END 255 256cat >answer <<END 257 1 dog 258 1 sheep 259 2 big 260 2 black 261 2 cat 262 2 little 263 2 white 264 4 the 265END 266 267prep x | sort | uniq -c >y1 268sort <y1 >y 269if cmp -s y answer; then : ; else bomb "Error in pipeline test 1"; fi 270 271cat $f $f $f | sort | uniq >x 272sort <$f >y 273if cmp -s x y; then : ; else bomb "Error in pipeline test 2"; fi 274 275cd .. 276rm -rf $TESTDIR 277 278echo ok 279