summaryrefslogtreecommitdiff
path: root/minix/tests/testsh2.sh
blob: c95884981591d70d525d9c0479caea3b5bf2bbc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/sh

# Shell script #2 used to test MINIX.

# Helper function
bomb() {
    echo $*
    cd ..
    rm -rf $TESTDIR
    exit 1
}

PATH=:/bin:/usr/bin:/usr/pkg/bin
export PATH

TESTDIR=DIR_SH2
export TESTDIR

OLDPWD=`pwd`
export OLDPWD

# CC="exec cc -wo -F"		# nonstandard flags for ACK :-(
if which clang 2>/dev/null >/dev/null
then	CC=clang
elif which gcc 2>/dev/null >/dev/null
then	CC=gcc
else	echo "Can't find a compiler, skipping test"
	exit 0
fi

echo -n  "Shell test  2 "
rm -rf $TESTDIR
mkdir $TESTDIR			# all files are created here
cd $TESTDIR

cat >file <<END
The time has come the walrus said to talk of many things
Of shoes and ships and sealing wax of cabbages and kings
Of why the sea is boiling hot and whether pigs have wings
END
f=file				# scratch file

cat >makefile <<END		# create a makefile
all:	x.c
	@$CC x.c >/dev/null 2>&1
END
cat >x.c <<END			# create a C program
#include <stdio.h>
char s[] = {"MS-DOS: Just say no"};	/* used by strings later */
main() 
{
  int i; 
  for (i = 15; i < 18; i++) printf("%d\\n",i*i);
}
END

cat >answer <<END		# C program should produce these results
225
256
289
END

make
if test -f a.out; then : ; else bomb "Compilation failed"; fi
a.out >x
if test -f x; then : ; else bomb "No compiler output"; fi
if cmp -s x answer; then : ; else bomb "Error in cc test 1"; fi

#Test chmod
echo "Hi there folks" >x
if test -r x; then : ; else bomb "Error on chmod test 1"; fi
chmod 377 x
if test -r x; then test -w / || bomb "Error on chmod test 2"; fi
chmod 700 x
if test -r x; then : ; else bomb "Error on chmod test 3"; fi

#Test cut
cat >x <<END			# x is a test file with 3 columns
1 white bunny
2 gray  rabbits
3 brown hares
4 black conies
END

cat >answer <<END		# after cutting out cols 3-7, we get this
white
gray 
brown
black
END

cut -c 3-7 x >y			# extract columns 3-7
if cmp -s y answer; then : ; else bomb "Error in cut test 1"; fi

#Test dd
dd if=$f of=x bs=12 count=1 2>/dev/null		# x = bytes 0-11
dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null	# y = bytes 11-35
cat x y >z					# z = bytes 0-35
dd if=$f of=answer bs=9 count=4 2>/dev/null	# answer = bytes 0-35
if cmp -s z answer; then : ; else bomb "Error in dd test 1"; fi

#Test df			# hard to make a sensible Test here
rm ?
df >x
if test -r x; then : ; else bomb "Error in df Test 1"; fi

#Test du			# see df
rm ?
du >x
if test -r x; then : ; else bomb "Error in du Test 1"; fi

#Test od			
head -1 $f |od >x		# see if od converts ascii to octal ok
if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ]
then
cat >answer <<END
0000000   064124  020145  064564  062555  064040  071541  061440  066557
0000020   020145  064164  020145  060567  071154  071565  071440  064541
0000040   020144  067564  072040  066141  020153  063157  066440  067141
0000060   020171  064164  067151  071547  000012                        
0000071
END
else
cat >answer <<END
0000000   052150  062440  072151  066545  020150  060563  020143  067555
0000020   062440  072150  062440  073541  066162  072563  020163  060551
0000040   062040  072157  020164  060554  065440  067546  020155  060556
0000060   074440  072150  064556  063563  005000                        
0000071
END
fi

if cmp -s x answer; then : ; else bomb "Error in od test 1"; fi

head -1 $f |od -d >x		# see if od converts ascii to decimal ok
if [ $(/sbin/sysctl -n hw.byteorder) = "1234" ]
then
cat >answer <<END
0000000    26708   08293   26996   25965   26656   29537   25376   28015
0000020    08293   26740   08293   24951   29292   29557   29472   26977
0000040    08292   28532   29728   27745   08299   26223   27936   28257
0000060    08313   26740   28265   29543   00010                        
0000071
END
else
cat >answer <<END
0000000    21608   25888   29801   28005   08296   24947   08291   28525
0000020    25888   29800   25888   30561   27762   30067   08307   24937
0000040    25632   29807   08308   24940   27424   28518   08301   24942
0000060    31008   29800   26990   26483   02560                        
0000071
END
fi

if cmp -s x answer; then : ; else bomb "Error in od test 2"; fi

#Test paste
cat >x <<END
red
green
blue
END

cat >y <<END
rood
groen
blauw
END
cat >answer <<END
red	rood
green	groen
blue	blauw
END

paste x y >z
if cmp -s z answer; then : ; else bomb "Error in paste test 1"; fi

#Test prep
prep >x <<END
"Hi," said Carol, laughing, "How's life?"
END

cat >answer <<END
hi
said
carol
laughing
how's
life
END

if cmp -s x answer; then : ; else bomb "Error in prep test 1"; fi

#Test printenv
printenv >x
if grep HOME  x >/dev/null; then : ; else bomb "Error in printenv test 1"; fi
if grep PATH  x >/dev/null; then : ; else bomb "Error in printenv test 2"; fi
if grep SHELL x >/dev/null; then : ; else bomb "Error in printenv test 3"; fi
if grep USER  x >/dev/null; then : ; else bomb "Error in printenv test 4"; fi

#Test pwd
pwd >Pwd_file
cd `pwd`
pwd >x
if test -s Pwd_file;  then : ; else bomb "Error in pwd test 1"; fi
if cmp -s Pwd_file x; then : ; else bomb "Error in pwd test 2"; fi

#Test strings
strings a.out | grep "MS-DOS" >x
cat >answer <<END
MS-DOS: Just say no
END

if cmp -s x answer; then : ; else bomb "Error in strings test 1"; fi

#Test sum
sum $f >x
cat >answer <<END
29904 1 $f
END

if cmp -s x answer; then : ; else bomb "Error in sum test 1"; fi

#Test tee
cat $f | tee x >/dev/null
if cmp -s x $f; then : ; else bomb "Error in tee test 1"; fi

#Test true
if true ; then : ; else bomb "Error in true test 1"; fi

#Test uniq
cat >x <<END
100
200
200
300
END

cat >answer <<END
100
200
300
END

uniq <x >y
if cmp -s y answer; then : ; else bomb "Error in uniq test 1"; fi

#Test pipelines
cat >x <<END
the big black dog
the little white cat
the big white sheep
the little black cat
END

cat >answer <<END
   1 dog
   1 sheep
   2 big
   2 black
   2 cat
   2 little
   2 white
   4 the
END

prep x | sort | uniq -c >y1
sort <y1 >y
if cmp -s y answer; then : ; else bomb "Error in pipeline test 1"; fi

cat $f $f $f | sort | uniq >x
sort <$f >y
if cmp -s x y; then : ; else bomb "Error in pipeline test 2"; fi

cd ..
rm -rf $TESTDIR

echo ok