Skip to content

Commit

Permalink
started more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Mar 27, 2024
1 parent 16841d2 commit 0f3f8a5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
make
2 changes: 1 addition & 1 deletion include/flock/flock-group-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static inline ssize_t flock_group_view_metadata_binary_search(
const flock_group_view_t *view, const char* key)
{
ssize_t left = 0;
ssize_t right = view->members.size - 1;
ssize_t right = view->metadata.size - 1;
while (left <= right) {
ssize_t mid = left + (right - left) / 2;
int cmp = strcmp(view->metadata.data[mid].key, key);
Expand Down
62 changes: 62 additions & 0 deletions tests/helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <margo.h>
#include <flock/flock-server.h>
#include <flock/flock-client.h>
#include <flock/flock-group.h>
#include <stdexcept>
#include <vector>

struct TestGroup {

TestGroup(margo_instance_id mid,
size_t group_size,
const char* provider_config = R"({"group":{"type":"static","config":{}}})") {

// get address of current process
hg_addr_t addr = HG_ADDR_NULL;
hg_return_t hret = margo_addr_self(mid, &addr);
if(hret != HG_SUCCESS)
throw std::runtime_error("margo_addr_self failed when creating TestGroup");

// get self address as a string
char address[256];
hg_size_t address_size = 256;
hret = margo_addr_to_string(mid, address, &address_size, addr);
if(hret != HG_SUCCESS)
throw std::runtime_error("margo_addr_to_string failed when creating TestGroup");
margo_addr_free(mid, addr);

// create the initial group view to bootstrap with
flock_group_view_t initial_view = FLOCK_GROUP_VIEW_INITIALIZER;
for(size_t i = 0; i < group_size; ++i)
flock_group_view_add_member(&initial_view, i, (uint16_t)(i+1), address);

// add some metadata
flock_group_view_add_metadata(&initial_view, "matthieu", "dorier");
flock_group_view_add_metadata(&initial_view, "shane", "snyder");

// register flock providers
providers.resize(group_size, nullptr);
struct flock_provider_args args = FLOCK_PROVIDER_ARGS_INIT;
args.initial_view = &initial_view;
for(size_t i = 0; i < group_size; ++i) {
flock_return_t ret = flock_provider_register(
mid, i+1, provider_config, &args,
&providers[i]);
if(ret != FLOCK_SUCCESS)
throw std::runtime_error("flock_provider_register failed when initializing TestGroup");
}
}

virtual ~TestGroup() {
for(auto provider : providers)
flock_provider_destroy(provider);
}

std::vector<flock_provider_t> providers;
};
55 changes: 22 additions & 33 deletions tests/test-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,31 @@
#include <flock/flock-server.h>
#include <flock/flock-client.h>
#include <flock/flock-group.h>
#include "helper.hpp"

struct test_context {
margo_instance_id mid;
hg_addr_t addr;
};
struct TestContext {

margo_instance_id mid = MARGO_INSTANCE_NULL;
hg_addr_t addr = HG_ADDR_NULL;

TestContext() {
mid = margo_init("na+sm", MARGO_SERVER_MODE, 0, 0);
margo_addr_self(mid, &addr);
}

static const uint16_t provider_id = 42;
static const char* provider_config = "{ \"group\":{ \"type\":\"static\", \"config\":{} } }";
~TestContext() {
margo_addr_free(mid, addr);
margo_finalize(mid);
}
};

TEST_CASE("Test client interface", "[client]") {

flock_return_t ret;
margo_instance_id mid;
hg_addr_t addr;
// create margo instance
mid = margo_init("na+sm", MARGO_SERVER_MODE, 0, 0);
REQUIRE(mid != MARGO_INSTANCE_NULL);
// get address of current process
hg_return_t hret = margo_addr_self(mid, &addr);
REQUIRE(hret == HG_SUCCESS);
// register flock provider
struct flock_provider_args args = FLOCK_PROVIDER_ARGS_INIT;
ret = flock_provider_register(
mid, provider_id, provider_config, &args,
FLOCK_PROVIDER_IGNORE);
REQUIRE(ret == FLOCK_SUCCESS);
// create test context
auto context = std::make_unique<test_context>();
context->mid = mid;
context->addr = addr;
auto context = std::make_unique<TestContext>();

// create test group with 5 processes
auto group = std::make_unique<TestGroup>(context->mid, 5);

SECTION("Create client") {
flock_client_t client;
Expand All @@ -48,17 +43,17 @@ TEST_CASE("Test client interface", "[client]") {
ret = flock_client_init(context->mid, ABT_POOL_NULL, &client);
REQUIRE(ret == FLOCK_SUCCESS);

SECTION("Open group") {
SECTION("Create group handle") {
flock_group_handle_t rh;
// test that we can create a group handle
ret = flock_group_handle_create(client,
context->addr, provider_id, 0, &rh);
context->addr, 1, 0, &rh);
REQUIRE(ret == FLOCK_SUCCESS);

// test that we get an error when using a wrong provider ID
flock_group_handle_t rh2;
ret = flock_group_handle_create(client,
context->addr, provider_id + 123, 0, &rh2);
context->addr, 123, 0, &rh2);
REQUIRE(ret == FLOCK_ERR_INVALID_PROVIDER);

// test that we can increase the ref count
Expand All @@ -76,10 +71,4 @@ TEST_CASE("Test client interface", "[client]") {
ret = flock_client_finalize(client);
REQUIRE(ret == FLOCK_SUCCESS);
}

// free address
margo_addr_free(context->mid, context->addr);
// we are not checking the return value of the above function with
// munit because we need margo_finalize to be called no matter what.
margo_finalize(context->mid);
}

0 comments on commit 0f3f8a5

Please sign in to comment.