/[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.1 by sysadm, Fri May 16 12:22:35 2025 UTC Revision 1.3 by sysadm, Sun May 18 06:56:46 2025 UTC
# Line 18  Line 18 
18  #include "log.h"  #include "log.h"
19  #include <stdio.h>  #include <stdio.h>
20  #include <unistd.h>  #include <unistd.h>
21    #include <errno.h>
22    #include <sys/shm.h>
23    
24  const char *files[] = {  const char *files[] = {
25          "../data/welcome.txt",          "../data/welcome.txt",
26          "../data/copyright.txt",          "../data/copyright.txt",
27          "../data/register.txt",          "../data/register.txt",
28          "../data/license.txt",          "../data/license.txt",
29          "../data/login_error.txt"};          "../data/login_error.txt",
30            "../data/read_help.txt"};
31    
32  int files_cnt = 5;  int files_cnt = 6;
33    
34  int main(int argc, char *argv[])  int main(int argc, char *argv[])
35  {  {
36          int ret;          int ret;
         int file_loader_pool_size = 2;  
37          int i;          int i;
38          const FILE_MMAP *p_file_mmap;          const void *p_shm;
39            size_t data_len;
40            long line_total;
41            const void *p_data;
42            const long *p_line_offsets;
43    
44          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
45          {          {
# Line 44  int main(int argc, char *argv[]) Line 50  int main(int argc, char *argv[])
50          log_std_redirect(STDOUT_FILENO);          log_std_redirect(STDOUT_FILENO);
51          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
52    
53          ret = file_loader_init(file_loader_pool_size);          ret = file_loader_init();
54          if (ret < 0)          if (ret < 0)
55          {          {
56                  printf("file_loader_init() error (%d)\n", ret);                  printf("file_loader_init() error (%d)\n", ret);
57                  return ret;                  return ret;
58          }          }
59    
60          ret = file_loader_init(file_loader_pool_size);          ret = file_loader_init();
61          if (ret == 0)          if (ret == 0)
62          {          {
63                  printf("Rerun file_loader_init() error\n");                  printf("Rerun file_loader_init() error\n");
# Line 59  int main(int argc, char *argv[]) Line 65  int main(int argc, char *argv[])
65    
66          printf("Testing #1\n");          printf("Testing #1\n");
67    
68          for (i = 0; i < file_loader_pool_size; i++)          for (i = 0; i < files_cnt; i++)
69          {          {
70                  if (load_file_mmap(files[i]) < 0)                  if (load_file_shm(files[i]) < 0)
71                  {                  {
72                          printf("Load file %s error\n", files[i]);                          printf("Load file %s error\n", files[i]);
73                  }                  }
74          }          }
75    
76          for (i = 0; i < file_loader_pool_size; i++)          for (i = 0; i < files_cnt; i++)
77          {          {
78                  if ((p_file_mmap = get_file_mmap(files[i])) == NULL)                  if ((p_shm = get_file_shm(files[i], &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
79                  {                  {
80                          printf("Get file mmap %s error\n", files[i]);                          printf("Get file shm %s error\n", files[i]);
81                  }                  }
82                  else                  else
83                  {                  {
84                          printf("File: %s size: ", files[i]);                          printf("File: %s size: %ld lines: %ld\n", files[i], data_len, line_total);
                         printf("size: %ld lines: %ld\n", p_file_mmap->size, p_file_mmap->line_total);  
85                  }                  }
86          }          }
87    
88          for (i = 0; i < file_loader_pool_size; i++)          printf("Testing #2\n");
89    
90            for (i = 0; i < files_cnt; i++)
91          {          {
92                  if (unload_file_mmap(files[i]) < 0)                  if (unload_file_shm(files[i]) < 0)
93                  {                  {
94                          printf("Unload file %s error\n", files[i]);                          printf("Unload file %s error\n", files[i]);
95                  }                  }
96          }          }
97    
         printf("Testing #2\n");  
   
98          for (i = 0; i < files_cnt; i++)          for (i = 0; i < files_cnt; i++)
99          {          {
100                  if (i >= file_loader_pool_size)                  if (load_file_shm(files[i]) < 0)
                 {  
                         if (unload_file_mmap(files[i - file_loader_pool_size]) < 0)  
                         {  
                                 printf("Unload file %s error\n", files[i]);  
                         }  
                 }  
   
                 if (load_file_mmap(files[i]) < 0)  
101                  {                  {
102                          printf("Load file %s error\n", files[i]);                          printf("Load file %s error\n", files[i]);
103                  }                  }
# Line 110  int main(int argc, char *argv[]) Line 107  int main(int argc, char *argv[])
107    
108          for (i = 0; i < files_cnt; i++)          for (i = 0; i < files_cnt; i++)
109          {          {
110                  if ((p_file_mmap = get_file_mmap(files[i])) == NULL)                  if (i % 2 == 0)
111                  {                  {
112                          printf("Get file mmap %s error\n", files[i]);                          if (unload_file_shm(files[i]) < 0)
113                            {
114                                    printf("Unload file %s error\n", files[i]);
115                            }
116                  }                  }
117                  else          }
118    
119            for (i = 0; i < files_cnt; i++)
120            {
121                    if (i % 2 != 0)
122                  {                  {
123                          printf("File: %s size: ", files[i]);                          if ((p_shm = get_file_shm(files[i], &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
124                          printf("size: %ld lines: %ld\n", p_file_mmap->size, p_file_mmap->line_total);                          {
125                                    printf("Get file shm %s error\n", files[i]);
126                            }
127                            else
128                            {
129                                    printf("File: %s size: %ld lines: %ld\n", files[i], data_len, line_total);
130                            }
131                  }                  }
132          }          }
133    


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

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