Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/arith.stp

raw
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 println ("test " . (sprint (++testno)) . " [" . v . "]\t" . result)
12 }
13
14 function stest (v,n1,n2) {
15 if (n1 == n2) {
16 passes ++
17 result = "pass"
18 } else {
19 failures ++
20 result = "fail"
21 }
22 println ("test " . (sprint (++testno)) . " [" . v . "]\t" . result)
23 }
24
25
26 probe begin {
27 test ("+", 0, 0+0)
28 test ("+", 33339999, 33330000+9999)
29 test ("-", -1, 2-3)
30 test ("==", 1, -1==-1)
31 test ("!=", 1, -1!=1)
32 test (">", 1, 2>1)
33 test (">= (=)", 1, 1>=1)
34 test (">= (>)", 1, 2>=1)
35 test ("<", 1, -1<1)
36 test ("<= (=)", 1, 1<=1)
37 test ("<= (<)", 1, -1<=1)
38
39 test ("== s", 1, "foobar"=="foobar")
40 test (">= s (=)", 1, "foobar">="foobar")
41 test ("<= s (=)", 1, "foobar"<="foobar")
42 test ("<= s (<)", 1, "fooban"<="foobar")
43 test (">= s (>)", 1, "xxx">="aaa")
44 test ("> s", 1, "xxx">"aaa")
45 test ("< s", 1, "aaa"<"xxx")
46 test ("!= s", 1, "aaa"!="xxx")
47
48 test ("<", 1, -1<0)
49 test ("<", 1, 85723838<8273823892)
50 test ("*", 100300400500, 1003004005 * 100)
51 test ("*", -1*-500, 500)
52 test ("/", 1003004005/1000, 1003004)
53 test ("%", 1003004005%1000, 5)
54 test ("/", -1/-1, 1)
55 test ("%", -1%-1, 0)
56 test ("/", 0/-100, 0)
57 test ("%", 0%-100, 0)
58 test ("/", (-2147483647-1)/-1, 2147483648)
59 test ("%", (-2147483647-1)%-1, 0)
60 # but (-9223372036854775807-1)/-1 may overflow
61 test ("%", (-9223372036854775807-1)%-1, 0)
62 test ("&", 0x555&0xaaa, 0)
63 test ("|", 0x555|0xaaa, 0xfff)
64 test ("^", 0x55f^0xaaf, 0xff0)
65 test ("&&", 0x555&&0xaaa, 1)
66 test ("||", 0x555||0xaaa, 1)
67 test ("<<", 0<<5, 0)
68 test ("<<", 1<<8, 0x100)
69 test ("<<", 120<<-2, 120)
70 test ("<<", 120<<0, 120)
71 test ("<<", -4096<<-3, -4096)
72 test (">>", -4096>>3, -512)
73 test (">>", -4096>>-3, -4096)
74 test (">>", 120>>-2, 120)
75 test (">>", 120>>0, 120)
76 i=1; test ("--i", --i, 0)
77 i=1; test ("++i", ++i, 2)
78 i=1; test ("i--", i--, 1)
79 i=1; test ("i++", i++, 1)
80 i=1; test ("+=", i+=4, 5) test ("after +=", i, 5)
81 i=2; test ("*=", i-=1, 1) test ("after -=", i, 1)
82 i=5; test ("/=", i/=2, 2) test ("after /=", i, 2)
83 i=2; test ("*=", i*=2, 4) test ("after *=", i, 4)
84 i=3; test ("*=", i%=2, 1) test ("after %=", i, 1)
85 i=0xf; test (">>=", i>>=1, 7) test ("after >>=", i, 7)
86 i=0xf; test ("<<=", i<<=1, 30) test ("after <<=", i, 30)
87 i=0xf; test ("&=", i&=1, 1) test ("after &=", i, 1)
88 i=0xf; test ("^=", i^=1, 14) test ("after ^=", i, 14)
89 i=0xf; test ("|=", i|=1, 15) test ("after |=", i, 15)
90 i=+5; test ("+", i+5, 10)
91 i=-5; test ("+", i+5, 0)
92 i=5; test ("!", !i, 0)
93 i=0xf; test ("~", ~i, -16)
94 a="1" b="2"; stest (".=", a .= b, "12") stest ("after .=", a, "12")
95
96 test ("?:", 5==5?1:2, 1)
97 }
98
99
100 probe timer.sec(1) { # some time after all the begin probes
101 exit ()
102 }
103
104 probe end {
105 printf ("passes: %d failures: %d\n", passes, failures)
106 }