/[LeafOK_CVS]/lbbs/src/test_trie_dict.c
ViewVC logotype

Diff of /lbbs/src/test_trie_dict.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.6 by sysadm, Sun May 18 06:53:59 2025 UTC Revision 1.7 by sysadm, Sun May 25 06:45:42 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "trie_dict.h"  #include "trie_dict.h"
18    #include "log.h"
19  #include <stdio.h>  #include <stdio.h>
20  #include <string.h>  #include <string.h>
21    #include <unistd.h>
22    #include <errno.h>
23    
24  #define TEST_VAL ((int64_t)(0xcb429a63a017661f)) // int64_t  #define TEST_VAL ((int64_t)(0xcb429a63a017661f)) // int64_t
25    #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"
26    
27  const char *keys[] = {  const char *keys[] = {
28          "ABCDEFG",          "ABCDEFG",
# Line 31  const char *keys[] = { Line 35  const char *keys[] = {
35          "_bbBBz_Z_",          "_bbBBz_Z_",
36          ""};          ""};
37    
38  int keys_cnt = 9;  int keys_cnt = 8; // + 1 to trigger error handling of blank key
39    
40  void test_traverse_cb(const char *key, int64_t value)  void test_traverse_cb(const char *key, int64_t value)
41  {  {
# Line 43  int main(int argc, char *argv[]) Line 47  int main(int argc, char *argv[])
47          TRIE_NODE *p_dict;          TRIE_NODE *p_dict;
48          int ret;          int ret;
49          int64_t value;          int64_t value;
50            FILE *fp;
51    
52            if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
53            {
54                    printf("Open log error\n");
55                    return -1;
56            }
57    
58            log_std_redirect(STDOUT_FILENO);
59            log_err_redirect(STDERR_FILENO);
60    
61            if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL)
62            {
63                    log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE);
64                    return -1;
65            }
66            fclose(fp);
67    
68          for (int i = 0; i < keys_cnt; i++)          for (int i = 0; i < keys_cnt; i++)
69          {          {
70                  printf("Check key %d [%s] len=%ld\n", i, keys[i], strlen(keys[i]));                  printf("Check key %d [%s] len=%ld\n", i, keys[i], strlen(keys[i]));
71          }          }
72    
73            if (trie_dict_init(TRIE_DICT_SHM_FILE) < 0)
74            {
75                    printf("trie_dict_init failed\n");
76                    return -1;
77            }
78    
79            printf("Testing #1 ...\n");
80    
81          p_dict = trie_dict_create();          p_dict = trie_dict_create();
82    
83          if (p_dict == NULL)          if (p_dict == NULL)
# Line 186  int main(int argc, char *argv[]) Line 215  int main(int argc, char *argv[])
215          trie_dict_destroy(p_dict);          trie_dict_destroy(p_dict);
216          p_dict = NULL;          p_dict = NULL;
217    
218            printf("Testing #2 ...\n");
219    
220            for (int i = 0; i < 100000; i++)
221            {
222                    p_dict = trie_dict_create();
223    
224                    if (p_dict == NULL)
225                    {
226                            printf("OOM\n");
227                            return -1;
228                    }
229    
230                    trie_dict_destroy(p_dict);
231                    p_dict = NULL;
232            }
233    
234            printf("Testing #3 ...\n");
235    
236            if (set_trie_dict_shm_readonly() < 0)
237            {
238                    printf("load_trie_dict_shm_readonly() error\n");
239            }
240    
241            // if (unload_trie_dict_shm() < 0)
242            // {
243            //      printf("unload_trie_dict_shm() error\n");
244            // }
245    
246            trie_dict_cleanup();
247    
248          printf("Done\n");          printf("Done\n");
249    
250            if (unlink(TRIE_DICT_SHM_FILE) < 0)
251            {
252                    log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE);
253                    return -1;
254            }
255    
256            log_end();
257    
258          return 0;          return 0;
259  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1