/[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.11 by sysadm, Thu May 22 14:12:33 2025 UTC Revision 1.20 by sysadm, Sat May 24 13:52:44 2025 UTC
# Line 21  Line 21 
21  #include <unistd.h>  #include <unistd.h>
22  #include <errno.h>  #include <errno.h>
23    
24    #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"
25    #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"
26    
27  const char *sname[] = {  const char *sname[] = {
28          "Test",          "Test",
29          "ABCDEFG",          "ABCDEFG",
# Line 43  int main(int argc, char *argv[]) Line 46  int main(int argc, char *argv[])
46  {  {
47          SECTION_LIST *p_section[BBS_max_section];          SECTION_LIST *p_section[BBS_max_section];
48          ARTICLE *p_article;          ARTICLE *p_article;
49            ARTICLE *p_next;
50          ARTICLE article;          ARTICLE article;
51          int block_count;          int block_count;
52          int i, j;          int i, j;
53            int sid;
54          int last_aid;          int last_aid;
55          int current_tid;          int current_tid;
56          int section_first_aid;          int section_first_aid;
# Line 55  int main(int argc, char *argv[]) Line 60  int main(int argc, char *argv[])
60          int32_t page;          int32_t page;
61          int32_t offset;          int32_t offset;
62          int affected_count;          int affected_count;
63            FILE *fp;
64    
65          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
66          {          {
# Line 66  int main(int argc, char *argv[]) Line 72  int main(int argc, char *argv[])
72          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
73    
74          // - 1 to make blocks allocated is less than required, to trigger error handling          // - 1 to make blocks allocated is less than required, to trigger error handling
75          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK - 1;          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;
76    
77            if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
78            {
79                    log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
80                    return -1;
81            }
82            fclose(fp);
83    
84          if (article_block_init("../conf/menu.conf", block_count) < 0)          if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)
85          {          {
86                  log_error("section_data_pool_init() error\n");                  log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE);
87                    return -1;
88            }
89            fclose(fp);
90    
91            if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
92            {
93                    log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
94                    return -2;
95            }
96    
97            if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)
98            {
99                    log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
100                  return -2;                  return -2;
101          }          }
102    
# Line 78  int main(int argc, char *argv[]) Line 104  int main(int argc, char *argv[])
104    
105          last_aid = 0;          last_aid = 0;
106    
107            if (section_list_try_rw_lock(NULL, 1) < 0)
108            {
109                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
110            }
111    
112          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
113          {          {
114                  p_section[i] = section_list_create(sname[i % section_conf_count],                  sid = i * 3 + 1;
115                    p_section[i] = section_list_create(sid,
116                                                                                       sname[i % section_conf_count],
117                                                                                     stitle[i % section_conf_count],                                                                                     stitle[i % section_conf_count],
118                                                                                     master_name[i % section_conf_count]);                                                                                     master_name[i % section_conf_count]);
119                  if (p_section[i] == NULL)                  if (p_section[i] == NULL)
120                  {                  {
121                          log_error("section_data_create(i=%d) error\n", i);                          printf("section_list_create(i = %d) error\n", i);
122                            return -3;
123                    }
124    
125                    if (get_section_index(p_section[i]) != i)
126                    {
127                            printf("get_section_index(i = %d) error\n", i);
128                          return -3;                          return -3;
129                  }                  }
130          }          }
# Line 94  int main(int argc, char *argv[]) Line 133  int main(int argc, char *argv[])
133          {          {
134                  if (section_list_find_by_name(sname[i]) == NULL)                  if (section_list_find_by_name(sname[i]) == NULL)
135                  {                  {
136                          printf("section_data_find_section_by_name(%s) error\n", sname[i]);                          printf("section_list_find_by_name(%s) error\n", sname[i]);
137                            return -3;
138                    }
139            }
140    
141            for (i = 0; i < section_count; i++)
142            {
143                    sid = i * 3 + 1;
144                    if (section_list_find_by_sid(sid) == NULL || section_list_find_by_sid(sid)->sid != sid)
145                    {
146                            printf("section_list_find_by_sid(%d) error\n", sid);
147                          return -3;                          return -3;
148                  }                  }
149          }          }
150    
151            if (section_list_rw_unlock(NULL) < 0)
152            {
153                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
154            }
155    
156          for (j = 0; j < BBS_article_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
157          {          {
158                  for (i = 0; i < section_count; i++)                  for (i = 0; i < section_count; i++)
# Line 107  int main(int argc, char *argv[]) Line 161  int main(int argc, char *argv[])
161    
162                          // Set article data                          // Set article data
163                          article.aid = last_aid;                          article.aid = last_aid;
                         article.cid = article.aid;  
164                          article.tid = 0;                          article.tid = 0;
165                            article.sid = i * 3 + 1;
166                            article.cid = article.aid;
167                          article.uid = 1; // TODO: randomize                          article.uid = 1; // TODO: randomize
168                          article.visible = 1;                          article.visible = 1;
169                          article.excerption = 0;                          article.excerption = 0;
170                          article.ontop = 0;                          article.ontop = 0;
171                          article.lock = 0;                          article.lock = 0;
172    
173                            if (section_list_try_rw_lock(p_section[i], 1) < 0)
174                            {
175                                    printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
176                                    break;
177                            }
178    
179                          if (section_list_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
180                          {                          {
181                                  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);
182                                  break;                                  break;
183                          }                          }
184    
185                            if (section_list_rw_unlock(p_section[i]) < 0)
186                            {
187                                    printf("section_list_rw_unlock(sid = %d) error %d\n", p_section[i]->sid, errno);
188                                    break;
189                            }
190                  }                  }
191          }          }
192    
# Line 130  int main(int argc, char *argv[]) Line 197  int main(int argc, char *argv[])
197    
198          last_aid = 0;          last_aid = 0;
199    
200          for (i = 0; i < section_count; i++)          for (j = 0; j < BBS_article_limit_per_section; j++)
201          {          {
202                  if (p_section[i]->article_count == 0)                  for (i = 0; i < section_count; i++)
                 {  
                         continue;  
                 }  
   
                 for (j = 0; j < p_section[i]->article_count; j++)  
203                  {                  {
204                          last_aid++;                          last_aid++;
205    
# Line 147  int main(int argc, char *argv[]) Line 209  int main(int argc, char *argv[])
209                                  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);
210                          }                          }
211    
212                          p_article = article_block_find_by_index(last_aid - 1);                          if (section_list_try_rw_lock(p_section[i], 1) < 0)
                         if (p_article == NULL || p_article->aid != last_aid)  
213                          {                          {
214                                  printf("article_block_find_by_index() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);                                  printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
215                                    break;
216                          }                          }
217    
218                          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)
219                          {                          {
220                                  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);
221                          }                          }
222    
223                            if (section_list_rw_unlock(p_section[i]) < 0)
224                            {
225                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
226                                    break;
227                            }
228                  }                  }
229    
230                  // 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 164  int main(int argc, char *argv[]) Line 232  int main(int argc, char *argv[])
232    
233          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
234    
235            if (section_list_try_rw_lock(NULL, 1) < 0)
236            {
237                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
238            }
239    
240          if (article_block_reset() != 0)          if (article_block_reset() != 0)
241          {          {
242                  log_error("section_data_free_block(i=%d) error\n", i);                  log_error("article_block_reset() error\n");
243                  return -4;                  return -4;
244          }          }
245    
# Line 175  int main(int argc, char *argv[]) Line 248  int main(int argc, char *argv[])
248                  section_list_reset_articles(p_section[i]);                  section_list_reset_articles(p_section[i]);
249          }          }
250    
251            if (section_list_rw_unlock(NULL) < 0)
252            {
253                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
254            }
255    
256          last_aid = 0;          last_aid = 0;
257    
258          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
259          {          {
260                  section_first_aid = last_aid + 1;                  section_first_aid = last_aid + 1;
261    
262                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
263                    {
264                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
265                            break;
266                    }
267    
268                  for (j = 0; j < BBS_article_limit_per_section; j++)                  for (j = 0; j < BBS_article_limit_per_section; j++)
269                  {                  {
270                          last_aid++;                          last_aid++;
271    
272                          // Set article data                          // Set article data
273                          article.aid = last_aid;                          article.aid = last_aid;
                         article.cid = article.aid;  
274                          // Group articles into group_count topics                          // Group articles into group_count topics
275                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
276                            article.sid = i * 3 + 1;
277                            article.cid = article.aid;
278                          article.uid = 1; // TODO: randomize                          article.uid = 1; // TODO: randomize
279                          article.visible = 1;                          article.visible = 1;
280                          article.excerption = 0;                          article.excerption = 0;
# Line 203  int main(int argc, char *argv[]) Line 288  int main(int argc, char *argv[])
288                          }                          }
289                  }                  }
290    
291                    if (section_list_rw_unlock(p_section[i]) < 0)
292                    {
293                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
294                            break;
295                    }
296    
297                  // 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);
298          }          }
299    
# Line 216  int main(int argc, char *argv[]) Line 307  int main(int argc, char *argv[])
307                  article_count = 0;                  article_count = 0;
308                  last_aid = 0;                  last_aid = 0;
309    
310                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
311                    {
312                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
313                            break;
314                    }
315    
316                  p_article = p_section[i]->p_article_head;                  p_article = p_section[i]->p_article_head;
317    
318                  do                  do
# Line 238  int main(int argc, char *argv[]) Line 335  int main(int argc, char *argv[])
335                          break;                          break;
336                  }                  }
337    
338                    if (section_list_rd_unlock(p_section[i]) < 0)
339                    {
340                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
341                            break;
342                    }
343    
344                  // printf("Verified %d articles in section %d\n", group_count, i);                  // printf("Verified %d articles in section %d\n", group_count, i);
345          }          }
346    
# Line 248  int main(int argc, char *argv[]) Line 351  int main(int argc, char *argv[])
351                          continue;                          continue;
352                  }                  }
353    
354                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
355                    {
356                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
357                            break;
358                    }
359    
360                  if (p_section[i]->topic_count != group_count)                  if (p_section[i]->topic_count != group_count)
361                  {                  {
362                          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 305  int main(int argc, char *argv[]) Line 414  int main(int argc, char *argv[])
414                          {                          {
415                                  printf("Count of articles in topic %d is different from expected %d != %d\n",                                  printf("Count of articles in topic %d is different from expected %d != %d\n",
416                                             j + 1, article_count, p_section[i]->article_count / group_count);                                             j + 1, article_count, p_section[i]->article_count / group_count);
417                                  break;                                  // break;
418                          }                          }
419                  }                  }
420    
421                    if (section_list_rd_unlock(p_section[i]) < 0)
422                    {
423                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
424                            break;
425                    }
426    
427                  // printf("Verified %d topics in section %d\n", group_count, i);                  // printf("Verified %d topics in section %d\n", group_count, i);
428          }          }
429    
# Line 318  int main(int argc, char *argv[]) Line 433  int main(int argc, char *argv[])
433          {          {
434                  last_aid = 0;                  last_aid = 0;
435    
436                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
437                    {
438                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
439                            break;
440                    }
441    
442                  for (j = 0; j < p_section[i]->page_count; j++)                  for (j = 0; j < p_section[i]->page_count; j++)
443                  {                  {
444                          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 342  int main(int argc, char *argv[]) Line 463  int main(int argc, char *argv[])
463                                  }                                  }
464                          }                          }
465                  }                  }
466    
467                    if (section_list_rd_unlock(p_section[i]) < 0)
468                    {
469                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
470                            break;
471                    }
472          }          }
473    
474          printf("Testing #4 ...\n");          printf("Testing #4 ...\n");
475    
476          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
477          {          {
478                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
479                    {
480                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
481                            break;
482                    }
483    
484                  step = i % 10 + 1;                  step = i % 10 + 1;
485                  for (j = group_count; j < BBS_article_limit_per_section; j += step)                  for (j = group_count; j < BBS_article_limit_per_section; j += step)
486                  {                  {
487                          last_aid = i * BBS_article_limit_per_section + j + 1;                          last_aid = i * BBS_article_limit_per_section + j + 1;
488    
489                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
490    
491                          if (p_article == NULL)                          if (p_article == NULL)
492                          {                          {
# Line 410  int main(int argc, char *argv[]) Line 543  int main(int argc, char *argv[])
543                  {                  {
544                          last_aid = i * BBS_article_limit_per_section + j + 1;                          last_aid = i * BBS_article_limit_per_section + j + 1;
545    
546                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
547    
548                          if (p_article == NULL)                          if (p_article == NULL)
549                          {                          {
# Line 447  int main(int argc, char *argv[]) Line 580  int main(int argc, char *argv[])
580    
581                  if (p_section[i]->visible_article_count > 0)                  if (p_section[i]->visible_article_count > 0)
582                  {                  {
583                          printf("Inconsistent invisible count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);                          printf("Inconsistent invisible article count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);
584                            break;
585                    }
586    
587                    if (p_section[i]->visible_topic_count > 0)
588                    {
589                            printf("Inconsistent invisible topic count in section %d, %d > 0\n", i, p_section[i]->visible_topic_count);
590                            break;
591                    }
592    
593                    last_aid = p_section[i]->p_article_head->aid;
594                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
595                    {
596                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
597                            break;
598                    }
599    
600                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
601                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
602                            p_section[i]->page_count)
603                    {
604                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
605                                       "visible_article_count = %d, last_page_visible_count = %d\n",
606                                       i, j,
607                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
608                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
609                                       p_section[i]->page_count, p_section[i]->visible_article_count,
610                                       p_section[i]->last_page_visible_article_count);
611                            break;
612                    }
613    
614                    if (section_list_rw_unlock(p_section[i]) < 0)
615                    {
616                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
617                            break;
618                    }
619            }
620    
621            for (i = 0; i < BBS_max_section; i++)
622            {
623                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
624                    {
625                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
626                            break;
627                    }
628    
629                    affected_count = 0;
630    
631                    for (j = 0; j < BBS_article_limit_per_section; j += 1)
632                    {
633                            last_aid = i * BBS_article_limit_per_section + j + 1;
634    
635                            if (section_list_set_article_visible(p_section[i], last_aid, 1) <= 0)
636                            {
637                                    printf("Error set article %d visible in section %d offset %d\n", last_aid, i, j);
638                                    break;
639                            }
640    
641                            affected_count++;
642                    }
643    
644                    if (affected_count != p_section[i]->article_count)
645                    {
646                            printf("Inconsistent total set visible article count in section %d, %d != %d\n", i, affected_count, p_section[i]->article_count);
647                            break;
648                    }
649    
650                    if (p_section[i]->visible_article_count != p_section[i]->article_count)
651                    {
652                            printf("Inconsistent visible article count in section %d, %d != %d\n", i, p_section[i]->visible_article_count, p_section[i]->article_count);
653                            break;
654                    }
655    
656                    if (p_section[i]->visible_topic_count != group_count)
657                    {
658                            printf("Inconsistent visible topic count in section %d, %d != %d\n", i, p_section[i]->visible_topic_count, group_count);
659                            break;
660                    }
661    
662                    last_aid = p_section[i]->p_article_head->aid;
663                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
664                    {
665                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
666                            break;
667                    }
668    
669                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
670                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
671                            p_section[i]->page_count)
672                    {
673                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
674                                       "visible_article_count = %d, last_page_visible_count = %d\n",
675                                       i, j,
676                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
677                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
678                                       p_section[i]->page_count, p_section[i]->visible_article_count,
679                                       p_section[i]->last_page_visible_article_count);
680                            break;
681                    }
682    
683                    if (section_list_rw_unlock(p_section[i]) < 0)
684                    {
685                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
686                            break;
687                    }
688            }
689    
690            printf("Testing #5 ...\n");
691    
692            if (section_list_try_rw_lock(NULL, 1) < 0)
693            {
694                    printf("section_list_try_rw_lock(sid = %d) error\n", 0);
695            }
696    
697            if (article_block_reset() != 0)
698            {
699                    log_error("article_block_reset() error\n");
700                    return -4;
701            }
702    
703            for (i = 0; i < section_count; i++)
704            {
705                    section_list_reset_articles(p_section[i]);
706            }
707    
708            if (section_list_rw_unlock(NULL) < 0)
709            {
710                    printf("section_list_rw_unlock(sid = %d) error\n", 0);
711            }
712    
713            last_aid = 0;
714    
715            for (i = 0; i < section_count / 2; i++)
716            {
717                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
718                    {
719                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
720                            break;
721                    }
722    
723                    section_first_aid = last_aid + 1;
724    
725                    for (j = 0; j < BBS_article_limit_per_section; j++)
726                    {
727                            last_aid++;
728    
729                            // Set article data
730                            article.aid = last_aid;
731                            // Group articles into group_count topics
732                            article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
733                            article.sid = i * 3 + 1;
734                            article.cid = article.aid;
735                            article.uid = 1; // TODO: randomize
736                            article.visible = 1;
737                            article.excerption = 0;
738                            article.ontop = 0;
739                            article.lock = 0;
740    
741                            if (section_list_append_article(p_section[i], &article) < 0)
742                            {
743                                    printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
744                                    break;
745                            }
746                    }
747    
748                    if (section_list_rw_unlock(p_section[i]) < 0)
749                    {
750                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
751                            break;
752                    }
753    
754                    // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
755            }
756    
757            for (i = 0; i < section_count / 2; i++)
758            {
759                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
760                    {
761                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
762                            break;
763                    }
764    
765                    section_first_aid = p_section[i]->p_article_head->aid;
766    
767                    for (j = 0; j < group_count; j += 2)
768                    {
769                            p_article = section_list_find_article_with_offset(p_section[i], section_first_aid + j, &page, &offset, &p_next);
770                            if (p_article == NULL)
771                            {
772                                    printf("section_list_find_article_with_offset(aid = %d) not found in section %d\n",
773                                               section_first_aid + j, i);
774                                    break;
775                            }
776    
777                            if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != BBS_article_limit_per_section / group_count)
778                            {
779                                    printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
780                            }
781                    }
782    
783                    if (section_list_rw_unlock(p_section[i]) < 0)
784                    {
785                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
786                            break;
787                    }
788            }
789    
790            for (i = 0; i < section_count / 2; i++)
791            {
792                    if (section_list_try_rw_lock(p_section[i], 1) < 0)
793                    {
794                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid);
795                            break;
796                    }
797    
798                    if (section_list_try_rw_lock(p_section[section_count / 2 + i], 1) < 0)
799                    {
800                            printf("section_list_try_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);
801    
802                            if (section_list_rw_unlock(p_section[i]) < 0)
803                            {
804                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
805                            }
806                            break;
807                    }
808    
809                    section_first_aid = p_section[i]->p_article_head->aid;
810    
811                    for (j = 0; j < group_count; j++)
812                    {
813                            affected_count = section_list_move_topic(p_section[i], p_section[section_count / 2 + i], section_first_aid + j);
814    
815                            if (affected_count < 0)
816                            {
817                                    printf("move topic (aid = %d) error from section %d to section %d\n", section_first_aid + j, i, section_count / 2 + i);
818                                    break;
819                            }
820    
821                            if (affected_count != BBS_article_limit_per_section / group_count)
822                            {
823                                    printf("move topic (aid = %d) affected article count %d != %d\n",
824                                               section_first_aid + j, affected_count,
825                                               BBS_article_limit_per_section / group_count);
826                                    // break;
827                            }
828                    }
829    
830                    if (section_list_rw_unlock(p_section[i]) < 0)
831                    {
832                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
833                            break;
834                    }
835    
836                    if (section_list_rw_unlock(p_section[section_count / 2 + i]) < 0)
837                    {
838                            printf("section_list_rw_unlock(sid = %d) error\n", p_section[section_count / 2 + i]->sid);
839    
840                            if (section_list_rw_unlock(p_section[i]) < 0)
841                            {
842                                    printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid);
843                            }
844                            break;
845                    }
846            }
847    
848            for (i = 0; i < section_count; i++)
849            {
850                    if (section_list_try_rd_lock(p_section[i], 1) < 0)
851                    {
852                            printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid);
853                            break;
854                    }
855    
856                    if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
857                    {
858                            printf("Topic count error in section %d, %d != %d\n", i,
859                                       p_section[i]->topic_count, (i < section_count / 2 ? 0 : group_count));
860                            break;
861                    }
862    
863                    if (p_section[i]->visible_topic_count != (i < section_count / 2 ? 0 : group_count / 2))
864                    {
865                            printf("Visible topic count error in section %d, %d != %d\n", i,
866                                       p_section[i]->visible_topic_count, (i < section_count / 2 ? 0 : group_count / 2));
867                            break;
868                    }
869    
870                    if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))
871                    {
872                            printf("Article count error in section %d, %d != %d\n", i,
873                                       p_section[i]->article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section));
874                            break;
875                    }
876    
877                    if (p_section[i]->visible_article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2))
878                    {
879                            printf("Visible article count error in section %d, %d != %d\n", i,
880                                       p_section[i]->visible_article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2));
881                            break;
882                    }
883    
884                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page))
885                    {
886                            printf("Page count error in section %d, %d != %d\n", i,
887                                       p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));
888                            break;
889                    }
890    
891                    if (section_list_rd_unlock(p_section[i]) < 0)
892                    {
893                            printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid);
894                          break;                          break;
895                  }                  }
896          }          }
# Line 456  int main(int argc, char *argv[]) Line 899  int main(int argc, char *argv[])
899          getchar();          getchar();
900    
901          article_block_cleanup();          article_block_cleanup();
902            section_list_pool_cleanup();
903    
904            if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
905            {
906                    log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
907                    return -1;
908            }
909    
910            if (unlink(SECTION_LIST_SHM_FILE) < 0)
911            {
912                    log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE);
913                    return -1;
914            }
915    
916          log_end();          log_end();
917    


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

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