/[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.21 by sysadm, Sun May 25 06:56:48 2025 UTC Revision 1.26 by sysadm, Tue May 27 01:53:42 2025 UTC
# Line 97  int main(int argc, char *argv[]) Line 97  int main(int argc, char *argv[])
97          }          }
98          fclose(fp);          fclose(fp);
99    
100          if (trie_dict_init(TRIE_DICT_SHM_FILE) < 0)          if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0)
101          {          {
102                  printf("trie_dict_init failed\n");                  printf("trie_dict_init failed\n");
103                  return -1;                  return -1;
# Line 119  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)          if (section_list_rw_lock(NULL) < 0)
123          {          {
124                  printf("section_list_try_rw_lock(sid = %d) error\n", 0);                  printf("section_list_rw_lock(sid = %d) error\n", 0);
125          }          }
126    
127          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
# Line 185  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)                          if (section_list_rw_lock(p_section[i]) < 0)
189                          {                          {
190                                  printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                                  printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
191                                  break;                                  break;
192                          }                          }
193    
# Line 210  int main(int argc, char *argv[]) Line 210  int main(int argc, char *argv[])
210                  // 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);
211          }          }
212    
213            if (last_aid != article_block_last_aid())
214            {
215                    printf("last_aid != %d\n", article_block_last_aid());
216            }
217    
218            if (article_block_article_count() != section_count * BBS_article_limit_per_section)
219            {
220                    printf("article_block_article_count() error %d != %d * %d\n",
221                               article_block_article_count(), section_count, BBS_article_limit_per_section);
222            }
223    
224          last_aid = 0;          last_aid = 0;
225    
226          for (j = 0; j < BBS_article_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
# Line 224  int main(int argc, char *argv[]) Line 235  int main(int argc, char *argv[])
235                                  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);
236                          }                          }
237    
238                          if (section_list_try_rw_lock(p_section[i], 1) < 0)                          if (section_list_rw_lock(p_section[i]) < 0)
239                          {                          {
240                                  printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                                  printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
241                                  break;                                  break;
242                          }                          }
243    
# Line 247  int main(int argc, char *argv[]) Line 258  int main(int argc, char *argv[])
258    
259          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
260    
261          if (section_list_try_rw_lock(NULL, 1) < 0)          if (section_list_rw_lock(NULL) < 0)
262          {          {
263                  printf("section_list_try_rw_lock(sid = %d) error\n", 0);                  printf("section_list_rw_lock(sid = %d) error\n", 0);
264          }          }
265    
266          if (article_block_reset() != 0)          if (article_block_reset() != 0)
# Line 274  int main(int argc, char *argv[]) Line 285  int main(int argc, char *argv[])
285          {          {
286                  section_first_aid = last_aid + 1;                  section_first_aid = last_aid + 1;
287    
288                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
289                  {                  {
290                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
291                          break;                          break;
292                  }                  }
293    
# Line 322  int main(int argc, char *argv[]) Line 333  int main(int argc, char *argv[])
333                  article_count = 0;                  article_count = 0;
334                  last_aid = 0;                  last_aid = 0;
335    
336                  if (section_list_try_rd_lock(p_section[i], 1) < 0)                  if (section_list_rd_lock(p_section[i]) < 0)
337                  {                  {
338                          printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
339                          break;                          break;
340                  }                  }
341    
# Line 366  int main(int argc, char *argv[]) Line 377  int main(int argc, char *argv[])
377                          continue;                          continue;
378                  }                  }
379    
380                  if (section_list_try_rd_lock(p_section[i], 1) < 0)                  if (section_list_rd_lock(p_section[i]) < 0)
381                  {                  {
382                          printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
383                          break;                          break;
384                  }                  }
385    
# Line 448  int main(int argc, char *argv[]) Line 459  int main(int argc, char *argv[])
459          {          {
460                  last_aid = 0;                  last_aid = 0;
461    
462                  if (section_list_try_rd_lock(p_section[i], 1) < 0)                  if (section_list_rd_lock(p_section[i]) < 0)
463                  {                  {
464                          printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
465                          break;                          break;
466                  }                  }
467    
# Line 490  int main(int argc, char *argv[]) Line 501  int main(int argc, char *argv[])
501    
502          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
503          {          {
504                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
505                  {                  {
506                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
507                          break;                          break;
508                  }                  }
509    
# Line 635  int main(int argc, char *argv[]) Line 646  int main(int argc, char *argv[])
646    
647          for (i = 0; i < BBS_max_section; i++)          for (i = 0; i < BBS_max_section; i++)
648          {          {
649                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
650                  {                  {
651                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
652                          break;                          break;
653                  }                  }
654    
# Line 704  int main(int argc, char *argv[]) Line 715  int main(int argc, char *argv[])
715    
716          printf("Testing #5 ...\n");          printf("Testing #5 ...\n");
717    
718          if (section_list_try_rw_lock(NULL, 1) < 0)          if (section_list_rw_lock(NULL) < 0)
719          {          {
720                  printf("section_list_try_rw_lock(sid = %d) error\n", 0);                  printf("section_list_rw_lock(sid = %d) error\n", 0);
721          }          }
722    
723          if (article_block_reset() != 0)          if (article_block_reset() != 0)
# Line 729  int main(int argc, char *argv[]) Line 740  int main(int argc, char *argv[])
740    
741          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
742          {          {
743                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
744                  {                  {
745                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
746                          break;                          break;
747                  }                  }
748    
# Line 771  int main(int argc, char *argv[]) Line 782  int main(int argc, char *argv[])
782    
783          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
784          {          {
785                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
786                  {                  {
787                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
788                          break;                          break;
789                  }                  }
790    
# Line 804  int main(int argc, char *argv[]) Line 815  int main(int argc, char *argv[])
815    
816          for (i = 0; i < section_count / 2; i++)          for (i = 0; i < section_count / 2; i++)
817          {          {
818                  if (section_list_try_rw_lock(p_section[i], 1) < 0)                  if (section_list_rw_lock(p_section[i]) < 0)
819                  {                  {
820                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid);
821                          break;                          break;
822                  }                  }
823    
824                  if (section_list_try_rw_lock(p_section[section_count / 2 + i], 1) < 0)                  if (section_list_rw_lock(p_section[section_count / 2 + i]) < 0)
825                  {                  {
826                          printf("section_list_try_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);                          printf("section_list_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);
827    
828                          if (section_list_rw_unlock(p_section[i]) < 0)                          if (section_list_rw_unlock(p_section[i]) < 0)
829                          {                          {
# Line 862  int main(int argc, char *argv[]) Line 873  int main(int argc, char *argv[])
873    
874          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
875          {          {
876                  if (section_list_try_rd_lock(p_section[i], 1) < 0)                  if (section_list_rd_lock(p_section[i]) < 0)
877                  {                  {
878                          printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);                          printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
879                          break;                          break;
880                  }                  }
881    
# Line 910  int main(int argc, char *argv[]) Line 921  int main(int argc, char *argv[])
921                  }                  }
922          }          }
923    
924            printf("Testing #6 ...\n");
925    
926            for (i = 0; i < section_count; i++)
927            {
928                    if (section_list_rd_lock(p_section[i]) < 0)
929                    {
930                            printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
931                            break;
932                    }
933            }
934    
935            printf("Try rw_lock for 5 sec...\n");
936            if (section_list_try_rw_lock(NULL, 5) == 0)
937            {
938                    printf("section_list_try_rw_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);
939            }
940    
941            for (i = 0; i < section_count; i++)
942            {
943                    if (section_list_rd_unlock(p_section[i]) < 0)
944                    {
945                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
946                            break;
947                    }
948            }
949    
950            if (section_list_try_rw_lock(NULL, 5) < 0)
951            {
952                    printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
953            }
954    
955            for (i = 0; i < section_count; i++)
956            {
957                    if (section_list_try_rd_lock(p_section[i], 0) == 0)
958                    {
959                            printf("section_list_try_rd_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);
960                            break;
961                    }
962            }
963    
964            if (section_list_rw_unlock(NULL) < 0)
965            {
966                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
967            }
968    
969          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
970          getchar();          getchar();
971    


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

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