Commit 9001dcb1 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

started adding tests

parent dad8c266
......@@ -5,13 +5,20 @@ CLIENT_LiBS=@CLIENT_LIBS@
AM_CPPFLAGS = -I${srcdir}/src
bin_PROGRAMS = bin/sdskv-server-daemon
bin_PROGRAMS = bin/sdskv-server-daemon \
bin/sdskv-shutdown \
test/sdskv-client-test
bin_sdskv_server_daemon_SOURCES = src/sdskv-server-daemon.c
bin_sdskv_server_daemon_DEPENDENCIES = lib/libkvclient.la
bin_sdskv_server_daemon_DEPENDENCIES = lib/libsdskv-server.la
bin_sdskv_server_daemon_LDFLAGS = -Llib -lsdskv-server
bin_sdskv_server_daemon_LDADD = ${LIBS} -lsdskv-server ${SERVER_LIBS}
bin_sdskv_shutdown_SOURCES = src/sdskv-shutdown.c
bin_sdskv_shutdown_DEPENDENCIES = lib/libsdskv-client.la
bin_sdskv_shutdown_LDFLAGS = -Llib -lsdskv-client
bin_sdskv_shutdown_LDADD = ${LIBS} -lsdskv-client
lib_LTLIBRARIES = lib/libkvclient.la \
lib/libkvserver.la \
lib/libkvgroupclient.la \
......@@ -69,6 +76,16 @@ noinst_HEADERS = src/datastore/datastore.h \
lib_libkvgroupserver_la_SOURCES = src/kvgroup-server.cc
check_PROGRAMS = test/sdskv-client-test
TESTS = test/basic.sh
TESTS_ENVIRONMENT = TIMEOUT="$(TIMEOUT)" \
MKTEMP="$(MKTEMP)"
test_sdskv_client_test_SOURCES = test/sdskv-client-test.cc
test_sdskv_client_test_DEPENDENCIES = lib/libsdskv-client.la
test_sdskv_client_test_LDFLAGS = -Llib -lsdskv-client
#############################################################
## tests bellow correspond to old tests (see old-test folder)
......
......@@ -126,7 +126,7 @@ int sdskv_provider_handle_ref_incr(
return 0;
}
int sdskv_provider_release(sdskv_provider_handle_t handle)
int sdskv_provider_handle_release(sdskv_provider_handle_t handle)
{
if(handle == SDSKV_PROVIDER_HANDLE_NULL) return -1;
handle->refcount -= 1;
......
......@@ -28,7 +28,7 @@ int sdskv_provider_handle_create(
int sdskv_provider_handle_ref_incr(
sdskv_provider_handle_t handle);
int sdskv_provider_release(sdskv_provider_handle_t handle);
int sdskv_provider_handle_release(sdskv_provider_handle_t handle);
int sdskv_open(
sdskv_provider_handle_t provider,
......
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include "sdskv-client.h"
/* client program that will shut down a BAKE server. */
int main(int argc, char **argv)
{
int i;
char cli_addr_prefix[64] = {0};
char *svr_addr_str;
hg_addr_t svr_addr;
margo_instance_id mid;
hg_return_t hret;
int ret;
if(argc != 2)
{
fprintf(stderr, "Usage: sdskv-shutdown <server addr to stop>\n");
fprintf(stderr, " Example: ./sdskv-shutdown bmi+tcp://localhost:1234\n");
return(-1);
}
svr_addr_str = argv[1];
/* initialize Margo using the transport portion of the server
* address (i.e., the part before the first : character if present)
*/
for(i=0; (i<63 && svr_addr_str[i] != '\0' && svr_addr_str[i] != ':'); i++)
cli_addr_prefix[i] = svr_addr_str[i];
mid = margo_init(cli_addr_prefix, MARGO_CLIENT_MODE, 0, -1);
if(mid == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: margo_init()\n");
return -1;
}
hret = margo_addr_lookup(mid, svr_addr_str, &svr_addr);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_lookup()\n");
margo_finalize(mid);
return(-1);
}
sdskv_client_t kvc;
ret = sdskv_client_init(mid, &kvc);
if(ret < 0)
{
fprintf(stderr, "Error: sdskv_client_init()\n");
margo_addr_free(mid, svr_addr);
margo_finalize(mid);
return(-1);
}
/* shutdown server */
sdskv_shutdown_service(kvc, svr_addr);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvc);
margo_finalize(mid);
return(0);
}
#!/bin/bash -x
if [ -z $srcdir ]; then
echo srcdir variable not set.
exit 1
fi
source $srcdir/test/test-util.sh
# start a server with 2 second wait,
# 20s timeout, and my_test_db as database
test_start_server 2 20 my_test_db
sleep 1
#####################
# tear down
run_to 10 bin/sdskv-shutdown $svr_addr
if [ $? -ne 0 ]; then
wait
exit 1
fi
wait
echo cleaning up $TMPBASE
rm -rf $TMPBASE
exit 0
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <margo.h>
#include <string>
#include "sdskv-client.h"
static std::string gen_random_string(size_t len);
int main(int argc, char *argv[])
{
char cli_addr_prefix[64] = {0};
char *sdskv_svr_addr_str;
char *db_name;
margo_instance_id mid;
hg_addr_t svr_addr;
uint8_t mplex_id;
uint32_t num_keys;
sdskv_client_t kvcl;
sdskv_provider_handle_t kvph;
hg_return_t hret;
int ret;
if(argc != 5)
{
fprintf(stderr, "Usage: %s <sdskv_server_addr> <mplex_id> <db_name> <num_keys>\n", argv[0]);
fprintf(stderr, " Example: %s tcp://localhost:1234 1 foo 1000\n", argv[0]);
return(-1);
}
sdskv_svr_addr_str = argv[1];
mplex_id = atoi(argv[2]);
db_name = argv[3];
num_keys = atoi(argv[4]);
/* initialize Margo using the transport portion of the server
* address (i.e., the part before the first : character if present)
*/
for(unsigned i=0; (i<63 && sdskv_svr_addr_str[i] != '\0' && sdskv_svr_addr_str[i] != ':'); i++)
cli_addr_prefix[i] = sdskv_svr_addr_str[i];
/* start margo */
mid = margo_init(cli_addr_prefix, MARGO_SERVER_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
ret = sdskv_client_init(mid, &kvcl);
if(ret != 0)
{
fprintf(stderr, "Error: sdskv_client_init()\n");
margo_finalize(mid);
return -1;
}
/* look up the SDSKV server address */
hret = margo_addr_lookup(mid, sdskv_svr_addr_str, &svr_addr);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_lookup()\n");
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(-1);
}
/* create a SDSKV provider handle */
ret = sdskv_provider_handle_create(kvcl, svr_addr, mplex_id, &kvph);
if(ret != 0)
{
fprintf(stderr, "Error: sdskv_provider_handle_create()\n");
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(-1);
}
/* shutdown the server */
ret = sdskv_shutdown_service(kvcl, svr_addr);
/**** cleanup ****/
sdskv_provider_handle_release(kvph);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(ret);
}
static std::string gen_random_string(size_t len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string s(len, ' ');
for (unsigned i = 0; i < len; ++i) {
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
return s;
}
#
# General test script utilities
#
if [ -z "$TIMEOUT" ] ; then
echo expected TIMEOUT variable defined to its respective command
exit 1
fi
if [ -z "$MKTEMP" ] ; then
echo expected MKTEMP variable defined to its respective command
exit 1
fi
TMPDIR=/dev/shm
export TMPDIR
mkdir -p $TMPDIR
TMPBASE=$(${MKTEMP} --tmpdir -d test-XXXXXX)
if [ ! -d $TMPBASE ];
then
echo "Temp directory doesn't exist: $TMPBASE"
exit 3
fi
function run_to ()
{
maxtime=${1}s
shift
${TIMEOUT} --signal=9 $maxtime "$@"
}
function test_start_server ()
{
startwait=${1:-15}
maxtime=${2:-120}
run_to ${maxtime} src/sdskv-server-daemon -f $TMPBASE/sdskv.addr na+sm ${@:3} &
# wait for server to start
sleep ${startwait}
svr_addr=`cat $TMPBASE/sdskv.addr`
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment