From: Roman Marchenko Date: Thu, 23 Nov 2017 15:07:55 +0000 (+0200) Subject: utest: Add 33 tests cases for tdm_helper X-Git-Tag: accepted/tizen/unified/20171127.083156~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=c0c6fbadf2524cbffadaa6928e0d94a72b0325f0;p=platform%2Fcore%2Fuifw%2Flibtdm.git utest: Add 33 tests cases for tdm_helper Change-Id: I7b3d77866a67d45ffa740456351629d3cc85f148 Signed-off-by: Roman Marchenko --- diff --git a/utests/Makefile.am b/utests/Makefile.am index b919431..eee9511 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -8,6 +8,7 @@ tdm_utests_SOURCES = \ src/ut_tdm_output.cpp \ src/ut_tdm_hwc_window.cpp \ src/ut_tdm_buffer.cpp \ + src/ut_tdm_helper.cpp \ src/ut_tdm_layer.cpp \ src/ut_tdm_vblank.cpp diff --git a/utests/src/ut_tdm_helper.cpp b/utests/src/ut_tdm_helper.cpp new file mode 100644 index 0000000..917c3e3 --- /dev/null +++ b/utests/src/ut_tdm_helper.cpp @@ -0,0 +1,587 @@ +#include "gtest/gtest.h" +#include "ut_common.h" +#include "stdint.h" +#include +#include +#include + +extern "C" { +#include "tdm.h" +#include "tdm_helper.h" +#include "tdm_backend.h" +#include "tbm_bufmgr.h" +#include "tbm_surface.h" +#include "tbm_surface_internal.h" +#include "tbm_drm_helper.h" +} + +#define TMP_PATH_FOR_UTEST "tmp_utest_helper" +#define STR_LEN 8192 + +class TDMHelper : public ::testing::Test { +protected: + tdm_display *dpy = NULL; + tbm_bufmgr bufmgr = NULL; + int master_fd = -42; + /*list of connected outputs*/ + int output_count = 0; + const tdm_output_mode **preferred_mode_array = NULL; + tdm_output **outputs; + tdm_error error ; + tbm_surface_h surface; + virtual void SetEnv() + { + setenv("TDM_THREAD", "0", 1); + setenv("TDM_COMMIT_PER_VBLANK", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + } + + void UnsetEnv() + { + unsetenv("TDM_THREAD"); + unsetenv("TDM_COMMIT_PER_VBLANK"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DISPLAY_SERVER"); + } + + void SetUp(void) + { + const tdm_output_mode *preferred_mode = NULL; + tdm_error error = TDM_ERROR_NONE; + int all_output_count = 0; + + SetEnv(); + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(bufmgr == NULL); + + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + + master_fd = tbm_drm_helper_get_master_fd(); + ASSERT_TRUE(tdm_display_get_output_count(dpy, &all_output_count) == TDM_ERROR_NONE); + + outputs = (tdm_output **)calloc(all_output_count, sizeof(tdm_output *)); + ASSERT_FALSE(NULL == outputs); + + preferred_mode_array = (const tdm_output_mode **)calloc(all_output_count, sizeof(tdm_output_mode *)); + ASSERT_FALSE(NULL == preferred_mode_array); + + output_count = 0; + + for (int i = 0; i < all_output_count; i++) { + tdm_output *output = tdm_display_get_output(dpy, i, &error); + int output_modes_cnt = 0; + const tdm_output_mode *output_modes; + + if (TDM_ERROR_NONE != error || NULL == output) + continue; + + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status)) + continue; + + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; + + error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt); + if (TDM_ERROR_NONE != error) + continue; + if (output_modes_cnt <= 0) { + continue; + } + + for(int j = 0; j < output_modes_cnt; j++) + if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED) + preferred_mode = &output_modes[j]; + + if (!preferred_mode) + continue; + + if (preferred_mode_array) + preferred_mode_array[output_count] = preferred_mode; + if (outputs) + outputs[output_count] = output; + output_count++; + + error = tdm_output_set_mode(output, preferred_mode); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + surface = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888); + ASSERT_TRUE(surface != NULL); + } + + void TearDown(void) + { + if (surface) { + while (tbm_surface_internal_is_valid(surface)) + tbm_surface_destroy(surface); + } + tdm_display_deinit(dpy); + dpy = NULL; + tbm_bufmgr_deinit(bufmgr); + bufmgr = NULL; + if (outputs) + free(outputs); + if (preferred_mode_array) + free(preferred_mode_array); + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + } + + UnsetEnv(); + } +}; + +int remove_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) +{ + int rv = remove(fpath); + if (rv) + perror(fpath); + return rv; +} + +int rmrf(const char *path) +{ + return nftw(path, remove_cb, 64, FTW_DEPTH | FTW_PHYS); +} + +class TDMHelperSurface: public TDMHelper +{ +protected: + + void SetUp() + { + TDMHelper::SetUp(); + ASSERT_EQ(0, mkdir(TMP_PATH_FOR_UTEST, 0755)) << "error: " << strerror(errno); + } + void TearDown() + { + + rmrf(TMP_PATH_FOR_UTEST); + TDMHelper::TearDown(); + } +}; + +class TDMHelperDisplay: public TDMHelper { +}; + +class TDMHelperOutput: public TDMHelper { +}; + + +/* double tdm_helper_get_time(void); */ +TEST(TDMHelper, GetTime) +{ + double time; + time = tdm_helper_get_time(); + EXPECT_GT(time, 0); +} + +/* void tdm_helper_dump_start(char *dumppath, int *count); */ +TEST(TDMHelper, DumpStartFailNull) +{ + int count = 100; + tdm_helper_dump_start(NULL, &count); + + tdm_helper_dump_start((char *)TMP_PATH_FOR_UTEST, NULL); +} + +TEST(TDMHelper, DumpStartSuccessful) +{ + int count = 100; + tdm_helper_dump_start((char *)TMP_PATH_FOR_UTEST, &count); +} + +/* void tdm_helper_dump_stop(void); */ +TEST(TDMHelper, DumpStopSuccessful) +{ + tdm_helper_dump_stop(); +} + +/* void tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file); */ +TEST_F(TDMHelperSurface, DumpBufferFailNull) +{ + tdm_helper_dump_buffer(NULL, TMP_PATH_FOR_UTEST "/tmp"); +} + +TEST_F(TDMHelperSurface, DumpBufferFailInvalideOutput) +{ + int invalid_surface; + tdm_helper_dump_buffer((tbm_surface_h)&invalid_surface, TMP_PATH_FOR_UTEST "/xyz.png"); + + /* file name mast have an extension ".png" */ + tdm_helper_dump_buffer(surface, TMP_PATH_FOR_UTEST "/tmp.xyz"); +} + +TEST_F(TDMHelperSurface, DumpBufferFailUnknownFormat) +{ + tbm_surface_h surf; + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUV444); + ASSERT_TRUE(surf != NULL); + tdm_helper_dump_buffer(surface, TMP_PATH_FOR_UTEST "/xyz.png"); + tbm_surface_destroy(surf); +} + +TEST_F(TDMHelperSurface, DumpBufferSuccessful) +{ + tbm_surface_h surf; + + tdm_helper_dump_buffer(surface, TMP_PATH_FOR_UTEST "/rgb.png"); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUV420); + ASSERT_TRUE(surf != NULL); + tdm_helper_dump_buffer(surf, TMP_PATH_FOR_UTEST "/YUV.yuv"); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_NV12); + ASSERT_TRUE(surf != NULL); + tdm_helper_dump_buffer(surf, TMP_PATH_FOR_UTEST "/NV.yuv"); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUYV); + ASSERT_TRUE(surf != NULL); + tdm_helper_dump_buffer(surf, TMP_PATH_FOR_UTEST "/YUYV.yuv"); + tbm_surface_destroy(surf); +} + +/* void tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color); */ +TEST_F(TDMHelperSurface, ClearBufferColorFailNull) +{ + tdm_pos pos; + tdm_helper_clear_buffer_color(NULL, &pos, 0x0F0F0F); +} + +TEST_F(TDMHelperSurface, ClearBufferColorInvalideOutput) +{ + int invalid_surface; + tdm_pos pos; + tdm_helper_clear_buffer_color((tbm_surface_h)&invalid_surface, &pos, 0x0F0F0F); +} + +TEST_F(TDMHelperSurface, ClearBufferColorUnknownFormat) +{ + tdm_pos pos = { .x = 0, .y = 0, .w = 10, .h = 10 }; + tbm_surface_h surf; + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUV444); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_color(surf, &pos, 0x0F0F0F); + tbm_surface_destroy(surf); +} + +TEST_F(TDMHelperSurface, ClearBufferColorSuccessful) +{ + tdm_pos pos = { .x = 0, .y = 0, .w = 10, .h = 10 }; + tbm_surface_h surf; + + tdm_helper_clear_buffer_color(surface, &pos, 0x0F0F0F); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YVU420); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_color(surf, &pos, 0x0F0F0F); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_NV12); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_color(surf, &pos, 0x0F0F0F); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUYV); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_color(surf, &pos, 0x0F0F0F); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_UYVY); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_color(surf, &pos, 0x0F0F0F); + tbm_surface_destroy(surf); +} + +/* void tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos); */ +TEST_F(TDMHelperSurface, ClearBufferPosFailNull) +{ + tdm_pos pos; + tdm_helper_clear_buffer_pos(NULL, &pos); +} + +TEST_F(TDMHelperSurface, ClearBufferPosInvalideOutput) +{ + int invalid_surface; + tdm_pos pos; + tdm_helper_clear_buffer_pos((tbm_surface_h)&invalid_surface, &pos); +} + +TEST_F(TDMHelperSurface, ClearBufferPosUnknownFormat) +{ + tdm_pos pos = { .x = 0, .y = 0, .w = 10, .h = 10 }; + tbm_surface_h surf; + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUV444); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_pos(surf, &pos); + tbm_surface_destroy(surf); +} + +TEST_F(TDMHelperSurface, ClearBufferPosSuccessful) +{ + tdm_pos pos = { .x = 0, .y = 0, .w = 10, .h = 10 }; + tbm_surface_h surf; + + tdm_helper_clear_buffer_pos(surface, &pos); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YVU420); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_pos(surf, &pos); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_NV12); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_pos(surf, &pos); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUYV); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_pos(surf, &pos); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_UYVY); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer_pos(surf, &pos); + tbm_surface_destroy(surf); +} + +/* void tdm_helper_clear_buffer(tbm_surface_h buffer); */ +TEST_F(TDMHelperSurface, ClearBufferFailNull) +{ + tdm_helper_clear_buffer(NULL); +} + +TEST_F(TDMHelperSurface, ClearBufferInvalideOutput) +{ + int invalid_surface; + tdm_helper_clear_buffer((tbm_surface_h)&invalid_surface); +} + +TEST_F(TDMHelperSurface, ClearBufferUnknownFormat) +{ + tbm_surface_h surf; + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUV444); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer(surf); + tbm_surface_destroy(surf); +} + +TEST_F(TDMHelperSurface, ClearBufferSuccessful) +{ + tbm_surface_h surf; + + tdm_helper_clear_buffer(surface); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YVU420); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer(surf); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_NV12); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer(surf); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_YUYV); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer(surf); + tbm_surface_destroy(surf); + + surf = tbm_surface_create(256, 256, TBM_FORMAT_UYVY); + ASSERT_TRUE(surf != NULL); + tdm_helper_clear_buffer(surf); + tbm_surface_destroy(surf); +} + +/* void tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h); */ +TEST_F(TDMHelperSurface, GetBufferFullSizeFailNull) +{ + int buffer_w; + int buffer_h; + tdm_helper_get_buffer_full_size(NULL, &buffer_w, &buffer_h); +} + +TEST_F(TDMHelperSurface, GetBufferFullSizeFailinvalidBuffer) +{ + int invalid_surface; + int buffer_w; + int buffer_h; + tdm_helper_get_buffer_full_size((tbm_surface_h)&invalid_surface, &buffer_w, &buffer_h); +} + +TEST_F(TDMHelperSurface, GetBufferFullSizeSuccessful) +{ + int buffer_w = 0; + int buffer_h = 0; + tdm_helper_get_buffer_full_size(surface, &buffer_w, &buffer_h); + ASSERT_GE(buffer_w, 0); + ASSERT_GE(buffer_h, 0); +} + +/* tdm_error tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf, + tdm_pos *srcpos, tdm_pos *dstpos, + tdm_transform transform, int over); */ +TEST_F(TDMHelperSurface, ConvertBufferFailNull) +{ + tdm_pos srcpos = { 0, 0, 256, 256 }; + tdm_pos dstpos = { 0, 0, 256, 256 }; + tbm_surface_h dstbuf; + tdm_error error; + + dstbuf = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888); + ASSERT_TRUE(dstbuf != NULL); + + error = tdm_helper_convert_buffer(NULL, dstbuf, &srcpos, &dstpos, TDM_TRANSFORM_NORMAL, 0); + tbm_surface_destroy(dstbuf); + ASSERT_NE(TDM_ERROR_NONE, error); + + error = tdm_helper_convert_buffer(surface, NULL, &srcpos, &dstpos, TDM_TRANSFORM_NORMAL, 0); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMHelperSurface, ConvertBufferFailinvalidBuffer) +{ + int invalid_surface; + tdm_pos srcpos = { 0, 0, 256, 256 }; + tdm_pos dstpos = { 0, 0, 256, 256 }; + tbm_surface_h dstbuf; + tdm_error error; + + dstbuf = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888); + ASSERT_TRUE(dstbuf != NULL); + + error = tdm_helper_convert_buffer((tbm_surface_h)&invalid_surface, dstbuf, &srcpos, &dstpos, TDM_TRANSFORM_NORMAL, 0); + tbm_surface_destroy(dstbuf); + ASSERT_NE(TDM_ERROR_NONE, error); + + error = tdm_helper_convert_buffer(surface, (tbm_surface_h)&invalid_surface, &srcpos, &dstpos, TDM_TRANSFORM_NORMAL, 0); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMHelperSurface, ConvertBufferSuccessful) +{ + tdm_pos srcpos = { 0, 0, 256, 256 }; + tdm_pos dstpos = { 0, 0, 256, 256 }; + tbm_surface_h dstbuf; + tdm_error error; + + dstbuf = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888); + ASSERT_TRUE(dstbuf != NULL); + + error = tdm_helper_convert_buffer(surface, dstbuf, &srcpos, &dstpos, TDM_TRANSFORM_NORMAL, 0); + tbm_surface_destroy(dstbuf); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + + +/* void tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len); */ +TEST_F(TDMHelperDisplay, GetDisplayInformationFailNull) +{ + char reply[STR_LEN] = {0}; + int len = STR_LEN; + tdm_helper_get_display_information(NULL, reply, &len); + ASSERT_LT(len, STR_LEN); + ASSERT_EQ((STR_LEN - len), strlen(reply)); + + len = STR_LEN; + tdm_helper_get_display_information(dpy, NULL, &len); + ASSERT_EQ(STR_LEN, len); + + reply[0] = '\0'; + tdm_helper_get_display_information(dpy, reply, NULL); + ASSERT_EQ(0, reply[0]); +} + +TEST_F(TDMHelperDisplay, GetDisplayInformationSuccessful) +{ + char reply[STR_LEN] = {0}; + int len = STR_LEN; + tdm_helper_get_display_information(dpy, reply, &len); + ASSERT_LT(len, STR_LEN); + ASSERT_EQ((STR_LEN - len), strlen(reply)); +} +int capture_handler_is_called = 0; +void capture_handler(tbm_surface_h buffer, void *user_data) +{ + if (&capture_handler_is_called == user_data) + capture_handler_is_called = 1; +} +/* tdm_error tdm_helper_capture_output(...); */ +TEST_F(TDMHelperOutput, CaptureOutputFailNull) +{ + int output_count = 0; + tdm_output *output = NULL; + tdm_error error; + tbm_surface_h buffer = NULL; + + error = tdm_display_get_output_count(dpy, &output_count); + ASSERT_EQ(TDM_ERROR_NONE, error); + for (int i = 0; i < output_count; i++) { + + output = tdm_display_get_output(dpy, i, &error); + ASSERT_NE(NULL, output); + + error = tdm_helper_capture_output(NULL, buffer, 0, 0, 0, 0, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(output, NULL, 0, 0, 0, 0, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(output, buffer, 0, 0, 0, 0, NULL, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(output, buffer, 0, 0, 0, 0, capture_handler, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMHelperOutput, CaptureOutputFailInvalidInputs) +{ + for (int i = 0; i < output_count; i++) { + error = tdm_helper_capture_output(outputs[i], surface, -1, 0, 0, 0, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(outputs[i], surface, 0, -1, 0, 0, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(outputs[i], surface, 0, 0, -1, 0, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + error = tdm_helper_capture_output(outputs[i], surface, 0, 0, 0, -1, capture_handler, &capture_handler_is_called); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMHelperOutput, CaptureOutputSuccessful) +{ + error = tdm_display_get_output_count(dpy, &output_count); + ASSERT_EQ(TDM_ERROR_NONE, error); + for (int i = 0; i < output_count; i++) { + error = tdm_helper_capture_output(outputs[i], surface, 0, 0, 255, 255, capture_handler, &capture_handler_is_called); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* int tdm_helper_output_commit_per_vblank_enabled(tdm_output *output); */ +TEST_F(TDMHelperOutput, CommitPerVblankEnabledFailNull) +{ + int state; + state = tdm_helper_output_commit_per_vblank_enabled(NULL); + ASSERT_EQ(-1, state); +} + +TEST_F(TDMHelperOutput, CommitPerVblankEnabledSuccessful) +{ + int state; + + for (int i = 0; i < output_count; i++) { + state = tdm_helper_output_commit_per_vblank_enabled(outputs[i]); + ASSERT_EQ(1, state); + } +} +