summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2019-04-19 08:12:56 +0200
committerDaiki Ueno <dueno@redhat.com>2019-04-19 08:56:54 +0200
commit54690004aea7fd6bc07aeee919ab0848bf4549e6 (patch)
tree7cfe881f1522b1a7d1893af0b29b5a505af90e90
parent96a5dd4fa8e9c7b1d45fe934ec7829d494dbd372 (diff)
downloadgnutls-54690004aea7fd6bc07aeee919ab0848bf4549e6.tar.gz
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 <dueno@redhat.com>
-rw-r--r--.gitignore1
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/datefudge-check.c51
-rw-r--r--tests/scripts/common.sh2
4 files changed, 57 insertions, 1 deletions
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 <https://www.gnu.org/licenses/>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+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"