c-ipfs/test/testit.c

226 lines
6.2 KiB
C
Raw Normal View History

2016-12-05 11:13:20 +00:00
#include "cid/test_cid.h"
#include "cmd/ipfs/test_init.h"
#include "exchange/test_bitswap.h"
2017-07-24 14:09:22 +00:00
#include "exchange/test_bitswap_request_queue.h"
2016-12-05 11:13:20 +00:00
#include "flatfs/test_flatfs.h"
2016-12-05 15:50:17 +00:00
#include "merkledag/test_merkledag.h"
2016-12-05 11:13:20 +00:00
#include "node/test_node.h"
#include "node/test_importer.h"
#include "node/test_resolver.h"
2016-12-05 11:13:20 +00:00
#include "repo/test_repo_bootstrap_peers.h"
#include "repo/test_repo_config.h"
#include "repo/test_repo_fsrepo.h"
#include "repo/test_repo_identity.h"
#include "routing/test_routing.h"
#include "routing/test_supernode.h"
2016-12-05 11:13:20 +00:00
#include "storage/test_ds_helper.h"
#include "storage/test_datastore.h"
#include "storage/test_blocks.h"
2016-12-19 19:19:43 +00:00
#include "storage/test_unixfs.h"
#include "core/test_ping.h"
#include "core/test_null.h"
#include "core/test_daemon.h"
#include "core/test_node.h"
2017-04-27 05:10:25 +00:00
#include "libp2p/utils/logger.h"
2016-12-04 20:13:57 +00:00
2016-12-05 11:13:20 +00:00
int testit(const char* name, int (*func)(void)) {
2017-04-27 20:52:20 +00:00
printf("TESTING %s...\n", name);
2016-12-05 11:13:20 +00:00
int retVal = func();
if (retVal)
printf("%s success!\n", name);
else
printf("** Uh oh! %s failed.**\n", name);
return retVal == 0;
}
const char* names[] = {
"test_bitswap_new_free",
2017-07-24 14:09:22 +00:00
"test_bitswap_peer_request_queue_new",
2017-07-26 14:48:04 +00:00
"test_bitswap_retrieve_file",
2017-07-31 15:01:06 +00:00
"test_bitswap_retrieve_file_known_remote",
"test_bitswap_retrieve_file_remote",
2017-07-27 17:05:41 +00:00
"test_bitswap_retrieve_file_third_party",
2016-12-05 11:13:20 +00:00
"test_cid_new_free",
"test_cid_cast_multihash",
"test_cid_cast_non_multihash",
"test_cid_protobuf_encode_decode",
"test_daemon_startup_shutdown",
2016-12-05 11:13:20 +00:00
"test_repo_config_new",
"test_repo_config_init",
"test_repo_config_write",
"test_repo_config_identity_new",
"test_repo_config_identity_private_key",
"test_repo_fsrepo_write_read_block",
"test_repo_fsrepo_build",
"test_routing_supernode_start",
2016-12-05 11:13:20 +00:00
"test_get_init_command",
"test_import_small_file",
"test_import_large_file",
2016-12-05 11:13:20 +00:00
"test_repo_fsrepo_open_config",
"test_flatfs_get_directory",
"test_flatfs_get_filename",
"test_flatfs_get_full_filename",
"test_ds_key_from_binary",
"test_blocks_new",
"test_repo_bootstrap_peers_init",
"test_ipfs_datastore_put",
2016-12-05 15:50:17 +00:00
"test_node",
"test_node_link_encode_decode",
"test_node_encode_decode",
"test_node_peerstore",
"test_merkledag_add_data",
2016-12-12 11:27:06 +00:00
"test_merkledag_get_data",
"test_merkledag_add_node",
2016-12-19 19:19:43 +00:00
"test_merkledag_add_node_with_links",
2017-05-11 18:53:52 +00:00
"test_resolver_get",
2017-07-27 19:33:19 +00:00
"test_routing_find_peer",
"test_routing_provide" /*,
"test_routing_find_providers",
2017-03-19 19:40:16 +00:00
"test_routing_supernode_get_value",
"test_routing_supernode_get_remote_value",
"test_routing_retrieve_file_third_party",
"test_routing_retrieve_large_file",
2016-12-19 22:21:21 +00:00
"test_unixfs_encode_decode",
"test_unixfs_encode_smallfile",
2017-02-27 17:27:40 +00:00
"test_ping",
2017-04-03 16:55:36 +00:00
"test_ping_remote",
"test_null_add_provider",
2017-02-27 17:27:40 +00:00
"test_resolver_remote_get"
2017-04-27 20:52:20 +00:00
*/
2016-12-05 11:13:20 +00:00
};
int (*funcs[])(void) = {
test_bitswap_new_free,
2017-07-24 14:09:22 +00:00
test_bitswap_peer_request_queue_new,
2017-07-26 14:48:04 +00:00
test_bitswap_retrieve_file,
2017-07-31 15:01:06 +00:00
test_bitswap_retrieve_file_known_remote,
test_bitswap_retrieve_file_remote,
2017-07-27 17:05:41 +00:00
test_bitswap_retrieve_file_third_party,
2016-12-05 11:13:20 +00:00
test_cid_new_free,
test_cid_cast_multihash,
test_cid_cast_non_multihash,
test_cid_protobuf_encode_decode,
test_daemon_startup_shutdown,
2016-12-05 11:13:20 +00:00
test_repo_config_new,
test_repo_config_init,
test_repo_config_write,
test_repo_config_identity_new,
test_repo_config_identity_private_key,
test_repo_fsrepo_write_read_block,
test_repo_fsrepo_build,
test_routing_supernode_start,
2016-12-05 11:13:20 +00:00
test_get_init_command,
test_import_small_file,
test_import_large_file,
2016-12-05 11:13:20 +00:00
test_repo_fsrepo_open_config,
test_flatfs_get_directory,
test_flatfs_get_filename,
test_flatfs_get_full_filename,
test_ds_key_from_binary,
test_blocks_new,
test_repo_bootstrap_peers_init,
test_ipfs_datastore_put,
2016-12-05 15:50:17 +00:00
test_node,
test_node_link_encode_decode,
test_node_encode_decode,
test_node_peerstore,
test_merkledag_add_data,
2016-12-12 11:27:06 +00:00
test_merkledag_get_data,
test_merkledag_add_node,
2016-12-19 19:19:43 +00:00
test_merkledag_add_node_with_links,
2017-05-11 18:53:52 +00:00
test_resolver_get,
2017-07-27 19:33:19 +00:00
test_routing_find_peer,
test_routing_provide /*,
test_routing_find_providers,
test_routing_provide,
2017-03-19 19:40:16 +00:00
test_routing_supernode_get_value,
test_routing_supernode_get_remote_value,
test_routing_retrieve_file_third_party,
test_routing_retrieve_large_file,
2016-12-19 22:21:21 +00:00
test_unixfs_encode_decode,
test_unixfs_encode_smallfile,
2017-02-27 17:27:40 +00:00
test_ping,
2017-04-03 16:55:36 +00:00
test_ping_remote,
test_null_add_provider,
2017-05-11 18:53:52 +00:00
test_resolver_remote_get
*/
2016-12-05 11:13:20 +00:00
};
/**
2017-05-11 18:53:52 +00:00
* Pull the next test name from the command line
* @param the count of arguments on the command line
* @param argv the command line arguments
* @param arg_number the current argument we want
* @returns a null terminated string of the next test or NULL
*/
char* get_test(int argc, char** argv, int arg_number) {
char* retVal = NULL;
char* ptr = NULL;
if (argc > arg_number) {
ptr = argv[arg_number];
if (ptr[0] == '\'')
ptr++;
retVal = malloc(strlen(ptr) + 1);
strcpy(retVal, ptr);
ptr = strchr(ptr, '\'');
if (ptr != NULL)
ptr[0] = 0;
}
return retVal;
}
/**
* run certain tests or run all
2016-12-05 11:13:20 +00:00
*/
int main(int argc, char** argv) {
int counter = 0;
2016-12-05 18:11:22 +00:00
int tests_ran = 0;
2017-05-11 18:53:52 +00:00
char* test_wanted = NULL;
int certain_tests = 0;
int current_test_arg = 1;
2016-12-05 11:13:20 +00:00
if(argc > 1) {
2017-05-11 18:53:52 +00:00
certain_tests = 1;
2016-12-05 11:13:20 +00:00
}
2016-12-05 18:11:22 +00:00
int array_length = sizeof(funcs) / sizeof(funcs[0]);
int array2_length = sizeof(names) / sizeof(names[0]);
if (array_length != array2_length) {
printf("Test arrays are not of the same length. Funcs: %d, Names: %d\n", array_length, array2_length);
}
2017-05-11 18:53:52 +00:00
test_wanted = get_test(argc, argv, current_test_arg);
while (!certain_tests || test_wanted != NULL) {
for (int i = 0; i < array_length; i++) {
if (certain_tests) {
// get the test we currently want from the command line
const char* currName = names[i];
if (strcmp(currName, test_wanted) == 0) {
tests_ran++;
counter += testit(names[i], funcs[i]);
}
}
2017-05-11 18:53:52 +00:00
else
if (!certain_tests) {
tests_ran++;
counter += testit(names[i], funcs[i]);
}
2016-12-05 18:11:22 +00:00
}
2017-05-11 18:53:52 +00:00
if (!certain_tests) // we did them all, not certain ones
break;
free(test_wanted);
test_wanted = get_test(argc, argv, ++current_test_arg);
2016-12-05 11:13:20 +00:00
}
2016-12-05 18:11:22 +00:00
if (tests_ran == 0)
printf("***** No tests found *****\n");
else {
if (counter > 0) {
printf("***** There were %d failed (out of %d) test(s) *****\n", counter, tests_ran);
2016-12-05 18:11:22 +00:00
} else {
printf("All %d tests passed\n", tests_ran);
}
2016-12-05 11:13:20 +00:00
}
2017-04-27 05:10:25 +00:00
libp2p_logger_free();
2017-05-11 19:30:52 +00:00
fclose(stdin);
fclose(stdout);
fclose(stderr);
2016-12-05 11:13:20 +00:00
return 1;
}