From 18027decb17ff8f8af82062b7f61b47ddd15665a Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Fri, 23 Aug 2024 05:23:56 -0700 Subject: [PATCH] testsuite: add unit test for hostlist --- src/liblsd/Makefile.am | 16 +++++++++++ src/liblsd/test/hostlist.c | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/liblsd/test/hostlist.c diff --git a/src/liblsd/Makefile.am b/src/liblsd/Makefile.am index d56fa88b..29ad099e 100644 --- a/src/liblsd/Makefile.am +++ b/src/liblsd/Makefile.am @@ -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 diff --git a/src/liblsd/test/hostlist.c b/src/liblsd/test/hostlist.c new file mode 100644 index 00000000..7e889386 --- /dev/null +++ b/src/liblsd/test/hostlist.c @@ -0,0 +1,56 @@ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#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