xref: /aosp_15_r20/external/angle/src/tests/angle_end2end_tests_main.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2013 The ANGLE Project 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 //
6 
7 #include "gtest/gtest.h"
8 #if defined(ANGLE_HAS_RAPIDJSON)
9 #    include "test_utils/runner/TestSuite.h"
10 #endif  // defined(ANGLE_HAS_RAPIDJSON)
11 #include "util/OSWindow.h"
12 
13 void ANGLEProcessTestArgs(int *argc, char *argv[]);
14 
15 // Register* functions handle setting up special tests that need complex parameterization.
16 // GoogleTest relies heavily on static initialization to register test functions. This can
17 // cause all sorts of issues if the right variables aren't initialized in the right order.
18 // This register function needs to be called explicitly after static initialization and
19 // before the test launcher starts. This is a safer and generally better way to initialize
20 // tests. It's also more similar to how the dEQP Test harness works. In the future we should
21 // likely specialize more register functions more like dEQP instead of relying on static init.
22 void RegisterContextCompatibilityTests();
23 
24 namespace
25 {
HasArg(int argc,char ** argv,const char * arg)26 bool HasArg(int argc, char **argv, const char *arg)
27 {
28     for (int i = 1; i < argc; ++i)
29     {
30         if (strstr(argv[i], arg) != nullptr)
31         {
32             return true;
33         }
34     }
35     return false;
36 }
37 }  // namespace
38 
main(int argc,char ** argv)39 int main(int argc, char **argv)
40 {
41     if (!HasArg(argc, argv, "--list-tests") && !HasArg(argc, argv, "--gtest_list_tests") &&
42         HasArg(argc, argv, "--use-gl"))
43     {
44         std::cerr << "--use-gl isn't supported by end2end tests - use *_EGL configs instead "
45                      "(angle_test_enable_system_egl=true)\n";
46         return EXIT_FAILURE;
47     }
48 
49     // TODO(b/279980674): TestSuite depends on rapidjson which we don't have in aosp builds,
50     // for now disable both TestSuite and expectations.
51 #if defined(ANGLE_HAS_RAPIDJSON)
52     ANGLEProcessTestArgs(&argc, argv);
53 
54     auto registerTestsCallback = [] {
55         if (!IsTSan())
56         {
57             RegisterContextCompatibilityTests();
58         }
59     };
60     angle::TestSuite testSuite(&argc, argv, registerTestsCallback);
61 
62     constexpr char kTestExpectationsPath[] = "src/tests/angle_end2end_tests_expectations.txt";
63     constexpr size_t kMaxPath = 512;
64     std::array<char, kMaxPath> foundDataPath;
65     if (!angle::FindTestDataPath(kTestExpectationsPath, foundDataPath.data(), foundDataPath.size()))
66     {
67         std::cerr << "Unable to find test expectations path (" << kTestExpectationsPath << ")\n";
68         return EXIT_FAILURE;
69     }
70 
71     // end2end test expectations only allow SKIP at the moment.
72     testSuite.setTestExpectationsAllowMask(angle::GPUTestExpectationsParser::kGpuTestSkip |
73                                            angle::GPUTestExpectationsParser::kGpuTestTimeout);
74 
75     if (!testSuite.loadAllTestExpectationsFromFile(std::string(foundDataPath.data())))
76     {
77         return EXIT_FAILURE;
78     }
79 
80     return testSuite.run();
81 #else
82     ::testing::InitGoogleTest(&argc, argv);
83     return RUN_ALL_TESTS();
84 #endif  // defined(ANGLE_HAS_RAPIDJSON)
85 }
86