xref: /aosp_15_r20/external/deqp/modules/gles2/scripts/gen-invalid-implicit-conversions.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright (c) 2016 The Khronos Group Inc.
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import sys
24import string
25from genutil import *
26
27# Templates
28
29INVALID_IMPLICIT_CONVESION_TEMPLATE0 = """
30case ${{NAME}}
31    expect compile_fail
32
33    both ""
34        precision mediump float;
35        precision mediump int;
36
37        ${DECLARATIONS}
38
39        void main()
40        {
41            ${{TYPE0}} c;
42            ${{TYPE0}} a;
43            ${{TYPE1}} b;
44            ${{TYPE0}} c = a ${{OPERATION}} b;
45        }
46    ""
47end
48"""[1:-1]
49
50INVALID_IMPLICIT_CONVESION_TEMPLATE1 = """
51case ${{NAME}}
52    expect compile_fail
53
54    both ""
55        precision mediump float;
56        precision mediump int;
57
58        ${DECLARATIONS}
59
60        void main()
61        {
62            ${{TYPE1}} c;
63            ${{TYPE0}} a;
64            ${{TYPE1}} b;
65            ${{TYPE1}} c = a ${{OPERATION}} b;
66        }
67    ""
68end
69"""[1:-1]
70
71arithOperations = {'+': 'add', '*':'mul', '/': 'div', '-':'sub'}
72
73class InvalidImplicitConversionCase(ShaderCase):
74    def __init__(self, operation, type0, type1):
75        self.name = arithOperations[operation] + '_' + type0 + '_' + type1
76        self.operation = operation
77        self.type0 = type0
78        self.type1 = type1
79
80    def __str__(self):
81        params0 = { "NAME": self.name + '_' + self.type0, "TYPE0": self.type0, "TYPE1": self.type1, "OPERATION": self.operation }
82        params1 = { "NAME": self.name + '_' + self.type1, "TYPE0": self.type0, "TYPE1": self.type1, "OPERATION": self.operation }
83        return fillTemplate(INVALID_IMPLICIT_CONVESION_TEMPLATE0, params0) + '\n' + fillTemplate(INVALID_IMPLICIT_CONVESION_TEMPLATE1, params1)
84
85def createCase(operation, type0, type1):
86    cases = []
87    for t0 in type0:
88        for t1 in type1:
89            case = InvalidImplicitConversionCase(operation, t0, t1)
90            cases.append(case)
91    return cases
92
93floats = ['float', 'vec2', 'vec3', 'vec4']
94sintegers = ['int', 'ivec2', 'ivec3', 'ivec4']
95cases = []
96for op in arithOperations:
97    caseFpInt = createCase(op, floats, sintegers)
98    cases = cases + caseFpInt
99
100invalidImplicitConversionCases = [
101        CaseGroup("invalid_implicit_conversions", "Invalid Implicit Conversions", cases),
102]
103
104if __name__ == "__main__":
105    print("Generating shader case files.")
106    writeAllCases("invalid_implicit_conversions.test", invalidImplicitConversionCases)
107