/[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.20 by sysadm, Sat May 24 13:52:44 2025 UTC Revision 1.24 by sysadm, Mon May 26 03:32:55 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, TRIE_NODE_PER_POOL) < 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)          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 170  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 209  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)                          if (section_list_rw_lock(p_section[i]) < 0)
228                          {                          {
229                                  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);
230                                  break;                                  break;
231                          }                          }
232    
# Line 232  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)          if (section_list_rw_lock(NULL) < 0)
251          {          {
252                  printf("section_list_try_rw_lock(sid = %d) error\n", 0);                  printf("section_list_rw_lock(sid = %d) error\n", 0);
253          }          }
254    
255          if (article_block_reset() != 0)          if (article_block_reset() != 0)
# Line 259  int main(int argc, char *argv[]) Line 274  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
278                  {                  {
279                          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);
280                          break;                          break;
281                  }                  }
282    
# Line 307  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)                  if (section_list_rd_lock(p_section[i]) < 0)
326                  {                  {
327                          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);
328                          break;                          break;
329                  }                  }
330    
# Line 351  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)                  if (section_list_rd_lock(p_section[i]) < 0)
370                  {                  {
371                          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);
372                          break;                          break;
373                  }                  }
374    
# Line 433  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)                  if (section_list_rd_lock(p_section[i]) < 0)
452                  {                  {
453                          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);
454                          break;                          break;
455                  }                  }
456    
# Line 475  int main(int argc, char *argv[]) Line 490  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
494                  {                  {
495                          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);
496                          break;                          break;
497                  }                  }
498    
# Line 620  int main(int argc, char *argv[]) Line 635  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
639                  {                  {
640                          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);
641                          break;                          break;
642                  }                  }
643    
# Line 689  int main(int argc, char *argv[]) Line 704  int main(int argc, char *argv[])
704    
705          printf("Testing #5 ...\n");          printf("Testing #5 ...\n");
706    
707          if (section_list_try_rw_lock(NULL, 1) < 0)          if (section_list_rw_lock(NULL) < 0)
708          {          {
709                  printf("section_list_try_rw_lock(sid = %d) error\n", 0);                  printf("section_list_rw_lock(sid = %d) error\n", 0);
710          }          }
711    
712          if (article_block_reset() != 0)          if (article_block_reset() != 0)
# Line 714  int main(int argc, char *argv[]) Line 729  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
733                  {                  {
734                          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);
735                          break;                          break;
736                  }                  }
737    
# Line 756  int main(int argc, char *argv[]) Line 771  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
775                  {                  {
776                          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);
777                          break;                          break;
778                  }                  }
779    
# Line 789  int main(int argc, char *argv[]) Line 804  int main(int argc, char *argv[])
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)                  if (section_list_rw_lock(p_section[i]) < 0)
808                  {                  {
809                          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);
810                          break;                          break;
811                  }                  }
812    
813                  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)
814                  {                  {
815                          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);
816    
817                          if (section_list_rw_unlock(p_section[i]) < 0)                          if (section_list_rw_unlock(p_section[i]) < 0)
818                          {                          {
# Line 847  int main(int argc, char *argv[]) Line 862  int main(int argc, char *argv[])
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)                  if (section_list_rd_lock(p_section[i]) < 0)
866                  {                  {
867                          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);
868                          break;                          break;
869                  }                  }
870    
# Line 895  int main(int argc, char *argv[]) Line 910  int main(int argc, char *argv[])
910                  }                  }
911          }          }
912    
913            printf("Testing #6 ...\n");
914    
915            for (i = 0; i < section_count; i++)
916            {
917                    if (section_list_rd_lock(p_section[i]) < 0)
918                    {
919                            printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
920                            break;
921                    }
922            }
923    
924            printf("Try rw_lock for 5 sec...\n");
925            if (section_list_try_rw_lock(NULL, 5) == 0)
926            {
927                    printf("section_list_try_rw_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);
928            }
929    
930            for (i = 0; i < section_count; i++)
931            {
932                    if (section_list_rd_unlock(p_section[i]) < 0)
933                    {
934                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
935                            break;
936                    }
937            }
938    
939            if (section_list_try_rw_lock(NULL, 5) < 0)
940            {
941                    printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
942            }
943    
944            for (i = 0; i < section_count; i++)
945            {
946                    if (section_list_try_rd_lock(p_section[i], 0) == 0)
947                    {
948                            printf("section_list_try_rd_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);
949                            break;
950                    }
951            }
952    
953            if (section_list_rw_unlock(NULL) < 0)
954            {
955                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
956            }
957    
958          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
959          getchar();          getchar();
960    
961            section_list_cleanup();
962          article_block_cleanup();          article_block_cleanup();
963          section_list_pool_cleanup();          trie_dict_cleanup();
964    
965            if (unlink(TRIE_DICT_SHM_FILE) < 0)
966            {
967                    log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE);
968                    return -1;
969            }
970    
971          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
972          {          {


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

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