blob: fea7a26c98b23c5a639aebd7e4561e45673a21f3 [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Test the WHLSL test harness.</title>
<script src="js/test-harness.js"></script>
<script src="../js/webgpu-functions.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
const whlslTests = {};
whlslTests.equality = async () => {
let program = "bool foo(uint x, uint y) { return x == y; }";
assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(5)]), false);
assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(7)]), true);
program = "bool foo(int x, int y) { return x == y; }";
assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(5)]), false);
assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(7)]), true);
program = "bool foo(bool x, bool y) { return x == y; }";
assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(true)]), false);
assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(false)]), false);
assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(false)]), true);
assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(true)]), true);
}
whlslTests.notEquality = async () => {
let program = "bool foo(uint x, uint y) { return x != y; }";
assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(5)]), true);
assert_equals(await callBoolFunction(program, "foo", [makeUint(7), makeUint(7)]), false);
program = "bool foo(int x, int y) { return x != y; }";
assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(5)]), true);
assert_equals(await callBoolFunction(program, "foo", [makeInt(7), makeInt(7)]), false);
program = "bool foo(bool x, bool y) { return x != y; }";
assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(true)]), true);
assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(false)]), true);
assert_equals(await callBoolFunction(program, "foo", [makeBool(false), makeBool(false)]), false);
assert_equals(await callBoolFunction(program, "foo", [makeBool(true), makeBool(true)]), false);
};
whlslTests.equalityTypeFailure = async () => {
await checkFail("bool foo(int x, uint y) { return x == y; }");
};
whlslTests.equalsWrongArgumentLength = async () => {
await checkFail(
`
bool operator==() { return true; }
`);
await checkFail(
`
bool operator==(int) { return true; }
`);
await checkFail(
`
bool operator==(int, int, int) { return true; }
`);
};
whlslTests.equalsWrongReturnType = async () => {
await checkFail(
`
struct Foo { }
int operator==(Foo, Foo) { return 42; }
`);
}
whlslTests.lessEqualWrongArgumentLength = async () => {
await checkFail(
`
bool operator<=() { return true; }
`);
await checkFail(
`
bool operator<=(int) { return true; }
`);
await checkFail(
`
bool operator<=(int, int, int) { return true; }
`);
}
whlslTests.lessEqualWrongReturnType = async () => {
checkFail(
`
struct Foo { }
int operator<=(Foo, Foo) { return 42; }
`);
}
whlslTests.lessThanWrongArgumentLength = async () => {
await checkFail(
`
bool operator<() { return true; }
`);
await checkFail(
`
bool operator<(int) { return true; }
`);
await checkFail(
`
bool operator<(int, int, int) { return true; }
`);
}
whlslTests.lessThanWrongReturnType = async () => {
await checkFail(
`
struct Foo { }
int operator<(Foo, Foo) { return 42; }
`);
}
runTests(whlslTests);
</script>
</html>