khronos_glcts_test.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2014 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/khronos_glcts_support/khronos_glcts_test.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/at_exit.h"
  9. #include "base/base_paths.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 "base/path_service.h"
  15. #include "base/process/launch.h"
  16. #include "base/strings/string_util.h"
  17. #include "gpu/config/gpu_test_config.h"
  18. #include "gpu/config/gpu_test_expectations_parser.h"
  19. #include "testing/gtest/include/gtest/gtest.h"
  20. base::FilePath g_deqp_log_dir;
  21. bool RunKhronosGLCTSTest(const char* test_name) {
  22. // Load test expectations, and return early if a test is marked as FAIL.
  23. base::FilePath src_path;
  24. base::PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
  25. base::FilePath test_expectations_path =
  26. src_path.Append(FILE_PATH_LITERAL("gpu")).
  27. Append(FILE_PATH_LITERAL("khronos_glcts_support")).
  28. Append(FILE_PATH_LITERAL("khronos_glcts_test_expectations.txt"));
  29. if (!base::PathExists(test_expectations_path)) {
  30. LOG(ERROR) << "Fail to locate khronos_glcts_test_expectations.txt";
  31. return false;
  32. }
  33. gpu::GPUTestExpectationsParser test_expectations;
  34. if (!test_expectations.LoadTestExpectations(test_expectations_path)) {
  35. LOG(ERROR) << "Fail to load khronos_glcts_test_expectations.txt";
  36. return false;
  37. }
  38. gpu::GPUTestBotConfig bot_config;
  39. if (!bot_config.LoadCurrentConfig(nullptr)) {
  40. LOG(ERROR) << "Fail to load bot configuration";
  41. return false;
  42. }
  43. if (!bot_config.IsValid()) {
  44. LOG(ERROR) << "Invalid bot configuration";
  45. return false;
  46. }
  47. const ::testing::TestInfo* const test_info =
  48. ::testing::UnitTest::GetInstance()->current_test_info();
  49. int32_t expectation =
  50. test_expectations.GetTestExpectation(test_info->name(), bot_config);
  51. if (expectation != gpu::GPUTestExpectationsParser::kGpuTestPass) {
  52. LOG(WARNING) << "Test " << test_info->name() << " is bypassed";
  53. return true;
  54. }
  55. base::FilePath test_path;
  56. base::PathService::Get(base::DIR_EXE, &test_path);
  57. base::FilePath archive(test_path.Append(FILE_PATH_LITERAL(
  58. "khronos_glcts_data")));
  59. base::FilePath program(test_path.Append(FILE_PATH_LITERAL(
  60. "khronos_glcts_test_windowless")));
  61. base::FilePath log =
  62. g_deqp_log_dir.AppendASCII(test_info->name()).
  63. AddExtension(FILE_PATH_LITERAL(".log"));
  64. base::CommandLine cmdline(program);
  65. cmdline.AppendSwitchPath("--deqp-log-filename", log);
  66. cmdline.AppendSwitchPath("--deqp-archive-dir", archive);
  67. cmdline.AppendArg("--deqp-gl-config-id=-1");
  68. cmdline.AppendArg(std::string("--deqp-case=") + test_name);
  69. std::string output;
  70. bool success = base::GetAppOutput(cmdline, &output);
  71. if (success) {
  72. size_t success_index = output.find("Pass (Pass)");
  73. size_t failed_index = output.find("Fail (Fail)");
  74. success = (success_index != std::string::npos) &&
  75. (failed_index == std::string::npos);
  76. }
  77. if (!success) {
  78. LOG(ERROR) << output;
  79. }
  80. return success;
  81. }
  82. int main(int argc, char *argv[]) {
  83. base::AtExitManager at_exit;
  84. ::testing::InitGoogleTest(&argc, argv);
  85. if (argc == 2) {
  86. g_deqp_log_dir = base::FilePath::FromUTF8Unsafe(argv[1]);
  87. }
  88. else {
  89. base::GetTempDir(&g_deqp_log_dir);
  90. }
  91. return RUN_ALL_TESTS();
  92. }