-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.sh
128 lines (113 loc) · 2.06 KB
/
test.sh
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
# 2012, Georg Sauthoff <[email protected]>
# GPLv3+
set -e
set -u
TIME=/usr/bin/time
CGMEMTIME=./cgmemtime
TESTA=./testa
test_linux()
{
if uname -o | grep -q Linux ; then
true
else
echo -n Not a Linux system
return 1
fi
return 0
}
test_time()
{
if $TIME --verbose true 2>&1 | grep -q 'Maximum resident set size' ; then
true
else
echo -n '(GNU?)' time does not report maximum RSS
return 1
fi
return 0
}
test_simple()
{
for a in 4 5; do
x=`$CGMEMTIME -t $TESTA x 10 2>&1 | grep ';' | cut -d';' -f $a`
if [ $((x/1024)) -lt 10 -o $((x/1024)) -gt 11 ]; then
echo -n "Not 10 MiB (x=$x, a=$a)"
return 1
fi
done
return 0
}
test_accum()
{
o=`$CGMEMTIME -t $TESTA x 10 20 30 40 2>&1 | grep ';'`
x=`echo $o | cut -d';' -f 4`
if [ $((x/1024)) -lt 10 -o $((x/1024)) -gt 11 ]; then
echo -n "Not 10 MiB (x=$x)"
return 1
fi
x=`echo $o | cut -d';' -f 5`
if [ $((x/1024)) -ne 100 ]; then
echo -n "Not 100 MiB (x=$x)"
return 1
fi
return 0
}
test_wall()
{
x=`$CGMEMTIME -t sleep 3 2>&1 | grep ';' | cut -d';' -f 3 | cut -d'.' -f1`
if [ "$x" -ne 3 ]; then
echo -n "Not 3 seconds wall clock time (x=$x)"
return 1
fi
return 0
}
test_notfound()
{
$CGMEMTIME ./notfound 2>/dev/null
x=$?
if [ $x -ne 127 ]; then
echo -n "Exit status is not 127 (x=$x)"
return 1
fi
return 0
}
test_exitstatus()
{
$CGMEMTIME false 2>/dev/null
x=$?
if [ $x -ne 1 ]; then
echo -n "Exit status is not 1 (x=$x)"
return 1
fi
return 0
}
tests="
test_linux
test_time
test_simple
test_accum
test_wall
test_notfound
test_exitstatus
"
failed=0
set +e
for i in $tests; do
echo -n Executing $i ...
$i
if [ $? -eq 0 ]; then
echo ' OK'
else
echo ' FAIL'
failed=$((failed+1))
fi
done
set -e
echo ================================================================================
echo ================================================================================
if [ $failed -eq 0 ]; then
echo '=> Everything went just fine!'
exit 0
else
echo '=> '$failed' tests failed'
exit 1
fi