From 3ed3c84c5dc3137e1801ac55724bc0b9d34d9cf3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 3 Oct 2023 19:07:36 +0200
Subject: [PATCH] Move tools tests to tools/ subdirectory.

---
 ChangeLog                               | 12 ++++++++++++
 testsuite/Makefile.in                   |  8 +++-----
 testsuite/teardown-env                  |  3 ---
 tools/Makefile.in                       | 15 +++++++++++----
 {testsuite => tools}/nettle-pbkdf2-test |  2 +-
 {testsuite => tools}/pkcs1-conv-test    |  6 +++---
 {testsuite => tools}/sexp-conv-test     | 24 ++++++++++++------------
 7 files changed, 42 insertions(+), 28 deletions(-)
 delete mode 100755 testsuite/teardown-env
 rename {testsuite => tools}/nettle-pbkdf2-test (91%)
 rename {testsuite => tools}/pkcs1-conv-test (92%)
 rename {testsuite => tools}/sexp-conv-test (77%)

diff --git a/ChangeLog b/ChangeLog
index fe330d79..6e329321 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-10-03  Niels Möller  <nisse@lysator.liu.se>
+
+	* testsuite/Makefile.in (TS_SH): Delete tools tests from list.
+	* tools/Makefile.in (check): Run tools tests from this target.
+	(TS_ALL): New variable.
+	(DISTFILES): Add TS_ALL files.
+	* testsuite/teardown-env: Deleted, intead let make clean delete
+	test files.
+	* tools/nettle-pbkdf2-test: Moved, from testseuite/.
+	* tools/sexp-conv-test: Likewise.
+	* tools/pkcs1-conv-test: Likewise.
+
 2023-08-02  Niels Möller  <nisse@lysator.liu.se>
 
 	* configure.ac: Replace obsoleted macros, require autoconf-2.69,
diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in
index 5c2a0028..60c413cd 100644
--- a/testsuite/Makefile.in
+++ b/testsuite/Makefile.in
@@ -66,7 +66,7 @@ TS_HOGWEED = $(TS_HOGWEED_SOURCES:.c=$(EXEEXT))
 TS_C = $(TS_NETTLE) @IF_HOGWEED@ $(TS_HOGWEED)
 TS_CXX = @IF_CXX@ $(CXX_SOURCES:.cxx=$(EXEEXT))
 TARGETS = $(TS_C) $(TS_CXX)
-TS_SH = sexp-conv-test pkcs1-conv-test nettle-pbkdf2-test symbols-test
+TS_SH = symbols-test
 TS_ALL = $(TARGETS) $(TS_SH) @IF_DLOPEN_TEST@ dlopen-test$(EXEEXT)
 EXTRA_SOURCES = sha1-huge-test.c
 EXTRA_TARGETS = $(EXTRA_SOURCES:.c=$(EXEEXT))
@@ -76,8 +76,7 @@ EXTRA_TARGETS = $(EXTRA_SOURCES:.c=$(EXEEXT))
 SOURCES = $(TS_SOURCES) $(EXTRA_SOURCES) testutils.c dlopen-test.c
 
 DISTFILES = $(SOURCES) $(CXX_SOURCES) Makefile.in \
-	    $(TS_SH) teardown-env \
-	    gold-bug.txt testutils.h sha3.awk
+	    $(TS_SH) gold-bug.txt testutils.h sha3.awk
 
 all: $(EXTRA_TARGETS)
 
@@ -128,7 +127,6 @@ check: $(TS_ALL)
 	  EMULATOR="$(EMULATOR)" NM="$(NM)" EXEEXT="$(EXEEXT)" \
           $(top_srcdir)/run-tests $(TS_ALL)
 
-
 Makefile: $(srcdir)/Makefile.in ../config.status
 	cd .. && $(SHELL) ./config.status testsuite/$@
 
@@ -140,7 +138,7 @@ distdir: $(DISTFILES)
 
 clean:
 	-rm -f $(TARGETS) $(EXTRA_TARGETS) dlopen-test$(EXEEXT) \
-		*.$(OBJEXT) *.$(OBJEXT).d test.in test1.out test2.out
+		*.$(OBJEXT) *.$(OBJEXT).d test1.out
 
 distclean: clean
 	-rm -f Makefile *.d
diff --git a/testsuite/teardown-env b/testsuite/teardown-env
deleted file mode 100755
index f19bbe9c..00000000
--- a/testsuite/teardown-env
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-
-rm -rf testkey.priv testkey.pub testtmp testsignature testsignature2
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 4bdb11fb..b76024c2 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -22,6 +22,8 @@ TARGETS = sexp-conv$(EXEEXT) nettle-hash$(EXEEXT) nettle-pbkdf2$(EXEEXT) \
 	  nettle-lfib-stream$(EXEEXT) \
 	  @IF_HOGWEED@ $(HOGWEED_TARGETS)
 
+TS_ALL = sexp-conv-test pkcs1-conv-test nettle-pbkdf2-test
+
 all: $(TARGETS)
 
 getopt_OBJS = ../getopt.$(OBJEXT) ../getopt1.$(OBJEXT)
@@ -33,7 +35,7 @@ nettle_pbkdf2_SOURCES = nettle-pbkdf2.c misc.c
 
 SOURCES = $(sexp_conv_SOURCES) nettle-hash.c nettle-lfib-stream.c pkcs1-conv.c nettle-pbkdf2.c
 
-DISTFILES = $(SOURCES) Makefile.in input.h misc.h output.h parse.h
+DISTFILES = $(SOURCES) $(TS_ALL) Makefile.in input.h misc.h output.h parse.h
 
 sexp_conv_OBJS = $(sexp_conv_SOURCES:.c=.$(OBJEXT)) $(getopt_OBJS)
 sexp-conv$(EXEEXT): $(sexp_conv_OBJS) ../libnettle.stamp
@@ -69,8 +71,12 @@ nettle-pbkdf2$(EXEEXT): $(nettle_pbkdf2_OBJS) ../libnettle.stamp
 Makefile: $(srcdir)/Makefile.in ../config.status
 	cd .. && $(SHELL) ./config.status tools/$@
 
-check:
-	true
+check: $(TS_ALL)
+	TEST_SHLIB_DIR="$(TEST_SHLIB_DIR)" \
+	  srcdir="$(srcdir)" \
+	  EMULATOR="$(EMULATOR)" EXEEXT="$(EXEEXT)" \
+          $(top_srcdir)/run-tests $(TS_ALL)
+
 
 install: $(TARGETS)
 	$(MKDIR_P) $(DESTDIR)$(bindir)
@@ -89,7 +95,8 @@ distdir: $(DISTFILES)
 	cp $? $(distdir)
 
 clean:
-	-rm -f $(TARGETS) *.$(OBJEXT) *.$(OBJEXT).d
+	-rm -f $(TARGETS) *.$(OBJEXT) *.$(OBJEXT).d test.in test1.out test2.out \
+	testkey.priv testkey.pub testtmp testsignature testsignature2
 
 distclean: clean
 	-rm -f Makefile *.d
diff --git a/testsuite/nettle-pbkdf2-test b/tools/nettle-pbkdf2-test
similarity index 91%
rename from testsuite/nettle-pbkdf2-test
rename to tools/nettle-pbkdf2-test
index fb18c42f..2229cb9b 100755
--- a/testsuite/nettle-pbkdf2-test
+++ b/tools/nettle-pbkdf2-test
@@ -15,7 +15,7 @@ test_pbkdf2 () {
 
     # Delete carriage return characters, needed when testing with
     # wine.
-    printf "%s" "$password" | $EMULATOR ../tools/nettle-pbkdf2 \
+    printf "%s" "$password" | $EMULATOR ./nettle-pbkdf2 \
 	-i "$iters" -l "$length" "$salt" | tr -d '\r' > test1.out
     echo "$expected" | tr -d '\r' > test2.out
 
diff --git a/testsuite/pkcs1-conv-test b/tools/pkcs1-conv-test
similarity index 92%
rename from testsuite/pkcs1-conv-test
rename to tools/pkcs1-conv-test
index 31982322..0cc28b49 100755
--- a/testsuite/pkcs1-conv-test
+++ b/tools/pkcs1-conv-test
@@ -4,10 +4,10 @@ if [ -z "$srcdir" ] ; then
   srcdir=`pwd`
 fi
 
-[ -x ../tools/pkcs1-conv$EXEEXT ] || exit 77
+[ -x ./pkcs1-conv$EXEEXT ] || exit 77
 
 # Private RSA key, generated by openssl
-$EMULATOR ../tools/pkcs1-conv >testkey.priv <<EOF || exit 1
+$EMULATOR ./pkcs1-conv >testkey.priv <<EOF || exit 1
 -----BEGIN RSA PRIVATE KEY-----
 MIICXQIBAAKBgQC3792bBgQ/mc8aYOFaLEJES/JipmLAeVgznob/Vrzvdcx+bl6L
 6gTphctU9ToOLC049dZYW3DJ53owUmbQgqB0vvLTjM9lGSEw4oXLrp7x/XVo/fZM
@@ -25,7 +25,7 @@ PSVKy/gGBeN1Q7Rj+XoybQ/SqLpfgTYRI9UpbKmpkNuq
 -----END RSA PRIVATE KEY-----
 EOF
 
-$EMULATOR ../tools/pkcs1-conv >testkey.pub <<EOF || exit 1
+$EMULATOR ./pkcs1-conv >testkey.pub <<EOF || exit 1
 # Corresponding public key
 -----BEGIN PUBLIC KEY-----
 MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3792bBgQ/mc8aYOFaLEJES/Ji
diff --git a/testsuite/sexp-conv-test b/tools/sexp-conv-test
similarity index 77%
rename from testsuite/sexp-conv-test
rename to tools/sexp-conv-test
index 5b59cb71..587f16df 100755
--- a/testsuite/sexp-conv-test
+++ b/tools/sexp-conv-test
@@ -14,7 +14,7 @@ print_nl () {
 
 test_advanced () {
     print_raw "$1" test.in
-    if $EMULATOR ../tools/sexp-conv -s advanced <test.in | tr -d '\r' >test1.out ; then
+    if $EMULATOR ./sexp-conv -s advanced <test.in | tr -d '\r' >test1.out ; then
 	true
     else
 	exit 1
@@ -30,7 +30,7 @@ test_advanced () {
 
 test_advanced_hex () {
     print_raw "$1" test.in
-    if $EMULATOR ../tools/sexp-conv -s hex <test.in | tr -d '\r' >test1.out ; then
+    if $EMULATOR ./sexp-conv -s hex <test.in | tr -d '\r' >test1.out ; then
 	true
     else
 	exit 1
@@ -46,7 +46,7 @@ test_advanced_hex () {
 
 test_transport () {
     print_raw "$1" test.in
-    if $EMULATOR ../tools/sexp-conv -s transport <test.in | tr -d '\r' >test1.out ; then
+    if $EMULATOR ./sexp-conv -s transport <test.in | tr -d '\r' >test1.out ; then
 	true
     else
 	exit 1
@@ -62,7 +62,7 @@ test_transport () {
 
 test_canonical () {
     print_raw "$1" test.in
-    if $EMULATOR ../tools/sexp-conv -s canonical <test.in >test1.out ; then
+    if $EMULATOR ./sexp-conv -s canonical <test.in >test1.out ; then
 	true
     else
 	exit 1
@@ -80,18 +80,18 @@ test_advanced '0:' '""'
 test_advanced '3:foo' 'foo'
 test_advanced '12:fooooooooooo' 'fooooooooooo'
 test_advanced '10:fooooooooo' 'fooooooooo'
-test_advanced '4:3des' '"3des"' 
-test_advanced '"foo"' 'foo' 
+test_advanced '4:3des' '"3des"'
+test_advanced '"foo"' 'foo'
 test_advanced '4:foo
 ' '"foo\n"'
 # Having the string end with a \ breaks with sysv echo. \x seems harmless.
-test_advanced '3:"\x' '"\"\\x"' 
-test_advanced '()' '()' 
+test_advanced '3:"\x' '"\"\\x"'
+test_advanced '()' '()'
 test_advanced '(foo bar baz)' '(foo bar
-     baz)' 
+     baz)'
 test_advanced '; comment
 ()' '; comment
-()' 
+()'
 test_advanced '(foo ; gazonk
 bar)' '(foo ; gazonk
      bar)'
@@ -118,7 +118,7 @@ test_canonical '{MTpB}' '1:A'
 test_canonical 'foo' '3:foo'
 test_canonical 'fooooooooooo' '12:fooooooooooo'
 test_canonical 'fooooooooo' '10:fooooooooo'
-test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)' 
-test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)' 
+test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)'
+test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)'
 
 exit 0
-- 
GitLab