Added test for api

This commit is contained in:
jmjatlanta 2017-09-13 05:02:59 -05:00
parent bf7ba9049c
commit d0eb0acc9d
8 changed files with 32 additions and 15 deletions

View file

@ -7,7 +7,7 @@ endif
LFLAGS = LFLAGS =
DEPS = builder.h ipfs_node.h DEPS = builder.h ipfs_node.h
OBJS = builder.o daemon.o null.o ping.o bootstrap.o ipfs_node.o OBJS = builder.o daemon.o null.o ping.o bootstrap.o ipfs_node.o api.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View file

@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/uio.h>
#include <fcntl.h> #include <fcntl.h>
@ -44,7 +45,7 @@ int find_chunk(char *buf, const size_t buf_size, size_t *pos, size_t *size)
char *p = NULL; char *p = NULL;
*size = strtol(buf, &p, 16); *size = strtol(buf, &p, 16);
if (*size < 0 || !p || p < buf || p > (buf + 10)) { if (!p || p < buf || p > (buf + 10)) {
return 0; return 0;
} }
*pos = (int)(p - buf); *pos = (int)(p - buf);

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <pthread.h>
#ifdef __x86_64__ #ifdef __x86_64__
#define INT_TYPE uint64_t #define INT_TYPE uint64_t
#else #else

View file

@ -7,7 +7,7 @@ OBJS = main.o \
../cid/cid.o \ ../cid/cid.o \
../cmd/ipfs/init.o \ ../cmd/ipfs/init.o \
../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \ ../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \
../core/builder.o ../core/daemon.o ../core/null.o ../core/ping.o ../core/bootstrap.o ../core/ipfs_node.o \ ../core/*.o \
../datastore/ds_helper.o \ ../datastore/ds_helper.o \
../datastore/key.o \ ../datastore/key.o \
../dnslink/*.o \ ../dnslink/*.o \

View file

@ -7,12 +7,7 @@ OBJS = testit.o test_helper.o \
../cid/cid.o \ ../cid/cid.o \
../cmd/ipfs/init.o \ ../cmd/ipfs/init.o \
../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \ ../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \
../core/builder.o \ ../core/*.o \
../core/daemon.o \
../core/null.o \
../core/bootstrap.o \
../core/ping.o \
../core/ipfs_node.o \
../datastore/ds_helper.o \ ../datastore/ds_helper.o \
../exchange/bitswap/*.o \ ../exchange/bitswap/*.o \
../flatfs/flatfs.o \ ../flatfs/flatfs.o \

15
test/core/test_api.h Normal file
View file

@ -0,0 +1,15 @@
#include "ipfs/core/api.h"
#include "libp2p/utils/logger.h"
int test_core_api_startup_shutdown() {
if (!api_start(1234, 10, 5)) {
libp2p_logger_error("test_api", "api_start failed.\n");
return 0;
}
sleep(5);
if (!api_stop()) {
libp2p_logger_error("test_api", "api_stop failed.\n");
return 0;
}
return 1;
}

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include "ipfs/importer/importer.h"
int test_null_add_provider() { int test_null_add_provider() {
int retVal = 0; int retVal = 0;
@ -17,7 +18,7 @@ int test_null_add_provider() {
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1); sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1);
ma_peer1 = multiaddress_new_from_string(multiaddress_string); ma_peer1 = multiaddress_new_from_string(multiaddress_string);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0)
goto exit; goto exit;
thread1_started = 1; thread1_started = 1;
@ -35,7 +36,7 @@ int test_null_add_provider() {
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
ipfs_node_free(local_node2); ipfs_node_free(local_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0)
goto exit; goto exit;
thread2_started = 1; thread2_started = 1;
// wait for everything to start up // wait for everything to start up

View file

@ -1,5 +1,10 @@
#include "cid/test_cid.h" #include "cid/test_cid.h"
#include "cmd/ipfs/test_init.h" #include "cmd/ipfs/test_init.h"
#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"
#include "exchange/test_bitswap.h" #include "exchange/test_bitswap.h"
#include "exchange/test_bitswap_request_queue.h" #include "exchange/test_bitswap_request_queue.h"
#include "flatfs/test_flatfs.h" #include "flatfs/test_flatfs.h"
@ -18,10 +23,6 @@
#include "storage/test_datastore.h" #include "storage/test_datastore.h"
#include "storage/test_blocks.h" #include "storage/test_blocks.h"
#include "storage/test_unixfs.h" #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"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"
int testit(const char* name, int (*func)(void)) { int testit(const char* name, int (*func)(void)) {
@ -45,6 +46,7 @@ const char* names[] = {
"test_cid_cast_multihash", "test_cid_cast_multihash",
"test_cid_cast_non_multihash", "test_cid_cast_non_multihash",
"test_cid_protobuf_encode_decode", "test_cid_protobuf_encode_decode",
"test_core_api_startup_shutdown",
"test_daemon_startup_shutdown", "test_daemon_startup_shutdown",
"test_datastore_list_journal", "test_datastore_list_journal",
"test_journal_encode_decode", "test_journal_encode_decode",
@ -105,6 +107,7 @@ int (*funcs[])(void) = {
test_cid_cast_multihash, test_cid_cast_multihash,
test_cid_cast_non_multihash, test_cid_cast_non_multihash,
test_cid_protobuf_encode_decode, test_cid_protobuf_encode_decode,
test_core_api_startup_shutdown,
test_daemon_startup_shutdown, test_daemon_startup_shutdown,
test_datastore_list_journal, test_datastore_list_journal,
test_journal_encode_decode, test_journal_encode_decode,