1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6 * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7 * Contact: Roman Marchenko <r.marchenko@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sub license, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
31 #include "gtest/gtest.h"
32 #include "ut_common.h"
36 #include "tbm_bufmgr.h"
37 #include "tbm_drm_helper.h"
40 class TDMLayer : public ::testing::Test {
42 tdm_display *dpy = NULL;
43 tbm_bufmgr tbm_bufmgr = NULL;
44 int master_fd = -42, tbm_fd = -42, layer_count = 0, output_count = 0;
45 tdm_layer ** tdm_layer_array = NULL;
46 bool has_layers = false;
49 setenv("TDM_DLOG", "1", 1);
50 setenv("XDG_RUNTIME_DIR", ".", 1);
51 setenv("TBM_DLOG", "1", 1);
52 setenv("TBM_DISPLAY_SERVER", "1", 1);
53 tbm_bufmgr = tbm_bufmgr_init(-1);
54 ASSERT_FALSE(tbm_bufmgr == NULL);
55 tdm_error error = TDM_ERROR_NONE;
56 dpy = tdm_display_init(&error);
57 ASSERT_TRUE(error == TDM_ERROR_NONE);
58 ASSERT_FALSE(dpy == NULL);
59 master_fd = tbm_drm_helper_get_master_fd();
60 tbm_fd = tbm_drm_helper_get_fd();
61 ASSERT_TRUE(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE);
62 for (int i = 0; i < output_count; i++) {
63 tdm_output * output = tdm_display_get_output(dpy, i, &error);
64 if (TDM_ERROR_NONE != error || NULL == output)
66 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
67 if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
69 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
71 int temp_layer_count = 0;
72 if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count))
74 if (0 == temp_layer_count)
76 tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array,
77 (layer_count + temp_layer_count)*sizeof(tdm_layer *));
78 ASSERT_FALSE(NULL == tdm_layer_array);
79 for (int k = layer_count; k < (layer_count + temp_layer_count); k++) {
80 tdm_layer_array[k] = tdm_output_get_layer(output, k, &error);
81 ASSERT_TRUE(TDM_ERROR_NONE == error);
82 ASSERT_FALSE(NULL == tdm_layer_array[k]);
84 layer_count+=temp_layer_count;
87 #ifdef FAIL_ON_UNSUPPORTED
88 ASSERT_GT(layer_count, 0);
95 tdm_display_deinit(dpy);
97 tbm_bufmgr_deinit(tbm_bufmgr);
100 free(tdm_layer_array);
101 if (master_fd > -1) {
102 int temp_master_fd = tbm_drm_helper_get_master_fd();
103 EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
104 if (temp_master_fd > -1)
109 int temp_tbm_fd = tbm_drm_helper_get_fd();
110 EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
111 if (temp_tbm_fd > -1)
115 unsetenv("TDM_DLOG");
116 unsetenv("XDG_RUNTIME_DIR");
117 unsetenv("TBM_DLOG");
118 unsetenv("TBM_DISPLAY_SERVER");
122 TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful)
124 SKIP_FLAG(has_layers);
125 for (int i = 0; i < layer_count; i++) {
126 tdm_layer_capability capabilities = (tdm_layer_capability) -42;
127 ASSERT_TRUE(TDM_ERROR_NONE == tdm_layer_get_capabilities(tdm_layer_array[i], &capabilities));
128 ASSERT_NE(capabilities, -42);
132 TEST_F(TDMLayer, LayerGetCapabilitiesFailNullAll)
134 SKIP_FLAG(has_layers);
135 ASSERT_EXIT({if (tdm_layer_get_capabilities(NULL, NULL) == TDM_ERROR_NONE) exit(1);
136 exit(0);}, ::testing::ExitedWithCode(0), "");
139 TEST_F(TDMLayer, LayerGetCapabilitiesFailOnlyLayer)
141 SKIP_FLAG(has_layers);
142 ASSERT_EXIT({for (int i = 0; i < layer_count; i++) {
143 if (tdm_layer_get_capabilities(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
145 exit(0);}, ::testing::ExitedWithCode(0), "");
148 TEST_F(TDMLayer, OutputGetPrimaryIndexSuccessful)
150 SKIP_FLAG(has_layers);
151 for (int i = 0; i < output_count; i++) {
152 tdm_error error = TDM_ERROR_NONE;
154 tdm_output * output = tdm_display_get_output(dpy, i, &error);
155 ASSERT_FALSE(NULL == output);
156 ASSERT_TRUE(TDM_ERROR_NONE == error);
157 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_primary_index(output, &index));
158 ASSERT_NE(index, -42);
162 TEST_F(TDMLayer, OutputGetPrimaryIndexFailNullAll)
164 SKIP_FLAG(has_layers);
165 ASSERT_EXIT({if (tdm_output_get_primary_index(NULL, NULL) == TDM_ERROR_NONE) exit(1);
166 exit(0);}, ::testing::ExitedWithCode(0), "");
169 TEST_F(TDMLayer, OutputGetPrimaryIndexFailOnlyOutput)
171 SKIP_FLAG(has_layers);
172 ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
173 tdm_error error = TDM_ERROR_NONE;
174 tdm_output * output = tdm_display_get_output(dpy, i, &error);
175 if (NULL == output) exit(1);
176 if (TDM_ERROR_NONE != error) exit(1);
177 if (tdm_output_get_primary_index(output, NULL) == TDM_ERROR_NONE) exit(1);
179 exit(0);}, ::testing::ExitedWithCode(0), "");