gles2_conform_test.cc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "gpu/gles2_conform_support/gles2_conform_test.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/base_paths.h"
  9. #include "base/bind.h"
  10. #include "base/command_line.h"
  11. #include "base/files/file_path.h"
  12. #include "base/files/file_util.h"
  13. #include "base/logging.h"
  14. #include "build/build_config.h"
  15. #if BUILDFLAG(IS_MAC)
  16. #include "base/mac/scoped_nsautorelease_pool.h"
  17. #endif
  18. #include "base/path_service.h"
  19. #include "base/process/launch.h"
  20. #include "base/strings/string_util.h"
  21. #include "base/test/launcher/unit_test_launcher.h"
  22. #include "base/test/test_suite.h"
  23. #include "gpu/config/gpu_test_config.h"
  24. #include "gpu/config/gpu_test_expectations_parser.h"
  25. #include "testing/gtest/include/gtest/gtest.h"
  26. namespace {
  27. int RunHelper(base::TestSuite* test_suite) {
  28. return test_suite->Run();
  29. }
  30. } // namespace
  31. bool RunGLES2ConformTest(const char* path) {
  32. // Load test expectations, and return early if a test is marked as FAIL.
  33. base::FilePath src_path;
  34. base::PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
  35. base::FilePath test_expectations_path =
  36. src_path.Append(FILE_PATH_LITERAL("gpu")).
  37. Append(FILE_PATH_LITERAL("gles2_conform_support")).
  38. Append(FILE_PATH_LITERAL("gles2_conform_test_expectations.txt"));
  39. if (!base::PathExists(test_expectations_path)) {
  40. LOG(ERROR) << "Fail to locate gles2_conform_test_expectations.txt";
  41. return false;
  42. }
  43. gpu::GPUTestExpectationsParser test_expectations;
  44. if (!test_expectations.LoadTestExpectations(test_expectations_path)) {
  45. LOG(ERROR) << "Fail to load gles2_conform_test_expectations.txt";
  46. return false;
  47. }
  48. gpu::GPUTestBotConfig bot_config;
  49. if (!bot_config.LoadCurrentConfig(nullptr)) {
  50. LOG(ERROR) << "Fail to load bot configuration";
  51. return false;
  52. }
  53. // Set the bot config api based on the OS and command line
  54. base::CommandLine* current_cmd_line = base::CommandLine::ForCurrentProcess();
  55. int32_t config_os = bot_config.os();
  56. if ((config_os & gpu::GPUTestConfig::kOsWin) != 0) {
  57. std::string angle_renderer =
  58. current_cmd_line->HasSwitch("use-angle")
  59. ? current_cmd_line->GetSwitchValueASCII("use-angle")
  60. : "d3d11";
  61. if (angle_renderer == "d3d11") {
  62. bot_config.set_api(gpu::GPUTestConfig::kAPID3D11);
  63. } else if (angle_renderer == "d3d9") {
  64. bot_config.set_api(gpu::GPUTestConfig::kAPID3D9);
  65. } else if (angle_renderer == "gl") {
  66. bot_config.set_api(gpu::GPUTestConfig::kAPIGLDesktop);
  67. } else if (angle_renderer == "gles") {
  68. bot_config.set_api(gpu::GPUTestConfig::kAPIGLES);
  69. } else {
  70. bot_config.set_api(gpu::GPUTestConfig::kAPIUnknown);
  71. }
  72. } else if ((config_os & gpu::GPUTestConfig::kOsMac) != 0 ||
  73. config_os == gpu::GPUTestConfig::kOsLinux) {
  74. bot_config.set_api(gpu::GPUTestConfig::kAPIGLDesktop);
  75. } else if (config_os == gpu::GPUTestConfig::kOsChromeOS ||
  76. config_os == gpu::GPUTestConfig::kOsAndroid) {
  77. bot_config.set_api(gpu::GPUTestConfig::kAPIGLES);
  78. } else {
  79. bot_config.set_api(gpu::GPUTestConfig::kAPIUnknown);
  80. }
  81. if (!bot_config.IsValid()) {
  82. LOG(ERROR) << "Invalid bot configuration";
  83. return false;
  84. }
  85. std::string path_string(path);
  86. std::string test_name;
  87. base::ReplaceChars(path_string, "\\/.", "_", &test_name);
  88. int32_t expectation =
  89. test_expectations.GetTestExpectation(test_name, bot_config);
  90. if (expectation != gpu::GPUTestExpectationsParser::kGpuTestPass) {
  91. LOG(WARNING) << "Test " << test_name << " is bypassed";
  92. return true;
  93. }
  94. base::FilePath test_path;
  95. base::PathService::Get(base::DIR_EXE, &test_path);
  96. base::FilePath program(test_path.Append(FILE_PATH_LITERAL(
  97. "gles2_conform_test_windowless")));
  98. base::CommandLine cmd_line(program);
  99. cmd_line.AppendArguments(*current_cmd_line, false);
  100. cmd_line.AppendSwitch(std::string("--"));
  101. cmd_line.AppendArg(std::string("-run=") + path);
  102. std::string output;
  103. bool success = base::GetAppOutputAndError(cmd_line, &output);
  104. if (success) {
  105. size_t success_index = output.find("Conformance PASSED all");
  106. size_t failed_index = output.find("FAILED");
  107. success = (success_index != std::string::npos) &&
  108. (failed_index == std::string::npos);
  109. }
  110. if (!success) {
  111. LOG(ERROR) << output;
  112. }
  113. return success;
  114. }
  115. int main(int argc, char** argv) {
  116. base::CommandLine::Init(argc, argv);
  117. #if BUILDFLAG(IS_MAC)
  118. base::mac::ScopedNSAutoreleasePool pool;
  119. #endif
  120. ::testing::InitGoogleTest(&argc, argv);
  121. base::TestSuite test_suite(argc, argv);
  122. int rt = base::LaunchUnitTestsSerially(
  123. argc, argv, base::BindOnce(&RunHelper, base::Unretained(&test_suite)));
  124. return rt;
  125. }