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 a1438ef
Show file tree
Hide file tree
Showing 2 changed files with 68 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
52 changes: 52 additions & 0 deletions src/liblsd/test/hostlist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#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";
const char *hosts[] = { "pclstr201-p", "pclstr202-p", "pclstr203-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);
for (int i = 0; i < 3; i++) {
host = hostlist_next (itr);
ok (host && !strcmp (host, hosts[i]),
"host[%d] is %s", i, hosts[i]);
free (host);
}
hostlist_iterator_destroy (itr);
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 a1438ef

Please sign in to comment.