#!/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"