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

Diff of /lbbs/src/test_file_loader.c

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

Revision 1.8 by sysadm, Sat Jun 7 07:35:06 2025 UTC Revision 1.15 by sysadm, Thu Nov 20 01:09:27 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          test_file_loader.c  -  description  /*
3                                                           -------------------   * test_file_loader
4          Copyright            : (C) 2004-2025 by Leaflet   *   - tester for shared memory based file loader
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "file_loader.h"  #include "file_loader.h"
 #include "trie_dict.h"  
14  #include "log.h"  #include "log.h"
15    #include <errno.h>
16    #include <libgen.h>
17  #include <stdio.h>  #include <stdio.h>
18    #include <string.h>
19  #include <unistd.h>  #include <unistd.h>
 #include <errno.h>  
20  #include <sys/shm.h>  #include <sys/shm.h>
21    
 #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"  
   
22  const char *files[] = {  const char *files[] = {
23          "../data/welcome.txt",          "../data/welcome.txt",
24          "../data/copyright.txt",          "../data/copyright.txt",
# Line 36  int files_cnt = 6; Line 31  int files_cnt = 6;
31    
32  int main(int argc, char *argv[])  int main(int argc, char *argv[])
33  {  {
         int ret;  
34          int i;          int i;
35          const void *p_shm;          void *p_shm;
36          size_t data_len;          size_t data_len;
37          long line_total;          long line_total;
38          const void *p_data;          const void *p_data;
39          const long *p_line_offsets;          const long *p_line_offsets;
         FILE *fp;  
40    
41          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
42          {          {
# Line 54  int main(int argc, char *argv[]) Line 47  int main(int argc, char *argv[])
47          log_common_redir(STDOUT_FILENO);          log_common_redir(STDOUT_FILENO);
48          log_error_redir(STDERR_FILENO);          log_error_redir(STDERR_FILENO);
49    
         if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL)  
         {  
                 log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE);  
                 return -1;  
         }  
         fclose(fp);  
   
         if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0)  
         {  
                 printf("trie_dict_init failed\n");  
                 return -1;  
         }  
   
         ret = file_loader_init();  
         if (ret < 0)  
         {  
                 printf("file_loader_init() error (%d)\n", ret);  
                 return ret;  
         }  
   
         ret = file_loader_init();  
         if (ret == 0)  
         {  
                 printf("Rerun file_loader_init() error\n");  
         }  
   
50          printf("Testing #1\n");          printf("Testing #1\n");
51    
52          for (i = 0; i < files_cnt; i++)          for (i = 0; i < files_cnt; i++)
# Line 163  int main(int argc, char *argv[]) Line 130  int main(int argc, char *argv[])
130                  }                  }
131          }          }
132    
         file_loader_cleanup();  
         file_loader_cleanup();  
   
         trie_dict_cleanup();  
   
         if (unlink(TRIE_DICT_SHM_FILE) < 0)  
         {  
                 log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE);  
                 return -1;  
         }  
   
133          log_end();          log_end();
134    
135          return 0;          return 0;


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

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