xref: /OK3568_Linux_fs/external/mpp/osal/test/mpp_mem_pool_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define MODULE_TAG "mpp_mem_pool_test"
18 
19 #include <stdlib.h>
20 
21 #include "mpp_log.h"
22 #include "mpp_mem_pool.h"
23 
24 #define MPP_MEM_POOL_TEST_SIZE      1024
25 #define MPP_MEM_POOL_TEST_COUNT     20
26 
main()27 int main()
28 {
29     MppMemPool pool = NULL;
30     size_t size = MPP_MEM_POOL_TEST_SIZE;
31     void *p [MPP_MEM_POOL_TEST_COUNT];
32     RK_U32 i;
33 
34     mpp_log("mpp_mem_pool_test start\n");
35 
36     pool = mpp_mem_pool_init(size);
37     if (NULL == pool) {
38         mpp_err("mpp_mem_pool_test mpp_mem_pool_init failed\n");
39         goto mpp_mem_pool_test_failed;
40     }
41 
42     for (i = 0; i < MPP_MEM_POOL_TEST_COUNT; i++) {
43         p[i] = mpp_mem_pool_get(pool);
44         if (!p[i]) {
45             mpp_err("mpp_mem_pool_test mpp_mem_pool_get failed\n");
46             goto mpp_mem_pool_test_failed;
47         }
48     }
49 
50     for (i = 0; i < MPP_MEM_POOL_TEST_COUNT / 2; i++) {
51         if (p[i]) {
52             mpp_mem_pool_put(pool, p[i]);
53             p[i] = NULL;
54         }
55     }
56 
57     for (i = 0; i < MPP_MEM_POOL_TEST_COUNT / 4; i++) {
58         p[i] = mpp_mem_pool_get(pool);
59         if (!p[i]) {
60             mpp_err("mpp_mem_pool_test mpp_mem_pool_get failed\n");
61             goto mpp_mem_pool_test_failed;
62         }
63     }
64 
65     for (i = 0; i < MPP_MEM_POOL_TEST_COUNT; i++) {
66         if (p[i]) {
67             mpp_mem_pool_put(pool, p[i]);
68             p[i] = NULL;
69         }
70     }
71 
72     mpp_log("mpp_mem_pool_test success\n");
73     return MPP_OK;
74 
75 mpp_mem_pool_test_failed:
76     mpp_log("mpp_mem_pool_test failed\n");
77     return MPP_NOK;
78 }
79 
80