Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / tests / testsh2.sh
blobc95884981591d70d525d9c0479caea3b5bf2bbc4
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 echo -n "Shell test 2 "
32 rm -rf $TESTDIR
33 mkdir $TESTDIR # all files are created here
34 cd $TESTDIR
36 cat >file <<END
37 The time has come the walrus said to talk of many things
38 Of shoes and ships and sealing wax of cabbages and kings
39 Of why the sea is boiling hot and whether pigs have wings
40 END
41 f=file # scratch file
43 cat >makefile <<END # create a makefile
44 all: x.c
45 @$CC x.c >/dev/null 2>&1
46 END
47 cat >x.c <<END # create a C program
48 #include <stdio.h>
49 char s[] = {"MS-DOS: Just say no"}; /* used by strings later */
50 main()
52 int i;
53 for (i = 15; i < 18; i++) printf("%d\\n",i*i);
55 END
57 cat >answer <<END # C program should produce these results
58 225
59 256
60 289
61 END
63 make
64 if test -f a.out; then : ; else bomb "Compilation failed"; fi
65 a.out >x
66 if test -f x; then : ; else bomb "No compiler output"; fi
67 if cmp -s x answer; then : ; else bomb "Error in cc test 1"; fi
69 #Test chmod
70 echo "Hi there folks" >x
71 if test -r x; then : ; else bomb "Error on chmod test 1"; fi
72 chmod 377 x
73 if test -r x; then test -w / || bomb "Error on chmod test 2"; fi
74 chmod 700 x
75 if test -r x; then : ; else bomb "Error on chmod test 3"; fi
77 #Test cut
78 cat >x <<END # x is a test file with 3 columns
79 1 white bunny
80 2 gray rabbits
81 3 brown hares
82 4 black conies
83 END
85 cat >answer <<END # after cutting out cols 3-7, we get this
86 white
87 gray
88 brown
89 black
90 END
92 cut -c 3-7 x >y # extract columns 3-7
93 if cmp -s y answer; then : ; else bomb "Error in cut test 1"; fi
95 #Test dd
96 dd if=$f of=x bs=12 count=1 2>/dev/null # x = bytes 0-11
97 dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null # y = bytes 11-35
98 cat x y >z # z = bytes 0-35
99 dd if=$f of=answer bs=9 count=4 2>/dev/null # answer = bytes 0-35
100 if cmp -s z answer; then : ; else bomb "Error in dd test 1"; fi
102 #Test df # hard to make a sensible Test here
103 rm ?
104 df >x
105 if test -r x; then : ; else bomb "Error in df Test 1"; fi
107 #Test du # see df
108 rm ?
109 du >x
110 if test -r x; then : ; else bomb "Error in du Test 1"; fi
112 #Test od
113 head -1 $f |od >x # see if od converts ascii to octal ok
114 if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ]
115 then
116 cat >answer <<END
117 0000000 064124 020145 064564 062555 064040 071541 061440 066557
118 0000020 020145 064164 020145 060567 071154 071565 071440 064541
119 0000040 020144 067564 072040 066141 020153 063157 066440 067141
120 0000060 020171 064164 067151 071547 000012
121 0000071
123 else
124 cat >answer <<END
125 0000000 052150 062440 072151 066545 020150 060563 020143 067555
126 0000020 062440 072150 062440 073541 066162 072563 020163 060551
127 0000040 062040 072157 020164 060554 065440 067546 020155 060556
128 0000060 074440 072150 064556 063563 005000
129 0000071
133 if cmp -s x answer; then : ; else bomb "Error in od test 1"; fi
135 head -1 $f |od -d >x # see if od converts ascii to decimal ok
136 if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ]
137 then
138 cat >answer <<END
139 0000000 26708 08293 26996 25965 26656 29537 25376 28015
140 0000020 08293 26740 08293 24951 29292 29557 29472 26977
141 0000040 08292 28532 29728 27745 08299 26223 27936 28257
142 0000060 08313 26740 28265 29543 00010
143 0000071
145 else
146 cat >answer <<END
147 0000000 21608 25888 29801 28005 08296 24947 08291 28525
148 0000020 25888 29800 25888 30561 27762 30067 08307 24937
149 0000040 25632 29807 08308 24940 27424 28518 08301 24942
150 0000060 31008 29800 26990 26483 02560
151 0000071
155 if cmp -s x answer; then : ; else bomb "Error in od test 2"; fi
157 #Test paste
158 cat >x <<END
160 green
161 blue
164 cat >y <<END
165 rood
166 groen
167 blauw
169 cat >answer <<END
170 red rood
171 green groen
172 blue blauw
175 paste x y >z
176 if cmp -s z answer; then : ; else bomb "Error in paste test 1"; fi
178 #Test prep
179 prep >x <<END
180 "Hi," said Carol, laughing, "How's life?"
183 cat >answer <<END
185 said
186 carol
187 laughing
188 how's
189 life
192 if cmp -s x answer; then : ; else bomb "Error in prep test 1"; fi
194 #Test printenv
195 printenv >x
196 if grep HOME x >/dev/null; then : ; else bomb "Error in printenv test 1"; fi
197 if grep PATH x >/dev/null; then : ; else bomb "Error in printenv test 2"; fi
198 if grep SHELL x >/dev/null; then : ; else bomb "Error in printenv test 3"; fi
199 if grep USER x >/dev/null; then : ; else bomb "Error in printenv test 4"; fi
201 #Test pwd
202 pwd >Pwd_file
203 cd `pwd`
204 pwd >x
205 if test -s Pwd_file; then : ; else bomb "Error in pwd test 1"; fi
206 if cmp -s Pwd_file x; then : ; else bomb "Error in pwd test 2"; fi
208 #Test strings
209 strings a.out | grep "MS-DOS" >x
210 cat >answer <<END
211 MS-DOS: Just say no
214 if cmp -s x answer; then : ; else bomb "Error in strings test 1"; fi
216 #Test sum
217 sum $f >x
218 cat >answer <<END
219 29904 1 $f
222 if cmp -s x answer; then : ; else bomb "Error in sum test 1"; fi
224 #Test tee
225 cat $f | tee x >/dev/null
226 if cmp -s x $f; then : ; else bomb "Error in tee test 1"; fi
228 #Test true
229 if true ; then : ; else bomb "Error in true test 1"; fi
231 #Test uniq
232 cat >x <<END
239 cat >answer <<END
245 uniq <x >y
246 if cmp -s y answer; then : ; else bomb "Error in uniq test 1"; fi
248 #Test pipelines
249 cat >x <<END
250 the big black dog
251 the little white cat
252 the big white sheep
253 the little black cat
256 cat >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
267 prep x | sort | uniq -c >y1
268 sort <y1 >y
269 if cmp -s y answer; then : ; else bomb "Error in pipeline test 1"; fi
271 cat $f $f $f | sort | uniq >x
272 sort <$f >y
273 if cmp -s x y; then : ; else bomb "Error in pipeline test 2"; fi
275 cd ..
276 rm -rf $TESTDIR
278 echo ok