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

Diff of /lbbs/src/test_section_list.c

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

Revision 1.19 by sysadm, Sat May 24 07:32:46 2025 UTC Revision 1.21 by sysadm, Sun May 25 06:56:48 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "section_list.h"  #include "section_list.h"
18    #include "trie_dict.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "log.h"  #include "log.h"
21  #include <stdio.h>  #include <stdio.h>
# Line 23  Line 24 
24    
25  #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"  #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"
26  #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"  #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"
27    #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"
28    
29  const char *sname[] = {  const char *sname[] = {
30          "Test",          "Test",
# Line 88  int main(int argc, char *argv[]) Line 90  int main(int argc, char *argv[])
90          }          }
91          fclose(fp);          fclose(fp);
92    
93            if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL)
94            {
95                    log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE);
96                    return -1;
97            }
98            fclose(fp);
99    
100            if (trie_dict_init(TRIE_DICT_SHM_FILE) < 0)
101            {
102                    printf("trie_dict_init failed\n");
103                    return -1;
104            }
105    
106          if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)          if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
107          {          {
108                  log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);                  log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
109                  return -2;                  return -2;
110          }          }
111    
112          if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)          if (section_list_init(SECTION_LIST_SHM_FILE) < 0)
113          {          {
114                  log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);                  log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
115                  return -2;                  return -2;
# Line 104  int main(int argc, char *argv[]) Line 119  int main(int argc, char *argv[])
119    
120          last_aid = 0;          last_aid = 0;
121    
122            if (section_list_try_rw_lock(NULL, 1) < 0)
123            {
124                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
125            }
126    
127          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
128          {          {
129                  sid = i * 3 + 1;                  sid = i * 3 + 1;
# Line 116  int main(int argc, char *argv[]) Line 136  int main(int argc, char *argv[])
136                          printf("section_list_create(i = %d) error\n", i);                          printf("section_list_create(i = %d) error\n", i);
137                          return -3;                          return -3;
138                  }                  }
         }  
139    
         for (i = 0; i < section_count; i++)  
         {  
140                  if (get_section_index(p_section[i]) != i)                  if (get_section_index(p_section[i]) != i)
141                  {                  {
142                          printf("get_section_index(i = %d) error\n", i);                          printf("get_section_index(i = %d) error\n", i);
# Line 146  int main(int argc, char *argv[]) Line 163  int main(int argc, char *argv[])
163                  }                  }
164          }          }
165    
166            if (section_list_rw_unlock(NULL) < 0)
167            {
168                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
169            }
170    
171          for (j = 0; j < BBS_article_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
172          {          {
173                  for (i = 0; i < section_count; i++)                  for (i = 0; i < section_count; i++)
# Line 163  int main(int argc, char *argv[]) Line 185  int main(int argc, char *argv[])
185                          article.ontop = 0;                          article.ontop = 0;
186                          article.lock = 0;                          article.lock = 0;
187    
188                            if (section_list_try_rw_lock(p_section[i], 1) < 0)
189                            {
190                                    printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
191                                    break;
192                            }
193    
194                          if (section_list_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
195                          {                          {
196                                  printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);                                  printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
197                                  break;                                  break;
198                          }                          }
199    
200                            if (section_list_rw_unlock(p_section[i]) < 0)
201                            {
202                                    printf("section_list_rw_unlock(sid = %d) error %d\n", p_section[i]->sid, errno);
203                                    break;
204                            }
205                  }                  }
206          }          }
207    
# Line 190  int main(int argc, char *argv[]) Line 224  int main(int argc, char *argv[])
224                                  printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);                                  printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);
225                          }                          }
226    
227                            if (section_list_try_rw_lock(p_section[i], 1) < 0)
228                            {
229                                    printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
230                                    break;
231                            }
232    
233                          if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1)                          if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1)
234                          {                          {
235                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
236                          }                          }
237    
238                            if (section_list_rw_unlock(p_section[i]) < 0)
239                            {
240                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
241                                    break;
242                            }
243                  }                  }
244    
245                  // printf("Verified %d articles in section %d\n", p_section[i]->article_count, i);                  // printf("Verified %d articles in section %d\n", p_section[i]->article_count, i);
# Line 201  int main(int argc, char *argv[]) Line 247  int main(int argc, char *argv[])
247    
248          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
249    
250            if (section_list_try_rw_lock(NULL, 1) < 0)
251            {
252                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
253            }
254    
255          if (article_block_reset() != 0)          if (article_block_reset() != 0)
256          {          {
257                  log_error("article_block_reset() error\n");                  log_error("article_block_reset() error\n");
# Line 212  int main(int argc, char *argv[]) Line 263  int main(int argc, char *argv[])
263                  section_list_reset_articles(p_section[i]);                  section_list_reset_articles(p_section[i]);
264          }          }
265    
266            if (section_list_rw_unlock(NULL) < 0)
267            {
268                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
269            }
270    
271          last_aid = 0;          last_aid = 0;
272    
273          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
274          {          {
275                  section_first_aid = last_aid + 1;                  section_first_aid = last_aid + 1;
276    
277                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
278                    {
279                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
280                            break;
281                    }
282    
283                  for (j = 0; j < BBS_article_limit_per_section; j++)                  for (j = 0; j < BBS_article_limit_per_section; j++)
284                  {                  {
285                          last_aid++;                          last_aid++;
# Line 241  int main(int argc, char *argv[]) Line 303  int main(int argc, char *argv[])
303                          }                          }
304                  }                  }
305    
306                    if (section_list_rw_unlock(p_section[i]) < 0)
307                    {
308                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
309                            break;
310                    }
311    
312                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
313          }          }
314    
# Line 254  int main(int argc, char *argv[]) Line 322  int main(int argc, char *argv[])
322                  article_count = 0;                  article_count = 0;
323                  last_aid = 0;                  last_aid = 0;
324    
325                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
326                    {
327                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
328                            break;
329                    }
330    
331                  p_article = p_section[i]->p_article_head;                  p_article = p_section[i]->p_article_head;
332    
333                  do                  do
# Line 276  int main(int argc, char *argv[]) Line 350  int main(int argc, char *argv[])
350                          break;                          break;
351                  }                  }
352    
353                    if (section_list_rd_unlock(p_section[i]) < 0)
354                    {
355                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
356                            break;
357                    }
358    
359                  // printf("Verified %d articles in section %d\n", group_count, i);                  // printf("Verified %d articles in section %d\n", group_count, i);
360          }          }
361    
# Line 286  int main(int argc, char *argv[]) Line 366  int main(int argc, char *argv[])
366                          continue;                          continue;
367                  }                  }
368    
369                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
370                    {
371                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
372                            break;
373                    }
374    
375                  if (p_section[i]->topic_count != group_count)                  if (p_section[i]->topic_count != group_count)
376                  {                  {
377                          printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count);                          printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count);
# Line 347  int main(int argc, char *argv[]) Line 433  int main(int argc, char *argv[])
433                          }                          }
434                  }                  }
435    
436                    if (section_list_rd_unlock(p_section[i]) < 0)
437                    {
438                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
439                            break;
440                    }
441    
442                  // printf("Verified %d topics in section %d\n", group_count, i);                  // printf("Verified %d topics in section %d\n", group_count, i);
443          }          }
444    
# Line 356  int main(int argc, char *argv[]) Line 448  int main(int argc, char *argv[])
448          {          {
449                  last_aid = 0;                  last_aid = 0;
450    
451                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
452                    {
453                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
454                            break;
455                    }
456    
457                  for (j = 0; j < p_section[i]->page_count; j++)                  for (j = 0; j < p_section[i]->page_count; j++)
458                  {                  {
459                          if (p_section[i]->p_page_first_article[j]->aid <= last_aid)                          if (p_section[i]->p_page_first_article[j]->aid <= last_aid)
# Line 380  int main(int argc, char *argv[]) Line 478  int main(int argc, char *argv[])
478                                  }                                  }
479                          }                          }
480                  }                  }
481    
482                    if (section_list_rd_unlock(p_section[i]) < 0)
483                    {
484                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
485                            break;
486                    }
487          }          }
488    
489          printf("Testing #4 ...\n");          printf("Testing #4 ...\n");
490    
491          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
492          {          {
493                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
494                    {
495                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
496                            break;
497                    }
498    
499                  step = i % 10 + 1;                  step = i % 10 + 1;
500                  for (j = group_count; j < BBS_article_limit_per_section; j += step)                  for (j = group_count; j < BBS_article_limit_per_section; j += step)
501                  {                  {
# Line 515  int main(int argc, char *argv[]) Line 625  int main(int argc, char *argv[])
625                                     p_section[i]->last_page_visible_article_count);                                     p_section[i]->last_page_visible_article_count);
626                          break;                          break;
627                  }                  }
628    
629                    if (section_list_rw_unlock(p_section[i]) < 0)
630                    {
631                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
632                            break;
633                    }
634          }          }
635    
636          for (i = 0; i < BBS_max_section; i++)          for (i = 0; i < BBS_max_section; i++)
637          {          {
638                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
639                    {
640                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
641                            break;
642                    }
643    
644                  affected_count = 0;                  affected_count = 0;
645    
646                  for (j = 0; j < BBS_article_limit_per_section; j += 1)                  for (j = 0; j < BBS_article_limit_per_section; j += 1)
# Line 572  int main(int argc, char *argv[]) Line 694  int main(int argc, char *argv[])
694                                     p_section[i]->last_page_visible_article_count);                                     p_section[i]->last_page_visible_article_count);
695                          break;                          break;
696                  }                  }
697    
698                    if (section_list_rw_unlock(p_section[i]) < 0)
699                    {
700                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
701                            break;
702                    }
703          }          }
704    
705          printf("Testing #5 ...\n");          printf("Testing #5 ...\n");
706    
707            if (section_list_try_rw_lock(NULL, 1) < 0)
708            {
709                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
710            }
711    
712          if (article_block_reset() != 0)          if (article_block_reset() != 0)
713          {          {
714                  log_error("article_block_reset() error\n");                  log_error("article_block_reset() error\n");
# Line 587  int main(int argc, char *argv[]) Line 720  int main(int argc, char *argv[])
720                  section_list_reset_articles(p_section[i]);                  section_list_reset_articles(p_section[i]);
721          }          }
722    
723            if (section_list_rw_unlock(NULL) < 0)
724            {
725                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
726            }
727    
728          last_aid = 0;          last_aid = 0;
729    
730          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
731          {          {
732                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
733                    {
734                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
735                            break;
736                    }
737    
738                  section_first_aid = last_aid + 1;                  section_first_aid = last_aid + 1;
739    
740                  for (j = 0; j < BBS_article_limit_per_section; j++)                  for (j = 0; j < BBS_article_limit_per_section; j++)
# Line 616  int main(int argc, char *argv[]) Line 760  int main(int argc, char *argv[])
760                          }                          }
761                  }                  }
762    
763                    if (section_list_rw_unlock(p_section[i]) < 0)
764                    {
765                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
766                            break;
767                    }
768    
769                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
770          }          }
771    
772          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
773          {          {
774                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
775                    {
776                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
777                            break;
778                    }
779    
780                  section_first_aid = p_section[i]->p_article_head->aid;                  section_first_aid = p_section[i]->p_article_head->aid;
781    
782                  for (j = 0; j < group_count; j += 2)                  for (j = 0; j < group_count; j += 2)
# Line 638  int main(int argc, char *argv[]) Line 794  int main(int argc, char *argv[])
794                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
795                          }                          }
796                  }                  }
797    
798                    if (section_list_rw_unlock(p_section[i]) < 0)
799                    {
800                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
801                            break;
802                    }
803          }          }
804    
805          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
806          {          {
807                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
808                    {
809                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
810                            break;
811                    }
812    
813                    if (section_list_try_rw_lock(p_section[section_count / 2 + i], 1) < 0)
814                    {
815                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);
816    
817                            if (section_list_rw_unlock(p_section[i]) < 0)
818                            {
819                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
820                            }
821                            break;
822                    }
823    
824                  section_first_aid = p_section[i]->p_article_head->aid;                  section_first_aid = p_section[i]->p_article_head->aid;
825    
826                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
# Line 662  int main(int argc, char *argv[]) Line 841  int main(int argc, char *argv[])
841                                  // break;                                  // break;
842                          }                          }
843                  }                  }
844    
845                    if (section_list_rw_unlock(p_section[i]) < 0)
846                    {
847                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
848                            break;
849                    }
850    
851                    if (section_list_rw_unlock(p_section[section_count / 2 + i]) < 0)
852                    {
853                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);
854    
855                            if (section_list_rw_unlock(p_section[i]) < 0)
856                            {
857                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
858                            }
859                            break;
860                    }
861          }          }
862    
863          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
864          {          {
865                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
866                    {
867                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
868                            break;
869                    }
870    
871                  if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))                  if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
872                  {                  {
873                          printf("Topic count error in section %d, %d != %d\n", i,                          printf("Topic count error in section %d, %d != %d\n", i,
# Line 700  int main(int argc, char *argv[]) Line 902  int main(int argc, char *argv[])
902                                     p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));                                     p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));
903                          break;                          break;
904                  }                  }
905    
906                    if (section_list_rd_unlock(p_section[i]) < 0)
907                    {
908                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
909                            break;
910                    }
911          }          }
912    
913          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
914          getchar();          getchar();
915    
916            section_list_cleanup();
917          article_block_cleanup();          article_block_cleanup();
918          section_list_pool_cleanup();          trie_dict_cleanup();
919    
920            if (unlink(TRIE_DICT_SHM_FILE) < 0)
921            {
922                    log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE);
923                    return -1;
924            }
925    
926          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
927          {          {


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

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