![]() |
GNUnet
0.11.x
|
convenience API for writing testcases for GNUnet Many testcases need to start and stop a peer/service and this library is supposed to make that easier for TESTCASES. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
Go to the source code of this file.
Data Structures | |
struct | SharedServiceInstance |
struct | SharedService |
The structure for identifying a shared service. More... | |
struct | GNUNET_TESTING_System |
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths and ports. More... | |
struct | GNUNET_TESTING_Peer |
Handle for a GNUnet peer controlled by testing. More... | |
struct | UpdateContext |
Closure for update_rel_sum() and update_abs_sum(). More... | |
struct | ServiceContext |
Structure for holding service data. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) |
#define | LOW_PORT 12000 |
Lowest port used for GNUnet testing. More... | |
#define | HIGH_PORT 56000 |
Highest port used for GNUnet testing. More... | |
Functions | |
static int | hostkeys_load (struct GNUNET_TESTING_System *system) |
Testing includes a number of pre-created hostkeys for faster peer startup. More... | |
static void | hostkeys_unload (struct GNUNET_TESTING_System *system) |
Function to remove the loaded hostkeys. More... | |
static void | cfg_copy_iterator (void *cls, const char *section, const char *option, const char *value) |
Function to iterate over options. More... | |
struct GNUNET_TESTING_System * | GNUNET_TESTING_system_create_with_portrange (const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services, uint16_t lowport, uint16_t highport) |
Create a system handle. More... | |
struct GNUNET_TESTING_System * | GNUNET_TESTING_system_create (const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services) |
Create a system handle. More... | |
static void | cleanup_shared_service_instance (struct SharedServiceInstance *i) |
static int | start_shared_service_instance (struct SharedServiceInstance *i) |
static void | stop_shared_service_instance (struct SharedServiceInstance *i) |
void | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, int remove_paths) |
Free system resources. More... | |
uint16_t | GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) |
Reserve a TCP or UDP port for a peer. More... | |
void | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, uint16_t port) |
Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy()). More... | |
struct GNUNET_CRYPTO_EddsaPrivateKey * | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id) |
Testing includes a number of pre-created hostkeys for faster peer startup. More... | |
static void | update_config (void *cls, const char *section, const char *option, const char *value) |
Function to iterate over options. More... | |
static void | update_config_sections (void *cls, const char *section) |
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sections. More... | |
static struct SharedServiceInstance * | associate_shared_service (struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg) |
static int | GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports) |
Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system. More... | |
int | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg) |
Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system. More... | |
struct GNUNET_TESTING_Peer * | GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg) |
Configure a GNUnet peer. More... | |
void | GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id) |
Obtain the peer identity from a peer handle. More... | |
int | GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) |
Start the peer. More... | |
int | GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer) |
Sends SIGTERM to the peer's main process. More... | |
int | GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer) |
Waits for a peer to terminate. More... | |
int | GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) |
Stop the peer. More... | |
static void | disconn_status (void *cls, int connected) |
Function called whenever we connect to or disconnect from ARM. More... | |
int | GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, GNUNET_TESTING_PeerStopCallback cb, void *cb_cls) |
Stop a peer asynchronously using ARM API. More... | |
void | GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer) |
Cancel a previous asynchronous peer stop request. More... | |
void | GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) |
Destroy the peer. More... | |
int | GNUNET_TESTING_peer_run (const char *testdir, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls) |
Start a single peer and run a test using the testing library. More... | |
static void | service_run_main (void *cls) |
Callback to be called when SCHEDULER has been started. More... | |
int | GNUNET_TESTING_service_run (const char *testdir, const char *service_name, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls) |
Start a single service (no ARM, except of course if the given service name is 'arm') and run a test using the testing library. More... | |
char * | GNUNET_TESTING_get_testname_from_underscore (const char *argv0) |
Sometimes we use the binary name to determine which specific test to run. More... | |
convenience API for writing testcases for GNUnet Many testcases need to start and stop a peer/service and this library is supposed to make that easier for TESTCASES.
Normal programs should always use functions from gnunet_{util,arm}_lib.h. This API is ONLY for writing testcases (or internal use of the testbed).
Definition in file testing.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "testing-api", __VA_ARGS__) |
Definition at line 37 of file testing.c.
Referenced by GNUNET_TESTING_hostkey_get(), GNUNET_TESTING_release_port(), GNUNET_TESTING_reserve_port(), GNUNET_TESTING_service_run(), hostkeys_load(), and stop_shared_service_instance().
#define LOW_PORT 12000 |
Lowest port used for GNUnet testing.
Should be high enough to not conflict with other applications running on the hosts but be low enough to not conflict with client-ports (typically starting around 32k).
Definition at line 46 of file testing.c.
Referenced by GNUNET_TESTING_system_create().
#define HIGH_PORT 56000 |
Highest port used for GNUnet testing.
Should be low enough to not conflict with the port range for "local" ports (client apps; see /proc/sys/net/ipv4/ip_local_port_range on Linux for example).
Definition at line 53 of file testing.c.
Referenced by GNUNET_TESTING_system_create().
|
static |
Testing includes a number of pre-created hostkeys for faster peer startup.
This function loads such keys into memory from a file.
system | the testing system handle |
Definition at line 246 of file testing.c.
References _, GNUNET_DISK_FileHandle::fd, filename, fs, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SYSERR, GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_YES, GNUNET_TESTING_System::hostkeys_data, LOG, GNUNET_TESTING_System::map, and GNUNET_TESTING_System::total_hostkeys.
Referenced by GNUNET_TESTING_system_create_with_portrange().
|
static |
Function to remove the loaded hostkeys.
system | the testing system handle |
Definition at line 309 of file testing.c.
References GNUNET_break, GNUNET_DISK_file_unmap(), GNUNET_TESTING_System::hostkeys_data, GNUNET_TESTING_System::map, and GNUNET_TESTING_System::total_hostkeys.
Referenced by GNUNET_TESTING_service_run(), and GNUNET_TESTING_system_destroy().
|
static |
Function to iterate over options.
cls | closure |
section | name of the section |
option | name of the option |
value | value of the option |
Definition at line 329 of file testing.c.
References GNUNET_CONFIGURATION_set_value_string().
Referenced by associate_shared_service(), and GNUNET_TESTING_system_create_with_portrange().
|
static |
Definition at line 463 of file testing.c.
References SharedServiceInstance::cfg_fn, GNUNET_break, GNUNET_free, SharedServiceInstance::n_refs, SharedServiceInstance::port_str, SharedServiceInstance::proc, and SharedServiceInstance::unix_sock.
Referenced by associate_shared_service(), and GNUNET_TESTING_system_destroy().
|
static |
Definition at line 479 of file testing.c.
References SharedServiceInstance::cfg_fn, GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_start_process(), GNUNET_SYSERR, SharedServiceInstance::proc, SharedService::sname, and SharedServiceInstance::ss.
Referenced by GNUNET_TESTING_peer_start().
|
static |
Definition at line 506 of file testing.c.
References GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_TERM_SIG, LOG, SharedServiceInstance::n_refs, SharedServiceInstance::proc, SharedService::sname, and SharedServiceInstance::ss.
Referenced by GNUNET_TESTING_peer_kill(), and GNUNET_TESTING_system_destroy().
|
static |
Function to iterate over options.
Copies the options to the target configuration, updating PORT values as needed.
cls | the UpdateContext |
section | name of the section |
option | name of the option |
value | value of the option |
Definition at line 779 of file testing.c.
References UpdateContext::cfg, GNUNET_array_append, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, UpdateContext::gnunet_home, GNUNET_OK, GNUNET_snprintf(), GNUNET_SYSERR, GNUNET_TESTING_reserve_port(), GNUNET_YES, GNUNET_TESTING_System::hostname, UpdateContext::nports, PATH_MAX, UpdateContext::ports, UpdateContext::status, UpdateContext::system, and uc.
Referenced by GNUNET_TESTING_configuration_create_().
|
static |
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sections.
cls | the UpdateContext |
section | name of the section |
Definition at line 876 of file testing.c.
References UpdateContext::cfg, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_YES, key, UpdateContext::system, GNUNET_TESTING_System::trusted_ip, and uc.
Referenced by GNUNET_TESTING_configuration_create_().
|
static |
Definition at line 982 of file testing.c.
References SharedService::cfg, cfg_copy_iterator(), SharedServiceInstance::cfg_fn, cleanup_shared_service_instance(), GNUNET_array_append, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_iterate_section_values(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_free, GNUNET_new, GNUNET_SYSERR, GNUNET_TESTING_reserve_port(), SharedService::instances, SharedService::n_instances, SharedService::n_peers, port, SharedServiceInstance::port_str, SharedService::share, SharedService::sname, SharedServiceInstance::ss, GNUNET_TESTING_System::tmppath, and SharedServiceInstance::unix_sock.
Referenced by GNUNET_TESTING_peer_configure().
|
static |
Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system.
The default configuration will be available in PATHS section under the option DEFAULTCONFIG after the call. GNUNET_HOME is also set in PATHS section to the temporary directory specific to this configuration. If we run out of "*port" numbers, return GNUNET_SYSERR.
This is primarily a helper function used internally by 'GNUNET_TESTING_peer_configure'.
system | system to use to coordinate resource usage |
cfg | template configuration to update |
ports | array with port numbers used in the created configuration. Will be updated upon successful return. Can be NULL |
nports | the size of the `ports' array. Will be updated. |
Definition at line 1075 of file testing.c.
References cfg, UpdateContext::cfg, GNUNET_asprintf(), GNUNET_CONFIGURATION_iterate(), GNUNET_CONFIGURATION_iterate_sections(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, UpdateContext::gnunet_home, GNUNET_OK, UpdateContext::nports, GNUNET_TESTING_System::path_counter, UpdateContext::ports, UpdateContext::status, UpdateContext::system, GNUNET_TESTING_System::tmppath, update_config(), and update_config_sections().
Referenced by GNUNET_TESTING_configuration_create(), and GNUNET_TESTING_peer_configure().
|
static |
Function called whenever we connect to or disconnect from ARM.
cls | closure |
connected | GNUNET_YES if connected, GNUNET_NO if disconnected, GNUNET_SYSERR on error. |
Definition at line 1474 of file testing.c.
References GNUNET_TESTING_Peer::ah, GNUNET_TESTING_Peer::cb, GNUNET_TESTING_Peer::cb_cls, GNUNET_ARM_disconnect(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_peer_kill(), GNUNET_TESTING_peer_wait(), GNUNET_YES, and peer.
Referenced by GNUNET_TESTING_peer_stop_async().
|
static |
Callback to be called when SCHEDULER has been started.
cls | the ServiceContext |
Definition at line 1632 of file testing.c.
References ServiceContext::cfg, ServiceContext::peer, sc, ServiceContext::tm, and ServiceContext::tm_cls.
Referenced by GNUNET_TESTING_service_run().