Home | History | Annotate | Download | only in deqp_tests
      1 //
      2 // Copyright (c) 2014 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 "deqp_tests.h"
      8 
      9 #include <EGL/eglext.h>
     10 
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 #include <vector>
     14 #include <sstream>
     15 #include <stdarg.h>
     16 #include <windows.h>
     17 
     18 #include "tcuDefs.hpp"
     19 #include "tcuCommandLine.hpp"
     20 #include "tcuPlatform.hpp"
     21 #include "tcuApp.hpp"
     22 #include "tcuResource.hpp"
     23 #include "tcuTestLog.hpp"
     24 #include "tcuTestExecutor.hpp"
     25 #include "deUniquePtr.hpp"
     26 #include "tes3TestPackage.hpp"
     27 
     28 #include "win32/tcuWin32EglPlatform.hpp"
     29 
     30 // Register the gles3 test cases
     31 static tcu::TestPackage* createTestPackage(tcu::TestContext& testCtx)
     32 {
     33     return new deqp::gles3::TestPackage(testCtx);
     34 }
     35 tcu::TestPackageDescriptor g_gles3PackageDescriptor("dEQP-GLES3", createTestPackage);
     36 
     37 // Create a platform that supports custom display types
     38 class Win32EglCustomDisplayPlatform  : public tcu::Win32EglPlatform
     39 {
     40 public:
     41     Win32EglCustomDisplayPlatform(EGLNativeDisplayType displayType)
     42         : mDisplayType(displayType)
     43     {
     44     }
     45 
     46     virtual ~Win32EglCustomDisplayPlatform()
     47     {
     48     }
     49 
     50     virtual tcu::NativeDisplay* createDefaultDisplay()
     51     {
     52         return new tcu::Win32EglDisplay(mDisplayType);
     53     }
     54 
     55 private:
     56     EGLNativeDisplayType mDisplayType;
     57 };
     58 
     59 static std::vector<char> FormatArg(const char* fmt, ...)
     60 {
     61     va_list vararg;
     62     va_start(vararg, fmt);
     63     int len = vsnprintf(NULL, 0, fmt, vararg);
     64     va_end(vararg);
     65 
     66     std::vector<char> buf(len + 1);
     67 
     68     va_start(vararg, fmt);
     69     vsnprintf(buf.data(), buf.size(), fmt, vararg);
     70     va_end(vararg);
     71 
     72     return buf;
     73 }
     74 
     75 static std::string GetExecutableDirectory()
     76 {
     77     std::vector<char> executableFileBuf(MAX_PATH);
     78     DWORD executablePathLen = GetModuleFileNameA(NULL, executableFileBuf.data(), executableFileBuf.size());
     79     if (executablePathLen == 0)
     80     {
     81         return false;
     82     }
     83 
     84     std::string executableLocation = executableFileBuf.data();
     85     size_t lastPathSepLoc = executableLocation.find_last_of("\\/");
     86     if (lastPathSepLoc != std::string::npos)
     87     {
     88         executableLocation = executableLocation.substr(0, lastPathSepLoc);
     89     }
     90     else
     91     {
     92         executableLocation = "";
     93     }
     94 
     95     return executableLocation;
     96 }
     97 
     98 static DEQPConfig kCurrentConfig = { 256, 256, false, EGL_D3D11_ONLY_DISPLAY_ANGLE };
     99 
    100 void SetCurrentConfig(const DEQPConfig& config)
    101 {
    102     kCurrentConfig = config;
    103 }
    104 
    105 const DEQPConfig& GetCurrentConfig()
    106 {
    107     return kCurrentConfig;
    108 }
    109 
    110 void RunDEQPTest(const std::string &testPath, const DEQPConfig& config)
    111 {
    112     try
    113     {
    114         std::vector<char*> args;
    115 
    116         // Empty first argument for the program name
    117         args.push_back("deqp-gles3");
    118 
    119         std::vector<char> visibilityArg = FormatArg("--deqp-visibility=%s", config.hidden ? "hidden" : "windowed");
    120         args.push_back(visibilityArg.data());
    121 
    122         std::vector<char> widthArg = FormatArg("--deqp-surface-width=%u", config.width);
    123         args.push_back(widthArg.data());
    124 
    125         std::vector<char> heightArg = FormatArg("--deqp-surface-height=%u", config.height);
    126         args.push_back(heightArg.data());
    127 
    128         std::vector<char> testNameArg = FormatArg("--deqp-case=%s", testPath.c_str());
    129         args.push_back(testNameArg.data());
    130 
    131         // Redirect cout
    132         std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
    133         std::ostringstream strCout;
    134         std::cout.rdbuf(strCout.rdbuf());
    135 
    136         tcu::CommandLine                cmdLine(args.size(), args.data());
    137         tcu::DirArchive                 archive(GetExecutableDirectory().c_str());
    138         tcu::TestLog                    log(cmdLine.getLogFileName(), cmdLine.getLogFlags());
    139         de::UniquePtr<tcu::Platform>    platform(new Win32EglCustomDisplayPlatform(config.displayType));
    140         de::UniquePtr<tcu::App>         app(new tcu::App(*platform, archive, log, cmdLine));
    141 
    142         // Main loop.
    143         for (;;)
    144         {
    145             if (!app->iterate())
    146             {
    147                 break;
    148             }
    149         }
    150 
    151         // Restore old cout
    152         std::cout.rdbuf(oldCoutStreamBuf);
    153 
    154         EXPECT_EQ(0, app->getResult().numFailed) << strCout.str();
    155     }
    156     catch (const std::exception& e)
    157     {
    158         FAIL() << e.what();
    159     }
    160 }
    161