custom message for vm_update
[minix3.git] / test / testsh2.sh
blob292b0e189d3a13000effbc83565ae236f38467f9
1 #!/bin/sh
3 # Shell script #2 used to test MINIX.
5 # Helper function
6 bomb() {
7 echo $*
8 cd ..
9 rm -rf $TESTDIR
10 exit 1
13 PATH=:/bin:/usr/bin:/usr/pkg/bin
14 export PATH
16 TESTDIR=DIR_SH2
17 export TESTDIR
19 OLDPWD=`pwd`
20 export OLDPWD
22 # CC="exec cc -wo -F" # nonstandard flags for ACK :-(
23 if which clang 2>/dev/null >/dev/null
24 then CC=clang
25 elif which gcc 2>/dev/null >/dev/null
26 then CC=gcc
27 else echo "Can't find a compiler, skipping test"
28 exit 0
31 ARCH=`uname -p`
33 echo -n "Shell test 2 "
34 rm -rf $TESTDIR
35 mkdir $TESTDIR # all files are created here
36 cd $TESTDIR
38 cat >file <<END
39 The time has come the walrus said to talk of many things
40 Of shoes and ships and sealing wax of cabbages and kings
41 Of why the sea is boiling hot and whether pigs have wings
42 END
43 f=file # scratch file
45 cat >makefile <<END # create a makefile
46 all: x.c
47 @$CC x.c >/dev/null 2>&1
48 END
49 cat >x.c <<END # create a C program
50 #include <stdio.h>
51 char s[] = {"MS-DOS: Just say no"}; /* used by strings later */
52 main()
54 int i;
55 for (i = 15; i < 18; i++) printf("%d\\n",i*i);
57 END
59 cat >answer <<END # C program should produce these results
60 225
61 256
62 289
63 END
65 make
66 if test -f a.out; then : ; else bomb "Compilation failed"; fi
67 a.out >x
68 if test -f x; then : ; else bomb "No compiler output"; fi
69 if cmp -s x answer; then : ; else bomb "Error in cc test 1"; fi
71 #Test chmod
72 echo "Hi there folks" >x
73 if test -r x; then : ; else bomb "Error on chmod test 1"; fi
74 chmod 377 x
75 if test -r x; then test -w / || bomb "Error on chmod test 2"; fi
76 chmod 700 x
77 if test -r x; then : ; else bomb "Error on chmod test 3"; fi
79 #Test cut
80 cat >x <<END # x is a test file with 3 columns
81 1 white bunny
82 2 gray rabbits
83 3 brown hares
84 4 black conies
85 END
87 cat >answer <<END # after cutting out cols 3-7, we get this
88 white
89 gray
90 brown
91 black
92 END
94 cut -c 3-7 x >y # extract columns 3-7
95 if cmp -s y answer; then : ; else bomb "Error in cut test 1"; fi
97 #Test dd
98 dd if=$f of=x bs=12 count=1 2>/dev/null # x = bytes 0-11
99 dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null # y = bytes 11-35
100 cat x y >z # z = bytes 0-35
101 dd if=$f of=answer bs=9 count=4 2>/dev/null # answer = bytes 0-35
102 if cmp -s z answer; then : ; else bomb "Error in dd test 1"; fi
104 #Test df # hard to make a sensible Test here
105 rm ?
106 df >x
107 if test -r x; then : ; else bomb "Error in df Test 1"; fi
109 #Test du # see df
110 rm ?
111 du >x
112 if test -r x; then : ; else bomb "Error in du Test 1"; fi
114 #Test od
115 head -1 $f |od >x # see if od converts ascii to octal ok
116 if [ $ARCH = i86 -o $ARCH = i386 -o $ARCH = arm ]
117 then
118 cat >answer <<END
119 0000000 064124 020145 064564 062555 064040 071541 061440 066557
120 0000020 020145 064164 020145 060567 071154 071565 071440 064541
121 0000040 020144 067564 072040 066141 020153 063157 066440 067141
122 0000060 020171 064164 067151 071547 000012
123 0000071
125 else
126 cat >answer <<END
127 0000000 052150 062440 072151 066545 020150 060563 020143 067555
128 0000020 062440 072150 062440 073541 066162 072563 020163 060551
129 0000040 062040 072157 020164 060554 065440 067546 020155 060556
130 0000060 074440 072150 064556 063563 005000
131 0000071
135 if cmp -s x answer; then : ; else bomb "Error in od test 1"; fi
137 head -1 $f |od -d >x # see if od converts ascii to decimal ok
138 if [ $ARCH = i86 -o $ARCH = i386 -o $ARCH = arm ]
139 then
140 cat >answer <<END
141 0000000 26708 08293 26996 25965 26656 29537 25376 28015
142 0000020 08293 26740 08293 24951 29292 29557 29472 26977
143 0000040 08292 28532 29728 27745 08299 26223 27936 28257
144 0000060 08313 26740 28265 29543 00010
145 0000071
147 else
148 cat >answer <<END
149 0000000 21608 25888 29801 28005 08296 24947 08291 28525
150 0000020 25888 29800 25888 30561 27762 30067 08307 24937
151 0000040 25632 29807 08308 24940 27424 28518 08301 24942
152 0000060 31008 29800 26990 26483 02560
153 0000071
157 if cmp -s x answer; then : ; else bomb "Error in od test 2"; fi
159 #Test paste
160 cat >x <<END
162 green
163 blue
166 cat >y <<END
167 rood
168 groen
169 blauw
171 cat >answer <<END
172 red rood
173 green groen
174 blue blauw
177 paste x y >z
178 if cmp -s z answer; then : ; else bomb "Error in paste test 1"; fi
180 #Test prep
181 prep >x <<END
182 "Hi," said Carol, laughing, "How's life?"
185 cat >answer <<END
187 said
188 carol
189 laughing
190 how's
191 life
194 if cmp -s x answer; then : ; else bomb "Error in prep test 1"; fi
196 #Test printenv
197 printenv >x
198 if grep HOME x >/dev/null; then : ; else bomb "Error in printenv test 1"; fi
199 if grep PATH x >/dev/null; then : ; else bomb "Error in printenv test 2"; fi
200 if grep SHELL x >/dev/null; then : ; else bomb "Error in printenv test 3"; fi
201 if grep USER x >/dev/null; then : ; else bomb "Error in printenv test 4"; fi
203 #Test pwd
204 pwd >Pwd_file
205 cd `pwd`
206 pwd >x
207 if test -s Pwd_file; then : ; else bomb "Error in pwd test 1"; fi
208 if cmp -s Pwd_file x; then : ; else bomb "Error in pwd test 2"; fi
210 #Test strings
211 strings a.out | grep "MS-DOS" >x
212 cat >answer <<END
213 MS-DOS: Just say no
216 if cmp -s x answer; then : ; else bomb "Error in strings test 1"; fi
218 #Test sum
219 sum $f >x
220 cat >answer <<END
221 29904 1 $f
224 if cmp -s x answer; then : ; else bomb "Error in sum test 1"; fi
226 #Test tee
227 cat $f | tee x >/dev/null
228 if cmp -s x $f; then : ; else bomb "Error in tee test 1"; fi
230 #Test true
231 if true ; then : ; else bomb "Error in true test 1"; fi
233 #Test uniq
234 cat >x <<END
241 cat >answer <<END
247 uniq <x >y
248 if cmp -s y answer; then : ; else bomb "Error in uniq test 1"; fi
250 #Test pipelines
251 cat >x <<END
252 the big black dog
253 the little white cat
254 the big white sheep
255 the little black cat
258 cat >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
269 prep x | sort | uniq -c >y1
270 sort <y1 >y
271 if cmp -s y answer; then : ; else bomb "Error in pipeline test 1"; fi
273 cat $f $f $f | sort | uniq >x
274 sort <$f >y
275 if cmp -s x y; then : ; else bomb "Error in pipeline test 2"; fi
277 cd ..
278 rm -rf $TESTDIR
280 echo ok