aboutsummaryrefslogtreecommitdiff
path: root/tests/run_tests.py
blob: 23789f6a786822b65992cfb135e593cf7a88c7a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/env python
# Copyright 2018 The Amber Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import difflib
import optparse
import os
import platform
import re
import subprocess
import sys
import tempfile

SUPPRESSIONS = {
  "Darwin": [
    # No geometry shader on MoltenVK
    "draw_triangle_list_using_geom_shader.vkscript",
    # No tessellation shader on MoltenVK
    "draw_triangle_list_using_tessellation.vkscript",
    # No std140 support for matrices in SPIRV-Cross
    "compute_mat2x2.vkscript",
    "compute_mat2x2float.vkscript",
    "compute_mat2x2.amber",
    "compute_mat3x2.vkscript",
    "compute_mat3x2float.vkscript",
    "compute_mat3x2.amber",
    # Metal vertex shaders cannot simultaneously write to a buffer and return
    # a value to the rasterizer rdar://48348476
    # https://github.com/KhronosGroup/MoltenVK/issues/527
    "multiple_ssbo_update_with_graphics_pipeline.vkscript",
    "multiple_ubo_update_with_graphics_pipeline.vkscript",
  ],
  "Linux": [
  ],
  "Win": [
  ]
}

DEBUGGER_CASES = [
  "debugger_hlsl_basic_compute.amber",
  "debugger_hlsl_basic_fragment.amber",
  "debugger_hlsl_basic_vertex.amber",
  "debugger_hlsl_shadowed_vars.amber",
  "debugger_spirv_line_stepping.amber",
  "debugger_hlsl_basic_fragment_with_legalization.amber",
  "debugger_hlsl_basic_vertex_with_legalization.amber",
  "debugger_hlsl_function_call.amber",
  "debugger_hlsl_shadowed_vars.amber",
]

SUPPRESSIONS_SWIFTSHADER = [
  # Incorrect rendering: github.com/google/amber/issues/727
  "draw_array_instanced.vkscript",
  # Exceeds device limit maxComputeWorkGroupInvocations
  "draw_sampled_image.amber",
  # No geometry shader support
  "draw_triangle_list_using_geom_shader.vkscript",
  # No tessellation shader support
  "draw_triangle_list_using_tessellation.vkscript",
  # Vertex buffer format not supported
  "draw_triangle_list_in_r8g8b8a8_srgb_color_frame.vkscript",
  "draw_triangle_list_in_r32g32b32a32_sfloat_color_frame.vkscript",
  "draw_triangle_list_in_r16g16b16a16_uint_color_frame.vkscript",
  # Color attachment format is not supported
  "draw_triangle_list_in_r16g16b16a16_snorm_color_frame.vkscript",
  "draw_triangle_list_in_r8g8b8a8_snorm_color_frame.vkscript",
  # No supporting device for Float16Int8Features
  "float16.amber",
  "int8.amber",
  # No supporting device for the required 16-bit storage features
  "storage16.amber",
  # Exceeded maxBoundDescriptorSets limit of physical device
  "multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript",
  # shaderStorageImageWriteWithoutFormat but is not enabled on the device
  "opencl_read_and_write_image3d_rgba32i.amber",
  "opencl_write_image.amber",
  "glsl_read_and_write_image3d_rgba32i.amber",
  # shaderStorageImageMultisample feature not supported
  "draw_storageimage_multisample.amber",
  # Fails on Ubuntu bot
  "debugger_hlsl_basic_vertex_with_legalization.amber",
  "debugger_hlsl_function_call.amber",
  "debugger_hlsl_shadowed_vars.amber",
  # Unsupported depth/stencil formats
  "draw_rectangles_depth_test_d24s8.amber",
  "draw_rectangles_depth_test_x8d24.amber",
  # Tessellation not supported
  "tessellation_isolines.amber",
  # 8 bit indices not supported
  "draw_indexed_uint8.amber",
]

OPENCL_CASES = [
  "opencl_bind_buffer.amber",
  "opencl_c_copy.amber",
  "opencl_generated_push_constants.amber",
  "opencl_read_and_write_image3d_rgba32i.amber",
  "opencl_read_image.amber",
  "opencl_read_image_literal_sampler.amber",
  "opencl_set_arg.amber",
  "opencl_write_image.amber",
 ]

DXC_CASES = [
  "draw_triangle_list_hlsl.amber",
  "relative_includes_hlsl.amber",
  "debugger_hlsl_basic_compute.amber",
  "debugger_hlsl_basic_fragment.amber",
  "debugger_hlsl_basic_vertex.amber",
  "debugger_hlsl_shadowed_vars.amber",
  "debugger_hlsl_basic_fragment_with_legalization.amber",
  "debugger_hlsl_basic_vertex_with_legalization.amber",
  "debugger_hlsl_function_call.amber",
  "debugger_hlsl_shadowed_vars.amber",
]

SUPPRESSIONS_DAWN = [
  # Dawn does not support push constants
  "graphics_push_constants.amber",
  "graphics_push_constants.vkscript",
  "compute_push_const_mat2x2.vkscript",
  "compute_push_const_mat2x2float.vkscript",
  "compute_push_const_mat2x3.vkscript",
  "compute_push_const_mat2x3float.vkscript",
  "compute_push_const_mat3x2.vkscript",
  "compute_push_const_mat3x2float.vkscript",
  "compute_push_const_mat3x3.vkscript",
  "compute_push_const_mat3x3float.vkscript",
  "compute_push_const_mat3x4.vkscript",
  "compute_push_const_mat3x4float.vkscript",
  "compute_push_const_mat4x3.vkscript",
  "compute_push_const_mat4x3float.vkscript",
  "compute_push_constant_and_ssbo.amber",
  "compute_push_constant_and_ssbo.vkscript",
  # Dawn does not support tessellation or geometry shader
  "draw_triangle_list_using_geom_shader.vkscript",
  "draw_triangle_list_using_tessellation.vkscript",
  # Dawn requires a fragmentStage now and in the medium term.
  # issue #556 (temp dawn limitation)
  "position_to_ssbo.amber",
  # DrawRect command is not supported in a pipeline with more than one vertex
  # buffer attached
  "draw_array_after_draw_rect.vkscript",
  "draw_rect_after_draw_array.vkscript",
  "draw_rect_and_draw_array_mixed.vkscript",
  # Dawn DoCommands require a pipeline
  "probe_no_compute_with_multiple_ssbo_commands.vkscript",
  "probe_no_compute_with_ssbo.vkscript",
  # Max number of descriptor sets is 4 in Dawn
  "multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript",
  # Dawn entry point has to be "main" as a result it does not support
  # doEntryPoint or opencl (in opencl using "main" as entry point is invalid).
  # issue #607 (temp dawn limitation)
  "compute_ssbo_with_entrypoint_command.vkscript",
  "entry_point.amber",
  "non_default_entry_point.amber",
  "opencl_bind_buffer.amber",
  "opencl_c_copy.amber",
  "opencl_set_arg.amber",
  "shader_specialization.amber",
  # framebuffer format is not supported according to table "Mandatory format
  # support" in Vulkan spec: VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT = 0
  "draw_triangle_list_in_r16g16b16a16_snorm_color_frame.vkscript",
  "draw_triangle_list_in_r16g16b16a16_uint_color_frame.vkscript",
  "draw_triangle_list_in_r32g32b32a32_sfloat_color_frame.vkscript",
  "draw_triangle_list_in_r8g8b8a8_snorm_color_frame.vkscript",
  "draw_triangle_list_in_r8g8b8a8_srgb_color_frame.vkscript",
  # Dawn does not support vertexPipelineStoresAndAtomics
  "multiple_ubo_update_with_graphics_pipeline.vkscript",
  "multiple_ssbo_update_with_graphics_pipeline.vkscript",
  # Currently not working, under investigation
  "draw_triangle_list_with_depth.vkscript",
  # draw_grid not implemented for dawn yet
  "draw_grid.amber",
  "draw_grid_multiple_color_attachment.amber",
  "draw_grid_multiple_pipeline.amber",
  "draw_grids.amber",
  "draw_grid.vkscript",
  "draw_grid_with_buffer.amber",
  "draw_grid_with_two_vertex_data_attached.expect_fail.amber",
]

class TestCase:
  def __init__(self, input_path, parse_only, use_dawn, use_opencl, use_dxc,
               use_swiftshader, test_debugger):
    self.input_path = input_path
    self.parse_only = parse_only
    self.use_dawn = use_dawn
    self.use_opencl = use_opencl
    self.use_dxc = use_dxc
    self.use_swiftshader = use_swiftshader
    self.test_debugger = test_debugger

    self.results = {}

  def IsExpectedFail(self):
    fail_re = re.compile('^.+[.]expect_fail[.][amber|vkscript]')
    return fail_re.match(self.GetInputPath())

  def IsSuppressed(self):
    system = platform.system()

    base = os.path.basename(self.input_path)
    is_dawn_suppressed = base in SUPPRESSIONS_DAWN
    if self.use_dawn and is_dawn_suppressed:
      return True

    is_swiftshader_suppressed = base in SUPPRESSIONS_SWIFTSHADER
    if self.use_swiftshader and is_swiftshader_suppressed:
      return True

    is_opencl_test = base in OPENCL_CASES
    if not self.use_opencl and is_opencl_test:
      return True

    is_dxc_test = base in DXC_CASES
    if not self.use_dxc and is_dxc_test:
      return True

    is_debugger_test = base in DEBUGGER_CASES
    if not self.test_debugger and is_debugger_test:
      return True

    if system in SUPPRESSIONS.keys():
      is_system_suppressed = base in SUPPRESSIONS[system]
      return is_system_suppressed

    return False

  def IsParseOnly(self):
    return self.parse_only

  def IsUseDawn(self):
    return self.use_dawn

  def GetInputPath(self):
    return self.input_path

  def GetResult(self, fmt):
    return self.results[fmt]


class TestRunner:
  def RunTest(self, tc):
    print("Testing {}".format(tc.GetInputPath()))

    # Amber and SwiftShader both use the VK_DEBUGGER_PORT environment variable
    # for specifying the Debug Adapter Protocol port number.
    # This needs to be set before creating the Vulkan device.
    # We remove this key from the enviroment if the test is not a debugger test
    # so that full SPIR-V optimizations are preserved.
    is_debugger_test = os.path.basename(tc.GetInputPath()) in DEBUGGER_CASES
    if is_debugger_test:
      os.environ["VK_DEBUGGER_PORT"] = "19020"
    elif "VK_DEBUGGER_PORT" in os.environ:
      del os.environ["VK_DEBUGGER_PORT"]

    cmd = [self.options.test_prog_path, '-q']
    if tc.IsParseOnly():
      cmd += ['-p']
    if tc.IsUseDawn():
      cmd += ['-e', 'dawn']
    cmd += [tc.GetInputPath()]

    try:
      err = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
      if len(err) != 0 and not tc.IsExpectedFail() and not tc.IsSuppressed():
        sys.stdout.write(err.decode('utf-8'))
        return False

    except Exception as e:
      if not tc.IsExpectedFail() and not tc.IsSuppressed():
        print("{}".format("".join(map(chr, bytearray(e.output)))))
        print(e)
      return False

    return True


  def RunTests(self):
    for tc in self.test_cases:
      result = self.RunTest(tc)

      if tc.IsSuppressed():
        self.suppressed.append(tc.GetInputPath())
      else:
        if not tc.IsExpectedFail() and not result:
          self.failures.append(tc.GetInputPath())
        elif tc.IsExpectedFail() and result:
          print("Expected: " + tc.GetInputPath() + " to fail but passed.")
          self.failures.append(tc.GetInputPath())

  def SummarizeResults(self):
    if len(self.failures) > 0:
      self.failures.sort()

      print('\nSummary of Failures:')
      for failure in self.failures:
        print(failure)

    if len(self.suppressed) > 0:
      self.suppressed.sort()

      print('\nSummary of Suppressions:')
      for suppression in self.suppressed:
        print(suppression)

    print('')
    print('Test cases executed: {}'.format(len(self.test_cases)))
    print('  Successes:  {}'.format((len(self.test_cases) - len(self.suppressed) - len(self.failures))))
    print('  Failures:   {}'.format(len(self.failures)))
    print('  Suppressed: {}'.format(len(self.suppressed)))
    print('')


  def Run(self):
    base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

    usage = 'usage: %prog [options] (file)'
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('--build-dir',
                      default=os.path.join(base_path, 'out', 'Debug'),
                      help='path to build directory')
    parser.add_option('--test-dir',
                      default=os.path.join(os.path.dirname(__file__), 'cases'),
                      help='path to directory containing test files')
    parser.add_option('--test-prog-path', default=None,
                      help='path to program to test')
    parser.add_option('--parse-only',
                      action="store_true", default=False,
                      help='only parse test cases; do not execute')
    parser.add_option('--use-dawn',
                      action="store_true", default=False,
                      help='Use dawn as the backend; Default is Vulkan')
    parser.add_option('--use-opencl',
                      action="store_true", default=False,
                      help='Enable OpenCL tests')
    parser.add_option('--use-dxc',
                      action="store_true", default=False,
                      help='Enable DXC tests')
    parser.add_option('--use-swiftshader',
                      action="store_true", default=False,
                      help='Tells test runner swiftshader is the device')
    parser.add_option('--test-debugger',
                      action="store_true", default=False,
                      help='Include debugger tests')

    self.options, self.args = parser.parse_args()

    if self.options.test_prog_path == None:
      test_prog = os.path.abspath(os.path.join(self.options.build_dir, 'amber'))
      if not os.path.isfile(test_prog):
        print("Cannot find test program {}".format(test_prog))
        return 1

      self.options.test_prog_path = test_prog

    if not os.path.isfile(self.options.test_prog_path):
      print("--test-prog-path must point to an executable")
      return 1

    input_file_re = re.compile('^.+[\.](amber|vkscript)')
    self.test_cases = []

    if self.args:
      for filename in self.args:
        input_path = os.path.join(self.options.test_dir, filename)
        if not os.path.isfile(input_path):
          print("Cannot find test file '{}'".format(filename))
          return 1

        self.test_cases.append(TestCase(input_path, self.options.parse_only,
            self.options.use_dawn, self.options.use_opencl,
            self.options.use_dxc, self.options.use_swiftshader,
            self.options.test_debugger))

    else:
      for file_dir, _, filename_list in os.walk(self.options.test_dir):
        for input_filename in filename_list:
          if input_file_re.match(input_filename):
            input_path = os.path.join(file_dir, input_filename)
            if os.path.isfile(input_path):
              self.test_cases.append(
                  TestCase(input_path, self.options.parse_only,
                      self.options.use_dawn, self.options.use_opencl,
                      self.options.use_dxc, self.options.use_swiftshader,
                      self.options.test_debugger))

    self.failures = []
    self.suppressed = []

    self.RunTests()
    self.SummarizeResults()

    return len(self.failures) != 0

def main():
  runner = TestRunner()
  return runner.Run()


if __name__ == '__main__':
  sys.exit(main())