[WHLSL] Move WHLSL tests to their own folder
[WebKit-https.git] / LayoutTests / webgpu / whlsl / builtin-vectors-2.html
1 <!DOCTYPE html>
2 <html>
3 <meta charset=utf-8>
4 <meta name="timeout" content="long">
5 <title>Test loops.</title>
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>
10 <script>
11 const whlslTests = {};
12
13 const checkFuncs = {
14     "uint": callUintFunction,
15     "int": callIntFunction,
16     "float": callFloatFunction
17 };
18 const typeNames = [ "uint", "int", "float" ];
19 const sizes = [ 2, 3, 4 ];
20 const elements = [ "x", "y", "z", "w" ];
21 const initializerList = [ 1, 2, 3, 4 ];
22
23 whlslTests.builtinVectorGetters = async () =>
24 {
25
26     let tests = [];
27     let src = "";
28     for (let typeName of typeNames) {
29         for (let size of sizes) {
30             for (let i = 0; i < size; i++) {
31                 const functionName = `${typeName}${size}${elements[i]}`;
32                 src += `${typeName} ${functionName}()
33                         {
34                             ${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")});
35                             return x.${elements[i]};
36                         }
37                         `;
38                 tests.push({ type: typeName, name: functionName, expectation: initializerList[i] });
39             }
40         }
41     }
42
43     let program = src;
44     for (let test of tests) {
45         const checkFunc = checkFuncs[test.type];
46         assert_equals(await checkFunc(program, test.name, []), test.expectation);
47     }
48 };
49
50 whlslTests.builtinVectorSetters = async () =>
51 {
52     let tests = [];
53     let src = "";
54     for (let typeName of typeNames) {
55         for (let size of sizes) {
56             for (let i = 0; i < size; i++) {
57                 const functionName = `${typeName}${size}${elements[i]}`;
58                 src += `${typeName} ${functionName}()
59                         {
60                             ${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")});
61                             x.${elements[i]} = 34;
62                             return x.${elements[i]};
63                         }
64                         `;
65                 tests.push({ type: typeName, name: functionName, expectation: 34 });
66             }
67         }
68     }
69
70     let program = src;
71     for (let test of tests) {
72         const checkFunc = checkFuncs[test.type];
73         assert_equals(await checkFunc(program, test.name, []), test.expectation);
74     }
75 }
76
77 runTests(whlslTests);
78 </script>
79 </html>
80