Hash :
4d06a24c
Author :
Date :
2015-06-26T11:12:24
dEQP: Extend GoogleTest support. *re-land after rebase on top of Chrome build fix* This patch will enable a Chromium-side CL to build dEQP/ANGLE with GoogleTest. BUG=angleproject:998 BUG=500736 Change-Id: Id02c66a260b0a7bab3de9cda624fe097322b2d3c Reviewed-on: https://chromium-review.googlesource.com/281824 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@google.com> Reviewed-by: Kenneth Russell <kbr@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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// deqp_libtester_main.cpp: Entry point for tester DLL.
#include <cstdio>
#include <iostream>
#include "angle_deqp_libtester.h"
#include "common/angleutils.h"
#include "deMath.h"
#include "deUniquePtr.hpp"
#include "tcuApp.hpp"
#include "tcuCommandLine.hpp"
#include "tcuDefs.hpp"
#include "tcuPlatform.hpp"
#include "tcuRandomOrderExecutor.h"
#include "tcuResource.hpp"
#include "tcuTestLog.hpp"
#if (DE_OS == DE_OS_WIN32)
#include <Windows.h>
#endif
// Located in tcuMain.cc in dEQP's sources.
int main(int argc, const char* argv[]);
tcu::Platform *createPlatform();
namespace
{
tcu::Platform *g_platform = nullptr;
tcu::CommandLine *g_cmdLine = nullptr;
tcu::DirArchive *g_archive = nullptr;
tcu::TestLog *g_log = nullptr;
tcu::TestContext *g_testCtx = nullptr;
tcu::TestPackageRoot *g_root = nullptr;
tcu::RandomOrderExecutor *g_executor = nullptr;
const char *g_dEQPDataSearchDirs[] =
{
"data",
"third_party/deqp/data",
"../third_party/deqp/src/data",
"deqp_support/data",
"third_party/deqp/src/data",
"../../third_party/deqp/src/data"
};
// TODO(jmadill): upstream to dEQP?
#if (DE_OS == DE_OS_WIN32)
deBool deIsDir(const char *filename)
{
DWORD attribs = GetFileAttributesA(filename);
return (attribs != INVALID_FILE_ATTRIBUTES) &&
((attribs & FILE_ATTRIBUTE_DIRECTORY) > 0);
}
#else
#error TODO(jmadill): support other platforms
//deBool deIsDir(const char *filename)
//{
// struct stat st;
// int result = stat(filename, &st);
// return result == 0 && ((st.st_mode & S_IFDIR) == S_IFDIR);
//}
#endif
const char *FindDataDir()
{
for (size_t dirIndex = 0; dirIndex < ArraySize(g_dEQPDataSearchDirs); ++dirIndex)
{
if (deIsDir(g_dEQPDataSearchDirs[dirIndex]))
{
return g_dEQPDataSearchDirs[dirIndex];
}
}
return nullptr;
}
bool InitPlatform()
{
try
{
#if (DE_OS != DE_OS_WIN32)
// Set stdout to line-buffered mode (will be fully buffered by default if stdout is pipe).
setvbuf(stdout, DE_NULL, _IOLBF, 4 * 1024);
#endif
g_platform = createPlatform();
if (!deSetRoundingMode(DE_ROUNDINGMODE_TO_NEAREST))
{
std::cout << "Failed to set floating point rounding mode." << std::endl;
return false;
}
const char *deqpDataDir = FindDataDir();
if (deqpDataDir == nullptr)
{
std::cout << "Failed to find dEQP data directory." << std::endl;
return false;
}
// TODO(jmadill): filter arguments
const char *emptyString = "";
g_cmdLine = new tcu::CommandLine(1, &emptyString);
g_archive = new tcu::DirArchive(deqpDataDir);
g_log = new tcu::TestLog(g_cmdLine->getLogFileName(), g_cmdLine->getLogFlags());
g_testCtx = new tcu::TestContext(*g_platform, *g_archive, *g_log, *g_cmdLine, DE_NULL);
g_root = new tcu::TestPackageRoot(*g_testCtx, tcu::TestPackageRegistry::getSingleton());
g_executor = new tcu::RandomOrderExecutor(*g_root, *g_testCtx);
}
catch (const std::exception& e)
{
tcu::die("%s", e.what());
return false;
}
return true;
}
} // anonymous namespace
// Exported to the tester app.
ANGLE_LIBTESTER_EXPORT int deqp_libtester_main(int argc, const char *argv[])
{
return main(argc, argv);
}
ANGLE_LIBTESTER_EXPORT void deqp_libtester_shutdown_platform()
{
delete g_executor;
delete g_root;
delete g_testCtx;
delete g_log;
delete g_archive;
delete g_cmdLine;
delete g_platform;
}
ANGLE_LIBTESTER_EXPORT bool deqp_libtester_run(const char *caseName)
{
if (g_platform == nullptr && !InitPlatform())
{
tcu::die("Failed to initialize platform.");
}
try
{
// Poll platform events
const bool platformOk = g_platform->processEvents();
if (platformOk)
{
const tcu::TestStatus &result = g_executor->execute(caseName);
switch (result.getCode())
{
case QP_TEST_RESULT_PASS:
case QP_TEST_RESULT_NOT_SUPPORTED:
return true;
case QP_TEST_RESULT_QUALITY_WARNING:
std::cout << "Quality warning! " << result.getDescription() << std::endl;
return true;
case QP_TEST_RESULT_COMPATIBILITY_WARNING:
std::cout << "Compatiblity warning! " << result.getDescription() << std::endl;
return true;
default:
return false;
}
}
else
{
std::cout << "Aborted test!" << std::endl;
}
}
catch (const std::exception &e)
{
std::cout << "Exception running test: " << e.what() << std::endl;
}
return false;
}