test_ext_api.c (3300B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 4 5 GNUnet is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with GNUnet; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file ext/test_ext_api.c 22 * @brief testcase for ext_api.c 23 */ 24 #include "gnunet_ext_config.h" 25 #include <stddef.h> 26 27 #if HAVE_NETINET_IN_H 28 #include <netinet/in.h> 29 #endif 30 31 #include <gnunet/gnunet_util_lib.h> 32 #include "gnunet_ext_service.h" 33 34 35 /** 36 * Return value from #main(). Set to 0 to mark test as passing. 37 */ 38 static int ok = 1; 39 40 41 /** 42 * Main function of the test. 43 */ 44 static void 45 run (void *cls, 46 char *const *args, 47 const char *cfgfile, 48 const struct GNUNET_CONFIGURATION_Handle *cfg) 49 { 50 ok = 0; 51 } 52 53 54 /** 55 * Launches the gnunet-service-ext and then the #run() function 56 * with some specified arguments, allowing it to then interact 57 * with the 'ext' service. 58 * 59 * Note that you may want to use libgnunettesting or 60 * libgnunettestbed to launch a "full" peer instead of just 61 * a single service. 62 * 63 * @param argc ignored 64 * @param argv ignored 65 * @return 77 if we failed to find gnunet-service-ext 66 */ 67 int 68 main (int argc, 69 char *argv[]) 70 { 71 char *const ext_argv[] = { 72 "test-ext-api", 73 NULL 74 }; 75 struct GNUNET_GETOPT_CommandLineOption options[] = { 76 GNUNET_GETOPT_OPTION_END 77 }; 78 struct GNUNET_OS_Process *proc; 79 char *path; 80 81 GNUNET_log_setup ("test_ext_api", 82 "WARNING", 83 NULL); 84 path = GNUNET_OS_get_libexec_binary_path ("gnunet-service-ext"); 85 if (NULL == path) 86 { 87 fprintf (stderr, 88 "Failed to determine path for `%s'\n", 89 "gnunet-service-ext"); 90 return 77; 91 } 92 proc = GNUNET_OS_start_process (GNUNET_NO, 93 GNUNET_OS_INHERIT_STD_ALL, 94 NULL, 95 NULL, 96 NULL, 97 path, 98 "gnunet-service-ext", 99 NULL); 100 GNUNET_free (path); 101 if (NULL == proc) 102 { 103 fprintf (stderr, 104 "Service executable not found `%s'\n", 105 "gnunet-service-ext"); 106 return 77; 107 } 108 GNUNET_PROGRAM_run (1, 109 ext_argv, 110 "test-ext-api", 111 "nohelp", 112 options, 113 &run, 114 &ok); 115 if (0 != GNUNET_OS_process_kill (proc, 116 SIGTERM)) 117 { 118 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 119 "kill"); 120 ok = 1; 121 } 122 GNUNET_OS_process_wait (proc); 123 GNUNET_OS_process_destroy (proc); 124 return ok; 125 } 126 127 /* end of test_ext_api.c */