From 54690004aea7fd6bc07aeee919ab0848bf4549e6 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 19 Apr 2019 08:12:56 +0200 Subject: tests: make datefudge check robuster When checking datefudge availability under cross-compiling environment with a binfmt wrapper, it is not sufficient to check against the host executable. This instead uses a test executable compiled for the target architecture. Signed-off-by: Daiki Ueno --- .gitignore | 1 + tests/Makefile.am | 4 ++++ tests/datefudge-check.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/scripts/common.sh | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/datefudge-check.c diff --git a/.gitignore b/.gitignore index 0e33b02d40..f7983c159b 100644 --- a/.gitignore +++ b/.gitignore @@ -369,6 +369,7 @@ tests/cve-2009-1415 tests/cve-2009-1416 tests/dane tests/dane-strcodes +tests/datefudge-check tests/dh-params tests/dhepskself tests/dhex509self diff --git a/tests/Makefile.am b/tests/Makefile.am index 3917967988..940e1ba605 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -527,6 +527,10 @@ sanity_cpp_CXXFLAGS = $(AM_CPPFLAGS) \ endif endif +if !WINDOWS +indirect_tests += datefudge-check +endif + check_PROGRAMS = $(cpptests) $(ctests) $(indirect_tests) TESTS = $(cpptests) $(ctests) $(dist_check_SCRIPTS) diff --git a/tests/datefudge-check.c b/tests/datefudge-check.c new file mode 100644 index 0000000000..f2d896d622 --- /dev/null +++ b/tests/datefudge-check.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Red Hat + * + * Author: Daiki Ueno + * + * This file is part of GnuTLS. + * + * GnuTLS 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 3 of the License, or + * (at your option) any later version. + * + * GnuTLS 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 Lesser General Public License + * along with this program. If not, see + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +int +main (void) +{ + char outstr[200]; + time_t t; + struct tm *tmp; + + t = time(NULL); + tmp = localtime(&t); + if (tmp == NULL) { + perror("localtime"); + exit(EXIT_FAILURE); + } + + if (strftime(outstr, sizeof(outstr), "%s", tmp) == 0) { + fprintf(stderr, "strftime returned 0"); + exit(EXIT_FAILURE); + } + + puts(outstr); + exit(EXIT_SUCCESS); +} diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh index a714bcd608..d34915e1d7 100644 --- a/tests/scripts/common.sh +++ b/tests/scripts/common.sh @@ -76,7 +76,7 @@ check_for_datefudge() { return fi - TSTAMP=`datefudge -s "2006-09-23" date -u +%s || true` + TSTAMP=`datefudge -s "2006-09-23" "${top_builddir}/tests/datefudge-check" || true` if test "$TSTAMP" != "1158969600" || test "$WINDOWS" = 1; then echo $TSTAMP echo "You need datefudge to run this test" -- cgit v1.2.1