utest: correct wrong behaviors
[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_print_stdout(TDM_LOG_LEVEL_INFO, fmt, ##args)
42 #define TDM_UT_ERR(fmt, args...)  tdm_log_print_stdout(TDM_LOG_LEVEL_ERR, fmt, ##args)
43
44 #define TDM_UT_ENTRY() \
45     TDM_ERR("--------------------------------------------- %s", typeid(*this).name())
46
47 #define TDM_UT_CHECK_FLAG(FLAG) \
48         do {\
49                 if(!(FLAG)) \
50                         TDM_UT_INFO("[          ] not supported");\
51         } while(0)
52
53 #define TDM_UT_SKIP_FLAG(FLAG) \
54         do {\
55                 if(!(FLAG)) {\
56                         TDM_UT_INFO("[  SKIPPED ] not supported");\
57                         return;\
58                 }\
59         } while(0)
60
61 #define TDM_UT_RETURN_IF_FAIL(cond) \
62         do { \
63                 if (!(cond)) { \
64                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
65                         return; \
66                 } \
67         } while(0)
68 #define TDM_UT_RETURN_FALSE_IF_FAIL(cond) \
69         do { \
70                 if (!(cond)) { \
71                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
72                         return false; \
73                 } \
74         } while(0)
75 #define TDM_UT_RETURN_VAL_IF_FAIL(cond, val) \
76         do { \
77                 if (!(cond)) { \
78                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
79                         return val; \
80                 } \
81         } while(0)
82 #define TDM_UT_GOTO_IF_FAIL(cond, dst) \
83         do { \
84                 if (!(cond)) { \
85                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
86                         goto dst; \
87                 } \
88         } while(0)
89
90 #define TDM_UT_ASSERT_TRUE(cond, fmt, args...) \
91         do { \
92                 if (!(cond)) { \
93                         if (enable_porting_debug) \
94                                 TDM_UT_ERR(fmt, ##args); \
95                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_FATAL_FAILURE_); \
96                 } \
97         } while(0)
98 #define TDM_UT_EXPECT_TRUE(cond, fmt, args...) \
99         do { \
100                 if (!(cond)) { \
101                         if (enable_porting_debug) \
102                                 TDM_UT_ERR(fmt, ##args); \
103                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_NONFATAL_FAILURE_); \
104                 } \
105         } while(0)
106
107 #define TDM_UT_ASK_YNR(fmt, ...) \
108         do { \
109                 if (enable_porting_debug) { \
110                         char ch; \
111                         printf(fmt" [Y]es, [n]o, [r]etry: ", ##__VA_ARGS__); \
112                         do { \
113                                 ch = getchar(); \
114                                 if (ch == '\n') \
115                                         ch = 'y'; \
116                                 else { \
117                                         char tch; \
118                                         while ((tch = getchar()) != '\n' && tch != EOF); \
119                                 } \
120                         } while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N' && ch != 'r' && ch != 'R'); \
121                         if (ch == 'n' || ch == 'N') \
122                                 GTEST_FATAL_FAILURE_("tc failed"); \
123                         if (ch == 'r' || ch == 'R') \
124                                 goto retry; \
125                 } else { \
126                         usleep(1000000); /* 1000 ms */ \
127                 } \
128         } while (0)
129
130 #define TDM_UT_SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
131
132 #define TDM_UT_DUMP_DIR          "/tmp/tdm_dump"
133 #define TDM_UT_INVALID_VALUE     -42
134 #define TDM_UT_BUFFER_SIZE       256
135 #define TDM_UT_VBLANK_NAME       "ut_tdm_vblank"
136
137 using ::testing::TestWithParam;
138 using ::testing::Bool;
139 using ::testing::Values;
140 using ::testing::Combine;
141
142 #ifdef TDM_UT_TEST_WITH_PARAMS
143 class TDMEnv : public TestWithParam< ::testing::tuple<bool, bool, const char*> >
144 {
145 public:
146         void SetUp(void);
147         void TearDown(void);
148 };
149 #else
150 class TDMEnv : public TestWithParam< ::testing::tuple<const char*> >
151 {
152 public:
153         void SetUp(void);
154         void TearDown(void);
155 };
156 #endif
157
158 class TDMDisplay : public TDMEnv
159 {
160 public:
161         tdm_display *dpy;
162         tbm_bufmgr bufmgr;
163
164         bool has_pp_cap;
165         bool has_capture_cap;
166
167         TDMDisplay();
168         void SetUp(void);
169         void TearDown(void);
170 };
171
172 class TDMOutput : public TDMDisplay
173 {
174 public:
175         bool has_outputs;
176         tdm_output **outputs;
177         int output_count;
178
179         bool done1, done2, done3;
180
181         TDMOutput();
182         void SetUp(void);
183         void TearDown(void);
184 };
185
186 #ifdef TIZEN_TEST_GCOV
187 extern "C" void __gcov_flush(void);
188 #endif
189
190 tdm_error ut_tdm_display_handle_events(tdm_display *dpy);
191 bool ut_tdm_display_has_pp_capability(tdm_display *dpy);
192 bool ut_tdm_display_has_capture_capability(tdm_display *dpy);
193
194 bool ut_tdm_buffer_create(int width, int height, tbm_format format, int flags, bool fill,
195                                                   int count, tbm_surface_h *buffers);
196
197 bool ut_tdm_output_is_async_dpms_enable(tdm_output *output);
198 bool ut_tdm_output_is_hwc_enable(tdm_output *output);
199 bool ut_tdm_output_is_aod_enable(tdm_output *output);
200 bool ut_tdm_output_is_connected(tdm_output *output);
201 bool ut_tdm_output_mode_setting(tdm_output *output);
202 bool ut_tdm_output_prepare(tdm_display *dpy, tdm_output *output, bool fill);
203 bool ut_tdm_output_prepare_all_output(tdm_display *dpy, tdm_output **outputs, int output_count, bool fill);
204 bool ut_tdm_output_unset(tdm_display *dpy, tdm_output *output);
205 double ut_tdm_output_get_vblank_interval_time(tdm_output *output);
206 tdm_layer *ut_tdm_output_get_primary_layer(tdm_output *output);
207
208 bool ut_tdm_layer_is_cursor_layer(tdm_layer *layer);
209 bool ut_tdm_layer_is_primary_layer(tdm_layer *layer);
210 bool ut_tdm_layer_is_video_layer(tdm_layer *layer);
211 bool ut_tdm_layer_support_scale(tdm_layer *layer);
212 bool ut_tdm_layer_support_no_crop(tdm_layer *layer);
213 bool ut_tdm_layer_prepare_buffer(tdm_layer *layer, tbm_surface_h *buffers, int buffer_count, bool fill);
214 bool ut_tdm_layer_prepare_buffer_queue(tdm_layer *layer, tbm_surface_queue_h *buffer_queue);
215 bool ut_tdm_layer_fill_info(tdm_layer *layer, int w, int h, tbm_format format, tdm_info_layer *info);
216 bool ut_tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
217 unsigned int ut_tdm_layer_get_output_pipe(tdm_layer *layer);
218 tbm_format ut_tdm_layer_find_best_format(tdm_layer *layer);
219 bool ut_tdm_layer_is_avaiable(tdm_layer *layer);
220
221 bool ut_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info);
222 bool ut_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
223                                                           tdm_capture_type type, int frequency, tdm_info_capture *info);
224
225 /******************************************************************************/
226 /** testing for checking backend's basic implementation                      **/
227 /******************************************************************************/
228 class TDMBackendEnv : public TDMEnv
229 {
230 public:
231         void SetUp(void);
232         void TearDown(void);
233 };
234
235 class TDMBackendBasic : public TDMBackendEnv
236 {
237 public:
238         tdm_display *dpy;
239
240         tdm_output **outputs;
241         int output_count;
242
243         tdm_layer **layers;
244         int layer_count;
245
246         tbm_surface_h buffers[3];
247
248         TDMBackendBasic();
249         void SetUp(void);
250         void TearDown(void);
251         void UnsetOutput(void);
252         void DestroyBuffers(void);
253 };
254
255 class TDMBackendDisplay : public TDMBackendBasic
256 {
257 public:
258         void SetUp(void) { TDMBackendBasic::SetUp(); }
259         void TearDown(void) { TDMBackendBasic::TearDown(); }
260 };
261
262 #endif // _UT_TDM_H_