From 1b5fbc1d8b21d73f4e4e74d559ee278257823f0c Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Wed, 24 Jan 2024 10:45:32 -0600 Subject: [PATCH] Add 2038 test during build -- make check will fail is there is a 2038 problem https://github.com/Hamlib/Hamlib/issues/1478 --- tests/Makefile.am | 8 ++++++-- tests/test2038.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/test2038.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 11831e511..977d0b69f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,7 +17,7 @@ DISTCLEANFILES = rigctl.log rigctl.sum testbcd.log testbcd.sum bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rigctltcp rigctlsync ampctl ampctld rigtestmcast rigtestmcastrx $(TESTLIBUSB) rigfreqwalk #check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid testsecurity -check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid hamlibmodels testmW2power +check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid hamlibmodels testmW2power test2038 RIGCOMMONSRC = rigctl_parse.c rigctl_parse.h dumpcaps.c dumpstate.c uthash.h rig_tests.c rig_tests.h dumpcaps.h ROTCOMMONSRC = rotctl_parse.c rotctl_parse.h dumpcaps_rot.c uthash.h dumpcaps_rot.h @@ -106,7 +106,7 @@ endif EXTRA_DIST = rigmatrix_head.html rig_split_lst.awk testctld.pl testrotctld.pl # Support 'make check' target for simple tests -check_SCRIPTS = testrig.sh testfreq.sh testbcd.sh testloc.sh testrigcaps.sh testcache.sh testcookie.sh testgrid.sh +check_SCRIPTS = testrig.sh testfreq.sh testbcd.sh testloc.sh testrigcaps.sh testcache.sh testcookie.sh testgrid.sh test2038.sh TESTS = $(check_SCRIPTS) @@ -143,4 +143,8 @@ testgrid.sh: echo './testgrid' > testgrid.sh chmod +x ./testgrid.sh +test2038.sh: + echo 'LD_LIBRARY_PATH=$(top_builddir)/src/.libs:$(top_builddir)/dummy/.libs ./test2038 1' > test2038.sh + chmod +x ./test2038.sh + CLEANFILES = testrig.sh testfreq.sh testbcd.sh testloc.sh testrigcaps.sh testcache.sh testcookie.sh rigtestlibusb build-w32.sh build-w64.sh build-w64-jtsdk.sh testgrid.sh testrigcaps.sh diff --git a/tests/test2038.c b/tests/test2038.c new file mode 100644 index 000000000..3145464d8 --- /dev/null +++ b/tests/test2038.c @@ -0,0 +1,33 @@ +/* 2038 test +This is OK on 64-bit systems and mingw64 +Does fail when compiled with gcc -m32 -o 2038 2038.c +*/ +#include +#include +#include + +int main(void) +{ + time_t x; + + x = (time_t)((1U << 31) - 1); + char *s = ctime(&x); + + //printf("%s", s); + if (!strstr(s, "2038")) { return 1; } + + x += 1; + s = ctime(&x); + + if (!strstr(s, "2038")) { return 1; } + + //printf("%s", s); + x += 1; + s = ctime(&x); + + if (!strstr(s, "2038")) { return 1; } + + //printf("%s", s); + + return 0; +}