test_challenger_db.c (3616B)
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_INFO, 84 "Creating tables failed\n"); 85 } 86 GNUNET_assert (GNUNET_OK == 87 CHALLENGERDB_preflight (pg)); 88 { 89 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 90 91 FAILIF (0 > 92 CHALLENGERDB_gc (pg, 93 ts)); 94 } 95 result = 0; 96 drop: 97 GNUNET_break (GNUNET_OK == 98 CHALLENGERDB_drop_tables (pg)); 99 CHALLENGERDB_disconnect (pg); 100 pg = NULL; 101 } 102 103 104 int 105 main (int argc, 106 char *const argv[]) 107 { 108 struct GNUNET_CONFIGURATION_Handle *cfg; 109 110 (void) argc; 111 result = EXIT_FAILURE; 112 GNUNET_log_setup (argv[0], 113 "DEBUG", 114 NULL); 115 cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ()); 116 if (GNUNET_OK != 117 GNUNET_CONFIGURATION_parse (cfg, 118 "test_challenger_db_postgres.conf")) 119 { 120 GNUNET_break (0); 121 return EXIT_NOTCONFIGURED; 122 } 123 GNUNET_SCHEDULER_run (&run, cfg); 124 GNUNET_CONFIGURATION_destroy (cfg); 125 return result; 126 } 127 128 129 /* end of test_challenger_db.c */