1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "gtest/gtest.h"
31 #include "ut_tbm_bufmgr.h"
33 #include "pthread_stubs.h"
34 #include "stdlib_stubs.h"
36 #define pthread_mutex_lock ut_pthread_mutex_lock
37 #define pthread_mutex_unlock ut_pthread_mutex_unlock
38 #define pthread_mutex_init ut_pthread_mutex_init
39 #define calloc ut_calloc
42 #include "tbm_bufmgr.c"
43 #include "tbm_bufmgr_stubs.h"
45 static void _init_test()
48 PTHREAD_MUTEX_INIT_ERROR = 0;
52 FREE_TESTED_PTR = NULL;
53 free_called_for_tested_ptr = 0;
57 TBM_BO_ALLOC_ERROR = 0;
58 TBM_BO_IMPORT_ERROR = 0;
59 bo_ret_flags = TBM_BO_SCANOUT;
62 /* tbm_bufmgr_bind_native_display() */
64 TEST(tbm_bufmgr_bind_native_display, work_flow_success_3)
67 struct _tbm_bufmgr bufmgr;
68 struct _tbm_bufmgr_backend backend;
74 memset(gBufMgr, 0, sizeof(bufmgr));
76 bufmgr.backend = &backend;
77 backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
79 actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
81 ASSERT_EQ(expected, actual);
84 TEST(tbm_bufmgr_bind_native_display, work_flow_success_2)
87 struct _tbm_bufmgr bufmgr;
88 struct _tbm_bufmgr_backend backend;
94 memset(gBufMgr, 0, sizeof(bufmgr));
96 bufmgr.backend = &backend;
97 backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
100 actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
102 ASSERT_EQ(expected, actual);
105 TEST(tbm_bufmgr_bind_native_display, work_flow_success_1)
108 struct _tbm_bufmgr bufmgr;
109 struct _tbm_bufmgr_backend backend;
115 memset(gBufMgr, 0, sizeof(bufmgr));
117 bufmgr.backend = &backend;
118 backend.bufmgr_bind_native_display = NULL;
120 actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
122 ASSERT_EQ(expected, actual);
125 TEST(tbm_bufmgr_bind_native_display, null_ptr_fail_1)
132 actual = tbm_bufmgr_bind_native_display(NULL, NULL);
134 ASSERT_EQ(expected, actual);
137 /* tbm_bo_get_flags() */
139 TEST(tbm_bo_get_flags, work_flow_success_2)
141 int expected_flags = 5;
143 struct _tbm_bufmgr bufmgr;
148 LIST_INITHEAD(&bufmgr.bo_list);
149 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
151 bo.flags = expected_flags;
153 actual_flags = tbm_bo_get_flags(&bo);
155 ASSERT_EQ(actual_flags, expected_flags);
158 TEST(tbm_bo_get_flags, work_flow_success_1)
162 struct _tbm_bufmgr bufmgr;
167 LIST_INITHEAD(&bufmgr.bo_list);
170 actual = tbm_bo_get_flags(&bo);
172 ASSERT_EQ(actual, expected);
175 TEST(tbm_bo_get_flags, null_ptr_fail_1)
182 actual = tbm_bo_get_flags(NULL);
184 ASSERT_EQ(actual, expected);
188 /* tbm_bufmgr_get_capability() */
190 TEST(tbm_bufmgr_get_capability, work_flow_success_2)
192 unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE;
193 unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_SHARE_FD;
194 struct _tbm_bufmgr bufmgr;
195 struct _tbm_bufmgr_backend backend;
200 memset(gBufMgr, 0, sizeof(bufmgr));
202 bufmgr.backend = &backend;
203 backend.bo_import = NULL;
204 backend.bo_export = NULL;
205 backend.bo_import_fd = ut_bo_import_fd;
206 backend.bo_export_fd = ut_bo_export_fd;
207 bufmgr.capabilities = TBM_BUFMGR_CAPABILITY_SHARE_FD;
209 capability = tbm_bufmgr_get_capability(&bufmgr);
211 ASSERT_EQ(capability, expected_capability);
214 TEST(tbm_bufmgr_get_capability, work_flow_success_1)
216 unsigned int capability = TBM_BUFMGR_CAPABILITY_SHARE_KEY;
217 unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_NONE;
221 capability = tbm_bufmgr_get_capability(NULL);
223 ASSERT_EQ(capability, expected_capability);
226 /* tbm_get_last_error() */
228 TEST(tbm_get_last_error, work_flow_success_1)
230 tbm_last_error = TBM_BO_ERROR_GET_FD_FAILED;
231 tbm_error_e expected_error = tbm_last_error;
235 tbm_error_e error = tbm_get_last_error();
237 ASSERT_EQ(error, expected_error);
240 /* tbm_bo_delete_user_data() */
242 TEST(tbm_bo_delete_user_data, work_flow_success_4)
244 unsigned int key = 5;
247 struct _tbm_bufmgr bufmgr;
253 LIST_INITHEAD(&bufmgr.bo_list);
254 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
256 LIST_INITHEAD(&bo.user_data_list);
257 tbm_user_data *user_data = (tbm_user_data *)calloc(1, sizeof(tbm_user_data));
258 user_data->data = &expected_data;
259 user_data->key = key;
260 user_data->free_func = NULL;
261 LIST_INITHEAD(&bo.user_data_list);
262 LIST_ADD(&user_data->item_link, &bo.user_data_list);
263 FREE_TESTED_PTR = user_data;
265 actual = tbm_bo_delete_user_data(&bo, key);
267 ASSERT_EQ(actual, expected);
268 ASSERT_EQ(free_called_for_tested_ptr, 1);
271 TEST(tbm_bo_delete_user_data, work_flow_success_3)
273 unsigned int key = 5;
276 struct _tbm_bufmgr bufmgr;
282 LIST_INITHEAD(&bufmgr.bo_list);
283 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
285 LIST_INITHEAD(&bo.user_data_list);
286 tbm_user_data user_data;
287 user_data.data = &expected_data;
288 user_data.key = key - 1;
289 LIST_INITHEAD(&bo.user_data_list);
290 LIST_ADD(&user_data.item_link, &bo.user_data_list);
292 actual = tbm_bo_delete_user_data(&bo, key);
294 ASSERT_EQ(actual, expected);
297 TEST(tbm_bo_delete_user_data, work_flow_success_2)
301 struct _tbm_bufmgr bufmgr;
306 LIST_INITHEAD(&bufmgr.bo_list);
307 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
309 LIST_INITHEAD(&bo.user_data_list);
311 actual = tbm_bo_delete_user_data(&bo, 1);
313 ASSERT_EQ(actual, expected);
316 TEST(tbm_bo_delete_user_data, work_flow_success_1)
320 struct _tbm_bufmgr bufmgr;
325 LIST_INITHEAD(&bufmgr.bo_list);
328 actual = tbm_bo_delete_user_data(&bo, 1);
330 ASSERT_EQ(actual, expected);
333 TEST(tbm_bo_delete_user_data, null_ptr_fail_1)
340 actual = tbm_bo_delete_user_data(NULL, 1);
342 ASSERT_EQ(actual, expected);
345 /* tbm_bo_get_user_data() */
347 TEST(tbm_bo_get_user_data, work_flow_success_5)
349 unsigned int key = 5;
353 struct _tbm_bufmgr bufmgr;
359 LIST_INITHEAD(&bufmgr.bo_list);
360 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
362 LIST_INITHEAD(&bo.user_data_list);
363 tbm_user_data user_data;
364 user_data.data = &expected_data;
366 LIST_INITHEAD(&bo.user_data_list);
367 LIST_ADD(&user_data.item_link, &bo.user_data_list);
369 actual = tbm_bo_get_user_data(&bo, key, &data);
371 ASSERT_EQ(actual, expected);
372 ASSERT_TRUE(data == &expected_data);
375 TEST(tbm_bo_get_user_data, work_flow_success_4)
377 unsigned int key = 5;
381 struct _tbm_bufmgr bufmgr;
383 tbm_user_data user_data;
388 LIST_INITHEAD(&bufmgr.bo_list);
389 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
391 LIST_INITHEAD(&bo.user_data_list);
392 user_data.data = &expected_data;
393 user_data.key = key - 1;
394 LIST_INITHEAD(&bo.user_data_list);
395 LIST_ADD(&user_data.item_link, &bo.user_data_list);
397 actual = tbm_bo_get_user_data(&bo, key, &data);
399 ASSERT_EQ(actual, expected);
402 TEST(tbm_bo_get_user_data, work_flow_success_3)
407 struct _tbm_bufmgr bufmgr;
412 LIST_INITHEAD(&bufmgr.bo_list);
413 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
415 LIST_INITHEAD(&bo.user_data_list);
417 actual = tbm_bo_get_user_data(&bo, 1, &data);
419 ASSERT_EQ(actual, expected);
422 TEST(tbm_bo_get_user_data, work_flow_success_2)
426 struct _tbm_bufmgr bufmgr;
431 LIST_INITHEAD(&bufmgr.bo_list);
432 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
435 actual = tbm_bo_get_user_data(&bo, 1, NULL);
437 ASSERT_EQ(actual, expected);
440 TEST(tbm_bo_get_user_data, work_flow_success_1)
444 struct _tbm_bufmgr bufmgr;
449 LIST_INITHEAD(&bufmgr.bo_list);
452 actual = tbm_bo_get_user_data(&bo, 1, NULL);
454 ASSERT_EQ(actual, expected);
457 TEST(tbm_bo_get_user_data, null_ptr_fail_1)
464 actual = tbm_bo_get_user_data(NULL, 1, NULL);
466 ASSERT_EQ(actual, expected);
469 /* tbm_bo_set_user_data() */
471 TEST(tbm_bo_set_user_data, work_flow_success_3)
473 unsigned int key = 5;
476 struct _tbm_bufmgr bufmgr;
481 LIST_INITHEAD(&bufmgr.bo_list);
482 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
484 tbm_user_data user_data;
485 user_data.data = NULL;
486 user_data.free_func = NULL;
488 LIST_INITHEAD(&bo.user_data_list);
489 LIST_ADD(&user_data.item_link, &bo.user_data_list);
491 actual = tbm_bo_set_user_data(&bo, key, &data);
493 ASSERT_EQ(actual, expected);
494 ASSERT_TRUE(user_data.data == &data);
497 TEST(tbm_bo_set_user_data, work_flow_success_2)
499 unsigned int key = 5;
502 struct _tbm_bufmgr bufmgr;
507 LIST_INITHEAD(&bufmgr.bo_list);
508 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
510 tbm_user_data user_data;
511 user_data.key = key - 1;
512 LIST_INITHEAD(&bo.user_data_list);
513 LIST_ADD(&user_data.item_link, &bo.user_data_list);
515 actual = tbm_bo_set_user_data(&bo, key, NULL);
517 ASSERT_EQ(actual, expected);
520 TEST(tbm_bo_set_user_data, work_flow_success_1)
524 struct _tbm_bufmgr bufmgr;
529 LIST_INITHEAD(&bufmgr.bo_list);
532 actual = tbm_bo_set_user_data(&bo, 1, NULL);
534 ASSERT_EQ(actual, expected);
537 TEST(tbm_bo_set_user_data, null_ptr_fail_1)
544 actual = tbm_bo_set_user_data(NULL, 1, NULL);
546 ASSERT_EQ(actual, expected);
549 /* tbm_bo_add_user_data() */
551 TEST(tbm_bo_add_user_data, work_flow_success_4)
553 tbm_user_data *data = NULL;
554 unsigned long key = 5;
557 struct _tbm_bufmgr bufmgr;
562 LIST_INITHEAD(&bufmgr.bo_list);
563 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
565 tbm_user_data user_data;
566 user_data.key = key - 1;
567 LIST_INITHEAD(&bo.user_data_list);
568 LIST_ADD(&user_data.item_link, &bo.user_data_list);
570 actual = tbm_bo_add_user_data(&bo, key, ut_tbm_data_free);
572 ASSERT_EQ(actual, expected);
573 data = user_data_lookup(&bo.user_data_list, key);
574 ASSERT_TRUE(data != NULL);
575 tbm_user_data copy_data = *data;
577 ASSERT_EQ(copy_data.key, key);
578 ASSERT_TRUE(copy_data.free_func == ut_tbm_data_free);
579 ASSERT_TRUE(copy_data.data == NULL);
582 TEST(tbm_bo_add_user_data, work_flow_success_3)
584 unsigned long key = 5;
587 struct _tbm_bufmgr bufmgr;
592 LIST_INITHEAD(&bufmgr.bo_list);
593 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
595 tbm_user_data user_data;
596 user_data.key = key - 1;
597 LIST_INITHEAD(&bo.user_data_list);
598 LIST_ADD(&user_data.item_link, &bo.user_data_list);
601 actual = tbm_bo_add_user_data(&bo, key, NULL);
603 ASSERT_EQ(actual, expected);
606 TEST(tbm_bo_add_user_data, work_flow_success_2)
608 unsigned long key = 5;
611 struct _tbm_bufmgr bufmgr;
616 LIST_INITHEAD(&bufmgr.bo_list);
617 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
619 tbm_user_data user_data;
621 LIST_INITHEAD(&bo.user_data_list);
622 LIST_ADD(&user_data.item_link, &bo.user_data_list);
624 actual = tbm_bo_add_user_data(&bo, key, NULL);
626 ASSERT_EQ(actual, expected);
629 TEST(tbm_bo_add_user_data, work_flow_success_1)
633 struct _tbm_bufmgr bufmgr;
638 LIST_INITHEAD(&bufmgr.bo_list);
641 actual = tbm_bo_add_user_data(&bo, 1, NULL);
643 ASSERT_EQ(actual, expected);
646 TEST(tbm_bo_add_user_data, null_ptr_fail_1)
653 actual = tbm_bo_add_user_data(NULL, 1, NULL);
655 ASSERT_EQ(actual, expected);
658 /* tbm_bo_locked() */
660 TEST(tbm_bo_locked, work_flow_success_4)
664 struct _tbm_bufmgr bufmgr;
669 LIST_INITHEAD(&bufmgr.bo_list);
670 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
673 bufmgr.lock_type = LOCK_TRY_ONCE;
676 actual = tbm_bo_locked(&bo);
678 ASSERT_EQ(actual, expected);
681 TEST(tbm_bo_locked, work_flow_success_3)
685 struct _tbm_bufmgr bufmgr;
690 LIST_INITHEAD(&bufmgr.bo_list);
691 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
694 bufmgr.lock_type = LOCK_TRY_ONCE;
697 actual = tbm_bo_locked(&bo);
699 ASSERT_EQ(actual, expected);
702 TEST(tbm_bo_locked, work_flow_success_2)
706 struct _tbm_bufmgr bufmgr;
711 LIST_INITHEAD(&bufmgr.bo_list);
712 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
715 bufmgr.lock_type = LOCK_TRY_NEVER;
717 actual = tbm_bo_locked(&bo);
719 ASSERT_EQ(actual, expected);
722 TEST(tbm_bo_locked, work_flow_success_1)
726 struct _tbm_bufmgr bufmgr;
731 LIST_INITHEAD(&bufmgr.bo_list);
734 actual = tbm_bo_locked(&bo);
736 ASSERT_EQ(actual, expected);
739 TEST(tbm_bo_locked, null_ptr_fail_1)
746 actual = tbm_bo_locked(NULL);
748 ASSERT_EQ(actual, expected);
753 TEST(tbm_bo_swap, work_flow_success_3)
760 struct _tbm_bufmgr bufmgr;
761 struct _tbm_bufmgr bufmgr2;
762 struct _tbm_bufmgr_backend backend1;
763 struct _tbm_bufmgr_backend backend2;
768 LIST_INITHEAD(&bufmgr.bo_list);
769 LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
770 LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
772 bufmgr.backend = &backend1;
773 bufmgr2.backend = &backend2;
774 bo1.bufmgr = &bufmgr;
775 bo2.bufmgr = &bufmgr2;
776 backend1.bo_size = ut_bo_size;
777 backend2.bo_size = ut_bo2_size;
781 actual = tbm_bo_swap(&bo1, &bo2);
783 ASSERT_EQ(actual, expected);
784 ASSERT_TRUE(bo1.priv == &priv2);
785 ASSERT_TRUE(bo2.priv == &priv1);
788 TEST(tbm_bo_swap, work_flow_success_2)
793 struct _tbm_bufmgr bufmgr;
798 LIST_INITHEAD(&bufmgr.bo_list);
799 LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
802 actual = tbm_bo_swap(&bo1, &bo2);
804 ASSERT_EQ(actual, expected);
807 TEST(tbm_bo_swap, work_flow_success_1)
812 struct _tbm_bufmgr bufmgr;
817 LIST_INITHEAD(&bufmgr.bo_list);
818 LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
821 actual = tbm_bo_swap(&bo1, &bo2);
823 ASSERT_EQ(actual, expected);
826 TEST(tbm_bo_swap, null_ptr_fail_2)
830 struct _tbm_bufmgr bufmgr;
835 LIST_INITHEAD(&bufmgr.bo_list);
838 actual = tbm_bo_swap(&bo1, NULL);
840 ASSERT_EQ(actual, expected);
843 TEST(tbm_bo_swap, null_ptr_fail_1)
847 struct _tbm_bufmgr bufmgr;
852 LIST_INITHEAD(&bufmgr.bo_list);
855 actual = tbm_bo_swap(NULL, &bo2);
857 ASSERT_EQ(actual, expected);
862 TEST(tbm_bo_unmap_null, work_flow_success_3)
864 int not_expected = 0;
866 struct _tbm_bufmgr bufmgr;
867 struct _tbm_bufmgr_backend backend;
872 LIST_INITHEAD(&bufmgr.bo_list);
873 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
876 bufmgr.backend = &backend;
877 backend.bo_unmap = ut_bo_unmap;
878 bufmgr.lock_type = LOCK_TRY_NEVER;
880 actual = tbm_bo_unmap(&bo);
882 ASSERT_NE(actual, not_expected);
885 TEST(tbm_bo_unmap_null, work_flow_success_2)
887 tbm_error_e expected_last_error = TBM_BO_ERROR_UNMAP_FAILED;
890 struct _tbm_bufmgr bufmgr;
891 struct _tbm_bufmgr_backend backend;
896 LIST_INITHEAD(&bufmgr.bo_list);
897 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
900 bufmgr.backend = &backend;
901 backend.bo_unmap = ut_bo_unmap;
904 actual = tbm_bo_unmap(&bo);
906 ASSERT_EQ(actual, expected);
907 ASSERT_EQ(tbm_last_error, expected_last_error);
910 TEST(tbm_bo_unmap_null, work_flow_success_1)
914 struct _tbm_bufmgr bufmgr;
919 LIST_INITHEAD(&bufmgr.bo_list);
922 actual = tbm_bo_unmap(&bo);
924 ASSERT_EQ(actual, expected);
927 TEST(tbm_bo_unmap, null_ptr_fail_1)
934 actual = tbm_bo_unmap(NULL);
936 ASSERT_EQ(actual, expected);
941 TEST(tbm_bo_map, work_flow_success_4)
945 unsigned int expected_map_cnt = bo.map_cnt + 1;
946 struct _tbm_bufmgr bufmgr;
947 struct _tbm_bufmgr_backend backend;
948 tbm_bo_handle handle;
952 LIST_INITHEAD(&bufmgr.bo_list);
953 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
955 bufmgr.lock_type = LOCK_TRY_NEVER;
957 bufmgr.backend = &backend;
958 backend.bo_map = ut_bo_map;
960 handle = tbm_bo_map(&bo, 1, 1);
962 ASSERT_TRUE(handle.ptr != NULL);
963 ASSERT_EQ(bo.map_cnt, expected_map_cnt);
966 TEST(tbm_bo_map, work_flow_success_3)
968 tbm_error_e expected_last_error = TBM_BO_ERROR_MAP_FAILED;
969 tbm_bo_handle expected_handle;
971 struct _tbm_bufmgr bufmgr;
972 struct _tbm_bufmgr_backend backend;
973 tbm_bo_handle handle;
977 expected_handle.ptr = NULL;
978 LIST_INITHEAD(&bufmgr.bo_list);
979 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
981 bufmgr.lock_type = LOCK_TRY_NEVER;
983 bufmgr.backend = &backend;
984 backend.bo_map = ut_bo_map;
987 handle = tbm_bo_map(&bo, 1, 1);
989 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
990 ASSERT_EQ(tbm_last_error, expected_last_error);
993 TEST(tbm_bo_map, work_flow_success_2)
995 tbm_error_e expected_last_error = TBM_BO_ERROR_LOCK_FAILED;
996 tbm_bo_handle expected_handle;
998 struct _tbm_bufmgr bufmgr;
999 tbm_bo_handle handle;
1003 expected_handle.ptr = NULL;
1004 LIST_INITHEAD(&bufmgr.bo_list);
1005 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1007 bufmgr.lock_type = LOCK_TRY_NEVER + 546;
1008 bo.bufmgr = &bufmgr;
1010 handle = tbm_bo_map(&bo, 1, 1);
1012 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1013 ASSERT_EQ(tbm_last_error, expected_last_error);
1016 TEST(tbm_bo_map, work_flow_success_1)
1018 tbm_bo_handle expected_handle;
1019 expected_handle.ptr = NULL;
1021 struct _tbm_bufmgr bufmgr;
1025 LIST_INITHEAD(&bufmgr.bo_list);
1028 tbm_bo_handle handle = tbm_bo_map(&bo, 1, 1);
1030 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1033 TEST(tbm_bo_map, null_ptr_fail_1)
1035 tbm_bo_handle expected_handle;
1036 expected_handle.ptr = NULL;
1037 tbm_bo_handle handle;
1041 handle = tbm_bo_map(NULL, 1, 1);
1043 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1046 /* tbm_bo_get_handle() */
1048 TEST(tbm_bo_get_handle, work_flow_success_3)
1051 struct _tbm_bufmgr bufmgr;
1052 struct _tbm_bufmgr_backend backend;
1053 tbm_bo_handle handle;
1057 LIST_INITHEAD(&bufmgr.bo_list);
1058 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1060 bo.bufmgr = &bufmgr;
1061 bufmgr.backend = &backend;
1062 backend.bo_get_handle = ut_bo_get_handle;
1064 handle = tbm_bo_get_handle(&bo, 1);
1066 ASSERT_TRUE(handle.ptr != NULL);
1069 TEST(tbm_bo_get_handle, work_flow_success_2)
1071 tbm_bo_handle expected_handle;
1072 expected_handle.ptr = NULL;
1073 tbm_error_e expected_last_result = TBM_BO_ERROR_GET_HANDLE_FAILED;
1075 struct _tbm_bufmgr bufmgr;
1076 struct _tbm_bufmgr_backend backend;
1080 LIST_INITHEAD(&bufmgr.bo_list);
1081 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1083 bo.bufmgr = &bufmgr;
1084 bufmgr.backend = &backend;
1085 backend.bo_get_handle = ut_bo_get_handle;
1088 tbm_bo_handle handle = tbm_bo_get_handle(&bo, 1);
1090 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1091 ASSERT_EQ(tbm_last_error, expected_last_result);
1094 TEST(tbm_bo_get_handle, work_flow_success_1)
1096 tbm_bo_handle expected_handle;
1097 expected_handle.ptr = NULL;
1099 struct _tbm_bufmgr bufmgr;
1100 tbm_bo_handle handle;
1104 LIST_INITHEAD(&bufmgr.bo_list);
1107 handle = tbm_bo_get_handle(&bo, 1);
1109 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1112 TEST(tbm_bo_get_handle, null_ptr_fail_1)
1114 tbm_bo_handle expected_handle;
1115 expected_handle.ptr = NULL;
1116 tbm_bo_handle handle;
1120 handle = tbm_bo_get_handle(NULL, 1);
1122 ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1125 /* tbm_bo_export_fd() */
1127 TEST(tbm_bo_export_fd, work_flow_success_3)
1130 struct _tbm_bufmgr bufmgr;
1131 struct _tbm_bufmgr_backend backend;
1136 LIST_INITHEAD(&bufmgr.bo_list);
1137 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1139 bo.bufmgr = &bufmgr;
1140 bufmgr.backend = &backend;
1141 backend.bo_export_fd = ut_bo_export_fd;
1143 key = tbm_bo_export_fd(&bo);
1148 TEST(tbm_bo_export_fd, work_flow_success_2)
1150 tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FD_FAILED;
1151 int expected_key = -1;
1153 struct _tbm_bufmgr bufmgr;
1154 struct _tbm_bufmgr_backend backend;
1159 LIST_INITHEAD(&bufmgr.bo_list);
1160 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1162 bo.bufmgr = &bufmgr;
1163 bufmgr.backend = &backend;
1164 backend.bo_export_fd = ut_bo_export_fd;
1167 key = tbm_bo_export_fd(&bo);
1169 ASSERT_EQ(key, expected_key);
1170 ASSERT_EQ(tbm_last_error, expected_last_result);
1173 TEST(tbm_bo_export_fd, work_flow_success_1)
1175 int expected_key = -1;
1177 struct _tbm_bufmgr bufmgr;
1182 LIST_INITHEAD(&bufmgr.bo_list);
1185 key = tbm_bo_export_fd(&bo);
1187 ASSERT_EQ(key, expected_key);
1190 TEST(tbm_bo_export_fd, null_ptr_fail_1)
1192 int expected_key = -1;
1197 key = tbm_bo_export_fd(NULL);
1199 ASSERT_EQ(key, expected_key);
1202 /* tbm_bo_export() */
1204 TEST(tbm_bo_export, work_flow_success_3)
1207 struct _tbm_bufmgr bufmgr;
1208 struct _tbm_bufmgr_backend backend;
1213 LIST_INITHEAD(&bufmgr.bo_list);
1214 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1216 bo.bufmgr = &bufmgr;
1217 bufmgr.backend = &backend;
1218 backend.bo_export = ut_bo_export;
1220 key = tbm_bo_export(&bo);
1225 TEST(tbm_bo_export, work_flow_success_2)
1227 tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FAILED;
1228 int expected_key = 0;
1230 struct _tbm_bufmgr bufmgr;
1231 struct _tbm_bufmgr_backend backend;
1236 LIST_INITHEAD(&bufmgr.bo_list);
1237 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1239 bo.bufmgr = &bufmgr;
1240 bufmgr.backend = &backend;
1241 backend.bo_export = ut_bo_export;
1244 key = tbm_bo_export(&bo);
1246 ASSERT_EQ(key, expected_key);
1247 ASSERT_EQ(tbm_last_error, expected_last_result);
1250 TEST(tbm_bo_export, work_flow_success_1)
1252 int expected_key = 0;
1254 struct _tbm_bufmgr bufmgr;
1259 LIST_INITHEAD(&bufmgr.bo_list);
1262 key = tbm_bo_export(&bo);
1264 ASSERT_EQ(key, expected_key);
1267 TEST(tbm_bo_export, null_ptr_fail_1)
1269 int expected_key = 0;
1274 key = tbm_bo_export(NULL);
1276 ASSERT_EQ(key, expected_key);
1279 /* tbm_bo_import_fd() */
1281 TEST(tbm_bo_import_fd, work_flow_success_5)
1283 int expected_flags = bo_ret_flags;
1284 int expected_ref_cnt = 1;
1285 struct _tbm_bufmgr bufmgr;
1286 struct _tbm_bufmgr_backend backend;
1287 struct _tbm_bo *actual_bo;
1288 struct _tbm_bo copy_bo;
1293 memset(gBufMgr, 0, sizeof(bufmgr));
1295 bufmgr.backend = &backend;
1297 backend.bo_import_fd = ut_bo_import_fd;
1298 LIST_INITHEAD(&bufmgr.bo_list);
1299 backend.bo_get_flags = ut_bo_get_flags;
1301 actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1303 ASSERT_TRUE(actual_bo != NULL);
1304 copy_bo = *actual_bo;
1306 ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1307 ASSERT_EQ(copy_bo.flags, expected_flags);
1308 ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1309 ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1312 TEST(tbm_bo_import_fd, work_flow_success_4)
1314 int expected_flags = TBM_BO_DEFAULT;
1315 int expected_ref_cnt = 1;
1316 struct _tbm_bufmgr bufmgr;
1317 struct _tbm_bufmgr_backend backend;
1318 struct _tbm_bo *actual_bo;
1319 struct _tbm_bo copy_bo;
1323 memset(gBufMgr, 0, sizeof(bufmgr));
1325 bufmgr.backend = &backend;
1327 backend.bo_import_fd = ut_bo_import_fd;
1328 LIST_INITHEAD(&bufmgr.bo_list);
1329 backend.bo_get_flags = NULL;
1331 actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1333 ASSERT_TRUE(actual_bo != NULL);
1334 copy_bo = *actual_bo;
1336 ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1337 ASSERT_EQ(copy_bo.flags, expected_flags);
1338 ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1339 ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1342 TEST(tbm_bo_import_fd, work_flow_success_3)
1344 struct _tbm_bufmgr bufmgr;
1345 struct _tbm_bufmgr_backend backend;
1346 struct _tbm_bo expected_bo;
1347 int expected_ref_cnt;
1352 memset(gBufMgr, 0, sizeof(bufmgr));
1354 bufmgr.backend = &backend;
1356 backend.bo_import_fd = ut_bo_import_fd;
1357 LIST_INITHEAD(&bufmgr.bo_list);
1358 LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
1359 expected_bo.priv = ret_bo;
1360 expected_bo.ref_cnt = 10;
1361 expected_ref_cnt = expected_bo.ref_cnt + 1;
1363 struct _tbm_bo *actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1365 ASSERT_TRUE(actual_bo == &expected_bo);
1366 ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
1369 TEST(tbm_bo_import_fd, work_flow_success_2)
1371 struct _tbm_bo *expected = NULL;
1372 struct _tbm_bufmgr bufmgr;
1373 struct _tbm_bufmgr_backend backend;
1374 struct _tbm_bo *actual;
1378 bufmgr.backend = &backend;
1380 backend.bo_import_fd = ut_bo_import_fd;
1381 TBM_BO_IMPORT_ERROR = 1;
1383 actual = tbm_bo_import_fd(&bufmgr, 1);
1385 ASSERT_TRUE(actual == expected);
1388 TEST(tbm_bo_import_fd, work_flow_success_1)
1390 struct _tbm_bo *expected = NULL;
1391 struct _tbm_bufmgr bufmgr;
1392 struct _tbm_bo *actual;
1398 actual = tbm_bo_import_fd(&bufmgr, 1);
1400 ASSERT_TRUE(actual == expected);
1403 TEST(tbm_bo_import_fd, null_ptr_fail_1)
1405 struct _tbm_bo *expected = NULL;
1406 struct _tbm_bo *actual;
1410 actual = tbm_bo_import_fd(NULL, 1);
1412 ASSERT_TRUE(actual == expected);
1415 /* tbm_bo_import() */
1417 TEST(tbm_bo_import, work_flow_success_5)
1419 int expected_flags = bo_ret_flags;
1420 int expected_ref_cnt = 1;
1421 struct _tbm_bufmgr bufmgr;
1422 struct _tbm_bufmgr_backend backend;
1423 struct _tbm_bo *actual_bo;
1424 struct _tbm_bo copy_bo;
1429 memset(gBufMgr, 0, sizeof(bufmgr));
1431 bufmgr.backend = &backend;
1433 backend.bo_import = ut_bo_import;
1434 LIST_INITHEAD(&bufmgr.bo_list);
1435 backend.bo_get_flags = ut_bo_get_flags;
1437 actual_bo = tbm_bo_import(&bufmgr, 1);
1439 ASSERT_TRUE(actual_bo != NULL);
1440 copy_bo = *actual_bo;
1442 ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1443 ASSERT_EQ(copy_bo.flags, expected_flags);
1444 ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1445 ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1448 TEST(tbm_bo_import, work_flow_success_4)
1450 int expected_flags = TBM_BO_DEFAULT;
1451 int expected_ref_cnt = 1;
1452 struct _tbm_bufmgr bufmgr;
1453 struct _tbm_bufmgr_backend backend;
1454 struct _tbm_bo *actual_bo;
1455 struct _tbm_bo copy_bo;
1460 memset(gBufMgr, 0, sizeof(bufmgr));
1462 bufmgr.backend = &backend;
1464 backend.bo_import = ut_bo_import;
1465 LIST_INITHEAD(&bufmgr.bo_list);
1466 backend.bo_get_flags = NULL;
1468 actual_bo = tbm_bo_import(&bufmgr, 1);
1470 ASSERT_TRUE(actual_bo != NULL);
1471 copy_bo = *actual_bo;
1473 ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1474 ASSERT_EQ(copy_bo.flags, expected_flags);
1475 ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1476 ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1479 TEST(tbm_bo_import, work_flow_success_3)
1481 struct _tbm_bufmgr bufmgr;
1482 struct _tbm_bufmgr_backend backend;
1483 struct _tbm_bo expected_bo;
1484 int expected_ref_cnt;
1485 struct _tbm_bo *actual_bo;
1491 memset(gBufMgr, 0, sizeof(bufmgr));
1493 bufmgr.backend = &backend;
1495 backend.bo_import = ut_bo_import;
1496 LIST_INITHEAD(&bufmgr.bo_list);
1497 LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
1498 expected_bo.priv = ret_bo;
1499 expected_bo.ref_cnt = 10;
1500 expected_ref_cnt = expected_bo.ref_cnt + 1;
1502 actual_bo = tbm_bo_import(&bufmgr, 1);
1504 ASSERT_TRUE(actual_bo == &expected_bo);
1505 ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
1508 TEST(tbm_bo_import, work_flow_success_2)
1510 struct _tbm_bo *expected = NULL;
1511 struct _tbm_bufmgr bufmgr;
1512 struct _tbm_bufmgr_backend backend;
1513 struct _tbm_bo *actual;
1517 bufmgr.backend = &backend;
1519 backend.bo_import = ut_bo_import;
1520 TBM_BO_IMPORT_ERROR = 1;
1522 actual = tbm_bo_import(&bufmgr, 1);
1524 ASSERT_TRUE(actual == expected);
1527 TEST(tbm_bo_import, work_flow_success_1)
1529 struct _tbm_bo *expected = NULL;
1530 struct _tbm_bufmgr bufmgr;
1531 struct _tbm_bo *actual;
1537 actual = tbm_bo_import(&bufmgr, 1);
1539 ASSERT_TRUE(actual == expected);
1542 TEST(tbm_bo_import, null_ptr_fail_1)
1544 struct _tbm_bo *expected = NULL;
1545 struct _tbm_bo *actual;
1549 actual = tbm_bo_import(NULL, 1);
1551 ASSERT_TRUE(actual == expected);
1554 /* tbm_bo_alloc() */
1556 TEST(tbm_bo_alloc, work_flow_success_3)
1559 int expected_ref_cnt = 1;
1560 struct _tbm_bo *not_expected_bo = NULL;
1561 struct _tbm_bufmgr bufmgr;
1562 struct _tbm_bufmgr_backend backend;
1563 struct _tbm_bo *actual_bo;
1564 struct _tbm_bo copy_bo;
1569 memset(gBufMgr, 0, sizeof(bufmgr));
1570 bufmgr.backend = &backend;
1571 backend.bo_alloc = ut_bo_alloc;
1572 LIST_INITHEAD(&bufmgr.bo_list);
1574 actual_bo = tbm_bo_alloc(&bufmgr, 1, flags);
1576 ASSERT_TRUE(actual_bo != not_expected_bo);
1577 copy_bo = *actual_bo;
1579 ASSERT_EQ(copy_bo.flags, flags);
1580 ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1581 ASSERT_TRUE(copy_bo.priv == ret_bo);
1582 ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1583 ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1586 TEST(tbm_bo_alloc, work_flow_success_2)
1588 struct _tbm_bo *expected = NULL;
1589 tbm_error_e expected_last_error = TBM_BO_ERROR_BO_ALLOC_FAILED;
1590 struct _tbm_bufmgr bufmgr;
1591 struct _tbm_bufmgr_backend backend;
1592 struct _tbm_bo *actual;
1597 memset(gBufMgr, 0, sizeof(bufmgr));
1598 LIST_INITHEAD(&gBufMgr->bo_list);
1600 bufmgr.backend = &backend;
1601 backend.bo_alloc = ut_bo_alloc;
1602 TBM_BO_ALLOC_ERROR = 1;
1604 actual = tbm_bo_alloc(&bufmgr, 1, 1);
1606 ASSERT_TRUE(actual == expected);
1607 ASSERT_EQ(tbm_last_error, expected_last_error);
1610 TEST(tbm_bo_alloc, work_flow_success_1)
1612 struct _tbm_bo *expected = NULL;
1613 struct _tbm_bufmgr bufmgr;
1614 tbm_error_e expected_last_error;
1615 struct _tbm_bo *actual;
1620 memset(gBufMgr, 0, sizeof(bufmgr));
1621 LIST_INITHEAD(&gBufMgr->bo_list);
1624 expected_last_error = TBM_BO_ERROR_HEAP_ALLOC_FAILED;
1626 actual = tbm_bo_alloc(&bufmgr, 1, 1);
1628 ASSERT_TRUE(actual == expected);
1629 ASSERT_EQ(tbm_last_error, expected_last_error);
1632 TEST(tbm_bo_alloc, null_int_fail_1)
1634 struct _tbm_bo *expected = NULL;
1635 struct _tbm_bufmgr bufmgr;
1636 struct _tbm_bo *actual;
1640 actual = tbm_bo_alloc(&bufmgr, 0, 1);
1642 ASSERT_TRUE(actual == expected);
1645 TEST(tbm_bo_alloc, null_ptr_fail_1)
1647 struct _tbm_bo *expected = NULL;
1648 struct _tbm_bo *actual;
1652 actual = tbm_bo_alloc(NULL, 1, 1);
1654 ASSERT_TRUE(actual == expected);
1657 /* tbm_bo_unref() */
1659 TEST(tbm_bo_unref, work_flow_success_1)
1662 struct _tbm_bufmgr bufmgr;
1663 int expected_ref_cnt;
1667 LIST_INITHEAD(&bufmgr.bo_list);
1668 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1671 expected_ref_cnt = bo.ref_cnt - 1;
1675 ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
1680 TEST(tbm_bo_ref, work_flow_success_3)
1683 struct _tbm_bufmgr bufmgr;
1684 struct _tbm_bo *expected;
1685 struct _tbm_bo *actual;
1689 LIST_INITHEAD(&bufmgr.bo_list);
1690 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1693 int expected_ref_cnt = bo.ref_cnt + 1;
1696 actual = tbm_bo_ref(&bo);
1698 ASSERT_TRUE(actual == expected);
1699 ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
1702 TEST(tbm_bo_ref, work_flow_success_2)
1704 struct _tbm_bo *expected = NULL;
1706 struct _tbm_bufmgr bufmgr;
1707 struct _tbm_bo *actual;
1711 LIST_INITHEAD(&bufmgr.bo_list);
1714 actual = tbm_bo_ref(&bo);
1716 ASSERT_TRUE(actual == expected);
1719 TEST(tbm_bo_ref, work_flow_success_1)
1721 struct _tbm_bo *expected = NULL;
1722 struct _tbm_bo *actual;
1726 actual = tbm_bo_ref(NULL);
1728 ASSERT_TRUE(actual == expected);
1733 TEST(tbm_bo_size, work_flow_success_3)
1735 int not_expected = 0;
1737 struct _tbm_bufmgr bufmgr;
1738 struct _tbm_bufmgr_backend backend;
1743 LIST_INITHEAD(&bufmgr.bo_list);
1744 LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1746 backend.bo_size = ut_bo_size;
1747 bufmgr.backend = &backend;
1748 bo.bufmgr = &bufmgr;
1750 actual = tbm_bo_size(&bo);
1752 ASSERT_TRUE(actual != not_expected);
1755 TEST(tbm_bo_size, work_flow_success_2)
1759 struct _tbm_bufmgr bufmgr;
1764 LIST_INITHEAD(&bufmgr.bo_list);
1767 actual = tbm_bo_size(&bo);
1769 ASSERT_EQ(actual, expected);
1772 TEST(tbm_bo_size, work_flow_success_1)
1779 actual = tbm_bo_size(NULL);
1781 ASSERT_EQ(actual, expected);