blob: 0f591399ada6f1c546a96d35cbae3c84aa77b5c6 [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/whlsl-test-harness.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
const whlslTests = {};
whlslTests.uintBitAnd = async () => {
let program = `
uint foo(uint a, uint b)
{
return a & b;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1), makeUint(7)]), 1);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535), makeUint(42)]), 42);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1), makeUint(Math.pow(2, 32) - 7)]), 4294967289);
assert_equals(await callUintFunction(program, "foo", [makeUint(0), makeUint(85732)]), 0);
}
whlslTests.uintBitOr = async () => {
let program = `
uint foo(uint a, uint b)
{
return a | b;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1), makeUint(7)]), 7);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535), makeUint(42)]), 65535);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1), makeUint(Math.pow(2, 32) - 7)]), 4294967295);
assert_equals(await callUintFunction(program, "foo", [makeUint(0), makeUint(85732)]), 85732);
}
whlslTests.uintBitXor = async () => {
let program = `
uint foo(uint a, uint b)
{
return a ^ b;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1), makeUint(7)]), 6);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535), makeUint(42)]), 65493);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1), makeUint(Math.pow(2, 32) - 7)]), 6);
assert_equals(await callUintFunction(program, "foo", [makeUint(0), makeUint(85732)]), 85732);
}
whlslTests.uintBitNot = async () => {
let program = `
uint foo(uint a)
{
return ~a;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1)]), 4294967294);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535)]), 4294901760);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(0)]), 4294967295);
}
whlslTests.uintLShift = async () => {
let program = `
uint foo(uint a, uint b)
{
return a << b;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1), makeUint(7)]), 128);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535), makeUint(2)]), 262140);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1), makeUint(5)]), 4294967264);
assert_equals(await callUintFunction(program, "foo", [makeUint(0), makeUint(3)]), 0);
};
whlslTests.uintRShift = async () => {
let program = `
uint foo(uint a, uint b)
{
return a >> b;
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(1), makeUint(7)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(65535), makeUint(2)]), 16383);
assert_equals(await callUintFunction(program, "foo", [makeUint(Math.pow(2, 32) - 1), makeUint(5)]), 134217727);
assert_equals(await callUintFunction(program, "foo", [makeUint(0), makeUint(3)]), 0);
};
whlslTests.uintSimpleMath = async () => {
let program = "uint foo(uint x, uint y) { return x + y; }";
assert_equals(await callUintFunction(program, "foo", [makeUint(7), makeUint(5)]), 12);
program = "uint foo(uint x, uint y) { return x - y; }";
assert_equals(await callUintFunction(program, "foo", [makeUint(7), makeUint(5)]), 2);
assert_equals(await callUintFunction(program, "foo", [makeUint(5), makeUint(7)]), 4294967294);
program = "uint foo(uint x, uint y) { return x * y; }";
assert_equals(await callUintFunction(program, "foo", [makeUint(7), makeUint(5)]), 35);
// FIXME: make this work: https://bugs.webkit.org/show_bug.cgi?id=199602
// program = "uint foo(uint x, uint y) { return x / y; }";
// assert_equals(await callUintFunction(program, "foo", [makeUint(7), makeUint(2)]), 3);
}
runTests(whlslTests);
</script>
</html>