Hash :
6ba49d94
Author :
Date :
2014-05-07T12:59:47
Automate the es conformance tests by wrapping them in the gtest suite. BUG=angle:497 Change-Id: If12b2dd79f9f666c5d686237d5663f316171b15c Reviewed-on: https://chromium-review.googlesource.com/200043 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shannon Woods <shannonwoods@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#include "gles_conformance_tests.h"
#include "GTFMain.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <sstream>
#include <stdarg.h>
static ConformanceConfig kCurrentConfig = { 64, 64, EGL_DEFAULT_DISPLAY };
void SetCurrentConfig(const ConformanceConfig& config)
{
kCurrentConfig = config;
}
const ConformanceConfig& GetCurrentConfig()
{
return kCurrentConfig;
}
static std::vector<char> FormatArg(const char* fmt, ...)
{
va_list vararg;
va_start(vararg, fmt);
int len = vsnprintf(NULL, 0, fmt, vararg);
va_end(vararg);
std::vector<char> buf(len + 1);
va_start(vararg, fmt);
vsnprintf(buf.data(), buf.size(), fmt, vararg);
va_end(vararg);
return buf;
}
static std::string GetExecutableDirectory()
{
std::vector<char> executableFileBuf(MAX_PATH);
DWORD executablePathLen = GetModuleFileNameA(NULL, executableFileBuf.data(), executableFileBuf.size());
if (executablePathLen == 0)
{
return false;
}
std::string executableLocation = executableFileBuf.data();
size_t lastPathSepLoc = executableLocation.find_last_of("\\/");
if (lastPathSepLoc != std::string::npos)
{
executableLocation = executableLocation.substr(0, lastPathSepLoc);
}
else
{
executableLocation = "";
}
return executableLocation;
}
void RunConformanceTest(const std::string &testPath, const ConformanceConfig& config)
{
std::vector<char*> args;
// Empty first argument for the program name
args.push_back("");
std::vector<char> widthArg = FormatArg("-width=%u", config.width);
args.push_back(widthArg.data());
std::vector<char> heightArg = FormatArg("-height=%u", config.height);
args.push_back(heightArg.data());
std::vector<char> displayArg = FormatArg("-d=%u", config.displayType);
args.push_back(displayArg.data());
std::vector<char> runArg = FormatArg("-run=%s/conformance_tests/%s", GetExecutableDirectory().c_str(), testPath.c_str());
args.push_back(runArg.data());
// Redirect cout
std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
std::ostringstream strCout;
std::cout.rdbuf(strCout.rdbuf());
if (GTFMain(args.size(), args.data()) != 0)
{
FAIL() << "GTFMain failed.";
}
// Restore old cout
std::cout.rdbuf(oldCoutStreamBuf);
std::string log = strCout.str();
// Look for failures
size_t offset = 0;
std::string offsetSearchString = "failure = ";
while ((offset = log.find("failure = ", offset)) != std::string::npos)
{
offset += offsetSearchString.length();
size_t failureCount = atoll(log.c_str() + offset);
EXPECT_EQ(0, failureCount) << log;
}
}