blob: 6d0c0f2adf427291c41c1adbfebb618b14b0705d [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Test loops.</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 = {};
const checkFuncs = {
"uint": callUintFunction,
"int": callIntFunction,
"float": callFloatFunction
};
const typeNames = [ "uint", "int", "float" ];
const sizes = [ 2, 3, 4 ];
const elements = [ "x", "y", "z", "w" ];
const initializerList = [ 1, 2, 3, 4 ];
whlslTests.builtinVectorGetters = async () =>
{
let tests = [];
let src = "";
for (let typeName of typeNames) {
for (let size of sizes) {
for (let i = 0; i < size; i++) {
const functionName = `${typeName}${size}${elements[i]}`;
src += `${typeName} ${functionName}()
{
${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")});
return x.${elements[i]};
}
`;
tests.push({ type: typeName, name: functionName, expectation: initializerList[i] });
}
}
}
let program = src;
for (let test of tests) {
const checkFunc = checkFuncs[test.type];
assert_equals(await checkFunc(program, test.name, []), test.expectation);
}
};
whlslTests.builtinVectorSetters = async () =>
{
let tests = [];
let src = "";
for (let typeName of typeNames) {
for (let size of sizes) {
for (let i = 0; i < size; i++) {
const functionName = `${typeName}${size}${elements[i]}`;
src += `${typeName} ${functionName}()
{
${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")});
x.${elements[i]} = 34;
return x.${elements[i]};
}
`;
tests.push({ type: typeName, name: functionName, expectation: 34 });
}
}
}
let program = src;
for (let test of tests) {
const checkFunc = checkFuncs[test.type];
assert_equals(await checkFunc(program, test.name, []), test.expectation);
}
}
runTests(whlslTests);
</script>
</html>