rename to tdm_log_printf
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm.h
index f8bff5c..4f899e1 100644 (file)
-#ifndef UT_COMMON_H
-#define UT_COMMON_H
-#define SKIP_FLAG(FLAG) \
-do {\
-  if(!(FLAG)) {\
-        std::cout << "[  SKIPPED ]" << " not supported" << std::endl;\
-        return;\
-  }\
-} while(0)
-#endif // UT_COMMON_H
+#ifndef _UT_TDM_H_
+#define _UT_TDM_H_
+
+#include <sys/epoll.h>
+#include <sys/timerfd.h>
+#include <limits.h>
+#include <vector>
+#include <list>
+#include <climits>
+#include <pthread.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <poll.h>
+
+extern "C" {
+#include <tbm_bufmgr.h>
+#include <tbm_drm_helper.h>
+}
+
+#include "tdm.h"
+#include "tdm_helper.h"
+#include "tdm_config.h"
+#include "tdm_log.h"
+#include "tdm_macro.h"
+#include "buffers.h"
+
+//#define TDM_UT_TEST_WITH_PARAMS
+
+extern bool enable_porting_debug;
+
+#undef TDM_DBG
+#undef TDM_INFO
+#undef TDM_WRN
+#undef TDM_ERR
+#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_ERR("--------------------------------------------- %s", typeid(*this).name())
+
+#define TDM_UT_CHECK_FLAG(FLAG) \
+       do {\
+               if(!(FLAG)) \
+                       TDM_UT_WRN("[          ] not supported");\
+       } while(0)
+
+#define TDM_UT_SKIP_FLAG(FLAG) \
+       do {\
+               if(!(FLAG)) {\
+                       TDM_UT_WRN("[  SKIPPED ] not supported");\
+                       return;\
+               }\
+       } while(0)
+
+#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_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))
+
+#define TDM_UT_DUMP_DIR          "/tmp/tdm_dump"
+#define TDM_UT_INVALID_VALUE     -42
+#define TDM_UT_BUFFER_SIZE       256
+#define TDM_UT_VBLANK_NAME       "ut_tdm_vblank"
+
+using ::testing::TestWithParam;
+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
+{
+public:
+       tdm_display *dpy;
+       tbm_bufmgr bufmgr;
+
+       bool has_pp_cap;
+       bool has_capture_cap;
+
+       TDMDisplay();
+       void SetUp(void);
+       void TearDown(void);
+};
+
+class TDMOutput : public TDMDisplay
+{
+public:
+       bool has_outputs;
+       tdm_output **outputs;
+       int output_count;
+
+       bool done1, done2, done3;
+
+       TDMOutput();
+       void SetUp(void);
+       void TearDown(void);
+};
+
+#ifdef TIZEN_TEST_GCOV
+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_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_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_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, 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, 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_