From 66f4782f1452d6fbfab78822b340a99aaeacc2f0 Mon Sep 17 00:00:00 2001 From: slontis Date: Mon, 20 Mar 2023 15:08:38 +1000 Subject: Create hierarchical demo Makefile. Adds a Makefile with all, clean, and test targets. This has only been added for demos that already contain Makefiles. For problematic tests that require inputs, the test target does nothing. (Note: Demos should be self contained and not require unknown external inputs. This PR does not attempt to fix this.) Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Tim Hudson (Merged from https://github.com/openssl/openssl/pull/20546) --- demos/Makefile | 14 ++++++++++++++ demos/bio/Makefile | 2 ++ demos/cipher/Makefile | 12 +++++++++++- demos/digest/Makefile | 15 ++++++++++++--- demos/encode/Makefile | 8 +++++--- demos/encrypt/Makefile | 16 ++++++++++++---- demos/kdf/Makefile | 17 +++++++++++++---- demos/keyexch/Makefile | 28 ++++++++++++++++++++++++++++ demos/mac/Makefile | 14 ++++++++++++-- demos/pkey/Makefile | 19 +++++++++++++------ demos/signature/Makefile | 16 ++++++++++++---- demos/sslecho/makefile | 2 ++ 12 files changed, 136 insertions(+), 27 deletions(-) create mode 100644 demos/Makefile create mode 100644 demos/keyexch/Makefile (limited to 'demos') diff --git a/demos/Makefile b/demos/Makefile new file mode 100644 index 0000000..4c807a0 --- /dev/null +++ b/demos/Makefile @@ -0,0 +1,14 @@ +MODULES=bio digest encode encrypt kdf keyexch mac pkey signature sslecho + +all: + @set -e; for i in $(MODULES); do \ + ${MAKE} -C $$i all; \ + done +clean: + @set -e; for i in $(MODULES); do \ + ${MAKE} -C $$i clean; \ + done +test: + @set -e; for i in $(MODULES); do \ + ${MAKE} -C $$i test; \ + done diff --git a/demos/bio/Makefile b/demos/bio/Makefile index 86f19d4..ca4dee8 100644 --- a/demos/bio/Makefile +++ b/demos/bio/Makefile @@ -18,6 +18,8 @@ LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto $(EX_LIBS) all: client-arg client-conf saccept sconnect server-arg server-cmod server-conf +test: + client-arg: client-arg.o client-conf: client-conf.o saccept: saccept.o diff --git a/demos/cipher/Makefile b/demos/cipher/Makefile index 81f5265..df6ebeb 100644 --- a/demos/cipher/Makefile +++ b/demos/cipher/Makefile @@ -13,7 +13,9 @@ CFLAGS = $(OPENSSL_INCS_LOCATION) LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto -all: aesccm aesgcm aeskeywrap ariacbc +TESTS=aesccm aesgcm aeskeywrap ariacbc + +all: $(TESTS) aesccm: aesccm.o aesgcm: aesgcm.o @@ -25,3 +27,11 @@ aesccm aesgcm aeskeywrap ariacbc: clean: $(RM) aesccm aesgcm aeskeywrap ariacbc *.o + +.PHONY: test +test: all + @echo "\nCipher tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/digest/Makefile b/demos/digest/Makefile index 0bfb6dd..d72a9d0 100644 --- a/demos/digest/Makefile +++ b/demos/digest/Makefile @@ -7,7 +7,9 @@ CFLAGS = -I../../include -g -Wall LDFLAGS = -L../.. LDLIBS = -lcrypto -all: EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md +TESTS=EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md + +all: $(TESTS) %.o: %.c $(CC) $(CFLAGS) -c $< @@ -17,7 +19,14 @@ EVP_MD_stdin: EVP_MD_stdin.o EVP_MD_xof: EVP_MD_xof.o BIO_f_md: BIO_f_md.o -test: ; +.PHONY: test +# Since some of these tests use stdin we use the source file as stdin when running the exes +test: all + @echo "\nDigest tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + cat $$tst.c | ./$$tst; \ + done clean: - $(RM) *.o EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md + $(RM) *.o $(TESTS) diff --git a/demos/encode/Makefile b/demos/encode/Makefile index b88d76b..9be1179 100644 --- a/demos/encode/Makefile +++ b/demos/encode/Makefile @@ -7,14 +7,16 @@ CFLAGS = -I../../include -g -Wall LDFLAGS = -L../.. LDLIBS = -lcrypto -all: ec_encode rsa_encode +TESTS=ec_encode rsa_encode + +all: $(TESTS) %.o: %.c $(CC) $(CFLAGS) -c $< %_encode: %_encode.o -test: ; +test: clean: - $(RM) *.o rsa_encode ec_encode + $(RM) *.o $(TESTS) diff --git a/demos/encrypt/Makefile b/demos/encrypt/Makefile index d07dc0c..6d4e060 100644 --- a/demos/encrypt/Makefile +++ b/demos/encrypt/Makefile @@ -7,14 +7,22 @@ CFLAGS = -I../../include -g LDFLAGS = -L../.. LDLIBS = -lcrypto -all: rsa_encrypt +TESTS=rsa_encrypt + +all: $(TESTS) %.o: %.c $(CC) $(CFLAGS) -c $< rsa_encrypt: rsa_encrypt.o -test: ; - clean: - $(RM) *.o rsa_encrypt + $(RM) *.o $(TESTS) + +.PHONY: test +test: all + @echo "\nEncrypt tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/kdf/Makefile b/demos/kdf/Makefile index 364a104..28ad720 100644 --- a/demos/kdf/Makefile +++ b/demos/kdf/Makefile @@ -7,7 +7,9 @@ CFLAGS = -I../../include -g LDFLAGS = -L../.. LDLIBS = -lcrypto -all: hkdf pbkdf2 scrypt argon2 +TESTS=hkdf pbkdf2 scrypt argon2 + +all: $(TESTS) %.o: %.c $(CC) $(CFLAGS) -c $< @@ -15,8 +17,15 @@ all: hkdf pbkdf2 scrypt argon2 hkdf: hkdf.o pbkdf2: pbkdf2.o scrypt: scrypt.o - -test: ; +argon2: argon2.o clean: - $(RM) *.o hkdf pbkdf2 scrypt argon2 + $(RM) *.o $(TESTS) + +.PHONY: test +test: all + @echo "\nKDF tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/keyexch/Makefile b/demos/keyexch/Makefile new file mode 100644 index 0000000..24243e1 --- /dev/null +++ b/demos/keyexch/Makefile @@ -0,0 +1,28 @@ +# +# To run the demos when linked with a shared library (default): +# +# LD_LIBRARY_PATH=../.. ./x25519 + +CFLAGS = -I../../include -g -Wall +LDFLAGS = -L../.. +LDLIBS = -lcrypto + +TESTS=x25519 + +all: $(TESTS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +%x25519: %x25519.o + +.PHONY: test +test: all + @echo "\nKeyExchange tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done + +clean: + $(RM) *.o $(TESTS) diff --git a/demos/mac/Makefile b/demos/mac/Makefile index 00d2d8d..629e77d 100644 --- a/demos/mac/Makefile +++ b/demos/mac/Makefile @@ -11,7 +11,9 @@ CFLAGS = $(OPENSSL_INCS_LOCATION) -Wall LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto -all: gmac hmac-sha512 cmac-aes256 poly1305 +TESTS=gmac hmac-sha512 cmac-aes256 poly1305 + +all: $(TESTS) gmac: gmac.o hmac-sha512: hmac-sha512.o @@ -22,4 +24,12 @@ gmac hmac-sha512 cmac-aes256 poly1305: $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) clean: - $(RM) gmac hmac-sha512 cmac-aes256 poly1305 *.o + $(RM) *.o $(TESTS) + +.PHONY: test +test: all + @echo "\nMAC tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/pkey/Makefile b/demos/pkey/Makefile index 9e70130..d84fcd6 100644 --- a/demos/pkey/Makefile +++ b/demos/pkey/Makefile @@ -12,8 +12,10 @@ CFLAGS = -I../../include -g -Wall LDFLAGS = -L../.. LDLIBS = -lcrypto -all: EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen EVP_PKEY_DSA_keygen \ - EVP_PKEY_DSA_paramgen EVP_PKEY_DSA_paramvalidate EVP_PKEY_DSA_paramfromdata \ +TESTS=EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen EVP_PKEY_DSA_keygen \ +EVP_PKEY_DSA_paramgen EVP_PKEY_DSA_paramvalidate EVP_PKEY_DSA_paramfromdata + +all: $(TESTS) %.o: %.c dsa.inc $(CC) $(CFLAGS) -c $< @@ -30,8 +32,13 @@ EVP_PKEY_DSA_paramvalidate: EVP_PKEY_DSA_paramvalidate.o EVP_PKEY_DSA_paramfromdata: EVP_PKEY_DSA_paramfromdata.o -test: ; - clean: - $(RM) *.o EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen EVP_PKEY_DSA_keygen \ - EVP_PKEY_DSA_paramgen EVP_PKEY_DSA_paramfromdata EVP_PKEY_DSA_paramvalidate + $(RM) *.o $(TESTS) + +.PHONY: test +test: all + @echo "\nPKEY tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/signature/Makefile b/demos/signature/Makefile index 2a7c196..50f1c34 100644 --- a/demos/signature/Makefile +++ b/demos/signature/Makefile @@ -11,7 +11,9 @@ CFLAGS = -I../../include -g -Wall LDFLAGS = -L../.. LDLIBS = -lcrypto -all: EVP_EC_Signature_demo EVP_DSA_Signature_demo EVP_ED_Signature_demo rsa_pss_direct rsa_pss_hash +TESTS=EVP_EC_Signature_demo EVP_DSA_Signature_demo EVP_ED_Signature_demo rsa_pss_direct rsa_pss_hash + +all: $(TESTS) %.o: %.c $(CC) $(CFLAGS) -c $< @@ -22,7 +24,13 @@ EVP_ED_Signature_demo: EVP_ED_Signature_demo.o rsa_pss_direct: rsa_pss_direct.o rsa_pss_hash: rsa_pss_hash.o -test: ; - clean: - $(RM) *.o EVP_EC_Signature_demo EVP_DSA_Signature_demo EVP_ED_Signature_demo rsa_pss_direct rsa_pss_hash + $(RM) *.o $(TESTS) + +.PHONY: test +test: all + @echo "\nSignature tests:" + @set -e; for tst in $(TESTS); do \ + echo "\n"$$tst; \ + LD_LIBRARY_PATH=../.. ./$$tst; \ + done diff --git a/demos/sslecho/makefile b/demos/sslecho/makefile index 6e63991..1e91567 100644 --- a/demos/sslecho/makefile +++ b/demos/sslecho/makefile @@ -8,5 +8,7 @@ $(PROG): main.c $(CC) -O0 -g3 -W -Wall -I../../include -L../../ -o $(PROG) main.c -lssl -lcrypto +test: + clean: rm -rf $(PROG) *.o *.obj -- cgit v1.1