summaryrefslogtreecommitdiff
path: root/run_tests.sh
blob: c2948bb3bc8b0525ec03a9f6aa6c4d765ce9aee1 (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
#!/bin/bash

MAX_SINT="2147483647"
MIN_SINT="-2147483648"

(( FAIL = 0 ))
(( PASS = 0 ))


run_test () {
  echo "Running $1"
  `$1 &>/dev/null`
  if [ $? -ne 0 ]; then
    echo "Failed"
    (( FAIL++ ))
  else
    echo "Passed"
    (( PASS++ ))
  fi
}

clear_memory() {
  `./memset 373598559 $1 1 1 &>/dev/null`
}

################################################################################
#Integer Add                                                                   #
################################################################################

#Test random add
run_test "./math-int add 1 2 3"
#Same as above with arguments reversed
run_test "./math-int add 2 1 3"
#Test negative plus positive
run_test "./math-int add -5 10 5"
#Test negative plus negative
run_test "./math-int add -1 -4 -5"

################################################################################
#Integer Multiply                                                              #
################################################################################

#Test random multiply
run_test "./math-int mul 4 5 20"
#Test multiply by 0
run_test "./math-int mul 8 0 0"
#Test multiply negative by positive
run_test "./math-int mul -3 8 -24"
#Test multiply negative by negative
run_test "./math-int mul -12 -6 72"

################################################################################
#Integer divide                                                                #
################################################################################

#Test even divide
run_test "./math-int div 20 5 4"
#Test divide with remainder
run_test "./math-int div 23 5 4"
#Test divide by 1
run_test "./math-int div 30 1 30"
#Test divide by -1
run_test "./math-int div 57 -1 -57"
#Test divide by a negative number
run_test "./math-int div 10 -2 -5"
#Test divide by a negative number with remainder
run_test "./math-int div 17 -3 -5"
#Test divide a negative number
run_test "./math-int div -28 2 -14"
#Test divide a negative number with remainder
run_test "./math-int div -8 3 -2"
#Two negative args
run_test "./math-int div -25 -5 5"
#Two nefative args with remainder
run_test "./math-int div -24 -5 4"

################################################################################
#Integer Modulo                                                                #
################################################################################

#Test Modulo is zero
run_test "./math-int mod 18 6 0"
#Test Modulo is non-zero
run_test "./math-int mod 59 12 11"
#Test arg0 negative modulo is zero
run_test "./math-int mod -20 5 0"
#Test arg0 negative modulo is non-zero (In the real world -18 % 5 = 2)
run_test "./math-int mod -18 5 -3"
#Test arg1 negative modulo is zero
run_test "./math-int mod 50 -10 0"
#Test arg1 negative modulo is non-zero (In the real world 16 % -3 = -2)
run_test "./math-int mod 16 -3 1"
#Test arg1 = MAX_SINT
run_test "./math-int mod ${MAX_SINT} 12345 9172"
#Test arg1 = MIN_SINT (In the real world MIN_SING % 476 = 348)
run_test "./math-int mod ${MIN_SINT} 476 -128"
#Test arg0 < arg1
run_test "./math-int mod 10 20 10"

#Test division paths with a constant divisor that are optimized with shifts
#(The second argument to these tests is ignored)
#Constant non-power of two divisor, modulo is zero
run_test "./math-int mod_nine 18 9 0"
#Constant non-power of two divisor, modulo is non-zero
run_test "./math-int mod_nine 23 9 5"
#Constant power of two divisor, modulo is zero
run_test "./math-int mod_four 20 4 0"
#Constant power of two divisor, modulo is non-zero
run_test "./math-int mod_four 5 4 1"

###############################################################################
#get_global_id()                                                              #
###############################################################################

#One work group
clear_memory 100
run_test "./get-global-id 100 100"
#One work item per work group
clear_memory 100
run_test "./get-global-id 250 1"
#Large number of threads in one work group
#run_test "./get-global-id 1000000 1000000"
#Large number of work groups, one work item per group
#run_test "./get-global-id 2000000 1"
#Large number of threads
#run_test "./get-global-id 5000000 1000"

################################################################################
#if (x > y)                                                                    #
################################################################################

#True case
run_test "./math-int if_gt 5 4 1"
#False case
run_test "./math-int if_gt 5 6 0"
# x < y but abs(x) > y
run_test "./math-int if_gt -20 10 0"
# x < y and abs(x) > y
run_test "./math-int if_gt -5 8 0"
# x > y, but x < abs(y)
run_test "./math-int if_gt 12 -15 1"
# x > y and x > abs(y)
run_test "./math-int if_gt 16 -3 1"

################################################################################
#if (x >= y)                                                                   #
################################################################################

#True (x > y)
run_test "./math-int if_ge 8 7 1"
#True (x == y)
run_test "./math-int if_ge 10 10 1"
#False (x < y)
run_test "./math-int if_ge 20 30 0"
#True (x > y), but x < abs(y)
run_test "./math-int if_ge 3 -8 1"
#False (x < y), but abs(x) == y
run_test "./math-int if_ge -5 5 0"
#False (x < y), but abs(x) > y
run_test "./math-int if_ge -20 10 0"

################################################################################
#if (x == y)                                                                   #
################################################################################

#True
run_test "./math-int if_eq 21 21 1"
#False
run_test "./math-int if_eq 30 18 0"
#False, but abs(x) == y
run_test "./math-int if_eq -12 12 0"
#False, but x == abs(y)
run_test "./math-int if_eq 81 -81 0"

################################################################################
#if (x < y)                                                                    #
################################################################################

#True
run_test "./math-int if_lt 2 10 1"
#True, but abs(x) > y
run_test "./math-int if_lt -20 3 1"
#False
run_test "./math-int if_lt 15 3 0"

################################################################################
#if (x <= y)                                                                   #
################################################################################

#True
run_test "./math-int if_le 20 25 1"
#True x == y
run_test "./math-int if_le 18 18 1"
#True, but abs(x) > y
run_test "./math-int if_le -10 5 1"
#False
run_test "./math-int if_le 18 9 0"
#False, but x < abs(y)
run_test "./math-int if_le 10 -20 0"

################################################################################
#if (x != y)                                                                   #
################################################################################

#True
run_test "./math-int if_ne 10 9 1"
#True, but abs(x) == y
run_test "./math-int if_ne -20 20 1"
#True, but x == abs(y)
run_test "./math-int if_ne 31 -31 1"
#False
run_test "./math-int if_ne 3 3 0"

################################################################################
#loop tests                                                                    #
################################################################################

clear_memory 100
run_test "./loop loop_lt 10"
clear_memory 100
run_test "./loop loop_le 10"
clear_memory 100
run_test "./loop loop_gt 10"
clear_memory 100
run_test "./loop loop_ge 10"

###############################################################################
#bit rotate left tests (not using the OpenCL C rotate builtin)
###############################################################################

#rotl(0x1, 1) = 0x2
run_test "./math-int rotl 1 1 2"
#rotl(0x1, 32) = 0x1
run_test "./math-int rotl 1 32 1"
#rotl(0xffffffff, 5) = 0xffffffff
run_test "./math-int rotl -1 5 -1"
#rotl(0x00001000, 23) = 0x8
run_test "./math-int rotl 4096 23 8"

################################################################################
#USE_HOST_PTR
################################################################################

clear_memory 100
run_test "./use-host-ptr 10"

################################################################################
#v4i32 loads
################################################################################

clear_memory 100
run_test "./vec-load"

echo "$PASS passes, $FAIL fails"