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
|
global testno, passes, failures
function test (v,n1,n2) {
if (n1 == n2) {
passes ++
result = "pass"
} else {
failures ++
result = "fail"
}
printf ("test %d [%s]\t\t%s\n", testno++, v, result)
}
# Exactly the same as test() except it will magically work for strings.
# Wouldn't it be nice if we didn't have to do this?
function teststr (v,n1,n2) {
if (n1 == n2) {
passes ++
result = "pass"
} else {
failures ++
result = "fail"
}
printf ("test %d [%s]\t\t%s\n", testno++, v, result)
}
probe begin {
# max/minimum signed 32-bit values.
# these could cause problems for 32-bit cpus when overflows
# occur into 64-but values
lmax = 0x7fffffff
lmin = -0x80000000
# max/minimum signed 64-bit values
llmax = 0x7fffffffffffffff
llmin = -0x7fffffffffffffff-1
# 32-bit limit tests
teststr ("string lmax", sprint(lmax), "2147483647")
teststr ("hex lmax", sprintf("0x%x", lmax), "0x7fffffff")
teststr ("string lmin", sprint(lmin), "-2147483648")
teststr ("hex lmin", sprintf("0x%x", lmin), "0xffffffff80000000")
test ("lmax/-1", lmax/-1, -2147483647);
test ("lmin/-1", lmin/-1, 2147483648);
test ("lmax +1", lmax+1, 2147483648);
test ("lmin -1", lmin-1, -2147483649);
# 64-bit limits
teststr ("string llmax", sprint(llmax), "9223372036854775807")
teststr ("hex llmax", sprintf("0x%x", llmax), "0x7fffffffffffffff")
teststr ("string llmin", sprint(llmin), "-9223372036854775808")
teststr ("hex llmin", sprintf("0x%x", llmin), "0x8000000000000000")
test ("llmax/-1", llmax/-1, -llmax)
test ("llmax*-1", llmax*-1, -llmax)
# the next three overflow and produce predictable, although
# wrong results
test ("llmin/-1", llmin/-1, llmin)
test ("llmin*-1", llmin*-1, llmin)
test ("llmax +1", llmax+1, llmin)
test ("llmin -1", llmin-1, llmax)
# modulo tests
test ("llmax%1", llmax%1, 0)
test ("llmin%1", llmin%1, 0)
test ("0%1 ", 0%1, 0)
test ("0%lmax", 0%lmax, 0)
test ("1%lmax", 1%lmax, 1)
test ("0%lmin", 0%lmin, 0)
test ("1%lmin", 1%lmin, 1)
exit()
}
probe end {
printf ("passes: %d failures: %d\n", passes, failures)
}
|