/[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.35 by sysadm, Fri Oct 24 02:00:59 2025 UTC Revision 1.42 by sysadm, Tue Nov 18 14:56:56 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          test_section_list.c  -  description  /*
3                                                           -------------------   * test_section_list
4          Copyright            : (C) 2004-2025 by Leaflet   *   - tester for data models and basic operations of section and article
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "log.h"  #include "log.h"
# Line 23  Line 19 
19  #include <stdio.h>  #include <stdio.h>
20  #include <unistd.h>  #include <unistd.h>
21    
22  #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"  static const char ARTICLE_BLOCK_SHM_FILE[] = "~article_block_shm.dat";
23  #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"  static const char SECTION_LIST_SHM_FILE[] = "~section_list_shm.dat";
24  #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"  static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat";
25  #define USER_LIST_SHM_FILE "~user_list_shm.dat"  static const char USER_LIST_SHM_FILE[] = "~user_list_shm.dat";
26    
27  const char *sname[] = {  const char *sname[] = {
28          "Test",          "Test",
# Line 76  int main(int argc, char *argv[]) Line 72  int main(int argc, char *argv[])
72          log_error_redir(STDERR_FILENO);          log_error_redir(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;          block_count = BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block;
76    
77          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
78          {          {
# Line 562  int main(int argc, char *argv[]) Line 558  int main(int argc, char *argv[])
558                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
559                          p_section[i]->page_count)                          p_section[i]->page_count)
560                  {                  {
561                          printf("Inconsistent page count in section %d offset %d, %d != %d, "                          printf("#1 Inconsistent page count in section %d offset %d, %d != %d, "
562                                     "visible_article_count = %d, last_page_visible_count = %d\n",                                     "visible_article_count = %d, last_page_visible_count = %d\n",
563                                     i, j,                                     i, j,
564                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +
# Line 645  int main(int argc, char *argv[]) Line 641  int main(int argc, char *argv[])
641                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
642                          p_section[i]->page_count)                          p_section[i]->page_count)
643                  {                  {
644                          printf("Inconsistent page count in section %d offset %d, %d != %d, "                          printf("#2 Inconsistent page count in section %d offset %d, %d != %d, "
645                                     "visible_article_count = %d, last_page_visible_count = %d\n",                                     "visible_article_count = %d, last_page_visible_count = %d\n",
646                                     i, j,                                     i, j,
647                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +
# Line 714  int main(int argc, char *argv[]) Line 710  int main(int argc, char *argv[])
710                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=                                  (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
711                          p_section[i]->page_count)                          p_section[i]->page_count)
712                  {                  {
713                          printf("Inconsistent page count in section %d offset %d, %d != %d, "                          printf("#3 Inconsistent page count in section %d offset %d, %d != %d, "
714                                     "visible_article_count = %d, last_page_visible_count = %d\n",                                     "visible_article_count = %d, last_page_visible_count = %d\n",
715                                     i, j,                                     i, j,
716                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +                                     p_section[i]->visible_article_count / BBS_article_limit_per_page +
# Line 951  int main(int argc, char *argv[]) Line 947  int main(int argc, char *argv[])
947                  }                  }
948          }          }
949    
950    #if !defined(__CYGWIN__)
951          printf("Try rw_lock for 5 sec...\n");          printf("Try rw_lock for 5 sec...\n");
952          if (section_list_try_rw_lock(NULL, 5) == 0)          if (section_list_try_rw_lock(NULL, 5) == 0)
953          {          {
954                  printf("section_list_try_rw_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);                  printf("section_list_try_rw_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid);
955          }          }
956    #endif
957    
958          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
959          {          {
# Line 971  int main(int argc, char *argv[]) Line 969  int main(int argc, char *argv[])
969                  printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);                  printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid);
970          }          }
971    
972    #if !defined(__CYGWIN__)
973          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
974          {          {
975                  if (section_list_try_rd_lock(p_section[i], 0) == 0)                  if (section_list_try_rd_lock(p_section[i], 0) == 0)
# Line 979  int main(int argc, char *argv[]) Line 978  int main(int argc, char *argv[])
978                          break;                          break;
979                  }                  }
980          }          }
981    #endif
982    
983          if (section_list_rw_unlock(NULL) < 0)          if (section_list_rw_unlock(NULL) < 0)
984          {          {


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

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