From 15793743667ab63fdf1c40d29fc51122a8bb66a7 Mon Sep 17 00:00:00 2001
From: Chad Vizino <chad@schedmd.com>
Date: Fri, 21 Feb 2020 14:38:16 -0700
Subject: [PATCH] Testsuite - Refactor test7.23 to unit test (parse_time)

Bug 8268
---
 testsuite/expect/Makefile.am                  |  2 -
 testsuite/expect/Makefile.in                  |  2 -
 testsuite/expect/README                       |  1 -
 testsuite/expect/test7.23                     | 43 ---------
 testsuite/expect/test7.23.prog.c              | 92 ------------------
 testsuite/slurm_unit/common/Makefile.am       |  5 +-
 testsuite/slurm_unit/common/Makefile.in       | 50 +++++++++-
 testsuite/slurm_unit/common/parse_time-test.c | 95 +++++++++++++++++++
 8 files changed, 145 insertions(+), 145 deletions(-)
 delete mode 100755 testsuite/expect/test7.23
 delete mode 100644 testsuite/expect/test7.23.prog.c
 create mode 100644 testsuite/slurm_unit/common/parse_time-test.c

diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index 1e115213a46..e28f281799f 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -284,8 +284,6 @@ EXTRA_DIST = \
 	test7.20			\
 	test7.21			\
 	test7.21.prog.c			\
-	test7.23			\
-	test7.23.prog.c			\
 	test8.12			\
 	test9.1				\
 	test9.2				\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index 13551e072c3..bc0ec029911 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -705,8 +705,6 @@ EXTRA_DIST = \
 	test7.20			\
 	test7.21			\
 	test7.21.prog.c			\
-	test7.23			\
-	test7.23.prog.c			\
 	test8.12			\
 	test9.1				\
 	test9.2				\
diff --git a/testsuite/expect/README b/testsuite/expect/README
index bf200a71e01..07c4b66bdb6 100644
--- a/testsuite/expect/README
+++ b/testsuite/expect/README
@@ -401,7 +401,6 @@ test7.19   Test sbatch/srun/salloc path resolving
 test7.20   Test lua JobSubmitPlugin
 test7.21   Test SPANK plugins that link against libslurm
 test7.22   Test basic functionality of backfill scheduler
-test7.23   Test time_str2secs parsing of different formats
 
 test8.#    Testing of advanced reservation functionality.
 =========================================================
diff --git a/testsuite/expect/test7.23 b/testsuite/expect/test7.23
deleted file mode 100755
index b0ab5c2d7bf..00000000000
--- a/testsuite/expect/test7.23
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env expect
-############################################################################
-# Purpose:  Test time_str2secs parsing of different formats
-#
-# Note:    This script generates and then deletes files in the working directory
-#          named test7.23.prog
-############################################################################
-# Copyright (C) 2019 SchedMD LLC
-# Written by Nathan Rini <nate@schedmd.com>
-# CODE-OCEC-09-009. All rights reserved.
-#
-# This file is part of Slurm, a resource management program.
-# For details, see <https://slurm.schedmd.com/>.
-# Please also read the included file: DISCLAIMER.
-#
-# Slurm is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation; either version 2 of the License, or (at your option)
-# any later version.
-#
-# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Slurm; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
-############################################################################
-source ./globals
-
-set test_prog   "test$test_id.prog"
-
-#
-# Delete left-over programs and rebuild them
-#
-file delete $test_prog
-
-if [compile_against_libslurm ${test_prog}] {
-	fail "Error compiling test_prog"
-}
-
-run_command -fail "./$test_prog"
diff --git a/testsuite/expect/test7.23.prog.c b/testsuite/expect/test7.23.prog.c
deleted file mode 100644
index 48d29915728..00000000000
--- a/testsuite/expect/test7.23.prog.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*****************************************************************************\
- *  test7.23.prog.c - Test time_str2secs parsing of different formats.
- *
- *  Usage: test7.23.prog
- *****************************************************************************
- *  Copyright (C) 2019 SchedMD LLC
- *  Written by Nathan Rini <nate@schedmd.com>
- *  CODE-OCEC-09-009. All rights reserved.
- *
- *  This file is part of Slurm, a resource management program.
- *  For details, see <https://slurm.schedmd.com/>.
- *  Please also read the included file: DISCLAIMER.
- *
- *  Slurm is free software; you can redistribute it and/or modify it under
- *  the terms of the GNU General Public License as published by the Free
- *  Software Foundation; either version 2 of the License, or (at your option)
- *  any later version.
- *
- *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
- *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- *  details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with Slurm; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
-\*****************************************************************************/
-
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <slurm/slurm.h>
-#include <slurm/slurm_errno.h>
-
-#include "src/common/slurm_xlator.h"
-
-#include "src/common/log.h"
-#include "src/common/parse_time.h"
-#include "src/common/xassert.h"
-#include "src/common/xstring.h"
-
-void _ct(const char *time_string, int value)
-{
-	int t = time_str2secs(time_string);
-
-	if (t != value)
-		fatal("check_time: %s -> %u != %u", time_string, t, value);
-}
-
-int main (int argc, char **argv)
-{
-	log_options_t logopt = LOG_OPTS_STDERR_ONLY;
-	logopt.prefix_level = 1;
-	log_init(xbasename(argv[0]), logopt, 0, NULL);
-	logopt.stderr_level += 5;
-	log_alter(logopt, 0, NULL);
-
-	_ct("INVALID TIME", NO_VAL);
-	_ct("-1", INFINITE);
-	_ct("INFINITE", INFINITE);
-	_ct("infinite", INFINITE);
-	_ct("UNLIMITED", INFINITE);
-	_ct("unlimited", INFINITE);
-	_ct("LONG --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- INVALID TIME", NO_VAL);
-	_ct("0", 0);
-	_ct("60", 60*60);
-	_ct("60:15", 60*60 + 15);
-	_ct("60:0", 60*60);
-	_ct("60:", NO_VAL);
-	_ct("60:-10", NO_VAL);
-	_ct("-60:10", NO_VAL);
-	_ct("1:60:15", 1*60*60 + 60*60 + 15);
-	_ct("2:60:15", 2*60*60 + 60*60 + 15);
-	_ct("0:0:15", 15);
-	_ct("0:60:0", 60*60);
-	_ct("0:0:0", 0);
-	_ct("-0:-0:-0", NO_VAL);
-	_ct(" 0:0:0 ", NO_VAL); //TODO: should we trim()?
-	_ct("0-1:60:15", 1*60*60 + 60*60 + 15);
-	_ct("1-1:60:15", 1*60*60*24 + 1*60*60 + 60*60 + 15);
-	_ct("365-1:60:15", 365*60*60*24 + 1*60*60 + 60*60 + 15);
-	_ct("365-0:0:0", 365*60*60*24);
-	/*
-	 * ct("9999999-0:0:0", 365*60*60*24)
-	 * doesn't work with 32-bit int (sets high bit)
-	 * TODO: Ignoring this edge for now until time_t
-	 */
-	//_ct("9999999-0:0:0", NO_VAL);
-
-	return 0;
-}
diff --git a/testsuite/slurm_unit/common/Makefile.am b/testsuite/slurm_unit/common/Makefile.am
index cc458d97ebb..4a7c372e0ea 100644
--- a/testsuite/slurm_unit/common/Makefile.am
+++ b/testsuite/slurm_unit/common/Makefile.am
@@ -20,7 +20,8 @@ TESTS += xtree-test \
 	 xhash-test \
 	 data-test \
 	 slurm_opt-test \
-	 xstring-test
+	 xstring-test \
+	 parse_time-test
 xtree_test_CFLAGS = $(MYCFLAGS)
 xtree_test_LDADD  = $(LDADD) @CHECK_LIBS@
 xhash_test_CFLAGS = $(MYCFLAGS)
@@ -31,5 +32,7 @@ slurm_opt_test_CFLAGS = $(MYCFLAGS)
 slurm_opt_test_LDADD  = $(LDADD) @CHECK_LIBS@
 xstring_test_CFLAGS   = $(MYCFLAGS)
 xstring_test_LDADD    = $(LDADD) @CHECK_LIBS@
+parse_time_test_CFLAGS= $(MYCFLAGS)
+parse_time_test_LDADD = $(LDADD) @CHECK_LIBS@
 endif
 
diff --git a/testsuite/slurm_unit/common/Makefile.in b/testsuite/slurm_unit/common/Makefile.in
index 51e3e59a4c9..6db9085b21a 100644
--- a/testsuite/slurm_unit/common/Makefile.in
+++ b/testsuite/slurm_unit/common/Makefile.in
@@ -95,7 +95,8 @@ TESTS = job-resources-test$(EXEEXT) log-test$(EXEEXT) \
 @HAVE_CHECK_TRUE@	 xhash-test \
 @HAVE_CHECK_TRUE@	 data-test \
 @HAVE_CHECK_TRUE@	 slurm_opt-test \
-@HAVE_CHECK_TRUE@	 xstring-test
+@HAVE_CHECK_TRUE@	 xstring-test \
+@HAVE_CHECK_TRUE@	 parse_time-test
 
 subdir = testsuite/slurm_unit/common
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -155,7 +156,8 @@ CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 @HAVE_CHECK_TRUE@am__EXEEXT_1 = xtree-test$(EXEEXT) \
 @HAVE_CHECK_TRUE@	xhash-test$(EXEEXT) data-test$(EXEEXT) \
-@HAVE_CHECK_TRUE@	slurm_opt-test$(EXEEXT) xstring-test$(EXEEXT)
+@HAVE_CHECK_TRUE@	slurm_opt-test$(EXEEXT) xstring-test$(EXEEXT) \
+@HAVE_CHECK_TRUE@	parse_time-test$(EXEEXT)
 am__EXEEXT_2 = job-resources-test$(EXEEXT) log-test$(EXEEXT) \
 	pack-test$(EXEEXT) $(am__EXEEXT_1)
 data_test_SOURCES = data-test.c
@@ -186,6 +188,13 @@ pack_test_OBJECTS = pack-test.$(OBJEXT)
 pack_test_LDADD = $(LDADD)
 pack_test_DEPENDENCIES = $(top_builddir)/src/api/libslurm.o \
 	$(am__DEPENDENCIES_1)
+parse_time_test_SOURCES = parse_time-test.c
+parse_time_test_OBJECTS = parse_time_test-parse_time-test.$(OBJEXT)
+@HAVE_CHECK_TRUE@parse_time_test_DEPENDENCIES = $(am__DEPENDENCIES_2)
+parse_time_test_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(parse_time_test_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
 slurm_opt_test_SOURCES = slurm_opt-test.c
 slurm_opt_test_OBJECTS = slurm_opt_test-slurm_opt-test.$(OBJEXT)
 @HAVE_CHECK_TRUE@slurm_opt_test_DEPENDENCIES = $(am__DEPENDENCIES_2)
@@ -229,6 +238,7 @@ am__maybe_remake_depfiles = depfiles
 am__depfiles_remade = ./$(DEPDIR)/data_test-data-test.Po \
 	./$(DEPDIR)/job-resources-test.Po ./$(DEPDIR)/log-test.Po \
 	./$(DEPDIR)/pack-test.Po \
+	./$(DEPDIR)/parse_time_test-parse_time-test.Po \
 	./$(DEPDIR)/slurm_opt_test-slurm_opt-test.Po \
 	./$(DEPDIR)/xhash_test-xhash-test.Po \
 	./$(DEPDIR)/xstring_test-xstring-test.Po \
@@ -253,9 +263,11 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = data-test.c job-resources-test.c log-test.c pack-test.c \
-	slurm_opt-test.c xhash-test.c xstring-test.c xtree-test.c
+	parse_time-test.c slurm_opt-test.c xhash-test.c xstring-test.c \
+	xtree-test.c
 DIST_SOURCES = data-test.c job-resources-test.c log-test.c pack-test.c \
-	slurm_opt-test.c xhash-test.c xstring-test.c xtree-test.c
+	parse_time-test.c slurm_opt-test.c xhash-test.c xstring-test.c \
+	xtree-test.c
 RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
 	ctags-recursive dvi-recursive html-recursive info-recursive \
 	install-data-recursive install-dvi-recursive \
@@ -799,6 +811,8 @@ LDADD = $(top_builddir)/src/api/libslurm.o $(DL_LIBS)
 @HAVE_CHECK_TRUE@slurm_opt_test_LDADD = $(LDADD) @CHECK_LIBS@
 @HAVE_CHECK_TRUE@xstring_test_CFLAGS = $(MYCFLAGS)
 @HAVE_CHECK_TRUE@xstring_test_LDADD = $(LDADD) @CHECK_LIBS@
+@HAVE_CHECK_TRUE@parse_time_test_CFLAGS = $(MYCFLAGS)
+@HAVE_CHECK_TRUE@parse_time_test_LDADD = $(LDADD) @CHECK_LIBS@
 all: all-recursive
 
 .SUFFIXES:
@@ -858,6 +872,10 @@ pack-test$(EXEEXT): $(pack_test_OBJECTS) $(pack_test_DEPENDENCIES) $(EXTRA_pack_
 	@rm -f pack-test$(EXEEXT)
 	$(AM_V_CCLD)$(LINK) $(pack_test_OBJECTS) $(pack_test_LDADD) $(LIBS)
 
+parse_time-test$(EXEEXT): $(parse_time_test_OBJECTS) $(parse_time_test_DEPENDENCIES) $(EXTRA_parse_time_test_DEPENDENCIES) 
+	@rm -f parse_time-test$(EXEEXT)
+	$(AM_V_CCLD)$(parse_time_test_LINK) $(parse_time_test_OBJECTS) $(parse_time_test_LDADD) $(LIBS)
+
 slurm_opt-test$(EXEEXT): $(slurm_opt_test_OBJECTS) $(slurm_opt_test_DEPENDENCIES) $(EXTRA_slurm_opt_test_DEPENDENCIES) 
 	@rm -f slurm_opt-test$(EXEEXT)
 	$(AM_V_CCLD)$(slurm_opt_test_LINK) $(slurm_opt_test_OBJECTS) $(slurm_opt_test_LDADD) $(LIBS)
@@ -884,6 +902,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/job-resources-test.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log-test.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pack-test.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse_time_test-parse_time-test.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slurm_opt_test-slurm_opt-test.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xhash_test-xhash-test.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xstring_test-xstring-test.Po@am__quote@ # am--include-marker
@@ -930,6 +949,20 @@ data_test-data-test.obj: data-test.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(data_test_CFLAGS) $(CFLAGS) -c -o data_test-data-test.obj `if test -f 'data-test.c'; then $(CYGPATH_W) 'data-test.c'; else $(CYGPATH_W) '$(srcdir)/data-test.c'; fi`
 
+parse_time_test-parse_time-test.o: parse_time-test.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(parse_time_test_CFLAGS) $(CFLAGS) -MT parse_time_test-parse_time-test.o -MD -MP -MF $(DEPDIR)/parse_time_test-parse_time-test.Tpo -c -o parse_time_test-parse_time-test.o `test -f 'parse_time-test.c' || echo '$(srcdir)/'`parse_time-test.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/parse_time_test-parse_time-test.Tpo $(DEPDIR)/parse_time_test-parse_time-test.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='parse_time-test.c' object='parse_time_test-parse_time-test.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(parse_time_test_CFLAGS) $(CFLAGS) -c -o parse_time_test-parse_time-test.o `test -f 'parse_time-test.c' || echo '$(srcdir)/'`parse_time-test.c
+
+parse_time_test-parse_time-test.obj: parse_time-test.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(parse_time_test_CFLAGS) $(CFLAGS) -MT parse_time_test-parse_time-test.obj -MD -MP -MF $(DEPDIR)/parse_time_test-parse_time-test.Tpo -c -o parse_time_test-parse_time-test.obj `if test -f 'parse_time-test.c'; then $(CYGPATH_W) 'parse_time-test.c'; else $(CYGPATH_W) '$(srcdir)/parse_time-test.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/parse_time_test-parse_time-test.Tpo $(DEPDIR)/parse_time_test-parse_time-test.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='parse_time-test.c' object='parse_time_test-parse_time-test.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(parse_time_test_CFLAGS) $(CFLAGS) -c -o parse_time_test-parse_time-test.obj `if test -f 'parse_time-test.c'; then $(CYGPATH_W) 'parse_time-test.c'; else $(CYGPATH_W) '$(srcdir)/parse_time-test.c'; fi`
+
 slurm_opt_test-slurm_opt-test.o: slurm_opt-test.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(slurm_opt_test_CFLAGS) $(CFLAGS) -MT slurm_opt_test-slurm_opt-test.o -MD -MP -MF $(DEPDIR)/slurm_opt_test-slurm_opt-test.Tpo -c -o slurm_opt_test-slurm_opt-test.o `test -f 'slurm_opt-test.c' || echo '$(srcdir)/'`slurm_opt-test.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/slurm_opt_test-slurm_opt-test.Tpo $(DEPDIR)/slurm_opt_test-slurm_opt-test.Po
@@ -1288,6 +1321,13 @@ xstring-test.log: xstring-test$(EXEEXT)
 	--log-file $$b.log --trs-file $$b.trs \
 	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
 	"$$tst" $(AM_TESTS_FD_REDIRECT)
+parse_time-test.log: parse_time-test$(EXEEXT)
+	@p='parse_time-test$(EXEEXT)'; \
+	b='parse_time-test'; \
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+	--log-file $$b.log --trs-file $$b.trs \
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
 .test.log:
 	@p='$<'; \
 	$(am__set_b); \
@@ -1411,6 +1451,7 @@ distclean: distclean-recursive
 	-rm -f ./$(DEPDIR)/job-resources-test.Po
 	-rm -f ./$(DEPDIR)/log-test.Po
 	-rm -f ./$(DEPDIR)/pack-test.Po
+	-rm -f ./$(DEPDIR)/parse_time_test-parse_time-test.Po
 	-rm -f ./$(DEPDIR)/slurm_opt_test-slurm_opt-test.Po
 	-rm -f ./$(DEPDIR)/xhash_test-xhash-test.Po
 	-rm -f ./$(DEPDIR)/xstring_test-xstring-test.Po
@@ -1464,6 +1505,7 @@ maintainer-clean: maintainer-clean-recursive
 	-rm -f ./$(DEPDIR)/job-resources-test.Po
 	-rm -f ./$(DEPDIR)/log-test.Po
 	-rm -f ./$(DEPDIR)/pack-test.Po
+	-rm -f ./$(DEPDIR)/parse_time_test-parse_time-test.Po
 	-rm -f ./$(DEPDIR)/slurm_opt_test-slurm_opt-test.Po
 	-rm -f ./$(DEPDIR)/xhash_test-xhash-test.Po
 	-rm -f ./$(DEPDIR)/xstring_test-xstring-test.Po
diff --git a/testsuite/slurm_unit/common/parse_time-test.c b/testsuite/slurm_unit/common/parse_time-test.c
new file mode 100644
index 00000000000..b483427c55c
--- /dev/null
+++ b/testsuite/slurm_unit/common/parse_time-test.c
@@ -0,0 +1,95 @@
+/*****************************************************************************\
+ *  parse_time-test.c - unit test for parse_time.c
+ *****************************************************************************
+ *  Copyright (C) 2021 SchedMD LLC.
+ *  Written by Chad Vizino <chad@schedmd.com>
+ *
+ *  This file is part of Slurm, a resource management program.
+ *  For details, see <https://slurm.schedmd.com/>.
+ *  Please also read the included file: DISCLAIMER.
+ *
+ *  Slurm is free software; you can redistribute it and/or modify it under
+ *  the terms of the GNU General Public License as published by the Free
+ *  Software Foundation; either version 2 of the License, or (at your option)
+ *  any later version.
+ *
+ *  In addition, as a special exception, the copyright holders give permission
+ *  to link the code of portions of this program with the OpenSSL library under
+ *  certain conditions as described in each individual source file, and
+ *  distribute linked combinations including the two. You must obey the GNU
+ *  General Public License in all respects for all of the code used other than
+ *  OpenSSL. If you modify file(s) with this exception, you may extend this
+ *  exception to your version of the file(s), but you are not obligated to do
+ *  so. If you do not wish to do so, delete this exception statement from your
+ *  version.  If you delete this exception statement from all source files in
+ *  the program, then also delete it here.
+ *
+ *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with Slurm; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+\*****************************************************************************/
+
+#include <check.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "slurm/slurm.h"
+#include "src/common/parse_time.h"
+
+START_TEST(test_time_str2secs)
+{
+	ck_assert_int_eq(time_str2secs(NULL), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs(""), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("INVALID TIME"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("-1"), (int)INFINITE);
+	ck_assert_int_eq(time_str2secs("INFINITE"), (int)INFINITE);
+	ck_assert_int_eq(time_str2secs("infinite"), (int)INFINITE);
+	ck_assert_int_eq(time_str2secs("UNLIMITED"), (int)INFINITE);
+	ck_assert_int_eq(time_str2secs("unlimited"), (int)INFINITE);
+	ck_assert_int_eq(time_str2secs("LONG --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- INVALID TIME"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("0"), 0);
+	ck_assert_int_eq(time_str2secs("60"), 60*60);
+	ck_assert_int_eq(time_str2secs("60:15"), 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("60:0"), 60*60);
+	ck_assert_int_eq(time_str2secs("60:"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("60:-10"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("-60:10"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("1:60:15"), 1*60*60 + 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("2:60:15"), 2*60*60 + 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("0:0:15"), 15);
+	ck_assert_int_eq(time_str2secs("0:60:0"), 60*60);
+	ck_assert_int_eq(time_str2secs("0:0:0"), 0);
+	ck_assert_int_eq(time_str2secs("-0:-0:-0"), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs(" 0:0:0 "), (int)NO_VAL);
+	ck_assert_int_eq(time_str2secs("0-1:60:15"), 1*60*60 + 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("1-1:60:15"), 1*60*60*24 + 1*60*60 + 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("365-1:60:15"), 365*60*60*24 + 1*60*60 + 60*60 + 15);
+	ck_assert_int_eq(time_str2secs("365-0:0:0"), 365*60*60*24);
+}
+END_TEST
+
+Suite *parse_time_suite(void)
+{
+	Suite *s = suite_create("parse_time");
+	TCase *tc_core = tcase_create("parse_time");
+	tcase_add_test(tc_core, test_time_str2secs);
+	suite_add_tcase(s, tc_core);
+	return s;
+}
+
+int main(void)
+{
+	int number_failed;
+	SRunner *sr = srunner_create(parse_time_suite());
+
+	srunner_run_all(sr, CK_ENV);
+	number_failed = srunner_ntests_failed(sr);
+	srunner_free(sr);
+
+	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
-- 
GitLab