generate_gles2_conform_tests.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2013 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """code generator for OpenGL ES 2.0 conformance tests."""
  6. import os
  7. import re
  8. import sys
  9. import typing
  10. def ReadFileAsLines(filename: str) -> typing.List[str]:
  11. """Reads a file, removing blank lines and lines that start with #"""
  12. with open(filename, "r") as in_file:
  13. raw_lines = in_file.readlines()
  14. lines = []
  15. for line in raw_lines:
  16. line = line.strip()
  17. if len(line) > 0 and not line.startswith("#"):
  18. lines.append(line)
  19. return lines
  20. def GenerateTests(out_file: typing.IO) -> None:
  21. """Generates gles2_conform_test_autogen.cc"""
  22. tests = ReadFileAsLines(
  23. "../../third_party/gles2_conform/GTF_ES/glsl/GTF/mustpass_es20.run")
  24. out_file.write("""
  25. #include "gpu/gles2_conform_support/gles2_conform_test.h"
  26. #include "testing/gtest/include/gtest/gtest.h"
  27. """.encode("utf8"))
  28. for test in tests:
  29. out_file.write(("""
  30. TEST(GLES2ConformTest, %(name)s) {
  31. EXPECT_TRUE(RunGLES2ConformTest("%(path)s"));
  32. }
  33. """ % {
  34. "name": re.sub(r'[^A-Za-z0-9]', '_', test),
  35. "path": test,
  36. }).encode("utf8"))
  37. def main(argv: typing.List[str]) -> int:
  38. """This is the main function."""
  39. if len(argv) >= 1:
  40. out_dir = argv[0]
  41. else:
  42. out_dir = '.'
  43. out_filename = os.path.join(out_dir, 'gles2_conform_test_autogen.cc')
  44. with open(out_filename, 'wb') as out_file:
  45. GenerateTests(out_file)
  46. return 0
  47. if __name__ == '__main__':
  48. sys.exit(main(sys.argv[1:]))