rename to tdm_log_printf
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm.h
1 #ifndef _UT_TDM_H_
2 #define _UT_TDM_H_
3
4 #include <sys/epoll.h>
5 #include <sys/timerfd.h>
6 #include <limits.h>
7 #include <vector>
8 #include <list>
9 #include <climits>
10 #include <pthread.h>
11 #include <gtest/gtest.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <poll.h>
15
16 extern "C" {
17 #include <tbm_bufmgr.h>
18 #include <tbm_drm_helper.h>
19 }
20
21 #include "tdm.h"
22 #include "tdm_helper.h"
23 #include "tdm_config.h"
24 #include "tdm_log.h"
25 #include "tdm_macro.h"
26 #include "buffers.h"
27
28 //#define TDM_UT_TEST_WITH_PARAMS
29
30 extern bool enable_porting_debug;
31
32 #undef TDM_DBG
33 #undef TDM_INFO
34 #undef TDM_WRN
35 #undef TDM_ERR
36 #define TDM_DBG(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_DBG, fmt, ##args)
37 #define TDM_INFO(fmt, args...) tdm_log_print(TDM_LOG_LEVEL_INFO, fmt, ##args)
38 #define TDM_WRN(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_WRN, fmt, ##args)
39 #define TDM_ERR(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_ERR, fmt, ##args)
40
41 #define TDM_UT_INFO(fmt, args...) tdm_log_printf(TDM_LOG_LEVEL_INFO, fmt, ##args)
42 #define TDM_UT_WRN(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_WRN, fmt, ##args)
43 #define TDM_UT_ERR(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_ERR, fmt, ##args)
44
45 #define TDM_UT_ENTRY() \
46     TDM_ERR("--------------------------------------------- %s", typeid(*this).name())
47
48 #define TDM_UT_CHECK_FLAG(FLAG) \
49         do {\
50                 if(!(FLAG)) \
51                         TDM_UT_WRN("[          ] not supported");\
52         } while(0)
53
54 #define TDM_UT_SKIP_FLAG(FLAG) \
55         do {\
56                 if(!(FLAG)) {\
57                         TDM_UT_WRN("[  SKIPPED ] not supported");\
58                         return;\
59                 }\
60         } while(0)
61
62 #define TDM_UT_RETURN_IF_FAIL(cond) \
63         do { \
64                 if (!(cond)) { \
65                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
66                         return; \
67                 } \
68         } while(0)
69 #define TDM_UT_RETURN_FALSE_IF_FAIL(cond) \
70         do { \
71                 if (!(cond)) { \
72                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
73                         return false; \
74                 } \
75         } while(0)
76 #define TDM_UT_RETURN_VAL_IF_FAIL(cond, val) \
77         do { \
78                 if (!(cond)) { \
79                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
80                         return val; \
81                 } \
82         } while(0)
83 #define TDM_UT_GOTO_IF_FAIL(cond, dst) \
84         do { \
85                 if (!(cond)) { \
86                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
87                         goto dst; \
88                 } \
89         } while(0)
90
91 #define TDM_UT_ASSERT_TRUE(cond, fmt, args...) \
92         do { \
93                 if (!(cond)) { \
94                         if (enable_porting_debug) \
95                                 TDM_UT_ERR(fmt, ##args); \
96                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_FATAL_FAILURE_); \
97                 } \
98         } while(0)
99 #define TDM_UT_EXPECT_TRUE(cond, fmt, args...) \
100         do { \
101                 if (!(cond)) { \
102                         if (enable_porting_debug) \
103                                 TDM_UT_ERR(fmt, ##args); \
104                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_NONFATAL_FAILURE_); \
105                 } \
106         } while(0)
107
108 #define TDM_UT_ASK_YNR(fmt, ...) \
109         do { \
110                 if (enable_porting_debug) { \
111                         char ch; \
112                         printf(fmt" [Y]es, [n]o, [r]etry: ", ##__VA_ARGS__); \
113                         do { \
114                                 ch = getchar(); \
115                                 if (ch == '\n') \
116                                         ch = 'y'; \
117                                 else { \
118                                         char tch; \
119                                         while ((tch = getchar()) != '\n' && tch != EOF); \
120                                 } \
121                         } while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N' && ch != 'r' && ch != 'R'); \
122                         if (ch == 'n' || ch == 'N') \
123                                 GTEST_FATAL_FAILURE_("tc failed"); \
124                         if (ch == 'r' || ch == 'R') \
125                                 goto retry; \
126                 } \
127         } while (0)
128
129 #define TDM_UT_ASK_YN(fmt, ...) \
130                         do { \
131                                 if (enable_porting_debug) { \
132                                         char ch; \
133                                         printf(fmt" [Y]es, [n]o: ", ##__VA_ARGS__); \
134                                         do { \
135                                                 ch = getchar(); \
136                                                 if (ch == '\n') \
137                                                         ch = 'y'; \
138                                                 else { \
139                                                         char tch; \
140                                                         while ((tch = getchar()) != '\n' && tch != EOF); \
141                                                 } \
142                                         } while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N'); \
143                                         if (ch == 'n' || ch == 'N') \
144                                                 GTEST_FATAL_FAILURE_("tc failed"); \
145                                 } \
146                         } while (0)
147
148 #define TDM_UT_SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
149
150 #define TDM_UT_DUMP_DIR          "/tmp/tdm_dump"
151 #define TDM_UT_INVALID_VALUE     -42
152 #define TDM_UT_BUFFER_SIZE       256
153 #define TDM_UT_VBLANK_NAME       "ut_tdm_vblank"
154
155 using ::testing::TestWithParam;
156 using ::testing::Bool;
157 using ::testing::Values;
158 using ::testing::Combine;
159
160 #ifdef TDM_UT_TEST_WITH_PARAMS
161 class TDMEnv : public TestWithParam< ::testing::tuple<bool, bool, const char*> >
162 {
163 public:
164         void SetUp(void);
165         void TearDown(void);
166 };
167 #else
168 class TDMEnv : public TestWithParam< ::testing::tuple<const char*> >
169 {
170 public:
171         void SetUp(void);
172         void TearDown(void);
173 };
174 #endif
175
176 class TDMDisplay : public TDMEnv
177 {
178 public:
179         tdm_display *dpy;
180         tbm_bufmgr bufmgr;
181
182         bool has_pp_cap;
183         bool has_capture_cap;
184
185         TDMDisplay();
186         void SetUp(void);
187         void TearDown(void);
188 };
189
190 class TDMOutput : public TDMDisplay
191 {
192 public:
193         bool has_outputs;
194         tdm_output **outputs;
195         int output_count;
196
197         bool done1, done2, done3;
198
199         TDMOutput();
200         void SetUp(void);
201         void TearDown(void);
202 };
203
204 #ifdef TIZEN_TEST_GCOV
205 extern "C" void __gcov_flush(void);
206 #endif
207
208 tdm_error ut_tdm_display_handle_events(tdm_display *dpy);
209 bool ut_tdm_display_has_pp_capability(tdm_display *dpy);
210 bool ut_tdm_display_has_capture_capability(tdm_display *dpy);
211
212 bool ut_tdm_buffer_create(int width, int height, tbm_format format, int flags, bool fill,
213                                                   int count, tbm_surface_h *buffers);
214
215 bool ut_tdm_output_is_async_dpms_enable(tdm_output *output);
216 bool ut_tdm_output_is_hwc_enable(tdm_output *output);
217 bool ut_tdm_output_is_aod_enable(tdm_output *output);
218 bool ut_tdm_output_is_connected(tdm_output *output);
219 bool ut_tdm_output_mode_setting(tdm_output *output);
220 bool ut_tdm_output_prepare(tdm_display *dpy, tdm_output *output, bool fill);
221 bool ut_tdm_output_prepare_all_output(tdm_display *dpy, tdm_output **outputs, int output_count, bool fill);
222 bool ut_tdm_output_unset(tdm_display *dpy, tdm_output *output);
223 double ut_tdm_output_get_vblank_interval_time(tdm_output *output);
224 tdm_layer *ut_tdm_output_get_primary_layer(tdm_output *output);
225
226 bool ut_tdm_layer_is_cursor_layer(tdm_layer *layer);
227 bool ut_tdm_layer_is_primary_layer(tdm_layer *layer);
228 bool ut_tdm_layer_is_video_layer(tdm_layer *layer);
229 bool ut_tdm_layer_support_scale(tdm_layer *layer);
230 bool ut_tdm_layer_support_no_crop(tdm_layer *layer);
231 bool ut_tdm_layer_prepare_buffer(tdm_layer *layer, tbm_surface_h *buffers, int buffer_count, bool fill);
232 bool ut_tdm_layer_prepare_buffer_queue(tdm_layer *layer, tbm_surface_queue_h *buffer_queue);
233 bool ut_tdm_layer_fill_info(tdm_layer *layer, tbm_surface_h buffer, tbm_surface_queue_h buffer_queue, tdm_info_layer *info);
234 bool ut_tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
235 bool ut_tdm_layer_set_buffer_with_pos(tdm_layer *layer, tbm_surface_h buffer, tdm_pos *pos);
236 unsigned int ut_tdm_layer_get_output_pipe(tdm_layer *layer);
237 tbm_format ut_tdm_layer_find_best_format(tdm_layer *layer);
238 bool ut_tdm_layer_is_avaiable(tdm_layer *layer);
239
240 bool ut_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info);
241 bool ut_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
242                                                           tdm_capture_type type, int frequency, bool stretch, tdm_info_capture *info);
243
244 /******************************************************************************/
245 /** testing for checking backend's basic implementation                      **/
246 /******************************************************************************/
247 class TDMBackendEnv : public TDMEnv
248 {
249 public:
250         void SetUp(void);
251         void TearDown(void);
252 };
253
254 class TDMBackendBasic : public TDMBackendEnv
255 {
256 public:
257         tdm_display *dpy;
258
259         tdm_output **outputs;
260         int output_count;
261
262         tdm_layer **layers;
263         int layer_count;
264
265         tbm_surface_h buffers[3];
266
267         TDMBackendBasic();
268         void SetUp(void);
269         void TearDown(void);
270         void UnsetOutput(void);
271         void DestroyBuffers(void);
272 };
273
274 class TDMBackendDisplay : public TDMBackendBasic
275 {
276 public:
277         void SetUp(void) { TDMBackendBasic::SetUp(); }
278         void TearDown(void) { TDMBackendBasic::TearDown(); }
279 };
280
281 #endif // _UT_TDM_H_