tbm_module: add tbm_module_bo_map and use it
[platform/core/uifw/libtbm.git] / haltests / tc_tbm_env.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
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:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
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.
28  *
29 **************************************************************************/
30
31 #include "tc_tbm.h"
32
33 void TBMEnv::SetUp(void)
34 {
35         setenv("XDG_RUNTIME_DIR", "/run", 1);
36         setenv("TBM_DISPLAY_SERVER", "1", 1);
37 #if 0
38         const char *test_backend;
39
40         tdm_config_set_int(TBM_CONFIG_KEY_GENERAL_THREAD, ::testing::get<0>(GetParam()));
41         tdm_config_set_int(TBM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, ::testing::get<1>(GetParam()));
42         if (getenv("TBM_DEBUG_MODULE"))
43                 tdm_config_set_string(TBM_CONFIG_KEY_DEBUG_MODULE, "buffer,thread,event,vblank,commit,pp,capture");
44
45         test_backend = ::testing::get<2>(GetParam());
46         if (!test_backend)
47                 test_backend = TBM_DEFAULT_MODULE;
48         tdm_config_set_string(TBM_CONFIG_KEY_GENERAL_BACKENDS, test_backend);
49 #endif
50 }
51
52 void TBMEnv::TearDown(void)
53 {
54         unsetenv("XDG_RUNTIME_DIR");
55         unsetenv("TBM_DISPLAY_SERVER");
56 }
57
58 /* tbm_bufmgr_init(), tbm_bufmgr_deinit() */
59
60 TEST_F(TBMEnv, BufmgrInitDeinit)
61 {
62         tbm_bufmgr bufmgr;
63
64         bufmgr = tbm_bufmgr_init(-1);
65         EXPECT_NE(bufmgr, nullptr);
66         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
67
68         tbm_bufmgr_deinit(bufmgr);
69
70         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
71 }
72
73 TEST_F(TBMEnv, BufmgrInitFewTimes)
74 {
75         tbm_bufmgr bufmgr[10];
76         int i;
77
78         for (i = 0; i < 10; i++) {
79                 bufmgr[i] = tbm_bufmgr_init(-1);
80                 EXPECT_NE(bufmgr[i], nullptr);
81                 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
82         }
83
84         for (i = 0; i < 10; i++)
85                 tbm_bufmgr_deinit(bufmgr[i]);
86
87         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
88 }
89
90 TEST_F(TBMEnv, BufmgrDeinitWithNULL)
91 {
92         tbm_bufmgr_deinit(NULL);
93
94         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
95 }
96
97 /* tbm_bufmgr_server_init() */
98 TEST_F(TBMEnv, BufmgrServerInitDeinit)
99 {
100         tbm_bufmgr bufmgr;
101
102         bufmgr = tbm_bufmgr_server_init();
103         EXPECT_NE(bufmgr, nullptr);
104         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
105
106         tbm_bufmgr_deinit(bufmgr);
107
108         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
109 }
110
111 TEST_F(TBMEnv, BufmgrServerInitWithoutEnv)
112 {
113         tbm_bufmgr bufmgr;
114
115         TBMEnv::TearDown();
116
117         bufmgr = tbm_bufmgr_server_init();
118         EXPECT_NE(bufmgr, nullptr);
119         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
120
121         tbm_bufmgr_deinit(bufmgr);
122
123         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
124 }
125
126 TEST_F(TBMEnv, BufmgrServerInitFewTimes)
127 {
128         tbm_bufmgr bufmgr[10];
129         int i;
130
131         for (i = 0; i < 10; i++) {
132                 bufmgr[i] = tbm_bufmgr_server_init();
133                 EXPECT_NE(bufmgr[i], nullptr);
134                 EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
135         }
136
137         for (i = 0; i < 10; i++)
138                 tbm_bufmgr_deinit(bufmgr[i]);
139
140         ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0);
141 }
142
143 /* int tbm_surface_internal_query_supported_formats(uint32_t **formats, uint32_t *num) */
144 TEST_F(TBMEnv, SurfaceInternalQueryFormats)
145 {
146         tbm_bufmgr bufmgr;
147         uint32_t num = 0;
148         tbm_format *formats = NULL;
149
150         bufmgr = tbm_bufmgr_server_init();
151         EXPECT_NE(bufmgr, nullptr);
152
153         EXPECT_EQ(tbm_surface_internal_query_supported_formats(&formats, &num), 1);
154         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
155         EXPECT_GT(num, 0);
156         EXPECT_NE(formats, nullptr);
157         for (uint32_t i = 0; i < num; i++)
158                 EXPECT_NE(formats[i], 0);
159
160         if (formats)
161                 free(formats);
162
163         tbm_bufmgr_deinit(bufmgr);
164 }
165
166 TEST_F(TBMEnv, SurfaceInternalQueryFormatsFailNull)
167 {
168         tbm_bufmgr bufmgr;
169         uint32_t num = 0;
170         tbm_format *formats = NULL;
171
172         bufmgr = tbm_bufmgr_server_init();
173         EXPECT_NE(bufmgr, nullptr);
174         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_NONE));
175
176         EXPECT_EQ(tbm_surface_internal_query_supported_formats(&formats, NULL), 0);
177         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
178         EXPECT_EQ(tbm_surface_internal_query_supported_formats(NULL, &num), 0);
179         EXPECT_STREQ(tbm_error_str(tbm_get_last_error()), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
180
181         tbm_bufmgr_deinit(bufmgr);
182 }
183
184 TEST_F(TBMEnv, SurfaceQueryFormatsFailNull)
185 {
186         uint32_t num = 0;
187         tbm_format *formats = NULL;
188         tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
189
190         result = (tbm_surface_error_e)tbm_surface_query_formats(&formats, NULL);
191         EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
192
193         result = (tbm_surface_error_e)tbm_surface_query_formats(NULL, &num);
194         EXPECT_STREQ(tbm_error_str(result), tbm_error_str(TBM_ERROR_INVALID_PARAMETER));
195 }
196
197 TEST_F(TBMEnv, SurfaceQueryFormatSuccess)
198 {
199         uint32_t num = 0;
200         tbm_format *formats = NULL;
201         tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE;
202
203         result = (tbm_surface_error_e)tbm_surface_query_formats(&formats, &num);
204         EXPECT_EQ(TBM_SURFACE_ERROR_NONE, result);
205         EXPECT_GT(num, 0);
206         EXPECT_NE((tbm_format *)NULL, formats);
207         for (uint32_t i = 0; i < num; i++)
208                 EXPECT_NE(0, formats[i]);
209         free(formats);
210 }
211
212 INSTANTIATE_TEST_CASE_P(TBMEnvParams,
213                                                 TBMEnv,
214                                                 Combine(Bool(), Bool(), Values("none")));