[WHLSL Import more JS reference spec tests
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jul 2019 20:01:55 +0000 (20:01 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jul 2019 20:01:55 +0000 (20:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199651

Rubber stamped by Robin Morisset.

* webgpu/whlsl-builtin-vectors-2-expected.txt: Added.
* webgpu/whlsl-builtin-vectors-2.html: Added.
* webgpu/whlsl-builtin-vectors-expected.txt: Added.
* webgpu/whlsl-builtin-vectors.html: Added.
* webgpu/whlsl-getter-setter-type-expected.txt: Added.
* webgpu/whlsl-getter-setter-type.html: Added.
* webgpu/whlsl-loops-spec-tests-expected.txt: Added.
* webgpu/whlsl-loops-spec-tests.html: Added.
* webgpu/whlsl-null-array-ref.html: Added.
* webgpu/whlsl-override-subscript-expected.txt: Added.
* webgpu/whlsl-override-subscript.html: Added.
* webgpu/whlsl-plus-equals-expected.txt: Added.
* webgpu/whlsl-plus-equals.html: Added.
* webgpu/whlsl-recursive-structs-expected.txt: Added.
* webgpu/whlsl-recursive-structs.html: Added.
* webgpu/whlsl-ternary-spec-test-expected.txt: Added.
* webgpu/whlsl-ternary-spec-test.html: Added.
* webgpu/whlsl-wrong-argument-length-expected.txt: Added.
* webgpu/whlsl-wrong-argument-length.html: Added.
* webgpu/whlsl-wrong-types-expected.txt: Added.
* webgpu/whlsl-wrong-types.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247319 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl-builtin-vectors-2-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-builtin-vectors-2.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-builtin-vectors-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-builtin-vectors.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-getter-setter-type-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-getter-setter-type.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-if-statement-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-if-statement.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-loops-spec-tests-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-loops-spec-tests.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-null-array-ref.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-override-subscript-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-override-subscript.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-plus-equals-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-plus-equals.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-recursive-structs-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-recursive-structs.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-ternary-spec-test-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-ternary-spec-test.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-wrong-argument-length-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-wrong-argument-length.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-wrong-types-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-wrong-types.html [new file with mode: 0644]

index e23a3c4..e2e072b 100644 (file)
@@ -1,3 +1,32 @@
+2019-07-10  Saam Barati  <sbarati@apple.com>
+
+        [WHLSL Import more JS reference spec tests
+        https://bugs.webkit.org/show_bug.cgi?id=199651
+
+        Rubber stamped by Robin Morisset.
+
+        * webgpu/whlsl-builtin-vectors-2-expected.txt: Added.
+        * webgpu/whlsl-builtin-vectors-2.html: Added.
+        * webgpu/whlsl-builtin-vectors-expected.txt: Added.
+        * webgpu/whlsl-builtin-vectors.html: Added.
+        * webgpu/whlsl-getter-setter-type-expected.txt: Added.
+        * webgpu/whlsl-getter-setter-type.html: Added.
+        * webgpu/whlsl-loops-spec-tests-expected.txt: Added.
+        * webgpu/whlsl-loops-spec-tests.html: Added.
+        * webgpu/whlsl-null-array-ref.html: Added.
+        * webgpu/whlsl-override-subscript-expected.txt: Added.
+        * webgpu/whlsl-override-subscript.html: Added.
+        * webgpu/whlsl-plus-equals-expected.txt: Added.
+        * webgpu/whlsl-plus-equals.html: Added.
+        * webgpu/whlsl-recursive-structs-expected.txt: Added.
+        * webgpu/whlsl-recursive-structs.html: Added.
+        * webgpu/whlsl-ternary-spec-test-expected.txt: Added.
+        * webgpu/whlsl-ternary-spec-test.html: Added.
+        * webgpu/whlsl-wrong-argument-length-expected.txt: Added.
+        * webgpu/whlsl-wrong-argument-length.html: Added.
+        * webgpu/whlsl-wrong-types-expected.txt: Added.
+        * webgpu/whlsl-wrong-types.html: Added.
+
 2019-07-10  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r247223.
diff --git a/LayoutTests/webgpu/whlsl-builtin-vectors-2-expected.txt b/LayoutTests/webgpu/whlsl-builtin-vectors-2-expected.txt
new file mode 100644 (file)
index 0000000..0e7b017
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS builtinVectorGetters 
+PASS builtinVectorSetters 
+
diff --git a/LayoutTests/webgpu/whlsl-builtin-vectors-2.html b/LayoutTests/webgpu/whlsl-builtin-vectors-2.html
new file mode 100644 (file)
index 0000000..f557a83
--- /dev/null
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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>
+
diff --git a/LayoutTests/webgpu/whlsl-builtin-vectors-expected.txt b/LayoutTests/webgpu/whlsl-builtin-vectors-expected.txt
new file mode 100644 (file)
index 0000000..101c7a2
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS builtinVectorIndexSetters 
+PASS builtinVectors 
+
diff --git a/LayoutTests/webgpu/whlsl-builtin-vectors.html b/LayoutTests/webgpu/whlsl-builtin-vectors.html
new file mode 100644 (file)
index 0000000..21494f3
--- /dev/null
@@ -0,0 +1,191 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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.builtinVectorIndexSetters = 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[${i}] = 34;
+                            return x[${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);
+    }
+};
+
+whlslTests.builtinVectors = async () =>
+{
+    let program = `
+        int foo()
+        {
+            int2 a = int2(3, 4);
+            return a[0];
+        }
+        int foo2()
+        {
+            int2 a = int2(3, 4);
+            int3 b = int3(a, 5);
+            return b[1];
+        }
+        int foo3()
+        {
+            int3 a = int3(3, 4, 5);
+            int4 b = int4(6, a);
+            return b[1];
+        }
+        int foo4()
+        {
+            int2 a = int2(3, 4);
+            int2 b = int2(5, 6);
+            int4 c = int4(a, b);
+            return c[2];
+        }
+        bool foo5()
+        {
+            int4 a = int4(3, 4, 5, 6);
+            int2 b = int2(4, 5);
+            int4 c = int4(3, b, 6);
+            return a == c;
+        }
+        bool foo6()
+        {
+            int2 a = int2(4, 5);
+            int3 b = int3(3, a);
+            int3 c = int3(3, 4, 6);
+            return b == c;
+        }
+        uint foou()
+        {
+            uint2 a = uint2(3, 4);
+            return a[0];
+        }
+        uint foou2()
+        {
+            uint2 a = uint2(3, 4);
+            uint3 b = uint3(a, 5);
+            return b[1];
+        }
+        uint foou3()
+        {
+            uint3 a = uint3(3, 4, 5);
+            uint4 b = uint4(6, a);
+            return b[1];
+        }
+        uint foou4()
+        {
+            uint2 a = uint2(3, 4);
+            uint2 b = uint2(5, 6);
+            uint4 c = uint4(a, b);
+            return c[2];
+        }
+        bool foou5()
+        {
+            uint4 a = uint4(3, 4, 5, 6);
+            uint2 b = uint2(4, 5);
+            uint4 c = uint4(3, b, 6);
+            return a == c;
+        }
+        bool foou6()
+        {
+            uint2 a = uint2(4, 5);
+            uint3 b = uint3(3, a);
+            uint3 c = uint3(3, 4, 6);
+            return b == c;
+        }
+        float foof()
+        {
+            float2 a = float2(3., 4.);
+            return a[0];
+        }
+        float foof2()
+        {
+            float2 a = float2(3., 4.);
+            float3 b = float3(a, 5.);
+            return b[1];
+        }
+        float foof3()
+        {
+            float3 a = float3(3., 4., 5.);
+            float4 b = float4(6., a);
+            return b[1];
+        }
+        float foof4()
+        {
+            float2 a = float2(3., 4.);
+            float2 b = float2(5., 6.);
+            float4 c = float4(a, b);
+            return c[2];
+        }
+        bool foof5()
+        {
+            float4 a = float4(3., 4., 5., 6.);
+            float2 b = float2(4., 5.);
+            float4 c = float4(3., b, 6.);
+            return a == c;
+        }
+        bool foof6()
+        {
+            float2 a = float2(4., 5.);
+            float3 b = float3(3., a);
+            float3 c = float3(3., 4., 6.);
+            return b == c;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 3);
+    assert_equals(await callIntFunction(program, "foo2", []), 4);
+    assert_equals(await callIntFunction(program, "foo3", []), 3);
+    assert_equals(await callIntFunction(program, "foo4", []), 5);
+    assert_equals(await callBoolFunction(program, "foo5", []), true);
+    assert_equals(await callBoolFunction(program, "foo6", []), false);
+    assert_equals(await callUintFunction(program, "foou", []), 3);
+    assert_equals(await callUintFunction(program, "foou2", []), 4);
+    assert_equals(await callUintFunction(program, "foou3", []), 3);
+    assert_equals(await callUintFunction(program, "foou4", []), 5);
+    assert_equals(await callBoolFunction(program, "foou5", []), true);
+    assert_equals(await callBoolFunction(program, "foou6", []), false);
+    assert_equals(await callFloatFunction(program, "foof", []), 3);
+    assert_equals(await callFloatFunction(program, "foof2", []), 4);
+    assert_equals(await callFloatFunction(program, "foof3", []), 3);
+    assert_equals(await callFloatFunction(program, "foof4", []), 5);
+    assert_equals(await callBoolFunction(program, "foof5", []), true);
+    assert_equals(await callBoolFunction(program, "foof6", []), false);
+};
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-getter-setter-type-expected.txt b/LayoutTests/webgpu/whlsl-getter-setter-type-expected.txt
new file mode 100644 (file)
index 0000000..0357ec7
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS getterType 
+PASS setterType 
+
diff --git a/LayoutTests/webgpu/whlsl-getter-setter-type.html b/LayoutTests/webgpu/whlsl-getter-setter-type.html
new file mode 100644 (file)
index 0000000..621f041
--- /dev/null
@@ -0,0 +1,103 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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.getterType = async () => {
+    await checkFail(`
+        int operator.x(thread int[] foo)
+        {
+            return foo[0];
+        }
+    `); 
+    await checkFail(`
+        int operator.x(int[3] foo)
+        {
+            return foo[0];
+        }
+    `); 
+    await checkFail(`
+        int operator[](thread int[] foo, int index)
+        {
+            return foo[index];
+        }
+    `); 
+    await checkFail(`
+        int operator.x(int[3] foo)
+        {
+            return foo[0];
+        }
+    `); 
+    await checkFail(`
+        struct Foo {
+            int x;
+        }
+        int operator[](Foo foo, uint4 index)
+        {
+            return foo[index.x];
+        }
+    `); 
+};
+
+whlslTests.setterType = async () => {
+    await checkFail(`
+        thread int[] operator.x=(thread int[] foo, uint x)
+        {
+            return foo;
+        }
+    `); 
+    await checkFail(`
+        int[3] operator.x=(int[3] foo, uint x)
+        {
+            return foo;
+        }
+    `); 
+    await checkFail(`
+        thread int[] operator[]=(thread int[] foo, uint x, uint y)
+        {
+            return foo;
+        }
+    `); 
+    await checkFail(`
+        int[3] operator.x=(int[3] foo, uint x)
+        {
+            return foo;
+        }
+    `); 
+    await checkFail(`
+        struct Foo {
+            int x;
+        }
+        Foo operator[]=(Foo foo, float4 y, uint z)
+        {
+            return foo.x;
+        }
+    `); 
+    await checkFail(`
+        struct Foo {
+            int x;
+        }
+        int operator.y(Foo foo)
+        {
+            return foo.x;
+        }
+        Foo operator.y=(Foo foo, int4 x)
+        {
+            Foo result;
+            foo.x = x.x;
+            return result;
+        }
+    `); 
+};
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-if-statement-expected.txt b/LayoutTests/webgpu/whlsl-if-statement-expected.txt
new file mode 100644 (file)
index 0000000..21383e7
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS ifStatement 
+PASS ifElseStatement 
+PASS ifElseIfStatement 
+PASS ifElseIfElseStatement 
+
diff --git a/LayoutTests/webgpu/whlsl-if-statement.html b/LayoutTests/webgpu/whlsl-if-statement.html
new file mode 100644 (file)
index 0000000..c42648c
--- /dev/null
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test int bit math.</title>
+<script src="js/whlsl-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.ifStatement = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            int y = 6;
+            if (x == 7) {
+                y = 8;
+            }
+            return y;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(3)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(4)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(5)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(6)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 8);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(8)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(9)]), 6);
+}
+
+whlslTests.ifElseStatement = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            int y = 6;
+            if (x == 7) {
+                y = 8;
+            } else {
+                y = 9;
+            }
+            return y;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(3)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(4)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(5)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(6)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 8);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(8)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(9)]), 9);
+}
+
+whlslTests.ifElseIfStatement = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            int y = 6;
+            if (x == 7) {
+                y = 8;
+            } else if (x == 8) {
+                y = 9;
+            }
+            return y;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(3)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(4)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(5)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(6)]), 6);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 8);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(8)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(9)]), 6);
+}
+
+whlslTests.ifElseIfElseStatement = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            int y = 6;
+            if (x == 7) {
+                y = 8;
+            } else if (x == 8) {
+                y = 9;
+            } else {
+                y = 10;
+            }
+            return y;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(3)]), 10);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(4)]), 10);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(5)]), 10);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(6)]), 10);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 8);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(8)]), 9);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(9)]), 10);
+}
+
+runTests(whlslTests);
+</script>
+</html>
diff --git a/LayoutTests/webgpu/whlsl-loops-spec-tests-expected.txt b/LayoutTests/webgpu/whlsl-loops-spec-tests-expected.txt
new file mode 100644 (file)
index 0000000..ffd2805
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS doWhile 
+PASS simpleWhile 
+
diff --git a/LayoutTests/webgpu/whlsl-loops-spec-tests.html b/LayoutTests/webgpu/whlsl-loops-spec-tests.html
new file mode 100644 (file)
index 0000000..e8a984d
--- /dev/null
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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.doWhile = async () =>
+{
+    let program = `
+        int foo1(int x)
+        {
+            int y = 7;
+            do {
+                y = 8;
+                break;
+            } while (x < 10);
+            return y;
+        }
+        int foo2(int x)
+        {
+            int y = 7;
+            do {
+                y = 8;
+                break;
+            } while (y == 7);
+            return y;
+        }
+        int foo3(int x)
+        {
+            int sum = 0;
+            do {
+                if (x == 11) {
+                    x = 15;
+                    continue;
+                }
+                sum = sum + x;
+                x = x + 1;
+            } while (x < 13);
+            return sum;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo1", [makeInt(1)]), 8);
+    assert_equals(await callIntFunction(program, "foo1", [makeInt(11)]), 8);
+    assert_equals(await callIntFunction(program, "foo2", [makeInt(1)]), 8);
+    assert_equals(await callIntFunction(program, "foo3", [makeInt(9)]), 19);
+}
+
+whlslTests.simpleWhile = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            while (x < 13)
+                x = x * 2;
+            return x;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(1)]), 16);
+}
+
+runTests(whlslTests);
+</script>
+</html>
diff --git a/LayoutTests/webgpu/whlsl-null-array-ref.html b/LayoutTests/webgpu/whlsl-null-array-ref.html
new file mode 100644 (file)
index 0000000..0d9c946
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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.dereferenceDefaultNullArrayRef = async () =>
+{
+    let program = `
+        int foo()
+        {
+            thread int[] p;
+            return p[0];
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 0);
+}
+
+whlslTests.defaultInitializedNullArrayRefIntLiteral = async () =>
+{
+    let program = `
+        int foo()
+        {
+            thread int[] p = null;
+            return p[0];
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 0);
+}
+
+whlslTests.passNullToPtrMonomorphicArrayRef = async () =>
+{
+    let program = `
+        int foo(thread int[] ptr)
+        {
+            return ptr[0u];
+        }
+        int bar()
+        {
+            return foo(null);
+        }
+    `;
+    assert_equals(await callIntFunction(program, "bar", []), 0);
+}
+
+whlslTests.loadNull = async () =>
+{
+    await checkFail(
+        `
+            void sink(thread int* x) { }
+            void foo() { sink(*null); }
+        `);
+}
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-override-subscript-expected.txt b/LayoutTests/webgpu/whlsl-override-subscript-expected.txt
new file mode 100644 (file)
index 0000000..3864009
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS overrideSubscriptStruct 
+PASS overrideSubscriptStructAndDoStores 
+PASS overrideSubscriptStructAndUsePointers 
+PASS overrideSubscriptStructAndUsePointersIncorrectly 
+
diff --git a/LayoutTests/webgpu/whlsl-override-subscript.html b/LayoutTests/webgpu/whlsl-override-subscript.html
new file mode 100644 (file)
index 0000000..c1f7aac
--- /dev/null
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test override subscripts.</title>
+<script src="js/whlsl-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.overrideSubscriptStruct = async () =>
+{
+    let program = `
+        struct Foo {
+            int x;
+            int y;
+        }
+        thread int* operator&[](thread Foo* foo, uint index)
+        {
+            if (index == 0)
+                return &foo->x;
+            if (index == 1)
+                return &foo->y;
+            return null;
+        }
+        int foo()
+        {
+            Foo foo;
+            foo.x = 498;
+            foo.y = 19;
+            return foo[0] + foo[1] * 3;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 498 + 19 * 3);
+}
+
+whlslTests.overrideSubscriptStructAndDoStores = async () =>
+{
+    let program = `
+        struct Foo {
+            int x;
+            int y;
+        }
+        thread int* operator&[](thread Foo* foo, uint index)
+        {
+            if (index == 0)
+                return &foo->x;
+            if (index == 1)
+                return &foo->y;
+            return null;
+        }
+        int foo()
+        {
+            Foo foo;
+            foo[0] = 498;
+            foo[1] = 19;
+            return foo.x + foo.y;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 498 + 19);
+}
+
+whlslTests.overrideSubscriptStructAndUsePointers = async () =>
+{
+    let program = `
+        struct Foo {
+            int x;
+            int y;
+        }
+        thread int* operator&[](thread Foo* foo, uint index)
+        {
+            if (index == 0)
+                return &foo->x;
+            if (index == 1)
+                return &foo->y;
+            return null;
+        }
+        int bar(thread Foo* foo)
+        {
+            return (*foo)[0] + (*foo)[1];
+        }
+        int foo()
+        {
+            Foo foo;
+            foo.x = 498;
+            foo.y = 19;
+            return bar(&foo);
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 498 + 19);
+}
+
+whlslTests.overrideSubscriptStructAndUsePointersIncorrectly = async () =>
+{
+    checkFail(
+        `
+            struct Foo {
+                int x;
+                int y;
+            }
+            thread int* operator&[](thread Foo* foo, uint index)
+            {
+                if (index == 0)
+                    return &foo->x;
+                if (index == 1)
+                    return &foo->y;
+                return null;
+            }
+            int bar(thread Foo* foo)
+            {
+                return foo[0] + foo[1];
+            }
+            int foo()
+            {
+                Foo foo;
+                foo.x = 498;
+                foo.y = 19;
+                return bar(&foo);
+            }
+        `);
+}
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-plus-equals-expected.txt b/LayoutTests/webgpu/whlsl-plus-equals-expected.txt
new file mode 100644 (file)
index 0000000..76f09cc
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS plusEquals 
+PASS plusEqualsResult 
+
diff --git a/LayoutTests/webgpu/whlsl-plus-equals.html b/LayoutTests/webgpu/whlsl-plus-equals.html
new file mode 100644 (file)
index 0000000..e2f5ecb
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test override subscripts.</title>
+<script src="js/whlsl-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.plusEquals = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            x += 42;
+            return x;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 + 42);
+}
+
+whlslTests.plusEqualsResult = async () =>
+{
+    let program = `
+        int foo(int x)
+        {
+            return x += 42;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 + 42);
+}
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-recursive-structs-expected.txt b/LayoutTests/webgpu/whlsl-recursive-structs-expected.txt
new file mode 100644 (file)
index 0000000..deb5348
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS mutuallyRecursiveStruct 
+PASS mutuallyRecursiveStructWithPointersBroken 
+
diff --git a/LayoutTests/webgpu/whlsl-recursive-structs.html b/LayoutTests/webgpu/whlsl-recursive-structs.html
new file mode 100644 (file)
index 0000000..82f08d4
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test loops.</title>
+<script src="js/whlsl-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.mutuallyRecursiveStruct = async () =>
+{
+    await checkFail(
+        `
+            struct Foo {
+                Bar bar;
+            }
+            struct Bar {
+                Foo foo;
+            }
+        `);
+        
+}
+
+whlslTests.mutuallyRecursiveStructWithPointersBroken = async () =>
+{
+    let program = `
+        struct Foo {
+            thread Bar* bar;
+            int foo;
+        }
+        struct Bar {
+            thread Foo* foo;
+            int bar;
+        }
+        int foo()
+        {
+            Foo foo;
+            Bar bar;
+            foo.foo = 564;
+            bar.bar = 53;
+            return foo.bar->bar - bar.foo->foo;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", []), 0);
+}
+
+runTests(whlslTests);
+</script>
+</html>
+
diff --git a/LayoutTests/webgpu/whlsl-ternary-spec-test-expected.txt b/LayoutTests/webgpu/whlsl-ternary-spec-test-expected.txt
new file mode 100644 (file)
index 0000000..82b8864
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS ternaryExpression 
+
diff --git a/LayoutTests/webgpu/whlsl-ternary-spec-test.html b/LayoutTests/webgpu/whlsl-ternary-spec-test.html
new file mode 100644 (file)
index 0000000..490aa83
--- /dev/null
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test int bit math.</title>
+<script src="js/whlsl-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.ternaryExpression = async () => {
+    let program = `
+        int foo(int x)
+        {
+            return x < 3 ? 4 : 5;
+        }
+        int bar(int x)
+        {
+            return x < 10 ? 11 : x < 12 ? 14 : 15;
+        }
+        int baz(int x)
+        {
+            return 3 < 4 ? x : 5;
+        }
+    `;
+    assert_equals(await callIntFunction(program, "foo", [makeInt(767)]), 5);
+    assert_equals(await callIntFunction(program, "foo", [makeInt(2)]), 4);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(8)]), 11);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(9)]), 11);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(10)]), 14);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(11)]), 14);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(12)]), 15);
+    assert_equals(await callIntFunction(program, "bar", [makeInt(13)]), 15);
+    assert_equals(await callIntFunction(program, "baz", [makeInt(14)]), 14);
+    await checkFail(
+        `
+            int foo()
+            {
+                int x;
+                (4 < 5 ? x : 7) = 8;
+            }
+        `);
+    await checkFail(
+        `
+            int foo()
+            {
+                int x;
+                int y;
+                (0 < 1 ? x : y) = 42;
+                return x;
+            }
+        `);
+    await checkFail(
+        `
+            int foo()
+            {
+                int x;
+                int y;
+                thread int* z = &(0 < 1 ? x : y);
+                return *z;
+            }
+        `);
+    await checkFail(
+        `
+            int foo()
+            {
+                int x;
+                int y;
+                thread int[] z = @(0 < 1 ? x : y);
+                return *z;
+            }
+        `);
+    await checkFail(
+        `
+            int foo()
+            {
+                int x;
+                float y;
+                return 4 < 5 ? x : y;
+            }
+        `);
+    await checkFail(
+        `
+            int foo()
+            {
+                return 4 < 5 ? 6 : 7.0;
+            }
+        `);
+}
+
+runTests(whlslTests);
+</script>
+</html>
diff --git a/LayoutTests/webgpu/whlsl-wrong-argument-length-expected.txt b/LayoutTests/webgpu/whlsl-wrong-argument-length-expected.txt
new file mode 100644 (file)
index 0000000..b2ce369
--- /dev/null
@@ -0,0 +1,21 @@
+
+PASS bitAndWrongArgumentLength 
+PASS bitNotWrongArgumentLength 
+PASS bitOrWrongArgumentLength 
+PASS bitXorWrongArgumentLength 
+PASS decWrongArgumentLength 
+PASS divideWrongArgumentLength 
+PASS dotOperatorSetterWrongArgumentLength 
+PASS dotOperatorWrongArgumentLength 
+PASS greaterEqualWrongArgumentLength 
+PASS greaterWrongArgumentLength 
+PASS incWrongArgumentLength 
+PASS indexOperatorSetterWrongArgumentLength 
+PASS indexOperatorWrongArgumentLength 
+PASS lShiftWrongArgumentLength 
+PASS minusWrongArgumentLength 
+PASS moduloWrongArgumentLength 
+PASS plusWrongArgumentLength 
+PASS rShiftWrongArgumentLength 
+PASS timesWrongArgumentLength 
+
diff --git a/LayoutTests/webgpu/whlsl-wrong-argument-length.html b/LayoutTests/webgpu/whlsl-wrong-argument-length.html
new file mode 100644 (file)
index 0000000..5ec4191
--- /dev/null
@@ -0,0 +1,364 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test int bit math.</title>
+<script src="js/whlsl-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.bitAndWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            struct Foo { }
+            int operator&(Foo) { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator&(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator&(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.bitNotWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator~() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator~(Foo, Foo) { return 534; }
+        `);
+        
+}
+whlslTests.bitOrWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            struct Foo { }
+            int operator|() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator|(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator|(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.bitXorWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator^() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator^(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator^(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.decWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator--() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator--(Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.divideWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator/() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator/(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator/(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.dotOperatorSetterWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            struct Foo { }
+            Foo operator.foo=() { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            Foo operator.foo=(Foo) { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            Foo operator.foo=(Foo, int, int) { return 42; }
+        `);
+        
+}
+whlslTests.dotOperatorWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator.foo() { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator.foo(Foo, int) { return 42; }
+        `);
+        
+}
+whlslTests.greaterEqualWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            bool operator>=() { return true; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            bool operator>=(Foo) { return true; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            bool operator>=(Foo, Foo, Foo) { return true; }
+        `);
+        
+}
+whlslTests.greaterWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            bool operator>() { return true; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            bool operator>(Foo) { return true; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            bool operator>(Foo, Foo, Foo) { return true; }
+        `);
+        
+}
+whlslTests.incWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator++() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator++(Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.indexOperatorSetterWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator[]=() { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            int operator[]=(int) { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            int operator[]=(int, int) { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            int operator[]=(int, int, int, int) { return 42; }
+        `);
+        
+}
+whlslTests.indexOperatorWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator[]() { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            int operator[](int) { return 42; }
+        `);
+        
+    await checkFail(
+        `
+            int operator[](int, int, int) { return 42; }
+        `);
+        
+}
+whlslTests.lShiftWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator<<() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator<<(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator<<(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.minusWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator-() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator-(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.moduloWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator%() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator%(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator%(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.plusWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator+() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator+(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.rShiftWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator>>() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator>>(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator>>(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+whlslTests.timesWrongArgumentLength = async () =>
+{
+    await checkFail(
+        `
+            int operator*() { return 32; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator*(Foo) { return 534; }
+        `);
+        
+    await checkFail(
+        `
+            struct Foo { }
+            int operator*(Foo, Foo, Foo) { return 76; }
+        `);
+        
+}
+
+runTests(whlslTests);
+</script>
+</html>
diff --git a/LayoutTests/webgpu/whlsl-wrong-types-expected.txt b/LayoutTests/webgpu/whlsl-wrong-types-expected.txt
new file mode 100644 (file)
index 0000000..b5518f1
--- /dev/null
@@ -0,0 +1,8 @@
+
+PASS decWrongTypes 
+PASS incWrongTypes 
+PASS greaterThanWrongReturnType 
+PASS greaterEqualWrongReturnType 
+PASS indexSetterWithMismatchedType 
+PASS setterWithMismatchedType 
+
diff --git a/LayoutTests/webgpu/whlsl-wrong-types.html b/LayoutTests/webgpu/whlsl-wrong-types.html
new file mode 100644 (file)
index 0000000..2e1a161
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test int bit math.</title>
+<script src="js/whlsl-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.decWrongTypes = async () =>
+{
+    await checkFail(
+        `
+            int operator--(float) { return 32; }
+        `);
+        
+}
+
+whlslTests.incWrongTypes = async () =>
+{
+    await checkFail(
+        `
+            int operator++(float) { return 32; }
+        `);
+        
+}
+
+whlslTests.greaterThanWrongReturnType = async () =>
+{
+    await checkFail(
+        `
+            int operator>(int a, int b) { return a + b; }
+        `);
+        
+}
+
+whlslTests.greaterEqualWrongReturnType = async () =>
+{
+    await checkFail(
+        `
+            int operator>=(int a, int b) { return a + b; }
+        `);
+        
+}
+
+whlslTests.indexSetterWithMismatchedType = async () =>
+{
+    checkFail(
+        `
+            float operator[](int, uint)
+            {
+                return 5.43;
+            }
+            int operator[]=(int, uint, int)
+            {
+                return 543;
+            }
+        `);
+}
+
+whlslTests.setterWithMismatchedType = async () =>
+{
+    checkFail(
+        `
+            float operator.foo(int)
+            {
+                return 5.43;
+            }
+            int operator.foo=(int, int)
+            {
+                return 543;
+            }
+        `);
+}
+
+runTests(whlslTests);
+</script>
+</html>