sbarati@apple.com | bf41af1 | 2019-07-10 00:23:19 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
sbarati@apple.com | 5371402 | 2019-07-09 23:05:45 +0000 | [diff] [blame] | 2 | <html> |
| 3 | <meta charset=utf-8> |
| 4 | <meta name="timeout" content="long"> |
| 5 | <title>Test the WHLSL test harness.</title> |
mmaxfield@apple.com | 87064d8 | 2019-07-17 19:37:56 +0000 | [diff] [blame] | 6 | <script src="js/test-harness.js"></script> |
| 7 | <script src="../js/webgpu-functions.js"></script> |
| 8 | <script src="../../resources/testharness.js"></script> |
| 9 | <script src="../../resources/testharnessreport.js"></script> |
sbarati@apple.com | 5371402 | 2019-07-09 23:05:45 +0000 | [diff] [blame] | 10 | <script> |
| 11 | const whlslTests = {}; |
| 12 | |
| 13 | whlslTests.equality = async () => { |
| 14 | let program = "bool foo(uint x, uint y) { return x == y; }"; |
| 15 | assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(5)]), false); |
| 16 | assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(7)]), true); |
| 17 | program = "bool foo(int x, int y) { return x == y; }"; |
| 18 | assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(5)]), false); |
| 19 | assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(7)]), true); |
| 20 | program = "bool foo(bool x, bool y) { return x == y; }"; |
| 21 | assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(true)]), false); |
| 22 | assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(false)]), false); |
| 23 | assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(false)]), true); |
| 24 | assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(true)]), true); |
| 25 | } |
| 26 | |
| 27 | whlslTests.notEquality = async () => { |
| 28 | let program = "bool foo(uint x, uint y) { return x != y; }"; |
| 29 | assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(5)]), true); |
| 30 | assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(7)]), false); |
| 31 | program = "bool foo(int x, int y) { return x != y; }"; |
| 32 | assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(5)]), true); |
| 33 | assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(7)]), false); |
| 34 | program = "bool foo(bool x, bool y) { return x != y; }"; |
| 35 | assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(true)]), true); |
| 36 | assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(false)]), true); |
| 37 | assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(false)]), false); |
| 38 | assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(true)]), false); |
| 39 | }; |
| 40 | |
| 41 | whlslTests.equalityTypeFailure = async () => { |
| 42 | await checkFail("bool foo(int x, uint y) { return x == y; }"); |
| 43 | }; |
| 44 | |
| 45 | whlslTests.equalsWrongArgumentLength = async () => { |
| 46 | await checkFail( |
| 47 | ` |
| 48 | bool operator==() { return true; } |
| 49 | `); |
| 50 | |
| 51 | await checkFail( |
| 52 | ` |
| 53 | bool operator==(int) { return true; } |
| 54 | `); |
| 55 | |
| 56 | await checkFail( |
| 57 | ` |
| 58 | bool operator==(int, int, int) { return true; } |
| 59 | `); |
| 60 | }; |
| 61 | |
| 62 | whlslTests.equalsWrongReturnType = async () => { |
| 63 | await checkFail( |
| 64 | ` |
| 65 | struct Foo { } |
| 66 | int operator==(Foo, Foo) { return 42; } |
| 67 | `); |
| 68 | } |
| 69 | |
| 70 | whlslTests.lessEqualWrongArgumentLength = async () => { |
| 71 | await checkFail( |
| 72 | ` |
| 73 | bool operator<=() { return true; } |
| 74 | `); |
| 75 | await checkFail( |
| 76 | ` |
| 77 | bool operator<=(int) { return true; } |
| 78 | `); |
| 79 | |
| 80 | await checkFail( |
| 81 | ` |
| 82 | bool operator<=(int, int, int) { return true; } |
| 83 | `); |
| 84 | } |
| 85 | |
| 86 | whlslTests.lessEqualWrongReturnType = async () => { |
| 87 | checkFail( |
| 88 | ` |
| 89 | struct Foo { } |
| 90 | int operator<=(Foo, Foo) { return 42; } |
| 91 | `); |
| 92 | } |
| 93 | |
| 94 | whlslTests.lessThanWrongArgumentLength = async () => { |
| 95 | await checkFail( |
| 96 | ` |
| 97 | bool operator<() { return true; } |
| 98 | `); |
| 99 | await checkFail( |
| 100 | ` |
| 101 | bool operator<(int) { return true; } |
| 102 | `); |
| 103 | await checkFail( |
| 104 | ` |
| 105 | bool operator<(int, int, int) { return true; } |
| 106 | `); |
| 107 | } |
| 108 | |
| 109 | whlslTests.lessThanWrongReturnType = async () => { |
| 110 | await checkFail( |
| 111 | ` |
| 112 | struct Foo { } |
| 113 | int operator<(Foo, Foo) { return 42; } |
| 114 | `); |
| 115 | } |
| 116 | |
| 117 | runTests(whlslTests); |
| 118 | </script> |
| 119 | </html> |