Skip to content

Commit

Permalink
Add seg_tree test, fix argobots in bootstrap.sh
Browse files Browse the repository at this point in the history
- Add a test case to exercise our segment tree library.
- Choose a specific version of argobots in bootstrap.sh (fixes LLNL#439)
- Have unifyfs_unmount correctly use the static libraries.  This
  fixes one of the 'make check' errors for me when libgotcha isn't in
  LD_LIBRARY_PATH.
  • Loading branch information
tonyhutter authored and adammoody committed Jan 23, 2020
1 parent ce78c0d commit 43e8fb8
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ examples/src/*-static
t/sys/open.t
t/test-results/
t/unifyfs_unmount.t
t/seg_tree_test.t
t/test_run_env.sh
deps
install
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cd ..

echo "### building argobots ###"
cd argobots
git checkout v1.0rc2
./autogen.sh && CC=gcc ./configure --prefix="$INSTALL_DIR"
make -j $(nproc) && make install
cd ..
Expand Down
8 changes: 8 additions & 0 deletions t/9006-seg-tree-test.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# Source sharness environment scripts to pick up test environment
# and UnifyFS runtime settings.
#
. $(dirname $0)/sharness.d/00-test-env.sh
. $(dirname $0)/sharness.d/01-unifyfs-settings.sh
$UNIFYFS_BUILD_DIR/t/seg_tree_test.t
15 changes: 12 additions & 3 deletions t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TESTS = \
0500-sysio-static.t \
0600-stdio-static.t \
9005-unifyfs-unmount.t \
9006-seg-tree-test.t \
9010-stop-unifyfsd.t \
9020-mountpoint-empty.t \
9100-metadata-api.t \
Expand All @@ -22,6 +23,7 @@ check_SCRIPTS = \
0500-sysio-static.t \
0600-stdio-static.t \
9005-unifyfs-unmount.t \
9006-seg-tree-test.t \
9010-stop-unifyfsd.t \
9020-mountpoint-empty.t \
9100-metadata-api.t \
Expand All @@ -44,7 +46,9 @@ libexec_PROGRAMS = \
sys/sysio-static.t \
std/stdio-static.t \
server/metadata.t \
unifyfs_unmount.t
unifyfs_unmount.t \
seg_tree_test.t


test_ldadd = \
$(top_builddir)/t/lib/libtap.la \
Expand Down Expand Up @@ -158,5 +162,10 @@ server_metadata_t_LDFLAGS = $(AM_LDFLAGS)

unifyfs_unmount_t_SOURCES = unifyfs_unmount.c
unifyfs_unmount_t_CPPFLAGS = $(test_cppflags)
unifyfs_unmount_t_LDADD = $(test_ldadd)
unifyfs_unmount_t_LDFLAGS = $(AM_LDFLAGS)
unifyfs_unmount_t_LDADD = $(test_static_ldadd)
unifyfs_unmount_t_LDFLAGS = $(test_static_ldflags)

seg_tree_test_t_SOURCES = seg_tree_test.c
seg_tree_test_t_CPPFLAGS = $(test_cppflags)
seg_tree_test_t_LDADD = $(test_static_ldadd)
seg_tree_test_t_LDFLAGS = $(test_static_ldflags)
147 changes: 147 additions & 0 deletions t/seg_tree_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2020, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory.
*
* Copyright 2018, UT-Battelle, LLC.
*
* LLNL-CODE-741539
* All rights reserved.
*
* This is the license for UnifyFS.
* For details, see https://github.com/LLNL/UnifyFS.
* Please read https://github.com/LLNL/UnifyFS/LICENSE for full license text.
*/

#include <stdio.h>
#include "seg_tree.h"
#include "t/lib/tap.h"
#include "t/lib/testutil.h"
/*
* Test our Segment Tree library
*/

/*
* Print the seg_tree to a buffer. Returns dst so we can directly print the
* result.
*/
char* print_tree(char* dst, struct seg_tree* seg_tree)
{
int ptr = 0;
struct seg_tree_node* node = NULL;

/* In case we don't actually print anything */
dst[0] = '\0';

seg_tree_rdlock(seg_tree);
while ((node = seg_tree_iter(seg_tree, node))) {
ptr += sprintf(&dst[ptr], "[%lu-%lu:%c]", node->start, node->end,
*((char*)node->ptr));
}
seg_tree_unlock(seg_tree);
return dst;
}

int main(int argc, char** argv)
{
struct seg_tree seg_tree;
char buf[500];
char tmp[255];
int i;
unsigned long max, count;

plan(NO_PLAN);

/*
* Initialize our buffer with the character for the buffer pos (0-9).
* We'll use this to make sure the node.ptr value is getting updated
* correctly by the seg_tree.
*/
for (i = 0; i < sizeof(buf); i++) {
buf[i] = (i % 10) + '0';
}

seg_tree_init(&seg_tree);

/* Initial insert */
seg_tree_add(&seg_tree, 5, 10, (unsigned long) (buf + 5));
is("[5-10:5]", print_tree(tmp, &seg_tree), "Initial insert works");

/* Non-overlapping insert */
seg_tree_add(&seg_tree, 100, 150, (unsigned long) (buf + 100));
is("[5-10:5][100-150:0]", print_tree(tmp, &seg_tree),
"Non-overlapping works");

/* Add range overlapping part of the left size */
seg_tree_add(&seg_tree, 2, 7, (unsigned long) (buf + 2));
is("[2-7:2][8-10:8][100-150:0]", print_tree(tmp, &seg_tree),
"Left size overlap works");

/* Add range overlapping part of the right size */
seg_tree_add(&seg_tree, 9, 12, (unsigned long) (buf + 9));
is("[2-7:2][8-8:8][9-12:9][100-150:0]", print_tree(tmp, &seg_tree),
"Right size overlap works");

/* Add range totally within another range */
seg_tree_add(&seg_tree, 3, 4, (unsigned long) (buf + 3));
is("[2-2:2][3-4:3][5-7:5][8-8:8][9-12:9][100-150:0]",
print_tree(tmp, &seg_tree), "Inside range works");

/* Test counts */
max = seg_tree_max(&seg_tree);
count = seg_tree_count(&seg_tree);
ok(max == 150, "max is 150 (got %lu)", max);
ok(count == 6, "count is 6 (got %lu)", count);

/* Add a range that blows away multiple ranges, and overlaps */
seg_tree_add(&seg_tree, 4, 120, (unsigned long) (buf + 4));
is("[2-2:2][3-3:3][4-120:4][121-150:1]", print_tree(tmp, &seg_tree),
"Blow away multiple ranges works");

/* Test counts */
max = seg_tree_max(&seg_tree);
count = seg_tree_count(&seg_tree);
ok(max == 150, "max is 150 (got %lu)", max);
ok(count == 4, "count is 4 (got %lu)", count);

seg_tree_clear(&seg_tree);
is("", print_tree(tmp, &seg_tree), "seg_tree_clear() works");

max = seg_tree_max(&seg_tree);
count = seg_tree_count(&seg_tree);
ok(max == 0, "max 0 (got %lu)", max);
ok(count == 0, "count is 0 (got %lu)", count);

/*
* Now let's write a long extent, and then sawtooth over it with 1 byte
* extents.
*/
seg_tree_add(&seg_tree, 0, 50, (unsigned long) (buf + 50));
seg_tree_add(&seg_tree, 0, 0, (unsigned long) (buf + 0));
seg_tree_add(&seg_tree, 2, 2, (unsigned long) (buf + 2));
seg_tree_add(&seg_tree, 4, 4, (unsigned long) (buf + 4));
seg_tree_add(&seg_tree, 6, 6, (unsigned long) (buf + 6));
is("[0-0:0][1-1:1][2-2:2][3-3:3][4-4:4][5-5:5][6-6:6][7-50:7]",
print_tree(tmp, &seg_tree), "Sawtooth extents works");

max = seg_tree_max(&seg_tree);
count = seg_tree_count(&seg_tree);
ok(max == 50, "max 50 (got %lu)", max);
ok(count == 8, "count is 8 (got %lu)", count);

/*
* Write a range, then completely overwrite it with the
* same range. Use a different buf value to verify it changed.
*/
seg_tree_clear(&seg_tree);
seg_tree_add(&seg_tree, 20, 30, (unsigned long) (buf + 0));
is("[20-30:0]", print_tree(tmp, &seg_tree), "Initial [20-30] write works");

seg_tree_add(&seg_tree, 20, 30, (unsigned long) (buf + 8));
is("[20-30:8]", print_tree(tmp, &seg_tree), "Same range overwrite works");

seg_tree_destroy(&seg_tree);

done_testing();

return 0;
}

0 comments on commit 43e8fb8

Please sign in to comment.