From: Russ Allbery Date: Fri, 28 May 2010 19:15:52 +0000 (+0000) Subject: Add a sample test program to the new test suite X-Git-Tag: openafs-devel-1_5_75~209 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=2e2494d6dbc3b4584c50b87073a2b7c7a0d13604 Add a sample test program to the new test suite Add a modified version of src/util/test_ktime to the new test suite as an example of how to write a test program with the new harness. Change-Id: Ifbceff1905f9f0dd686c2a2d2edc2f8796e7918f Reviewed-on: http://gerrit.openafs.org/2063 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/configure.in b/configure.in index beeb080..60ee219 100644 --- a/configure.in +++ b/configure.in @@ -176,7 +176,8 @@ src/volser/Makefile \ src/xstat/Makefile \ src/helper-splint.sh \ tests/Makefile \ -tests/tap/Makefile, +tests/tap/Makefile \ +tests/util/Makefile, [chmod a+x src/config/shlib-build chmod a+x src/config/shlib-install]) diff --git a/tests/Makefile.in b/tests/Makefile.in index 66d4ad2..7118378 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -10,6 +10,7 @@ RUNTESTS_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \ all: runtests cd tap && $(MAKE) $@ + cd util && $(MAKE) $@ runtests.o: $(srcdir)/runtests.c $(CCOBJ) $(CFLAGS) $(RUNTESTS_CPPFLAGS) -c $(srcdir)/runtests.c @@ -25,4 +26,5 @@ install: clean distclean: cd tap && $(MAKE) $@ + cd util && $(MAKE) $@ $(RM) -f *.o core runtests diff --git a/tests/TESTS b/tests/TESTS index e69de29..38f3826 100644 --- a/tests/TESTS +++ b/tests/TESTS @@ -0,0 +1 @@ +util/ktime diff --git a/tests/util/.gitignore b/tests/util/.gitignore new file mode 100644 index 0000000..d6963eb --- /dev/null +++ b/tests/util/.gitignore @@ -0,0 +1,5 @@ +# After changing this file, please run +# git ls-files -i --exclude-standard +# to check that you haven't inadvertently ignored any tracked files. + +/ktime-t diff --git a/tests/util/Makefile.in b/tests/util/Makefile.in new file mode 100644 index 0000000..763f1cd --- /dev/null +++ b/tests/util/Makefile.in @@ -0,0 +1,20 @@ +# Build rules for the OpenAFS util test suite. + +srcdir=@srcdir@ +abs_top_srcdir=@abs_top_srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + +CFLAGS += -I$(srcdir)/.. + +tests = ktime-t + +all: $(tests) + +ktime-t: ktime-t.o + $(CC) $(LDFLAGS) -o ktime-t ktime-t.o ../tap/libtap.a \ + $(abs_top_srcdir)/lib/util.a $(XLIBS) + +install: + +clean distclean: + $(RM) -f $(tests) *.o core diff --git a/tests/util/ktime-t.c b/tests/util/ktime-t.c new file mode 100644 index 0000000..f09f4e1 --- /dev/null +++ b/tests/util/ktime-t.c @@ -0,0 +1,86 @@ +/* + * Copyright 2000, International Business Machines Corporation and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +#include +#include + +#include + +#include +#include + +static struct testTime { + char *time; + long code; + long sec; +} testTimes[] = { + { "now", 1, 0 }, /* lookup current time */ + { "never", 0, 0xffffffff }, + { "12/3/89", 0, 628664400 }, + { "1/1/1", 0, 978325200 }, + { "1/0/80", -2, 0 }, + { "13/1/80", -2, 0 }, + { "0/1/80", -2, 0 }, + { "1/32/80", -2, 0 }, + { "2/30/80", 0, 320734799 }, + /* + * Oh, well: note that 2/30 is bigger than any real date in February, and + * since this algorithm approaches the correct value from below, this is + * the closest it can come. + */ + { "3/1/80", 0, 320734800 }, + { "3/1/80 0:00", 0, 320734800 }, + { "2/30/80 24:00", -2, 0 }, + { "2/30/80 23:60", -2, 0 }, + { "22/22/22", -2, 0 }, + { "12/31/69 19:07", 0, 420 }, + { "12/31/99 23:59", 0, 946702740 }, + { "12/31/99 23:59:59", 0, 946702799 }, + { "23:12", -1, 0 }, + { "22/12", -1, 0 }, + { "22/22/22 12", -1, 0 }, + { "12/31/199 23:59:59", -2, 0 }, + { "12/31/1888", -2, 0 }, + { "-13/-44/22 -15:77", -2, 0 }, + { "4/14/24", 0, 1713070800 }, + { "4/14/2024", 0, 1713070800 }, + { "4/14/68", 0, 0x7fffffff }, /* legal but w/sign bit on */ + { "4/14/69", 0, 0 }, + { NULL, 0, 0 } +}; + +int +main(void) +{ + long code, temp; + int errors; + time_t t; + struct testTime *tt; + + plan((sizeof(testTimes) / sizeof(testTimes[0]) - 1) * 2); + + /* should do timezone and daylight savings time correction so this program + * work in other than EST */ + putenv("TZ=EST"); + + errors = 0; + for (tt = testTimes; tt->time; tt++) { + t = 0; + code = ktime_DateToLong(tt->time, &t); + if (tt->code == 1) { + is_int(0, code, "ktime_DateToLong return for %s", tt->time); + ok((time(0) - t <= 1), "ktime_DateToLong result for %s", tt->time); + } else { + is_int(tt->code, code, "ktime_DateToLong return for %s", tt->time); + is_int(tt->sec, t, "ktime_DateToLong result for %s", tt->time); + } + } + + return 0; +}