| 1 |
global testno, passes, failures |
| 2 |
|
| 3 |
function test (v,n1,n2) { |
| 4 |
if (n1 == n2) { |
| 5 |
passes ++ |
| 6 |
result = "pass" |
| 7 |
} else { |
| 8 |
failures ++ |
| 9 |
result = "fail" |
| 10 |
} |
| 11 |
printf ("test %d [%s]\t\t%s\n", testno++, v, result) |
| 12 |
} |
| 13 |
|
| 14 |
# Exactly the same as test() except it will magically work for strings. |
| 15 |
# Wouldn't it be nice if we didn't have to do this? |
| 16 |
|
| 17 |
function teststr (v,n1,n2) { |
| 18 |
if (n1 == n2) { |
| 19 |
passes ++ |
| 20 |
result = "pass" |
| 21 |
} else { |
| 22 |
failures ++ |
| 23 |
result = "fail" |
| 24 |
} |
| 25 |
printf ("test %d [%s]\t\t%s\n", testno++, v, result) |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
probe begin { |
| 31 |
# max/minimum signed 32-bit values. |
| 32 |
# these could cause problems for 32-bit cpus when overflows |
| 33 |
# occur into 64-but values |
| 34 |
lmax = 0x7fffffff |
| 35 |
lmin = -0x80000000 |
| 36 |
|
| 37 |
# max/minimum signed 64-bit values |
| 38 |
llmax = 0x7fffffffffffffff |
| 39 |
llmin = -0x7fffffffffffffff-1 |
| 40 |
|
| 41 |
# 32-bit limit tests |
| 42 |
teststr ("string lmax", sprint(lmax), "2147483647") |
| 43 |
teststr ("hex lmax", sprintf("0x%x", lmax), "0x7fffffff") |
| 44 |
teststr ("string lmin", sprint(lmin), "-2147483648") |
| 45 |
teststr ("hex lmin", sprintf("0x%x", lmin), "0xffffffff80000000") |
| 46 |
test ("lmax/-1", lmax/-1, -2147483647); |
| 47 |
test ("lmin/-1", lmin/-1, 2147483648); |
| 48 |
test ("lmax +1", lmax+1, 2147483648); |
| 49 |
test ("lmin -1", lmin-1, -2147483649); |
| 50 |
|
| 51 |
# 64-bit limits |
| 52 |
teststr ("string llmax", sprint(llmax), "9223372036854775807") |
| 53 |
teststr ("hex llmax", sprintf("0x%x", llmax), "0x7fffffffffffffff") |
| 54 |
teststr ("string llmin", sprint(llmin), "-9223372036854775808") |
| 55 |
teststr ("hex llmin", sprintf("0x%x", llmin), "0x8000000000000000") |
| 56 |
test ("llmax/-1", llmax/-1, -llmax) |
| 57 |
test ("llmax*-1", llmax*-1, -llmax) |
| 58 |
|
| 59 |
# the next three overflow and produce predictable, although |
| 60 |
# wrong results |
| 61 |
test ("llmin/-1", llmin/-1, llmin) |
| 62 |
test ("llmin*-1", llmin*-1, llmin) |
| 63 |
test ("llmax +1", llmax+1, llmin) |
| 64 |
test ("llmin -1", llmin-1, llmax) |
| 65 |
|
| 66 |
# modulo tests |
| 67 |
test ("llmax%1", llmax%1, 0) |
| 68 |
test ("llmin%1", llmin%1, 0) |
| 69 |
test ("0%1 ", 0%1, 0) |
| 70 |
test ("0%lmax", 0%lmax, 0) |
| 71 |
test ("1%lmax", 1%lmax, 1) |
| 72 |
test ("0%lmin", 0%lmin, 0) |
| 73 |
test ("1%lmin", 1%lmin, 1) |
| 74 |
|
| 75 |
exit() |
| 76 |
} |
| 77 |
|
| 78 |
probe end { |
| 79 |
printf ("passes: %d failures: %d\n", passes, failures) |
| 80 |
} |