blob: b3f3a9eba29a5f3e322de1b5ea4e71c724bae0a7 [file] [log] [blame]
Tony Barbour34888cf2015-03-02 16:38:52 -07001#include "test_common.h"
2#include "xgltestbinding.h"
3#include "test_environment.h"
4
5#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
6
7namespace xgl_testing {
8
9Environment::Environment() :
10 default_dev_(0)
11{
12 app_.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
13 app_.pAppName = "xgl_testing";
14 app_.appVersion = 1;
15 app_.pEngineName = "xgl_testing";
16 app_.engineVersion = 1;
17 app_.apiVersion = XGL_API_VERSION;
18}
19
20bool Environment::parse_args(int argc, char **argv)
21{
22 int i;
23
24 for (i = 1; i < argc; i++) {
25#define ARG(name) (strcmp(argv[i], name) == 0)
26#define ARG_P(name) (i < argc - 1 && ARG(name))
27 if (ARG_P("--gpu")) {
28 default_dev_ = atoi(argv[++i]);
29 } else {
30 break;
31 }
32#undef ARG
33#undef ARG_P
34 }
35
36 if (i < argc) {
37 std::cout <<
38 "invalid argument: " << argv[i] << "\n\n" <<
39 "Usage: " << argv[0] << " <options>\n\n" <<
40 "Options:\n"
41 " --gpu <n> Use GPU<n> as the default GPU\n";
42
43 return false;
44 }
45
46 return true;
47}
48
49void Environment::SetUp()
50{
51
52 uint32_t count;
53 XGL_RESULT err;
54
55 err = xglCreateInstance(&app_, NULL, &inst);
56 ASSERT_EQ(XGL_SUCCESS, err);
57 err = xglEnumerateGpus(inst, ARRAY_SIZE(gpus), &count, gpus);
58 ASSERT_EQ(XGL_SUCCESS, err);
59 ASSERT_GT(count, default_dev_);
60
61 devs_.reserve(count);
62 for (uint32_t i = 0; i < count; i++) {
63 devs_.push_back(new Device(gpus[i]));
64 if (i == default_dev_) {
65 devs_[i]->init();
66 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
67 }
68 }
69}
70
71void Environment::X11SetUp()
72{
73
74 uint32_t count;
75 XGL_RESULT err;
76 const xcb_setup_t *setup;
77 xcb_screen_iterator_t iter;
78 int scr;
79
80 err = xglCreateInstance(&app_, NULL, &inst);
81 ASSERT_EQ(XGL_SUCCESS, err);
82 err = xglEnumerateGpus(inst, ARRAY_SIZE(gpus), &count, gpus);
83 ASSERT_EQ(XGL_SUCCESS, err);
84 ASSERT_GT(count, default_dev_);
85
86 m_connection = xcb_connect(NULL, &scr);
87
88 setup = xcb_get_setup(m_connection);
89 iter = xcb_setup_roots_iterator(setup);
90 while (scr-- > 0)
91 xcb_screen_next(&iter);
92
93 m_screen = iter.data;
94
95 const XGL_WSI_X11_CONNECTION_INFO connection_info = {
96 .pConnection = m_connection,
97 .root = m_screen->root,
98 .provider = 0,
99 };
100
101 err = xglWsiX11AssociateConnection(gpus[0], &connection_info);
102 assert(!err);
103
104
105 devs_.reserve(count);
106 for (uint32_t i = 0; i < count; i++) {
107 devs_.push_back(new Device(gpus[i]));
108 if (i == default_dev_) {
109 devs_[i]->init();
110 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
111 }
112 }
113}
114
115void Environment::TearDown()
116{
117 // destroy devices first
118 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
119 delete *it;
120 devs_.clear();
121
122 xglDestroyInstance(inst);
123 xcb_disconnect(m_connection);
124}
125} // xgl_testing namespace