2017-09-20 17:39:26 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2016-12-05 11:13:20 +00:00
|
|
|
#include "cid/test_cid.h"
|
|
|
|
#include "cmd/ipfs/test_init.h"
|
2017-09-13 10:02:59 +00:00
|
|
|
#include "core/test_api.h"
|
|
|
|
#include "core/test_ping.h"
|
|
|
|
#include "core/test_null.h"
|
|
|
|
#include "core/test_daemon.h"
|
|
|
|
#include "core/test_node.h"
|
2017-07-20 20:16:59 +00:00
|
|
|
#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"
|
2017-08-24 15:08:27 +00:00
|
|
|
#include "journal/test_journal.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"
|
2016-12-14 17:07:43 +00:00
|
|
|
#include "node/test_importer.h"
|
2016-12-30 00:05:44 +00:00
|
|
|
#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"
|
2017-04-13 14:31:58 +00:00
|
|
|
#include "routing/test_routing.h"
|
2017-03-19 12:47:19 +00:00
|
|
|
#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"
|
2017-04-27 05:10:25 +00:00
|
|
|
#include "libp2p/utils/logger.h"
|
2017-09-21 18:59:06 +00:00
|
|
|
#include "namesys/test_namesys.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-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "TESTING %s...\n", name);
|
2016-12-05 11:13:20 +00:00
|
|
|
int retVal = func();
|
|
|
|
if (retVal)
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "%s success!\n", name);
|
2016-12-05 11:13:20 +00:00
|
|
|
else
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "** Uh oh! %s failed.**\n", name);
|
2016-12-05 11:13:20 +00:00
|
|
|
return retVal == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* names[] = {
|
2017-07-20 20:16:59 +00:00
|
|
|
"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-10-04 11:34:37 +00:00
|
|
|
"test_bitswap_retrieve_file_go_remote",
|
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",
|
2017-10-04 11:34:37 +00:00
|
|
|
"test_bitswap_serve_file_go_remote",
|
2016-12-05 11:13:20 +00:00
|
|
|
"test_cid_new_free",
|
|
|
|
"test_cid_cast_multihash",
|
|
|
|
"test_cid_cast_non_multihash",
|
2016-12-12 20:06:17 +00:00
|
|
|
"test_cid_protobuf_encode_decode",
|
2017-09-13 10:02:59 +00:00
|
|
|
"test_core_api_startup_shutdown",
|
2017-09-20 15:50:32 +00:00
|
|
|
"test_core_api_object_cat",
|
2017-10-04 11:34:37 +00:00
|
|
|
"test_core_api_object_cat_binary",
|
2017-09-25 11:57:17 +00:00
|
|
|
"test_core_api_name_resolve",
|
2017-09-25 16:25:34 +00:00
|
|
|
"test_core_api_name_resolve_1",
|
|
|
|
"test_core_api_name_resolve_2",
|
|
|
|
"test_core_api_name_resolve_3",
|
2017-04-17 16:58:47 +00:00
|
|
|
"test_daemon_startup_shutdown",
|
2017-08-21 19:49:21 +00:00
|
|
|
"test_datastore_list_journal",
|
2017-09-07 19:58:02 +00:00
|
|
|
"test_journal_db",
|
2017-08-24 15:08:27 +00:00
|
|
|
"test_journal_encode_decode",
|
2017-08-28 18:04:27 +00:00
|
|
|
"test_journal_server_1",
|
|
|
|
"test_journal_server_2",
|
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",
|
2016-12-14 17:07:43 +00:00
|
|
|
"test_repo_fsrepo_write_read_block",
|
2017-04-17 16:58:47 +00:00
|
|
|
"test_repo_fsrepo_build",
|
2017-03-19 12:47:19 +00:00
|
|
|
"test_routing_supernode_start",
|
2016-12-05 11:13:20 +00:00
|
|
|
"test_get_init_command",
|
2016-12-14 17:07:43 +00:00
|
|
|
"test_import_small_file",
|
2016-12-15 10:40:24 +00:00
|
|
|
"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",
|
2016-12-12 20:06:17 +00:00
|
|
|
"test_node_link_encode_decode",
|
|
|
|
"test_node_encode_decode",
|
2017-04-20 22:56:03 +00:00
|
|
|
"test_node_peerstore",
|
2016-12-05 22:23:58 +00:00
|
|
|
"test_merkledag_add_data",
|
2016-12-12 11:27:06 +00:00
|
|
|
"test_merkledag_get_data",
|
2016-12-15 10:40:24 +00:00
|
|
|
"test_merkledag_add_node",
|
2016-12-19 19:19:43 +00:00
|
|
|
"test_merkledag_add_node_with_links",
|
2017-09-27 15:05:17 +00:00
|
|
|
// 50 below
|
2017-09-14 21:49:19 +00:00
|
|
|
"test_namesys_publisher_publish",
|
2017-09-21 18:59:06 +00:00
|
|
|
"test_namesys_resolver_resolve",
|
2017-05-11 18:53:52 +00:00
|
|
|
"test_resolver_get",
|
2017-07-27 19:33:19 +00:00
|
|
|
"test_routing_find_peer",
|
2017-09-27 15:05:17 +00:00
|
|
|
"test_routing_provide",
|
2017-04-17 04:47:53 +00:00
|
|
|
"test_routing_find_providers",
|
2017-09-28 18:21:34 +00:00
|
|
|
"test_routing_put_value",
|
2017-03-19 19:40:16 +00:00
|
|
|
"test_routing_supernode_get_value",
|
2017-03-23 13:28:35 +00:00
|
|
|
"test_routing_supernode_get_remote_value",
|
2017-04-20 22:56:03 +00:00
|
|
|
"test_routing_retrieve_file_third_party",
|
2017-04-24 21:33:59 +00:00
|
|
|
"test_routing_retrieve_large_file",
|
2016-12-19 22:21:21 +00:00
|
|
|
"test_unixfs_encode_decode",
|
2017-02-23 16:16:23 +00:00
|
|
|
"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",
|
2017-04-17 04:47:53 +00:00
|
|
|
"test_null_add_provider",
|
2017-02-27 17:27:40 +00:00
|
|
|
"test_resolver_remote_get"
|
2016-12-05 11:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int (*funcs[])(void) = {
|
2017-07-20 20:16:59 +00:00
|
|
|
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-10-04 11:34:37 +00:00
|
|
|
test_bitswap_retrieve_file_go_remote,
|
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,
|
2017-10-04 11:34:37 +00:00
|
|
|
test_bitswap_serve_file_go_remote,
|
2016-12-05 11:13:20 +00:00
|
|
|
test_cid_new_free,
|
|
|
|
test_cid_cast_multihash,
|
|
|
|
test_cid_cast_non_multihash,
|
2016-12-12 20:06:17 +00:00
|
|
|
test_cid_protobuf_encode_decode,
|
2017-09-13 10:02:59 +00:00
|
|
|
test_core_api_startup_shutdown,
|
2017-09-20 15:50:32 +00:00
|
|
|
test_core_api_object_cat,
|
2017-10-04 11:34:37 +00:00
|
|
|
test_core_api_object_cat_binary,
|
2017-09-25 11:57:17 +00:00
|
|
|
test_core_api_name_resolve,
|
2017-09-25 16:25:34 +00:00
|
|
|
test_core_api_name_resolve_1,
|
|
|
|
test_core_api_name_resolve_2,
|
|
|
|
test_core_api_name_resolve_3,
|
2017-04-17 16:58:47 +00:00
|
|
|
test_daemon_startup_shutdown,
|
2017-08-21 19:49:21 +00:00
|
|
|
test_datastore_list_journal,
|
2017-09-07 19:58:02 +00:00
|
|
|
test_journal_db,
|
2017-08-24 15:08:27 +00:00
|
|
|
test_journal_encode_decode,
|
2017-08-28 18:04:27 +00:00
|
|
|
test_journal_server_1,
|
|
|
|
test_journal_server_2,
|
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,
|
2016-12-14 17:07:43 +00:00
|
|
|
test_repo_fsrepo_write_read_block,
|
2017-04-17 16:58:47 +00:00
|
|
|
test_repo_fsrepo_build,
|
2017-03-19 12:47:19 +00:00
|
|
|
test_routing_supernode_start,
|
2016-12-05 11:13:20 +00:00
|
|
|
test_get_init_command,
|
2016-12-14 17:07:43 +00:00
|
|
|
test_import_small_file,
|
2016-12-15 10:40:24 +00:00
|
|
|
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,
|
2016-12-12 20:06:17 +00:00
|
|
|
test_node_link_encode_decode,
|
|
|
|
test_node_encode_decode,
|
2017-04-20 22:56:03 +00:00
|
|
|
test_node_peerstore,
|
2016-12-05 22:23:58 +00:00
|
|
|
test_merkledag_add_data,
|
2016-12-12 11:27:06 +00:00
|
|
|
test_merkledag_get_data,
|
2016-12-15 10:40:24 +00:00
|
|
|
test_merkledag_add_node,
|
2016-12-19 19:19:43 +00:00
|
|
|
test_merkledag_add_node_with_links,
|
2017-09-27 15:05:17 +00:00
|
|
|
// 50 below
|
2017-09-14 21:49:19 +00:00
|
|
|
test_namesys_publisher_publish,
|
2017-09-21 18:59:06 +00:00
|
|
|
test_namesys_resolver_resolve,
|
2017-05-11 18:53:52 +00:00
|
|
|
test_resolver_get,
|
2017-07-27 19:33:19 +00:00
|
|
|
test_routing_find_peer,
|
2017-04-17 19:02:33 +00:00
|
|
|
test_routing_provide,
|
2017-09-27 15:05:17 +00:00
|
|
|
test_routing_find_providers,
|
2017-09-28 18:21:34 +00:00
|
|
|
test_routing_put_value,
|
2017-03-19 19:40:16 +00:00
|
|
|
test_routing_supernode_get_value,
|
2017-03-23 13:28:35 +00:00
|
|
|
test_routing_supernode_get_remote_value,
|
2017-04-20 22:56:03 +00:00
|
|
|
test_routing_retrieve_file_third_party,
|
2017-04-24 21:33:59 +00:00
|
|
|
test_routing_retrieve_large_file,
|
2016-12-19 22:21:21 +00:00
|
|
|
test_unixfs_encode_decode,
|
2017-02-23 16:16:23 +00:00
|
|
|
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,
|
2017-04-17 04:47:53 +00:00
|
|
|
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);
|
2017-08-03 19:35:06 +00:00
|
|
|
ptr = strchr(retVal, '\'');
|
2017-05-11 18:53:52 +00:00
|
|
|
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]);
|
2016-12-15 10:40:24 +00:00
|
|
|
int array2_length = sizeof(names) / sizeof(names[0]);
|
|
|
|
if (array_length != array2_length) {
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "Test arrays are not of the same length. Funcs: %d, Names: %d\n", array_length, array2_length);
|
2016-12-15 10:40:24 +00:00
|
|
|
}
|
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]);
|
|
|
|
}
|
2016-12-12 20:06:17 +00:00
|
|
|
}
|
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)
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "***** No tests found *****\n");
|
2016-12-05 18:11:22 +00:00
|
|
|
else {
|
|
|
|
if (counter > 0) {
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "***** There were %d failed (out of %d) test(s) *****\n", counter, tests_ran);
|
2016-12-05 18:11:22 +00:00
|
|
|
} else {
|
2017-09-25 20:11:44 +00:00
|
|
|
fprintf(stderr, "All %d tests passed\n", tests_ran);
|
2016-12-05 18:11:22 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|