From f2158adb44dc331780fe439c733a3050834859fa Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 5 Mar 2018 20:42:02 +0900 Subject: [PATCH] utest: add tbm_backend utest Change-Id: I311353eecd1e41c2b218cc470a4006c17da3721f --- utests/Makefile.am | 3 +- utests/ut_tbm.h | 1 + utests/ut_tbm_backend.cpp | 318 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 utests/ut_tbm_backend.cpp diff --git a/utests/Makefile.am b/utests/Makefile.am index 7b70a5c..6da0398 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -7,7 +7,8 @@ tbm_utests_SOURCES = \ ut_tbm_bo.cpp \ ut_tbm_surface.cpp \ ut_tbm_surface_internal.cpp \ - ut_tbm_surface_queue.cpp + ut_tbm_surface_queue.cpp \ + ut_tbm_backend.cpp tbm_utests_CXXFLAGS = \ ${CXXFLAGS} \ diff --git a/utests/ut_tbm.h b/utests/ut_tbm.h index a3f05aa..719e739 100644 --- a/utests/ut_tbm.h +++ b/utests/ut_tbm.h @@ -43,6 +43,7 @@ #include #include #include +#include #undef TBM_DBG #define TBM_DBG(fmt, args...) \ diff --git a/utests/ut_tbm_backend.cpp b/utests/ut_tbm_backend.cpp new file mode 100644 index 0000000..c38cbe0 --- /dev/null +++ b/utests/ut_tbm_backend.cpp @@ -0,0 +1,318 @@ +/************************************************************************** + * + * Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: SooChan Lim + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +**************************************************************************/ + +#include "ut_tbm.h" + +#define UT_TBM_ITER_COUNT 100 + +class TBMBackend : public TBMEnv +{ +public: + void SetUp(void); + void TearDown(void); +}; + +void TBMBackend::SetUp() +{ + TBMEnv::SetUp(); +} + +void TBMBackend::TearDown() +{ + TBMEnv::TearDown(); +} + +// bufmgr init, deinit +TEST_F(TBMBackend, BufmgrInitDeinit) +{ + tbm_bufmgr bufmgr; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + tbm_bufmgr_deinit(bufmgr); +} + +// backend symbol check +TEST_F(TBMBackend, BufmgrCheckSymbols) +{ + tbm_bufmgr bufmgr; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + // check backend symbols + EXPECT_TRUE(bufmgr->backend->priv); + EXPECT_TRUE(bufmgr->backend->bufmgr_deinit); + EXPECT_TRUE(bufmgr->backend->bufmgr_bind_native_display); + EXPECT_TRUE(bufmgr->backend->bo_alloc); + EXPECT_TRUE(bufmgr->backend->bo_free); + EXPECT_TRUE(bufmgr->backend->bo_size); + EXPECT_TRUE(bufmgr->backend->bo_get_flags); + EXPECT_TRUE(bufmgr->backend->bo_get_handle); + EXPECT_TRUE(bufmgr->backend->bo_map && bufmgr->backend->bo_unmap); + EXPECT_TRUE(bufmgr->backend->bo_lock && bufmgr->backend->bo_unlock); + EXPECT_TRUE(bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd); + EXPECT_TRUE(bufmgr->backend->bo_import && bufmgr->backend->bo_export); + EXPECT_TRUE(bufmgr->backend->surface_supported_format); + EXPECT_TRUE(bufmgr->backend->surface_bo_alloc); + EXPECT_TRUE(bufmgr->backend->surface_get_plane_data); + + tbm_bufmgr_deinit(bufmgr); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// bo_alloc, bo_free, bo_size test +TEST_F(TBMBackend, BufmgrBindNativeDisplay) +{ + tbm_bufmgr bufmgr; + struct wl_display *native_display = NULL; + int ret; + + native_display = wl_display_create(); + assert(native_display != NULL); + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + ret = wl_display_add_socket(native_display, "ut-tbm-socket"); + ASSERT_TRUE(ret == 0); + + ret = tbm_bufmgr_bind_native_display(bufmgr, (void *)native_display); + ASSERT_TRUE(ret == 1); + + tbm_bufmgr_deinit(bufmgr); + + wl_display_destroy(native_display); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// bo_alloc, bo_free, bo_size test +TEST_F(TBMBackend, BoAllocFree) +{ + tbm_bufmgr bufmgr; + tbm_bo bo[UT_TBM_ITER_COUNT]; + int i, alloc_size, ret_size; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + // bufmgr->backend->bo_alloc + for (i = 0; i < UT_TBM_ITER_COUNT; i++) { + alloc_size = 10 * i + 1; + bo[i] = tbm_bo_alloc(bufmgr, alloc_size, TBM_BO_DEFAULT); + EXPECT_TRUE(bo[i] != NULL); + + // bufmgr->backend->bo_size + ret_size = tbm_bo_size(bo[i]); + EXPECT_TRUE(alloc_size == ret_size); + } + + // bufmgr->backend->bo_free + for (i = 0; i < UT_TBM_ITER_COUNT; i++) + tbm_bo_unref(bo[i]); + + tbm_bufmgr_deinit(bufmgr); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// bo_get_handle, bo_map/bo_lock, bo_unmap/bo_unlock, test +TEST_F(TBMBackend, BoGetHandleMapUnmap) +{ + tbm_bufmgr bufmgr; + tbm_bo_handle bo_handle[UT_TBM_ITER_COUNT]; + tbm_bo bo[UT_TBM_ITER_COUNT]; + int i, j, alloc_size, ret_size; + int ret = 0; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + // bufmgr->backend->bo_alloc + for (i = 0; i < UT_TBM_ITER_COUNT; i++) { + alloc_size = 10 * i + 1; + bo[i] = tbm_bo_alloc(bufmgr, alloc_size, TBM_BO_DEFAULT); + EXPECT_TRUE(bo[i] != NULL); + + // bufmgr->backend->bo_size + ret_size = tbm_bo_size(bo[i]); + EXPECT_TRUE(alloc_size == ret_size); + + for (j = TBM_DEVICE_DEFAULT; j <= TBM_DEVICE_MM; j++) { + bo_handle[i] = tbm_bo_get_handle(bo[i], j); + EXPECT_TRUE(bo_handle[i].ptr != NULL); + bo_handle[i] = tbm_bo_map(bo[i], j, TBM_OPTION_READ|TBM_OPTION_WRITE); + EXPECT_TRUE(bo_handle[i].ptr != NULL); + ret = tbm_bo_unmap(bo[i]); + EXPECT_TRUE(ret == 1); + } + } + + // bufmgr->backend->bo_free + for (i = 0; i < UT_TBM_ITER_COUNT; i++) + tbm_bo_unref(bo[i]); + + tbm_bufmgr_deinit(bufmgr); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// bo_export_fd, bo_import_fd +TEST_F(TBMBackend, BoExportImportFd) +{ + tbm_bufmgr bufmgr; + tbm_bo_handle bo_handle[UT_TBM_ITER_COUNT]; + tbm_bo_handle import_bo_handle[UT_TBM_ITER_COUNT]; + tbm_bo bo[UT_TBM_ITER_COUNT]; + tbm_bo import_bo[UT_TBM_ITER_COUNT]; + tbm_fd fd[UT_TBM_ITER_COUNT]; + int i, alloc_size; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + // bufmgr->backend->bo_alloc + for (i = 0; i < UT_TBM_ITER_COUNT; i++) { + alloc_size = 10 * i + 1; + bo[i] = tbm_bo_alloc(bufmgr, alloc_size, TBM_BO_DEFAULT); + EXPECT_TRUE(bo[i] != NULL); + + bo_handle[i] = tbm_bo_get_handle(bo[i], TBM_DEVICE_CPU); + EXPECT_TRUE(bo_handle[i].ptr != NULL); + + fd[i] = tbm_bo_export_fd(bo[i]); + EXPECT_TRUE(fd[i] >= 0); + + import_bo[i] = tbm_bo_import_fd(bufmgr, fd[i]); + EXPECT_TRUE(import_bo[i] != NULL); + + import_bo_handle[i] = tbm_bo_get_handle(import_bo[i], TBM_DEVICE_CPU); + EXPECT_TRUE(import_bo_handle[i].ptr != NULL); + + EXPECT_TRUE(import_bo_handle[i].ptr == bo_handle[i].ptr); + } + + // bufmgr->backend->bo_free + for (i = 0; i < UT_TBM_ITER_COUNT; i++) + tbm_bo_unref(bo[i]); + + tbm_bufmgr_deinit(bufmgr); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// bo_export, bo_import +TEST_F(TBMBackend, BoExportImport) +{ + tbm_bufmgr bufmgr; + tbm_bo_handle bo_handle[UT_TBM_ITER_COUNT]; + tbm_bo_handle import_bo_handle[UT_TBM_ITER_COUNT]; + tbm_bo bo[UT_TBM_ITER_COUNT]; + tbm_bo import_bo[UT_TBM_ITER_COUNT]; + tbm_key key[UT_TBM_ITER_COUNT]; + int i, alloc_size; + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_TRUE(bufmgr != NULL); + + // bufmgr->backend->bo_alloc + for (i = 0; i < UT_TBM_ITER_COUNT; i++) { + alloc_size = 10 * i + 1; + bo[i] = tbm_bo_alloc(bufmgr, alloc_size, TBM_BO_DEFAULT); + EXPECT_TRUE(bo[i] != NULL); + + bo_handle[i] = tbm_bo_get_handle(bo[i], TBM_DEVICE_CPU); + EXPECT_TRUE(bo_handle[i].ptr != NULL); + + key[i] = tbm_bo_export(bo[i]); + EXPECT_TRUE(key[i] >= 0); + + import_bo[i] = tbm_bo_import(bufmgr, key[i]); + EXPECT_TRUE(import_bo[i] != NULL); + + import_bo_handle[i] = tbm_bo_get_handle(import_bo[i], TBM_DEVICE_CPU); + EXPECT_TRUE(import_bo_handle[i].ptr != NULL); + + EXPECT_TRUE(import_bo_handle[i].ptr == bo_handle[i].ptr); + } + + // bufmgr->backend->bo_free + for (i = 0; i < UT_TBM_ITER_COUNT; i++) + tbm_bo_unref(bo[i]); + + tbm_bufmgr_deinit(bufmgr); + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// surface_supported_format +TEST_F(TBMBackend, SurfaceSupportedFormat) +{ + uint32_t num_formats = 0; + tbm_format *formats = NULL; + int format = -1; + int ret = 0; + + ret = tbm_surface_internal_query_supported_formats(&formats, &num_formats); + ASSERT_TRUE(ret == 1); + ASSERT_TRUE(formats != NULL); + + for (uint32_t i = 0; i < num_formats; i++) + if (formats[i] == TBM_FORMAT_ARGB8888) + format = TBM_FORMAT_ARGB8888; + + /* fail if there is no TBM_FORMAT_ARGB8888 format */ + ASSERT_TRUE(format == TBM_FORMAT_ARGB8888); + + free(formats); + + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + +// surface_bo_alloc, surface_get_plane_data +TEST_F(TBMBackend, SurfaceBoAlloc) +{ + uint32_t num_formats = 0; + tbm_format *formats = NULL; + int ret = 0; + tbm_surface_h surface; + + ret = tbm_surface_internal_query_supported_formats(&formats, &num_formats); + ASSERT_TRUE(ret == 1); + ASSERT_TRUE(formats != NULL); + + for (uint32_t i = 0; i < num_formats; i++) { + surface = tbm_surface_internal_create_with_flags(720, 1024, formats[i], TBM_BO_DEFAULT); + ASSERT_TRUE(surface != NULL); + tbm_surface_internal_destroy(surface); + } + + free(formats); + + ASSERT_TRUE(tbm_bufmgr_debug_get_ref_count() == 0); +} + + + -- 2.7.4