blob: 75902004eaa18459cb4dcec569251bcea8c321ba [file] [log] [blame]
Tony Barbour92400bb2015-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
Tony Barbourbdf0a312015-04-01 17:10:07 -060095 XGL_WSI_X11_CONNECTION_INFO connection_info = {};
96 connection_info.pConnection = m_connection;
97 connection_info.root = m_screen->root;
98 connection_info.provider = 0;
Tony Barbour92400bb2015-03-02 16:38:52 -070099
100 err = xglWsiX11AssociateConnection(gpus[0], &connection_info);
101 assert(!err);
102
103
104 devs_.reserve(count);
105 for (uint32_t i = 0; i < count; i++) {
106 devs_.push_back(new Device(gpus[i]));
107 if (i == default_dev_) {
108 devs_[i]->init();
109 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
110 }
111 }
112}
113
114void Environment::TearDown()
115{
116 // destroy devices first
117 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
118 delete *it;
119 devs_.clear();
120
121 xglDestroyInstance(inst);
122 xcb_disconnect(m_connection);
123}
124} // xgl_testing namespace