blob: 981dc0eb813683332094b6eb8022105f90b693e7 [file] [log] [blame]
// XGL tests
//
// Copyright (C) 2014 LunarG, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#ifndef XGLTESTFRAMEWORK_H
#define XGLTESTFRAMEWORK_H
#include "gtest-1.7.0/include/gtest/gtest.h"
#include "ShaderLang.h"
#include "GLSL450Lib.h"
#include "icd-spv.h"
#include "test_common.h"
#include "xgltestbinding.h"
#include "test_environment.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <list>
#include <xglWsiX11Ext.h>
// Can be used by tests to record additional details / description of test
#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
using namespace std;
class XglImage;
class XglTestImageRecord
{
public:
XglTestImageRecord();
XglTestImageRecord(const XglTestImageRecord &);
~XglTestImageRecord();
XglTestImageRecord &operator=(const XglTestImageRecord &rhs);
int operator==(const XglTestImageRecord &rhs) const;
int operator<(const XglTestImageRecord &rhs) const;
string m_title;
int m_width;
int m_height;
void *m_data;
XGL_IMAGE m_presentableImage;
XGL_GPU_MEMORY m_presentableMemory;
unsigned m_data_size;
};
class XglTestFramework : public ::testing::Test
{
public:
XglTestFramework();
~XglTestFramework();
static void InitArgs(int *argc, char *argv[]);
static void Finish();
void WritePPM( const char *basename, XglImage *image );
void Show(const char *comment, XglImage *image);
void Compare(const char *comment, XglImage *image);
void RecordImage(XglImage * image);
void RecordImages(vector<XglImage *> image);
bool GLSLtoSPV(const XGL_PIPELINE_SHADER_STAGE shader_type,
const char *pshader,
std::vector<unsigned int> &spv);
static bool m_use_spv;
char** ReadFileData(const char* fileName);
void FreeFileData(char** data);
private:
int m_compile_options;
int m_num_shader_strings;
TBuiltInResource Resources;
void SetMessageOptions(EShMessages& messages);
void ProcessConfigFile();
EShLanguage FindLanguage(const std::string& name);
EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type);
std::string ConfigFile;
bool SetConfigFile(const std::string& name);
static bool m_show_images;
static bool m_save_images;
static bool m_compare_images;
static std::list<XglTestImageRecord> m_images;
static std::list<XglTestImageRecord>::iterator m_display_image;
static int m_display_image_idx;
static int m_width; // Window width
static int m_height; // Window height
int m_frameNum;
string m_testName;
};
class TestFrameworkXglPresent
{
public:
TestFrameworkXglPresent();
void Run();
void InitPresentFramework(std::list<XglTestImageRecord> &imagesIn);
void CreateMyWindow();
void CreatePresentableImages();
void TearDown();
protected:
xgl_testing::Device &m_device;
xgl_testing::Queue &m_queue;
xgl_testing::CmdBuffer m_cmdbuf;
private:
xcb_window_t m_window;
xcb_intern_atom_reply_t *m_atom_wm_delete_window;
std::list<XglTestImageRecord> m_images;
bool m_quit;
bool m_pause;
uint32_t m_width;
uint32_t m_height;
std::list<XglTestImageRecord>::iterator m_display_image;
void Display();
void HandleEvent(xcb_generic_event_t *event);
};
class TestEnvironment : public ::testing::Environment
{
public:
void SetUp();
void TearDown();
};
#endif // XGLTESTFRAMEWORK_H