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 5#include "gpu/gles2_conform_support/gles2_conform_test.h" 6 7#include <string> 8 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" 17#endif 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" 24 25bool 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"; 35 return false; 36 } 37 gpu::GPUTestExpectationsParser test_expectations; 38 if (!test_expectations.LoadTestExpectations(test_expectations_path)) { 39 LOG(ERROR) << "Fail to load gles2_conform_test_expectations.txt"; 40 return false; 41 } 42 gpu::GPUTestBotConfig bot_config; 43 if (!bot_config.LoadCurrentConfig(NULL)) { 44 LOG(ERROR) << "Fail to load bot configuration"; 45 return false; 46 } 47 if (!bot_config.IsValid()) { 48 LOG(ERROR) << "Invalid bot configuration"; 49 return false; 50 } 51 std::string path_string(path); 52 std::string test_name; 53 base::ReplaceChars(path_string, "\\/.", "_", &test_name); 54 int32 expectation = 55 test_expectations.GetTestExpectation(test_name, bot_config); 56 if (expectation != gpu::GPUTestExpectationsParser::kGpuTestPass) { 57 LOG(WARNING) << "Test " << test_name << " is bypassed"; 58 return true; 59 } 60 61 base::FilePath test_path; 62 PathService::Get(base::DIR_EXE, &test_path); 63 base::FilePath program(test_path.Append(FILE_PATH_LITERAL( 64 "gles2_conform_test_windowless"))); 65 66 CommandLine* currentCmdLine = CommandLine::ForCurrentProcess(); 67 CommandLine cmdline(program); 68 cmdline.AppendArguments(*currentCmdLine, false); 69 cmdline.AppendSwitch(std::string("--")); 70 cmdline.AppendArg(std::string("-run=") + path); 71 72 std::string output; 73 bool success = base::GetAppOutput(cmdline, &output); 74 if (success) { 75 size_t success_index = output.find("Conformance PASSED all"); 76 size_t failed_index = output.find("FAILED"); 77 success = (success_index != std::string::npos) && 78 (failed_index == std::string::npos); 79 } 80 if (!success) { 81 LOG(ERROR) << output; 82 } 83 return success; 84} 85 86int main(int argc, char** argv) { 87 base::AtExitManager exit_manager; 88 CommandLine::Init(argc, argv); 89#if defined(OS_MACOSX) 90 base::mac::ScopedNSAutoreleasePool pool; 91#endif 92 ::testing::InitGoogleTest(&argc, argv); 93 return RUN_ALL_TESTS(); 94} 95 96 97 98