Skip to content

Commit

Permalink
testsuite: add unit test for hostlist
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Aug 23, 2024
1 parent 91d9c21 commit 18027de
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/liblsd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ liblsd_la_SOURCES = \
hash.h \
cbuf.c \
cbuf.h

TESTS = \
test_hostlist.t

check_PROGRAMS = $(TESTS)

TEST_EXTENSIONS = .t
T_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/config/tap-driver.sh

test_hostlist_t_CPPFLAGS = \
-I$(top_srcdir)/src/libtap
test_hostlist_t_SOURCES = test/hostlist.c
test_hostlist_t_LDADD = \
$(builddir)/liblsd.la \
$(top_builddir)/src/libtap/libtap.la
56 changes: 56 additions & 0 deletions src/liblsd/test/hostlist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>

#include "tap.h"
#include "hostlist.h"

void lsd_fatal_error(char *file, int line, char *mesg)
{
BAIL_OUT ("%s::%d: %s", file, line, mesg);
}

void *lsd_nomem_error(char *file, int line, char *mesg)
{
BAIL_OUT ("%s: out of memory", mesg);
return NULL;
}

static void test_issue197 (void)
{
const char *t1 = "pclstr[201-203]-p";
hostlist_t hl;
hostlist_iterator_t itr;
char *host;

hl = hostlist_create (t1);
itr = hostlist_iterator_create (hl);
if (!hl || !itr)
BAIL_OUT ("cannot continue without hostlist and iterator");
ok (hl != NULL,
"decoded %s", t1);
host = hostlist_next (itr);
ok (host && !strcmp (host, "pclstr201-p"),
"first host is pclstr201-p");
host = hostlist_next (itr);
ok (host && !strcmp (host, "pclstr202-p"),
"next host is pclstr202-p");
host = hostlist_next (itr);
ok (host && !strcmp (host, "pclstr203-p"),
"next host is pclstr203-p");
host = hostlist_next (itr);
ok (host == NULL,
"next host is NULL");
hostlist_destroy (hl);
}

int main (int argc, char *argv[])
{
plan (NO_PLAN);
test_issue197 ();
done_testing ();
}

// vi: ts=4 sw=4 expandtab

0 comments on commit 18027de

Please sign in to comment.