#include "pthread_stubs.h"
#include "stdlib_stubs.h"
+#include "tbm_bufmgr_stubs.h"
/* HELPER FUNCTIONS */
#include "tbm_bufmgr.h"
static int UT_TBM_SURFACE_INTERNAL_ERROR = 0;
-static struct _tbm_bufmgr ut_ret_bufmgr;
static int ut_tbm_bo_unmap_count = 0;
-static int ut_tbm_data_free_called = 0;
-static tbm_bufmgr ut_tbm_bufmgr_init(int __attribute__((unused)) fd)
+static void ut_tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
{
- return &ut_ret_bufmgr;
+ (void)bufmgr;
}
-static void ut_tbm_bufmgr_deinit(tbm_bufmgr __attribute__((unused)) bufmgr) {}
-
-static int ut_surface_supported_format(uint32_t __attribute__((unused)) **formats,
- uint32_t __attribute__((unused)) *num)
+static int ut_surface_supported_format(uint32_t **formats,
+ uint32_t *num)
{
+ (void)formats;
+ (void)num;
+
if (UT_TBM_SURFACE_INTERNAL_ERROR) {
return 0;
}
return 1;
}
-static tbm_bo_handle ut_tbm_bo_get_handle(tbm_bo __attribute__((unused)) bo,
- int __attribute__((unused)) device)
+static tbm_bo_handle ut_tbm_bo_get_handle(tbm_bo bo, int device)
{
+ (void)bo;
+ (void)device;
+
tbm_bo_handle ut_ret_handle;
+ ut_ret_handle.s64 = 12;
return ut_ret_handle;
}
-static int ut_tbm_bo_unmap(tbm_bo __attribute__((unused)) bo)
+static int ut_tbm_bo_unmap(tbm_bo bo)
{
+ (void)bo;
+
ut_tbm_bo_unmap_count++;
return 0;
}
-static void ut_tbm_data_free(void __attribute__((unused)) *user_data)
+static int ut_surface_get_plane_data(int width, int height,
+ tbm_format format, int plane_idx,
+ uint32_t * size, uint32_t * offset,
+ uint32_t * pitch, int *bo_idx)
{
- ut_tbm_data_free_called = 1;
+ (void)width;
+ (void)height;
+ (void)format;
+ (void)plane_idx;
+
+ if (size)
+ *size = 4000;
+
+ if (offset)
+ *offset = 0;
+
+ if (pitch)
+ *pitch = 1000;
+
+ if (bo_idx)
+ *bo_idx = 0;
+
+ return 1;
+}
+
+void *ut_surface_bo_alloc(tbm_bo bo, int width, int height, int format,
+ int flags, int bo_idx)
+{
+ return (void *)0xefefeffe;
}
#define pthread_mutex_lock ut_pthread_mutex_lock
#define tbm_bufmgr_deinit ut_tbm_bufmgr_deinit
#define tbm_bo_get_handle ut_tbm_bo_get_handle
#define tbm_bo_unmap ut_tbm_bo_unmap
+#define tbm_bufmgr_init ut_tbm_bufmgr_init
#include "tbm_surface_internal.c"
UT_TBM_SURFACE_INTERNAL_ERROR = 0;
ut_tbm_bo_unmap_count = 0;
ut_tbm_data_free_called = 0;
+ ut_tbm_bufmgr_init_error = 0;
}
/* tbm_surface_internal_delete_user_data() */
LIST_ADD(&surface.item_link, &bufmgr.surf_list);
LIST_INITHEAD(&surface.user_data_list);
- tbm_user_data *old_data = (tbm_user_data *)calloc(1, sizeof(*old_data));
+ tbm_user_data *old_data = (tbm_user_data *) calloc(1, sizeof(*old_data));
old_data->data = &data;
old_data->free_func = ut_tbm_data_free;
old_data->key = key;
TEST(tbm_surface_internal_unref, work_flow_success_2)
{
- tbm_surface_h surface = (tbm_surface_h)calloc(1, sizeof(*surface));
+ tbm_surface_h surface = (tbm_surface_h) calloc(1, sizeof(*surface));
surface->refcnt = 1;
struct _tbm_bufmgr bufmgr;
g_surface_bufmgr = &bufmgr;
LIST_INITHEAD(&bufmgr.surf_list);
+ LIST_INITHEAD(&bufmgr.debug_key_list);
LIST_INITHEAD(&surface->user_data_list);
+ LIST_INITHEAD(&surface->debug_data_list);
LIST_ADD(&surface->item_link, &bufmgr.surf_list);
surface->num_bos = 0;
FREE_TESTED_PTR = surface;
surface.refcnt = expected_refcnt + 1;
g_surface_bufmgr = &bufmgr;
LIST_INITHEAD(&bufmgr.surf_list);
+ LIST_INITHEAD(&bufmgr.debug_key_list);
+ LIST_INITHEAD(&surface.user_data_list);
+ LIST_INITHEAD(&surface.debug_data_list);
LIST_ADD(&surface.item_link, &bufmgr.surf_list);
tbm_surface_internal_unref(&surface);
surface.refcnt = expected_refcnt - 1;
g_surface_bufmgr = &bufmgr;
LIST_INITHEAD(&bufmgr.surf_list);
+ LIST_INITHEAD(&bufmgr.debug_key_list);
+ LIST_INITHEAD(&surface.user_data_list);
+ LIST_INITHEAD(&surface.debug_data_list);
LIST_ADD(&surface.item_link, &bufmgr.surf_list);
tbm_surface_internal_ref(&surface);
TEST(tbm_surface_internal_destroy, work_flow_success_2)
{
- tbm_surface_h surface = (tbm_surface_h)calloc(1, sizeof(*surface));
+ tbm_surface_h surface = (tbm_surface_h) calloc(1, sizeof(*surface));
struct _tbm_bufmgr bufmgr;
_init_test();
surface->refcnt = 1;
g_surface_bufmgr = &bufmgr;
LIST_INITHEAD(&bufmgr.surf_list);
+ LIST_INITHEAD(&bufmgr.debug_key_list);
LIST_INITHEAD(&surface->user_data_list);
+ LIST_INITHEAD(&surface->debug_data_list);
LIST_ADD(&surface->item_link, &bufmgr.surf_list);
surface->num_bos = 0;
FREE_TESTED_PTR = surface;
surface.refcnt = expected_refcnt + 1;
g_surface_bufmgr = &bufmgr;
LIST_INITHEAD(&bufmgr.surf_list);
+ LIST_INITHEAD(&bufmgr.debug_key_list);
+ LIST_INITHEAD(&surface.user_data_list);
+ LIST_INITHEAD(&surface.debug_data_list);
LIST_ADD(&surface.item_link, &bufmgr.surf_list);
tbm_surface_internal_destroy(&surface);
ASSERT_EQ(ret, expecte_ret);
}
+
+/* tbm_surface_internal_create_with_flags() */
+
+TEST(tbm_surface_internal_create_with_flags, error_calloc)
+{
+ tbm_surface_h surface_ret;
+
+ _init_test();
+
+ CALLOC_ERROR = 1;
+
+ surface_ret = tbm_surface_internal_create_with_flags(10, 10, 10, 10);
+
+ ASSERT_TRUE(surface_ret == NULL);
+}
+
+TEST(tbm_surface_internal_create_with_flags, success)
+{
+ tbm_surface_h surface_ret;
+ int width = 1080;
+ int height = 1920;
+ int format = TBM_FORMAT_ARGB8888;
+ int flags = 1;
+ struct _tbm_bufmgr mgr;
+ struct _tbm_bufmgr_backend backend;
+
+ _init_test();
+
+ g_surface_bufmgr = &mgr;
+ mgr.backend = &backend;
+ backend.surface_get_plane_data = ut_surface_get_plane_data;
+ backend.surface_bo_alloc = ut_surface_bo_alloc;
+
+ LIST_INITHEAD(&mgr.bo_list);
+ LIST_INITHEAD(&mgr.surf_list);
+
+ surface_ret =
+ tbm_surface_internal_create_with_flags(width, height, format, flags);
+
+ ASSERT_TRUE(surface_ret != NULL);
+ ASSERT_FALSE(LIST_IS_EMPTY(&mgr.bo_list));
+ ASSERT_FALSE(LIST_IS_EMPTY(&mgr.surf_list));
+}