test_challenger_db.c (3985B)
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_plugin.h" 25 #include "challenger_database_lib.h" 26 #include "challenger_util.h" 27 28 29 #define FAILIF(cond) \ 30 do { \ 31 if (! (cond)) { break;} \ 32 GNUNET_break (0); \ 33 goto drop; \ 34 } while (0) 35 36 #define RND_BLK(ptr) \ 37 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ 38 ptr)) 39 40 /** 41 * Global return value for the test. Initially -1, set to 0 upon 42 * completion. Other values indicate some kind of error. 43 */ 44 static int result; 45 46 /** 47 * Handle to the plugin we are testing. 48 */ 49 static struct CHALLENGER_DatabasePlugin *plugin; 50 51 52 /** 53 * Main function that will be run by the scheduler. 54 * 55 * @param cls closure with config 56 */ 57 static void 58 run (void *cls) 59 { 60 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 61 62 if (NULL == (plugin = CHALLENGER_DB_plugin_load (cfg, 63 true))) 64 { 65 result = 77; 66 return; 67 } 68 if (GNUNET_OK != 69 plugin->drop_tables (plugin->cls)) 70 { 71 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 72 "Dropping tables failed\n"); 73 } 74 if (GNUNET_OK != 75 plugin->create_tables (plugin->cls)) 76 { 77 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 78 "Creating tables failed\n"); 79 } 80 GNUNET_assert (GNUNET_OK == 81 plugin->preflight (plugin->cls)); 82 { 83 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 84 85 FAILIF (0 > 86 plugin->gc (plugin->cls, 87 ts)); 88 } 89 result = 0; 90 drop: 91 GNUNET_break (GNUNET_OK == 92 plugin->drop_tables (plugin->cls)); 93 CHALLENGER_DB_plugin_unload (plugin); 94 plugin = NULL; 95 } 96 97 98 int 99 main (int argc, 100 char *const argv[]) 101 { 102 const char *plugin_name; 103 char *config_filename; 104 char *testname; 105 struct GNUNET_CONFIGURATION_Handle *cfg; 106 107 (void) argc; 108 result = EXIT_FAILURE; 109 if (NULL == (plugin_name = strrchr (argv[0], (int) '-'))) 110 { 111 GNUNET_break (0); 112 return EXIT_FAILURE; 113 } 114 GNUNET_log_setup (argv[0], 115 "DEBUG", 116 NULL); 117 plugin_name++; 118 (void) GNUNET_asprintf (&testname, 119 "%s", 120 plugin_name); 121 (void) GNUNET_asprintf (&config_filename, 122 "test_challenger_db_%s.conf", 123 testname); 124 cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ()); 125 if (GNUNET_OK != 126 GNUNET_CONFIGURATION_parse (cfg, 127 config_filename)) 128 { 129 GNUNET_break (0); 130 GNUNET_free (config_filename); 131 GNUNET_free (testname); 132 return EXIT_NOTCONFIGURED; 133 } 134 GNUNET_SCHEDULER_run (&run, cfg); 135 GNUNET_CONFIGURATION_destroy (cfg); 136 GNUNET_free (config_filename); 137 GNUNET_free (testname); 138 return result; 139 } 140 141 142 /* end of test_challenger_db.c */