From 99705a68138f929e932f6d97ce0073545155b655 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Apr 2021 00:21:58 +0200 Subject: [PATCH 1/3] Use Python 3 instead of Python 2 to generate test files Python 2 is no longer officially supported, but we were still using it to generate test suite .c files from .function files when using GNU make. Switch to looking for Python 3. CMake currently uses a system-dependent version of the Python language. This commit does not affect CMake builds. Signed-off-by: Gilles Peskine --- tests/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 1555b559e5..79f5b8e703 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -44,8 +44,7 @@ else DLEXT ?= so EXEXT= SHARED_SUFFIX= -# python2 for POSIX since FreeBSD has only python2 as default. -PYTHON ?= python2 +PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi) endif # Zlib shared library extensions: From 484df7583bf16252ec28bb3522d06f8739a86935 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 6 May 2021 11:34:07 +0200 Subject: [PATCH 2/3] Changelog entry for no longer explicitly invoking python2 Signed-off-by: Gilles Peskine --- ChangeLog.d/make-generate-tests-python.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ChangeLog.d/make-generate-tests-python.txt diff --git a/ChangeLog.d/make-generate-tests-python.txt b/ChangeLog.d/make-generate-tests-python.txt new file mode 100644 index 0000000000..0feeff8857 --- /dev/null +++ b/ChangeLog.d/make-generate-tests-python.txt @@ -0,0 +1,4 @@ +Changes + * When building the test suites with GNU make, invoke python3 or python, not + python2. The build still works with either Python 2.7 or 3.5+, but we + recommend using a version of Python that is supported upstream. From 3c546f71c9dd9d752a259fffa60da6d4f7c19558 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 6 May 2021 15:07:29 +0200 Subject: [PATCH 3/3] Test that generate_test_code.py is still compatible with Python 2 When Mbed TLS 2.16 was released, the requirement was Python 2, not Python 3. Since then, upstream Python 2 support has stopped, but it is still maintained in some long-term-support distributions. For the sake of users who build the unit tests in such environments, test that generate_test_code.py remains compatible with Python 2. Signed-off-by: Gilles Peskine --- tests/Makefile | 3 ++- tests/scripts/all.sh | 12 ++++++++++++ tests/scripts/generate_test_code.py | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 79f5b8e703..29f2fa142f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -62,7 +62,7 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS)) .SILENT: -.PHONY: all check test clean +.PHONY: all c_files check test clean all: $(BINARIES) @@ -70,6 +70,7 @@ $(DEP): $(MAKE) -C ../library C_FILES := $(addsuffix .c,$(APPS)) +c_files: $(C_FILES) # Wildcard target for test code generation: # A .c file is generated for each .data file in the suites/ directory. Each .c diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 1e56c3e62a..1a4de44b66 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -691,6 +691,18 @@ component_check_doxygen_warnings () { record_status tests/scripts/doxygen.sh } +component_check_python2 () { + # Check that what used to work with Python 2 still works with Python 2. + msg "check: python2 compatibility" + mkdir -p tests/with_python2 tests/with_python3 + make -C tests PYTHON=python2 c_files + mv tests/test_suite_*.c tests/with_python2/ + make -C tests PYTHON=python3 c_files + mv tests/test_suite_*.c tests/with_python3/ + diff -r tests/with_python2 tests/with_python3 + rm -rf tests/with_python2 tests/with_python3 +} + ################################################################ diff --git a/tests/scripts/generate_test_code.py b/tests/scripts/generate_test_code.py index f452b3767a..b74ed5501f 100755 --- a/tests/scripts/generate_test_code.py +++ b/tests/scripts/generate_test_code.py @@ -1,4 +1,7 @@ #!/usr/bin/env python3 + +# This script should still be compatible with Python 2 in Mbed TLS 2.16.x. + # Test suites code generator. # # Copyright The Mbed TLS Contributors