rename to tdm_log_printf
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm.h
index 890f182..4f899e1 100644 (file)
@@ -9,6 +9,9 @@
 #include <climits>
 #include <pthread.h>
 #include <gtest/gtest.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <poll.h>
 
 extern "C" {
 #include <tbm_bufmgr.h>
@@ -22,73 +25,125 @@ extern "C" {
 #include "tdm_macro.h"
 #include "buffers.h"
 
-#define UT_TDM_BUFFER_ENABLE
-#define UT_TDM_CAPTURE_ENABLE
-#define UT_TDM_CLIENT_ENABLE
-#define UT_TDM_DISPLAY_ENABLE
-#define UT_TDM_ENV_ENABLE
-#define UT_TDM_EVENT_LOOP_ENABLE
-#define UT_TDM_HELPER_ENABLE
-#define UT_TDM_OUTPUT_HWC_ENABLE
-//#define UT_TDM_HWC_WINDOW_ENABLE
-#define UT_TDM_LAYER_ENABLE
-#define UT_TDM_LOG_ENABLE
-#define UT_TDM_OUTPUT_ENABLE
-#define UT_TDM_PP_ENABLE
-#define UT_TDM_VBLANK_ENABLE
+//#define TDM_UT_TEST_WITH_PARAMS
+
+extern bool enable_porting_debug;
 
 #undef TDM_DBG
-#define TDM_DBG(fmt, args...) \
-    tdm_log_print(TDM_LOG_LEVEL_DBG, fmt, ##args);
 #undef TDM_INFO
-#define TDM_INFO(fmt, args...) \
-    tdm_log_print(TDM_LOG_LEVEL_INFO, fmt, ##args);
 #undef TDM_WRN
-#define TDM_WRN(fmt, args...) \
-    tdm_log_print(TDM_LOG_LEVEL_WRN, fmt, ##args);
 #undef TDM_ERR
-#define TDM_ERR(fmt, args...) \
-    tdm_log_print(TDM_LOG_LEVEL_ERR, fmt, ##args);
+#define TDM_DBG(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_DBG, fmt, ##args)
+#define TDM_INFO(fmt, args...) tdm_log_print(TDM_LOG_LEVEL_INFO, fmt, ##args)
+#define TDM_WRN(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_WRN, fmt, ##args)
+#define TDM_ERR(fmt, args...)  tdm_log_print(TDM_LOG_LEVEL_ERR, fmt, ##args)
+
+#define TDM_UT_INFO(fmt, args...) tdm_log_printf(TDM_LOG_LEVEL_INFO, fmt, ##args)
+#define TDM_UT_WRN(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_WRN, fmt, ##args)
+#define TDM_UT_ERR(fmt, args...)  tdm_log_printf(TDM_LOG_LEVEL_ERR, fmt, ##args)
 
 #define TDM_UT_ENTRY() \
-    TDM_INFO("--------------------------------------------- %s", typeid(*this).name())
+    TDM_ERR("--------------------------------------------- %s", typeid(*this).name())
 
 #define TDM_UT_CHECK_FLAG(FLAG) \
        do {\
                if(!(FLAG)) \
-                       TDM_INFO("[          ] not supported");\
+                       TDM_UT_WRN("[          ] not supported");\
        } while(0)
 
 #define TDM_UT_SKIP_FLAG(FLAG) \
        do {\
                if(!(FLAG)) {\
-                       TDM_INFO("[  SKIPPED ] not supported");\
+                       TDM_UT_WRN("[  SKIPPED ] not supported");\
                        return;\
                }\
        } while(0)
 
-#define TDM_UT_NEVER_GET_HERE() \
-       do {\
-               TDM_INFO("!!! TDM UT NEVER GET HERE !!!");\
+#define TDM_UT_RETURN_IF_FAIL(cond) \
+       do { \
+               if (!(cond)) { \
+                       TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
+                       return; \
+               } \
+       } while(0)
+#define TDM_UT_RETURN_FALSE_IF_FAIL(cond) \
+       do { \
+               if (!(cond)) { \
+                       TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
+                       return false; \
+               } \
+       } while(0)
+#define TDM_UT_RETURN_VAL_IF_FAIL(cond, val) \
+       do { \
+               if (!(cond)) { \
+                       TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
+                       return val; \
+               } \
+       } while(0)
+#define TDM_UT_GOTO_IF_FAIL(cond, dst) \
+       do { \
+               if (!(cond)) { \
+                       TDM_UT_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
+                       goto dst; \
+               } \
+       } while(0)
+
+#define TDM_UT_ASSERT_TRUE(cond, fmt, args...) \
+       do { \
+               if (!(cond)) { \
+                       if (enable_porting_debug) \
+                               TDM_UT_ERR(fmt, ##args); \
+                       GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_FATAL_FAILURE_); \
+               } \
+       } while(0)
+#define TDM_UT_EXPECT_TRUE(cond, fmt, args...) \
+       do { \
+               if (!(cond)) { \
+                       if (enable_porting_debug) \
+                               TDM_UT_ERR(fmt, ##args); \
+                       GTEST_TEST_BOOLEAN_((cond), #cond, false, true, GTEST_NONFATAL_FAILURE_); \
+               } \
        } while(0)
-#define TDM_UT_RETURN_IF_FAIL(cond) { \
-       if (!(cond)) { \
-               TDM_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
-               return; \
-       } \
-}
-#define TDM_UT_RETURN_FALSE_IF_FAIL(cond) { \
-       if (!(cond)) { \
-               TDM_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
-               return false; \
-       } \
-}
-#define TDM_UT_GOTO_IF_FAIL(cond, dst) { \
-       if (!(cond)) { \
-               TDM_ERR("[%s,%d] '%s' failed", __FUNCTION__, __LINE__, #cond); \
-               goto dst; \
-       } \
-}
+
+#define TDM_UT_ASK_YNR(fmt, ...) \
+       do { \
+               if (enable_porting_debug) { \
+                       char ch; \
+                       printf(fmt" [Y]es, [n]o, [r]etry: ", ##__VA_ARGS__); \
+                       do { \
+                               ch = getchar(); \
+                               if (ch == '\n') \
+                                       ch = 'y'; \
+                               else { \
+                                       char tch; \
+                                       while ((tch = getchar()) != '\n' && tch != EOF); \
+                               } \
+                       } while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N' && ch != 'r' && ch != 'R'); \
+                       if (ch == 'n' || ch == 'N') \
+                               GTEST_FATAL_FAILURE_("tc failed"); \
+                       if (ch == 'r' || ch == 'R') \
+                               goto retry; \
+               } \
+       } while (0)
+
+#define TDM_UT_ASK_YN(fmt, ...) \
+                       do { \
+                               if (enable_porting_debug) { \
+                                       char ch; \
+                                       printf(fmt" [Y]es, [n]o: ", ##__VA_ARGS__); \
+                                       do { \
+                                               ch = getchar(); \
+                                               if (ch == '\n') \
+                                                       ch = 'y'; \
+                                               else { \
+                                                       char tch; \
+                                                       while ((tch = getchar()) != '\n' && tch != EOF); \
+                                               } \
+                                       } while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N'); \
+                                       if (ch == 'n' || ch == 'N') \
+                                               GTEST_FATAL_FAILURE_("tc failed"); \
+                               } \
+                       } while (0)
 
 #define TDM_UT_SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
 
@@ -102,12 +157,21 @@ using ::testing::Bool;
 using ::testing::Values;
 using ::testing::Combine;
 
+#ifdef TDM_UT_TEST_WITH_PARAMS
 class TDMEnv : public TestWithParam< ::testing::tuple<bool, bool, const char*> >
 {
 public:
        void SetUp(void);
        void TearDown(void);
 };
+#else
+class TDMEnv : public TestWithParam< ::testing::tuple<const char*> >
+{
+public:
+       void SetUp(void);
+       void TearDown(void);
+};
+#endif
 
 class TDMDisplay : public TDMEnv
 {
@@ -129,6 +193,9 @@ public:
        bool has_outputs;
        tdm_output **outputs;
        int output_count;
+
+       bool done1, done2, done3;
+
        TDMOutput();
        void SetUp(void);
        void TearDown(void);
@@ -138,30 +205,77 @@ public:
 extern "C" void __gcov_flush(void);
 #endif
 
+tdm_error ut_tdm_display_handle_events(tdm_display *dpy);
+bool ut_tdm_display_has_pp_capability(tdm_display *dpy);
+bool ut_tdm_display_has_capture_capability(tdm_display *dpy);
+
 bool ut_tdm_buffer_create(int width, int height, tbm_format format, int flags, bool fill,
                                                  int count, tbm_surface_h *buffers);
 
-bool ut_tdm_output_mode_setting(tdm_output *output);
 bool ut_tdm_output_is_async_dpms_enable(tdm_output *output);
 bool ut_tdm_output_is_hwc_enable(tdm_output *output);
 bool ut_tdm_output_is_aod_enable(tdm_output *output);
 bool ut_tdm_output_is_connected(tdm_output *output);
-bool ut_tdm_output_prepare(tdm_display *dpy, tdm_output *output);
+bool ut_tdm_output_mode_setting(tdm_output *output);
+bool ut_tdm_output_prepare(tdm_display *dpy, tdm_output *output, bool fill);
+bool ut_tdm_output_prepare_all_output(tdm_display *dpy, tdm_output **outputs, int output_count, bool fill);
 bool ut_tdm_output_unset(tdm_display *dpy, tdm_output *output);
 double ut_tdm_output_get_vblank_interval_time(tdm_output *output);
+tdm_layer *ut_tdm_output_get_primary_layer(tdm_output *output);
 
 bool ut_tdm_layer_is_cursor_layer(tdm_layer *layer);
 bool ut_tdm_layer_is_primary_layer(tdm_layer *layer);
 bool ut_tdm_layer_is_video_layer(tdm_layer *layer);
-bool ut_tdm_layer_prepare_buffer(tdm_layer *layer, tbm_surface_h *buffers, int buffer_count);
+bool ut_tdm_layer_support_scale(tdm_layer *layer);
+bool ut_tdm_layer_support_no_crop(tdm_layer *layer);
+bool ut_tdm_layer_prepare_buffer(tdm_layer *layer, tbm_surface_h *buffers, int buffer_count, bool fill);
 bool ut_tdm_layer_prepare_buffer_queue(tdm_layer *layer, tbm_surface_queue_h *buffer_queue);
-bool ut_tdm_layer_fill_info(tdm_layer *layer, int w, int h, tbm_format format, tdm_info_layer *info);
+bool ut_tdm_layer_fill_info(tdm_layer *layer, tbm_surface_h buffer, tbm_surface_queue_h buffer_queue, tdm_info_layer *info);
+bool ut_tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
+bool ut_tdm_layer_set_buffer_with_pos(tdm_layer *layer, tbm_surface_h buffer, tdm_pos *pos);
 unsigned int ut_tdm_layer_get_output_pipe(tdm_layer *layer);
 tbm_format ut_tdm_layer_find_best_format(tdm_layer *layer);
+bool ut_tdm_layer_is_avaiable(tdm_layer *layer);
 
 bool ut_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info);
 bool ut_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
-                                                         tdm_capture_type type, int frequency, tdm_info_capture *info);
+                                                         tdm_capture_type type, int frequency, bool stretch, tdm_info_capture *info);
+
+/******************************************************************************/
+/** testing for checking backend's basic implementation                      **/
+/******************************************************************************/
+class TDMBackendEnv : public TDMEnv
+{
+public:
+       void SetUp(void);
+       void TearDown(void);
+};
+
+class TDMBackendBasic : public TDMBackendEnv
+{
+public:
+       tdm_display *dpy;
 
+       tdm_output **outputs;
+       int output_count;
+
+       tdm_layer **layers;
+       int layer_count;
+
+       tbm_surface_h buffers[3];
+
+       TDMBackendBasic();
+       void SetUp(void);
+       void TearDown(void);
+       void UnsetOutput(void);
+       void DestroyBuffers(void);
+};
+
+class TDMBackendDisplay : public TDMBackendBasic
+{
+public:
+       void SetUp(void) { TDMBackendBasic::SetUp(); }
+       void TearDown(void) { TDMBackendBasic::TearDown(); }
+};
 
 #endif // _UT_TDM_H_