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.
5 #include "gpu/gles2_conform_support/gles2_conform_test.h"
9 #include "base/at_exit.h"
10 #include "base/base_paths.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/logging.h"
15 #if defined(OS_MACOSX)
16 #include "base/mac/scoped_nsautorelease_pool.h"
18 #include "base/path_service.h"
19 #include "base/process/launch.h"
20 #include "base/strings/string_util.h"
21 #include "gpu/config/gpu_test_config.h"
22 #include "gpu/config/gpu_test_expectations_parser.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 bool RunGLES2ConformTest(const char* path
) {
26 // Load test expectations, and return early if a test is marked as FAIL.
27 base::FilePath src_path
;
28 PathService::Get(base::DIR_SOURCE_ROOT
, &src_path
);
29 base::FilePath test_expectations_path
=
30 src_path
.Append(FILE_PATH_LITERAL("gpu")).
31 Append(FILE_PATH_LITERAL("gles2_conform_support")).
32 Append(FILE_PATH_LITERAL("gles2_conform_test_expectations.txt"));
33 if (!base::PathExists(test_expectations_path
)) {
34 LOG(ERROR
) << "Fail to locate gles2_conform_test_expectations.txt";
37 gpu::GPUTestExpectationsParser test_expectations
;
38 if (!test_expectations
.LoadTestExpectations(test_expectations_path
)) {
39 LOG(ERROR
) << "Fail to load gles2_conform_test_expectations.txt";
42 gpu::GPUTestBotConfig bot_config
;
43 if (!bot_config
.LoadCurrentConfig(NULL
)) {
44 LOG(ERROR
) << "Fail to load bot configuration";
48 // Set the bot config api based on the OS and command line
49 base::CommandLine
* current_cmd_line
= base::CommandLine::ForCurrentProcess();
50 int32 config_os
= bot_config
.os();
51 if ((config_os
& gpu::GPUTestConfig::kOsWin
) != 0) {
52 std::string angle_renderer
=
53 current_cmd_line
->HasSwitch("use-angle")
54 ? current_cmd_line
->GetSwitchValueASCII("use-angle")
56 if (angle_renderer
== "d3d11") {
57 bot_config
.set_api(gpu::GPUTestConfig::kAPID3D11
);
58 } else if (angle_renderer
== "d3d9") {
59 bot_config
.set_api(gpu::GPUTestConfig::kAPID3D9
);
60 } else if (angle_renderer
== "gl") {
61 bot_config
.set_api(gpu::GPUTestConfig::kAPIGLDesktop
);
62 } else if (angle_renderer
== "gles") {
63 bot_config
.set_api(gpu::GPUTestConfig::kAPIGLES
);
65 bot_config
.set_api(gpu::GPUTestConfig::kAPIUnknown
);
67 } else if ((config_os
& gpu::GPUTestConfig::kOsMac
) != 0 ||
68 config_os
== gpu::GPUTestConfig::kOsLinux
) {
69 bot_config
.set_api(gpu::GPUTestConfig::kAPIGLDesktop
);
70 } else if (config_os
== gpu::GPUTestConfig::kOsChromeOS
||
71 config_os
== gpu::GPUTestConfig::kOsAndroid
) {
72 bot_config
.set_api(gpu::GPUTestConfig::kAPIGLES
);
74 bot_config
.set_api(gpu::GPUTestConfig::kAPIUnknown
);
77 if (!bot_config
.IsValid()) {
78 LOG(ERROR
) << "Invalid bot configuration";
81 std::string
path_string(path
);
82 std::string test_name
;
83 base::ReplaceChars(path_string
, "\\/.", "_", &test_name
);
85 test_expectations
.GetTestExpectation(test_name
, bot_config
);
86 if (expectation
!= gpu::GPUTestExpectationsParser::kGpuTestPass
) {
87 LOG(WARNING
) << "Test " << test_name
<< " is bypassed";
91 base::FilePath test_path
;
92 PathService::Get(base::DIR_EXE
, &test_path
);
93 base::FilePath
program(test_path
.Append(FILE_PATH_LITERAL(
94 "gles2_conform_test_windowless")));
96 base::CommandLine
cmd_line(program
);
97 cmd_line
.AppendArguments(*current_cmd_line
, false);
98 cmd_line
.AppendSwitch(std::string("--"));
99 cmd_line
.AppendArg(std::string("-run=") + path
);
102 bool success
= base::GetAppOutput(cmd_line
, &output
);
104 size_t success_index
= output
.find("Conformance PASSED all");
105 size_t failed_index
= output
.find("FAILED");
106 success
= (success_index
!= std::string::npos
) &&
107 (failed_index
== std::string::npos
);
110 LOG(ERROR
) << output
;
115 int main(int argc
, char** argv
) {
116 base::AtExitManager exit_manager
;
117 base::CommandLine::Init(argc
, argv
);
118 #if defined(OS_MACOSX)
119 base::mac::ScopedNSAutoreleasePool pool
;
121 ::testing::InitGoogleTest(&argc
, argv
);
122 return RUN_ALL_TESTS();