test_challenger_db.c (3417B)
1 /* 2 This file is part of Challenger 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 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 challengerdb/test_challenger_db.c 18 * @brief testcase for challenger 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 /** 40 * Global return value for the test. Initially -1, set to 0 upon 41 * completion. Other values indicate some kind of error. 42 */ 43 static int result; 44 45 /** 46 * Handle to the database we are testing. 47 */ 48 static struct CHALLENGERDB_PostgresContext *pg; 49 50 51 /** 52 * Main function that will be run by the scheduler. 53 * 54 * @param cls closure with config 55 */ 56 static void 57 run (void *cls) 58 { 59 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 60 61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 62 "Connecting\n"); 63 if (NULL == (pg = CHALLENGERDB_connect_admin (cfg))) 64 { 65 result = 77; 66 return; 67 } 68 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 69 "Connected\n"); 70 if (GNUNET_OK != 71 CHALLENGERDB_drop_tables (pg)) 72 { 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 74 "Dropping tables failed\n"); 75 } 76 if (GNUNET_OK != 77 CHALLENGERDB_create_tables (pg)) 78 { 79 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 80 "Creating tables failed\n"); 81 goto drop; 82 } 83 GNUNET_assert (GNUNET_OK == 84 CHALLENGERDB_preflight (pg)); 85 { 86 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 87 88 FAILIF (0 > 89 CHALLENGERDB_gc (pg, 90 ts)); 91 } 92 result = 0; 93 drop: 94 GNUNET_break (GNUNET_OK == 95 CHALLENGERDB_drop_tables (pg)); 96 CHALLENGERDB_disconnect (pg); 97 pg = NULL; 98 } 99 100 101 int 102 main (int argc, 103 char *const argv[]) 104 { 105 struct GNUNET_CONFIGURATION_Handle *cfg; 106 107 (void) argc; 108 result = EXIT_FAILURE; 109 GNUNET_log_setup (argv[0], 110 "DEBUG", 111 NULL); 112 cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ()); 113 if (GNUNET_OK != 114 GNUNET_CONFIGURATION_parse (cfg, 115 "test_challenger_db_postgres.conf")) 116 { 117 GNUNET_break (0); 118 return EXIT_NOTCONFIGURED; 119 } 120 GNUNET_SCHEDULER_run (&run, cfg); 121 GNUNET_CONFIGURATION_destroy (cfg); 122 return result; 123 } 124 125 126 /* end of test_challenger_db.c */