xref: /OK3568_Linux_fs/external/mpp/mpp/base/test/mpp_trie_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_trie_test"
18 
19 #include <string.h>
20 
21 #include "mpp_log.h"
22 #include "mpp_mem.h"
23 #include "mpp_time.h"
24 #include "mpp_common.h"
25 
26 #include "mpp_trie.h"
27 
28 typedef void *(*TestProc)(void *);
29 
30 typedef struct TestAction_t {
31     const char          *name;
32     void                *ctx;
33     TestProc            proc;
34 } TestAction;
35 
print_opt(void * ctx)36 void *print_opt(void *ctx)
37 {
38     RK_U8 **str = (RK_U8 **)ctx;
39 
40     if (str && *str)
41         mpp_log("get option %s\n", *str);
42 
43     return NULL;
44 }
45 
46 TestAction test_info[] = {
47     { "rc:mode",        &test_info[0],  print_opt},
48     { "rc:bps_target",  &test_info[1],  print_opt},
49     { "rc:bps_max",     &test_info[2],  print_opt},
50     { "rc:bps_min",     &test_info[3],  print_opt},
51 };
52 
53 const char *test_str[] = {
54     "rc:mode",
55     "rc:bps_target",
56     "rc:bps_max",
57 };
58 
main()59 int main()
60 {
61     MppTrie trie = NULL;
62     void *info = NULL;
63     RK_U32 i;
64     RK_S64 end = 0;
65     RK_S64 start = 0;
66     RK_S32 info_cnt = MPP_ARRAY_ELEMS(test_info);
67     RK_S32 node_cnt = 100;
68 
69     mpp_trie_init(&trie, node_cnt, info_cnt);
70 
71     start = mpp_time();
72     mpp_trie_add_info(trie, &test_info[0].name);
73     mpp_trie_add_info(trie, &test_info[1].name);
74     mpp_trie_add_info(trie, &test_info[2].name);
75     mpp_trie_add_info(trie, &test_info[3].name);
76     end = mpp_time();
77     mpp_log("add act time %lld us\n", end - start);
78 
79     for (i = 0; i < MPP_ARRAY_ELEMS(test_str); i++) {
80         start = mpp_time();
81         info = mpp_trie_get_info(trie, test_str[i]);
82         end = mpp_time();
83         if (info) {
84             TestAction *act = (TestAction *)info;
85 
86             if (act && act->proc) {
87                 act->proc(act->ctx);
88                 mpp_log("search time %lld us\n", end - start);
89             }
90         }
91     }
92 
93     mpp_trie_deinit(trie);
94 
95     return 0;
96 }
97