change the utests to haltests
[platform/core/uifw/libtdm.git] / haltests / src / tc_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 /* LCOV_EXCL_START */
22
23 #include "tdm.h"
24 #include "tdm_helper.h"
25 #include "tdm_config.h"
26 #include "tdm_log.h"
27 #include "tdm_macro.h"
28 #include "buffers.h"
29
30 //#define TDM_UT_TEST_WITH_PARAMS
31
32 extern bool enable_porting_debug;
33
34 #undef TDM_DBG
35 #undef TDM_INFO
36 #undef TDM_WRN
37 #undef TDM_ERR
38 #define TDM_DBG(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_DBG, fmt, ##args)
39 #define TDM_INFO(fmt, args...) tdm_log_print(TDM_LOG_LEVEL_INFO, fmt, ##args)
40 #define TDM_WRN(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_WRN, fmt, ##args)
41 #define TDM_ERR(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_ERR, fmt, ##args)
42
43 #define TDM_UT_INFO(fmt, args...) tdm_log_printf(TDM_LOG_LEVEL_INFO, fmt, ##args)
44 #define TDM_UT_WRN(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_WRN, fmt, ##args)
45 #define TDM_UT_ERR(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_ERR, fmt, ##args)
46
47 #define TDM_UT_ENTRY() \
48     TDM_ERR("--------------------------------------------- %s", typeid(*this).name())
49
50 #define TDM_UT_CHECK_FLAG(FLAG) \
51         do {\
52                 if(!(FLAG)) \
53                         TDM_UT_WRN("[          ] not supported");\
54         } while(0)
55
56 #define TDM_UT_SKIP_FLAG(FLAG) \
57         do {\
58                 if(!(FLAG)) {\
59                         TDM_UT_WRN("[  SKIPPED ] not supported");\
60                         return;\
61                 }\
62         } while(0)
63
64 #define TDM_UT_RETURN_IF_FAIL(cond) \
65         do { \
66                 if (!(cond)) { \
67                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
68                         return; \
69                 } \
70         } while(0)
71 #define TDM_UT_RETURN_FALSE_IF_FAIL(cond) \
72         do { \
73                 if (!(cond)) { \
74                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
75                         return false; \
76                 } \
77         } while(0)
78 #define TDM_UT_RETURN_VAL_IF_FAIL(cond, val) \
79         do { \
80                 if (!(cond)) { \
81                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
82                         return val; \
83                 } \
84         } while(0)
85 #define TDM_UT_GOTO_IF_FAIL(cond, dst) \
86         do { \
87                 if (!(cond)) { \
88                         TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
89                         goto dst; \
90                 } \
91         } while(0)
92
93 #define TDM_UT_ASSERT_TRUE(cond, fmt, args...) \
94         do { \
95                 if (!(cond)) { \
96                         if (enable_porting_debug) \
97                                 TDM_UT_ERR(fmt, ##args); \
98                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_FATAL_FAILURE_); \
99                 } \
100         } while(0)
101 #define TDM_UT_EXPECT_TRUE(cond, fmt, args...) \
102         do { \
103                 if (!(cond)) { \
104                         if (enable_porting_debug) \
105                                 TDM_UT_ERR(fmt, ##args); \
106                         GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_NONFATAL_FAILURE_); \
107                 } \
108         } while(0)
109
110 #define TDM_UT_SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
111
112 #define TDM_UT_DUMP_DIR          "/tmp/tdm_dump"
113 #define TDM_UT_INVALID_VALUE     -42
114 #define TDM_UT_BUFFER_SIZE       256
115 #define TDM_UT_VBLANK_NAME       "tc_tdm_vblank"
116
117 using ::testing::TestWithParam;
118 using ::testing::Bool;
119 using ::testing::Values;
120 using ::testing::Combine;
121
122 #ifdef TDM_UT_TEST_WITH_PARAMS
123 class TDMEnv : public TestWithParam< ::testing::tuple<bool, bool, const char*> >
124 {
125 public:
126         void SetUp(void);
127         void TearDown(void);
128 };
129 #else
130 class TDMEnv : public TestWithParam< ::testing::tuple<const char*> >
131 {
132 public:
133         void SetUp(void);
134         void TearDown(void);
135 };
136 #endif
137
138 class TDMDisplay : public TDMEnv
139 {
140 public:
141         tdm_display *dpy;
142         tbm_bufmgr bufmgr;
143
144         bool has_pp_cap;
145         bool has_capture_cap;
146
147         TDMDisplay();
148         void SetUp(void);
149         void TearDown(void);
150 };
151
152 class TDMOutput : public TDMDisplay
153 {
154 public:
155         bool has_outputs;
156         tdm_output **outputs;
157         int output_count;
158
159         bool done1, done2, done3;
160
161         TDMOutput();
162         void SetUp(void);
163         void TearDown(void);
164 };
165
166 #ifdef TIZEN_TEST_GCOV
167 extern "C" void __gcov_flush(void);
168 #endif
169
170 tdm_error tc_tdm_display_handle_events(tdm_display *dpy);
171 bool tc_tdm_display_has_pp_capability(tdm_display *dpy);
172 bool tc_tdm_display_has_capture_capability(tdm_display *dpy);
173
174 bool tc_tdm_buffer_create(int width, int height, tbm_format format, int flags, bool fill,
175                                                   int count, tbm_surface_h *buffers);
176
177 bool tc_tdm_output_is_async_dpms_enable(tdm_output *output);
178 bool tc_tdm_output_is_hwc_enable(tdm_output *output);
179 bool tc_tdm_output_is_aod_enable(tdm_output *output);
180 bool tc_tdm_output_is_connected(tdm_output *output);
181 bool tc_tdm_output_mode_setting(tdm_output *output);
182 bool tc_tdm_output_prepare(tdm_display *dpy, tdm_output *output, bool fill);
183 bool tc_tdm_output_prepare_all_output(tdm_display *dpy, tdm_output **outputs, int output_count, bool fill);
184 bool tc_tdm_output_unset(tdm_display *dpy, tdm_output *output);
185 double tc_tdm_output_get_vblank_interval_time(tdm_output *output);
186 tdm_layer *tc_tdm_output_get_primary_layer(tdm_output *output);
187
188 bool tc_tdm_layer_is_cursor_layer(tdm_layer *layer);
189 bool tc_tdm_layer_is_primary_layer(tdm_layer *layer);
190 bool tc_tdm_layer_is_video_layer(tdm_layer *layer);
191 bool tc_tdm_layer_support_scale(tdm_layer *layer);
192 bool tc_tdm_layer_support_no_crop(tdm_layer *layer);
193 bool tc_tdm_layer_prepare_buffer(tdm_layer *layer, tbm_surface_h *buffers, int buffer_count, bool fill);
194 bool tc_tdm_layer_prepare_buffer_queue(tdm_layer *layer, tbm_surface_queue_h *buffer_queue);
195 bool tc_tdm_layer_fill_info(tdm_layer *layer, tbm_surface_h buffer, tbm_surface_queue_h buffer_queue, tdm_info_layer *info);
196 bool tc_tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
197 bool tc_tdm_layer_set_buffer_with_pos(tdm_layer *layer, tbm_surface_h buffer, tdm_pos *pos);
198 unsigned int tc_tdm_layer_get_output_pipe(tdm_layer *layer);
199 tbm_format tc_tdm_layer_find_best_format(tdm_layer *layer);
200 bool tc_tdm_layer_is_avaiable(tdm_layer *layer);
201
202 bool tc_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info);
203 bool tc_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
204                                                           tdm_capture_type type, int frequency, bool stretch, tdm_info_capture *info);
205
206 /******************************************************************************/
207 /** testing for checking backend's basic implementation                      **/
208 /******************************************************************************/
209 class TDMBackendEnv : public TDMEnv
210 {
211 public:
212         void SetUp(void);
213         void TearDown(void);
214 };
215
216 class TDMBackendBasic : public TDMBackendEnv
217 {
218 public:
219         tdm_display *dpy;
220
221         tdm_output **outputs;
222         int output_count;
223
224         tdm_layer **layers;
225         int layer_count;
226
227         tbm_surface_h buffers[3];
228
229         TDMBackendBasic();
230         void SetUp(void);
231         void TearDown(void);
232         void UnsetOutput(void);
233         void DestroyBuffers(void);
234 };
235
236 class TDMBackendDisplay : public TDMBackendBasic
237 {
238 public:
239         void SetUp(void) { TDMBackendBasic::SetUp(); }
240         void TearDown(void) { TDMBackendBasic::TearDown(); }
241 };
242
243 char tc_tdm_backend_getchar(void);
244
245 #define TDM_UT_ASK_YNR(fmt, ...) \
246         do { \
247                 if (enable_porting_debug) { \
248                         char ch; \
249                         do { \
250                                 printf(fmt" [Y]es, [n]o, [r]etry): ", ##__VA_ARGS__); \
251                                 ch = tc_tdm_backend_getchar(); \
252                         } while(ch != 'y' && ch != 'n' && ch != 'r'); \
253                         if (ch == 'n') \
254                                 GTEST_FATAL_FAILURE_("tc failed"); \
255                         if (ch == 'r') \
256                                 goto retry; \
257                 } \
258         } while (0)
259
260 /* LCOV_EXCL_STOP */
261
262 #endif // _UT_TDM_H_