• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "gles_conformance_tests.h"
2 #include "GTFMain.h"
3 
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sstream>
8 #include <vector>
9 
10 ANGLE_FORMAT_PRINTF(1, 2)
FormatArg(const char * fmt,...)11 static std::vector<char> FormatArg(const char *fmt, ...)
12 {
13     va_list vararg;
14     va_start(vararg, fmt);
15     int len = vsnprintf(nullptr, 0, fmt, vararg);
16     va_end(vararg);
17 
18     std::vector<char> buf(len + 1);
19 
20     va_start(vararg, fmt);
21     vsnprintf(buf.data(), buf.size(), fmt, vararg);
22     va_end(vararg);
23 
24     return buf;
25 }
26 
GetExecutableDirectory()27 static std::string GetExecutableDirectory()
28 {
29     std::vector<char> executableFileBuf(MAX_PATH);
30     DWORD executablePathLen =
31         GetModuleFileNameA(nullptr, executableFileBuf.data(), executableFileBuf.size());
32     if (executablePathLen == 0)
33     {
34         return false;
35     }
36 
37     std::string executableLocation = executableFileBuf.data();
38     size_t lastPathSepLoc          = executableLocation.find_last_of("\\/");
39     if (lastPathSepLoc != std::string::npos)
40     {
41         executableLocation = executableLocation.substr(0, lastPathSepLoc);
42     }
43     else
44     {
45         executableLocation = "";
46     }
47 
48     return executableLocation;
49 }
50 
RunConformanceTest(const std::string & testPath,EGLNativeDisplayType nativeDisplay)51 void RunConformanceTest(const std::string &testPath, EGLNativeDisplayType nativeDisplay)
52 {
53     std::vector<char *> args;
54 
55     // Empty first argument for the program name
56     args.push_back("");
57 
58     std::vector<char> widthArg = FormatArg("-width=%u", 64);
59     args.push_back(widthArg.data());
60 
61     std::vector<char> heightArg = FormatArg("-height=%u", 64);
62     args.push_back(heightArg.data());
63 
64     std::vector<char> displayArg = FormatArg("-d=%llu", nativeDisplay);
65     args.push_back(displayArg.data());
66 
67     std::vector<char> runArg = FormatArg("-run=%s/conformance_tests/%s",
68                                          GetExecutableDirectory().c_str(), testPath.c_str());
69     args.push_back(runArg.data());
70 
71     // Redirect cout
72     std::streambuf *oldCoutStreamBuf = std::cout.rdbuf();
73     std::ostringstream strCout;
74     std::cout.rdbuf(strCout.rdbuf());
75 
76     if (GTFMain(args.size(), args.data()) != 0)
77     {
78         FAIL() << "GTFMain failed.";
79     }
80 
81     // Restore old cout
82     std::cout.rdbuf(oldCoutStreamBuf);
83     std::string log = strCout.str();
84 
85     // Look for failures
86     size_t offset                  = 0;
87     std::string offsetSearchString = "failure = ";
88     while ((offset = log.find("failure = ", offset)) != std::string::npos)
89     {
90         offset += offsetSearchString.length();
91 
92         size_t failureCount = atoll(log.c_str() + offset);
93         EXPECT_EQ(0, failureCount) << log;
94     }
95 }
96