src/ut_tbm_surface.cpp \
src/ut_tbm_surface_queue.cpp \
src/ut_tbm_surface_internal.cpp \
- stubs/stdlib_stubs.cpp
+ stubs/stdlib_stubs.cpp \
+ stubs/pthread_stubs.cpp
tbm_utests_CXXFLAGS = \
${CXXFLAGS} \
-I./gtest/googletest/include \
-fpermissive \
-w
+# The flag -w is used, because there are many warnings in libtbm's sources.
+# Warnings occur because we build project with g++.
+# In C++ we need to use explicit types conversion.
tbm_utests_LDADD = \
gtest/googletest/lib/.libs/libgtest.a
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
- *
- * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
- *
- * 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.
- *
-**************************************************************************/
-
-#ifndef _STUBS_H
-#define _STUBS_H
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "tbm_bufmgr_tgl.h"
-
-#define IOCTL_FD_ERROR_NONE 1
-#define IOCTL_FD_ERROR 2
-#define IOCTL_FD_GET 3
-
-FILE g_file;
-FILE g_error_file;
-int CALLOC_ERROR;
-int free_called;
-int DLOPEN_ERROR;
-
-int ut_fclose(FILE *stream)
-{
- return 0;
-}
-
-FILE *ut_fopen(const char *filename, const char *mode)
-{
- if (!filename || !mode)
- return NULL;
-
- if (!strcmp(filename, "/proc/111/cmdline"))
- return NULL;
-
- if (!strcmp(filename, "/proc/222/cmdline"))
- return &g_error_file;
-
- return &g_file;
-}
-
-char *ut_fgets(char *str, int num, FILE *stream)
-{
- if (!str || num < 1 || !stream)
- return NULL;
-
- if (stream == &g_error_file)
- return NULL;
-
- strncpy(str, "application", 255);
-
- return "application";
-}
-
-int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
- return 0;
-}
-
-int dup2(int old_handle, int new_handle)
-{
- if (old_handle == new_handle)
- return -1;
-
- return 0;
-}
-
-int dup(int handle)
-{
- if (1 == handle)
- return -1;
-
- return 0;
-}
-
-int ioctl(int fd, unsigned long int request, ...)
-{
- if (IOCTL_FD_ERROR == fd)
- return 1;
-
- if (IOCTL_FD_GET == fd) {
- va_list argList;
- va_start(argList, request);
- struct tgl_user_data *arg = va_arg(argList, struct tgl_user_data *);
- arg->data1 = 1;
- arg->locked = 1;
- va_end(argList);
- }
-
- return 0;
-}
-
-void *ut_calloc(size_t nmemb, size_t size)
-{
- if (CALLOC_ERROR)
- return NULL;
-
- return calloc(nmemb, size);
-}
-
-void ut_free(void *ptr)
-{
- free_called = 1;
- free(ptr);
-}
-
-#endif /* _STUBS_H */
LIST_ADD(&bo.item_link, &bufmgr.bo_list);
gBufMgr = &bufmgr;
LIST_INITHEAD(&bo.user_data_list);
- tbm_user_data *user_data = calloc(1, sizeof(tbm_user_data));
+ tbm_user_data *user_data = (tbm_user_data *)calloc(1, sizeof(tbm_user_data));
user_data->data = &expected_data;
user_data->key = key;
user_data->free_func = NULL;
TEST(tbm_backend_free, work_flow_success_1)
{
- tbm_bufmgr_backend backend = calloc(1, sizeof(*backend));
+ tbm_bufmgr_backend backend = (tbm_bufmgr_backend)calloc(1, sizeof(*backend));
_init_test();
static int ut_ret_format = 10;
static int
-ut_tbm_surface_internal_query_supported_formats(uint32_t **formats, uint32_t *num)
+ut_tbm_surface_internal_query_supported_formats(uint32_t __attribute__((unused)) **formats,
+ uint32_t __attribute__((unused)) *num)
{
if (TBM_SURFACE_ERROR) {
return 0;
}
static tbm_surface_h
-ut_tbm_surface_internal_create_with_flags(int width, int height,
- int format, int flags)
+ut_tbm_surface_internal_create_with_flags(int __attribute__((unused)) width,
+ int __attribute__((unused)) height,
+ int __attribute__((unused)) format,
+ int __attribute__((unused))flags)
{
if (TBM_SURFACE_ERROR) {
return NULL;
return &ut_ret_surface;
}
-static int
-ut_tbm_surface_is_valid(tbm_surface_h surface)
-{
- if (TBM_SURFACE_VALID_ERROR) {
- return 0;
- }
-
- return 1;
-}
-
static void
-ut_tbm_surface_internal_destroy(tbm_surface_h surface)
+ut_tbm_surface_internal_destroy(tbm_surface_h __attribute__((unused)) surface)
{
}
static int
-ut_tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
- tbm_surface_info_s *info, int map)
+ut_tbm_surface_internal_get_info(tbm_surface_h __attribute__((unused)) surface,
+ int __attribute__((unused)) opt,
+ tbm_surface_info_s __attribute__((unused)) *info,
+ int __attribute__((unused)) map)
{
if (TBM_SURFACE_ERROR) {
return 0;
}
static void
-ut_tbm_surface_internal_unmap(tbm_surface_h surface)
+ut_tbm_surface_internal_unmap(tbm_surface_h __attribute__((unused)) surface)
{
}
static unsigned int
-ut_tbm_surface_internal_get_width(tbm_surface_h surface)
+ut_tbm_surface_internal_get_width(tbm_surface_h __attribute__((unused)) surface)
{
return ut_ret_width;
}
unsigned int
-ut_tbm_surface_internal_get_height(tbm_surface_h surface)
+ut_tbm_surface_internal_get_height(tbm_surface_h __attribute__((unused)) surface)
{
return ut_ret_height;
}
static tbm_format
-ut_tbm_surface_internal_get_format(tbm_surface_h surface)
+ut_tbm_surface_internal_get_format(tbm_surface_h __attribute__((unused)) surface)
{
return ut_ret_format;
}
ut_tbm_surface_internal_query_supported_formats
#define tbm_surface_internal_create_with_flags \
ut_tbm_surface_internal_create_with_flags
-#define tbm_surface_internal_is_valid ut_tbm_surface_is_valid
#define tbm_surface_internal_destroy ut_tbm_surface_internal_destroy
#define tbm_surface_internal_get_info ut_tbm_surface_internal_get_info
#define tbm_surface_internal_unmap ut_tbm_surface_internal_unmap
static int ut_tbm_bo_unmap_count = 0;
static int ut_tbm_data_free_called = 0;
-static tbm_bufmgr ut_tbm_bufmgr_init(int fd)
+static tbm_bufmgr ut_tbm_bufmgr_init(int __attribute__((unused)) fd)
{
return &ut_ret_bufmgr;
}
-static void ut_tbm_bufmgr_deinit(tbm_bufmgr bufmgr) {}
+static void ut_tbm_bufmgr_deinit(tbm_bufmgr __attribute__((unused)) bufmgr) {}
-static int ut_surface_supported_format(uint32_t **formats, uint32_t *num)
+static int ut_surface_supported_format(uint32_t __attribute__((unused)) **formats,
+ uint32_t __attribute__((unused)) *num)
{
if (UT_TBM_SURFACE_INTERNAL_ERROR) {
return 0;
return 1;
}
-static tbm_bo_handle ut_tbm_bo_get_handle(tbm_bo bo, int device)
+static tbm_bo_handle ut_tbm_bo_get_handle(tbm_bo __attribute__((unused)) bo,
+ int __attribute__((unused)) device)
{
tbm_bo_handle ut_ret_handle;
+
return ut_ret_handle;
}
-static int ut_tbm_bo_unmap(tbm_bo bo)
+static int ut_tbm_bo_unmap(tbm_bo __attribute__((unused)) bo)
{
ut_tbm_bo_unmap_count++;
+
+ return 0;
}
-static void ut_tbm_data_free(void *user_data)
+static void ut_tbm_data_free(void __attribute__((unused)) *user_data)
{
ut_tbm_data_free_called = 1;
}
LIST_ADD(&surface.item_link, &bufmgr.surf_list);
LIST_INITHEAD(&surface.user_data_list);
- tbm_user_data *old_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 = calloc(1, sizeof(*surface));
+ tbm_surface_h surface = (tbm_surface_h)calloc(1, sizeof(*surface));
surface->refcnt = 1;
struct _tbm_bufmgr bufmgr;
TEST(tbm_surface_internal_destroy, work_flow_success_2)
{
- tbm_surface_h surface = calloc(1, sizeof(*surface));
+ tbm_surface_h surface = (tbm_surface_h)calloc(1, sizeof(*surface));
struct _tbm_bufmgr bufmgr;
_init_test();
{
int ret = 0;
int expecte_ret = 1;
- uint32_t *formats, num;
+ uint32_t *formats, num = 0;
struct _tbm_bufmgr bufmgr;
struct _tbm_bufmgr_backend backend;
ut_ret_bufmgr.backend = &backend;
backend.surface_supported_format = ut_surface_supported_format;
- ret = tbm_surface_internal_query_supported_formats(&formats, num);
+ ret = tbm_surface_internal_query_supported_formats(&formats, &num);
ASSERT_EQ(ret, expecte_ret);
}
{
int ret = 0;
int expecte_ret = 0;
- uint32_t *formats, num;
+ uint32_t *formats, num = 0;
struct _tbm_bufmgr bufmgr;
struct _tbm_bufmgr_backend backend;
backend.surface_supported_format = ut_surface_supported_format;
UT_TBM_SURFACE_INTERNAL_ERROR = 1;
- ret = tbm_surface_internal_query_supported_formats(&formats, num);
+ ret = tbm_surface_internal_query_supported_formats(&formats, &num);
ASSERT_EQ(ret, expecte_ret);
}
{
int ret = 0;
int expecte_ret = 0;
- uint32_t *formats, num;
+ uint32_t *formats, num = 0;
struct _tbm_bufmgr bufmgr;
struct _tbm_bufmgr_backend backend;
ut_ret_bufmgr.backend = &backend;
backend.surface_supported_format = NULL;
- ret = tbm_surface_internal_query_supported_formats(&formats, num);
+ ret = tbm_surface_internal_query_supported_formats(&formats, &num);
ASSERT_EQ(ret, expecte_ret);
}
/* HELPER FUNCTIONS */
-static void ut_tbm_surface_queue_notify_cb(tbm_surface_queue_h surface_queue,
- void *data) {}
+static void
+ut_tbm_surface_queue_notify_cb(tbm_surface_queue_h __attribute__((unused)) surface_queue,
+ void __attribute__((unused)) *data) {}
-static tbm_surface_h ut_tbm_surface_alloc_cb(tbm_surface_queue_h surface_queue,
- void *data) {}
+static tbm_surface_h
+ut_tbm_surface_alloc_cb(tbm_surface_queue_h __attribute__((unused)) surface_queue,
+ void __attribute__((unused)) *data)
+{
+ return NULL;
+}
-static void ut_tbm_surface_free_cb(tbm_surface_queue_h surface_queue,
- void *data, tbm_surface_h surface) {}
+static void
+ut_tbm_surface_free_cb(tbm_surface_queue_h __attribute__((unused)) surface_queue,
+ void __attribute__((unused)) *data,
+ tbm_surface_h __attribute__((unused)) surface) {}
-static void ut_enqueue(tbm_surface_queue_h queue, queue_node *node) {}
+static void
+ut_enqueue(tbm_surface_queue_h __attribute__((unused)) queue,
+ queue_node __attribute__((unused)) *node) {}
-static queue_node *ut_dequeue(tbm_surface_queue_h queue)
+static queue_node *
+ut_dequeue(tbm_surface_queue_h __attribute__((unused)) queue)
{
return NULL;
}
-static void ut_release(tbm_surface_queue_h queue, queue_node *node) {}
+static void
+ut_release(tbm_surface_queue_h __attribute__((unused)) queue,
+ queue_node __attribute__((unused)) *node) {}
-static queue_node *ut_acquire(tbm_surface_queue_h queue)
+static queue_node *
+ut_acquire(tbm_surface_queue_h __attribute__((unused)) queue)
{
return NULL;
}
TEST(tbm_surface_queue_destroy, work_flow_success_1)
{
- tbm_surface_queue_h surface_queue = calloc(1, sizeof(*surface_queue));
+ tbm_surface_queue_h surface_queue;
queue_notify *destory_item1;
queue_notify *destory_item2;
queue_notify *acquirable_item1;
queue_notify *reset_item1;
queue_notify *reset_item2;
+ surface_queue = (tbm_surface_queue_h)calloc(1, sizeof(*surface_queue));
+
_init_test();
surface_queue->impl = NULL;
- destory_item1 = calloc(1, sizeof(*destory_item1));
- destory_item2 = calloc(1, sizeof(*destory_item2));
- acquirable_item1 = calloc(1, sizeof(*acquirable_item1));
- acquirable_item2 = calloc(1, sizeof(*acquirable_item2));
- dequeuable_item1 = calloc(1, sizeof(*dequeuable_item1));
- dequeuable_item2 = calloc(1, sizeof(*dequeuable_item2));
- reset_item1 = calloc(1, sizeof(*reset_item1));
- reset_item2 = calloc(1, sizeof(*reset_item2));
+ destory_item1 = (queue_notify *)calloc(1, sizeof(*destory_item1));
+ destory_item2 = (queue_notify *)calloc(1, sizeof(*destory_item2));
+ acquirable_item1 = (queue_notify *)calloc(1, sizeof(*acquirable_item1));
+ acquirable_item2 = (queue_notify *)calloc(1, sizeof(*acquirable_item2));
+ dequeuable_item1 = (queue_notify *)calloc(1, sizeof(*dequeuable_item1));
+ dequeuable_item2 = (queue_notify *)calloc(1, sizeof(*dequeuable_item2));
+ reset_item1 = (queue_notify *)calloc(1, sizeof(*reset_item1));
+ reset_item2 = (queue_notify *)calloc(1, sizeof(*reset_item2));
destory_item1->cb = ut_tbm_surface_queue_notify_cb;
destory_item2->cb = ut_tbm_surface_queue_notify_cb;
LIST_INITHEAD(&surface_queue->destory_noti);
TBM_SURFACE_QUEUE_ERROR_NONE;
tbm_surface_queue_s surface;
int data;
- queue_notify *item;
+ queue_notify *item = NULL;
queue_notify *tmp;
_init_test();
TBM_SURFACE_QUEUE_ERROR_NONE;
tbm_surface_queue_s surface;
int data;
- queue_notify *item;
+ queue_notify *item = NULL;
queue_notify *tmp;
tbm_surface_queue_notify_cb cb;
tbm_surface_queue_notify_cb expected_cb;
TBM_SURFACE_QUEUE_ERROR_NONE;
tbm_surface_queue_s surface;
int data;
- queue_notify *item;
+ queue_notify *item = NULL;
queue_notify *tmp;
_init_test();
TBM_SURFACE_QUEUE_ERROR_NONE;
tbm_surface_queue_s surface;
int data;
- queue_notify *item;
- queue_notify *tmp;
+ queue_notify *item = NULL;
+ queue_notify *tmp = NULL;
tbm_surface_queue_notify_cb cb;
tbm_surface_queue_notify_cb expected_cb;
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ *
+ * 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 "pthread_stubs.h"
+
+int PTHREAD_MUTEX_INIT_ERROR;
+
+int
+ut_pthread_mutex_lock(pthread_mutex_t __attribute__((unused)) *mutex)
+{
+ return 0;
+}
+
+int
+ut_pthread_mutex_unlock(pthread_mutex_t __attribute__((unused)) *mutex)
+{
+ return 0;
+}
+
+int
+ut_pthread_mutex_init(pthread_mutex_t __attribute__((unused)) *mutex,
+ const pthread_mutexattr_t __attribute__((unused)) *mutexattr)
+{
+ if (PTHREAD_MUTEX_INIT_ERROR)
+ return PTHREAD_MUTEX_INIT_ERROR;
+
+ return 0;
+}
+
+int
+ut_pthread_cond_signal(pthread_cond_t __attribute__((unused)) *cond)
+{
+ return 0;
+}
+
+int
+ut_pthread_cond_wait(pthread_cond_t __attribute__((unused)) *cond,
+ pthread_mutex_t __attribute__((unused)) *mutex)
+{
+ return 0;
+}
#include <pthread.h>
#include <stdio.h>
-static int PTHREAD_MUTEX_INIT_ERROR;
+extern int PTHREAD_MUTEX_INIT_ERROR;
-static int ut_pthread_mutex_lock(pthread_mutex_t * __mutex) {}
+int ut_pthread_mutex_lock(pthread_mutex_t *mutex);
-static int ut_pthread_mutex_unlock(pthread_mutex_t * __mutex) {}
+int ut_pthread_mutex_unlock(pthread_mutex_t *mutex);
-static int ut_pthread_mutex_init(pthread_mutex_t * __mutex,
- const pthread_mutexattr_t * __mutexattr)
-{
- if (PTHREAD_MUTEX_INIT_ERROR)
- return PTHREAD_MUTEX_INIT_ERROR;
+int ut_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);
- return 0;
-}
+int ut_pthread_cond_signal(pthread_cond_t *cond);
-static int ut_pthread_cond_signal(pthread_cond_t *cond) {}
-
-static int ut_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {}
+int ut_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
#endif /* _PTHREAD_STUBS_H */
static int bo_size = 100;
static int bo2_size = 100;
-static void *ret_bo = "bo_alloc";
+static void *ret_bo = (void *)"bo_alloc";
static int UT_TBM_ERROR = 0;
static int TBM_BO_ALLOC_ERROR = 0;
static int TBM_BO_IMPORT_ERROR = 0;
static int bo_ret_flags = TBM_BO_SCANOUT;
-static int ut_bo_size(tbm_bo bo)
+static int ut_bo_size(tbm_bo __attribute__ ((unused)) bo)
{
return bo_size;
}
-static int ut_bo2_size(tbm_bo bo)
+static int ut_bo2_size(tbm_bo __attribute__ ((unused)) bo)
{
return bo2_size;
}
-static void *ut_bo_alloc(tbm_bo bo, int size, int flags)
+static void *ut_bo_alloc(tbm_bo __attribute__ ((unused)) bo,
+ int __attribute__ ((unused)) size,
+ int __attribute__ ((unused)) flags)
{
if (TBM_BO_ALLOC_ERROR)
return NULL;
return ret_bo;
}
-static void *ut_bo_import(tbm_bo bo, unsigned int key)
+static void *ut_bo_import(tbm_bo __attribute__ ((unused)) bo,
+ unsigned int __attribute__ ((unused)) key)
{
if (TBM_BO_IMPORT_ERROR)
return NULL;
return ret_bo;
}
-static int ut_bo_get_flags(tbm_bo bo)
+static int ut_bo_get_flags(tbm_bo __attribute__ ((unused)) bo)
{
return bo_ret_flags;
}
-static void *ut_bo_import_fd(tbm_bo bo, tbm_fd fd)
+static void *ut_bo_import_fd(tbm_bo __attribute__ ((unused)) bo,
+ tbm_fd __attribute__ ((unused)) fd)
{
if (TBM_BO_IMPORT_ERROR)
return NULL;
return ret_bo;
}
-static unsigned int ut_bo_export(tbm_bo bo)
+static unsigned int ut_bo_export(tbm_bo __attribute__ ((unused)) bo)
{
if (UT_TBM_ERROR)
return 0;
return 1;
}
-static tbm_fd ut_bo_export_fd(tbm_bo bo)
+static tbm_fd ut_bo_export_fd(tbm_bo __attribute__ ((unused)) bo)
{
if (UT_TBM_ERROR)
return -1;
return 1;
}
-static tbm_bo_handle ut_bo_get_handle(tbm_bo bo, int device)
+static tbm_bo_handle ut_bo_get_handle(tbm_bo __attribute__ ((unused)) bo,
+ int __attribute__ ((unused)) device)
{
tbm_bo_handle ret;
return ret;
}
-static tbm_bo_handle ut_bo_map(tbm_bo bo, int device, int opt)
+static tbm_bo_handle ut_bo_map(tbm_bo __attribute__ ((unused)) bo,
+ int __attribute__ ((unused)) device,
+ int __attribute__ ((unused)) opt)
{
tbm_bo_handle ret;
return ret;
}
-static int ut_bo_unmap(tbm_bo bo)
+static int ut_bo_unmap(tbm_bo __attribute__ ((unused)) bo)
{
if (UT_TBM_ERROR)
return 0;
return 1;
}
-static void ut_tbm_data_free(void *user_data) {}
+static void ut_tbm_data_free(void __attribute__ ((unused)) *user_data) {}
-static int ut_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
+static int ut_bufmgr_bind_native_display(tbm_bufmgr __attribute__ ((unused)) bufmgr,
+ void __attribute__ ((unused)) *NativeDisplay)
{
if (UT_TBM_ERROR)
return 0;