test_challenger_db.c (3632B)
1 /* 2 This file is part of 3 (C) 2023 Taler Systems SA 4 5 Challenger is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Challenger is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file sync/test_sync_db.c 18 * @brief testcase for sync postgres db plugin 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <gnunet/gnunet_util_lib.h> 23 #include <taler/taler_util.h> 24 #include "challenger_database_lib.h" 25 #include "challenger-database/drop_tables.h" 26 #include "challenger-database/create_tables.h" 27 #include "challenger-database/preflight.h" 28 #include "challenger-database/gc.h" 29 #include "challenger_util.h" 30 31 32 #define FAILIF(cond) \ 33 do { \ 34 if (! (cond)) { break;} \ 35 GNUNET_break (0); \ 36 goto drop; \ 37 } while (0) 38 39 #define RND_BLK(ptr) \ 40 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ 41 ptr)) 42 43 /** 44 * Global return value for the test. Initially -1, set to 0 upon 45 * completion. Other values indicate some kind of error. 46 */ 47 static int result; 48 49 /** 50 * Handle to the database we are testing. 51 */ 52 static struct CHALLENGERDB_PostgresContext *pg; 53 54 55 /** 56 * Main function that will be run by the scheduler. 57 * 58 * @param cls closure with config 59 */ 60 static void 61 run (void *cls) 62 { 63 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 64 65 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 66 "Connecting\n"); 67 if (NULL == (pg = CHALLENGERDB_connect_admin (cfg))) 68 { 69 result = 77; 70 return; 71 } 72 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 73 "Connected\n"); 74 if (GNUNET_OK != 75 CHALLENGERDB_drop_tables (pg)) 76 { 77 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 78 "Dropping tables failed\n"); 79 } 80 if (GNUNET_OK != 81 CHALLENGERDB_create_tables (pg)) 82 { 83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 84 "Creating tables failed\n"); 85 goto drop; 86 } 87 GNUNET_assert (GNUNET_OK == 88 CHALLENGERDB_preflight (pg)); 89 { 90 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 91 92 FAILIF (0 > 93 CHALLENGERDB_gc (pg, 94 ts)); 95 } 96 result = 0; 97 drop: 98 GNUNET_break (GNUNET_OK == 99 CHALLENGERDB_drop_tables (pg)); 100 CHALLENGERDB_disconnect (pg); 101 pg = NULL; 102 } 103 104 105 int 106 main (int argc, 107 char *const argv[]) 108 { 109 struct GNUNET_CONFIGURATION_Handle *cfg; 110 111 (void) argc; 112 result = EXIT_FAILURE; 113 GNUNET_log_setup (argv[0], 114 "DEBUG", 115 NULL); 116 cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ()); 117 if (GNUNET_OK != 118 GNUNET_CONFIGURATION_parse (cfg, 119 "test_challenger_db_postgres.conf")) 120 { 121 GNUNET_break (0); 122 return EXIT_NOTCONFIGURED; 123 } 124 GNUNET_SCHEDULER_run (&run, cfg); 125 GNUNET_CONFIGURATION_destroy (cfg); 126 return result; 127 } 128 129 130 /* end of test_challenger_db.c */