From 8a07110cef2df5960792fed94efbcb85dbd736b8 Mon Sep 17 00:00:00 2001 From: Norbert Heusser Date: Mon, 28 Nov 2022 15:00:03 +0000 Subject: [PATCH] Moved python tests inside test/apps to subfolder per app Signed-off-by: Norbert Heusser --- Makefile | 4 +-- test/apps/CMakeLists.txt | 22 ++------------ test/apps/Makefile | 30 +++++++------------ test/apps/ctrl/CMakeLists.txt | 19 ++++++++++++ test/apps/ctrl/Makefile | 19 ++++++++++++ .../{02-ctrl-args.py => ctrl/ctrl-args.py} | 0 .../ctrl-broker.py} | 0 .../ctrl-dynsec.py} | 0 test/apps/ctrl/mosq_test_helper.py | 19 ++++++++++++ test/apps/ctrl/test.py | 13 ++++++++ test/apps/db_dump/CMakeLists.txt | 19 ++++++++++++ test/apps/db_dump/Makefile | 21 +++++++++++++ .../db-dump-client-stats.py} | 9 +++--- .../db-dump-corrupt.py} | 9 +++--- .../db-dump-print-empty.py} | 7 +++-- .../db-dump-print-v6-all.py} | 15 ++++++++-- .../db-dump-print-v6-mqtt-v5-props.py} | 7 +++-- .../db-dump-stats-current.py} | 19 +++++++----- .../db-dump-stats.py} | 7 +++-- test/apps/db_dump/mosq_test_helper.py | 18 +++++++++++ test/apps/db_dump/test.py | 12 ++++++++ test/apps/passwd/CMakeLists.txt | 19 ++++++++++++ test/apps/passwd/Makefile | 18 +++++++++++ test/apps/passwd/mosq_test_helper.py | 18 +++++++++++ .../passwd-args.py} | 0 .../passwd-changes.py} | 0 test/apps/passwd/test.py | 12 ++++++++ 27 files changed, 268 insertions(+), 68 deletions(-) create mode 100644 test/apps/ctrl/CMakeLists.txt create mode 100644 test/apps/ctrl/Makefile rename test/apps/{02-ctrl-args.py => ctrl/ctrl-args.py} (100%) rename test/apps/{02-ctrl-broker.py => ctrl/ctrl-broker.py} (100%) rename test/apps/{02-ctrl-dynsec.py => ctrl/ctrl-dynsec.py} (100%) create mode 100644 test/apps/ctrl/mosq_test_helper.py create mode 100755 test/apps/ctrl/test.py create mode 100644 test/apps/db_dump/CMakeLists.txt create mode 100644 test/apps/db_dump/Makefile rename test/apps/{01-db-dump-client-stats.py => db_dump/db-dump-client-stats.py} (78%) rename test/apps/{01-db-dump-corrupt.py => db_dump/db-dump-corrupt.py} (87%) rename test/apps/{01-db-dump-print-empty.py => db_dump/db-dump-print-empty.py} (88%) rename test/apps/{01-db-dump-print-v6-all.py => db_dump/db-dump-print-v6-all.py} (71%) rename test/apps/{01-db-dump-print-v6-mqtt-v5-props.py => db_dump/db-dump-print-v6-mqtt-v5-props.py} (93%) rename test/apps/{01-db-dump-stats-current.py => db_dump/db-dump-stats-current.py} (88%) rename test/apps/{01-db-dump-stats.py => db_dump/db-dump-stats.py} (91%) create mode 100644 test/apps/db_dump/mosq_test_helper.py create mode 100755 test/apps/db_dump/test.py create mode 100644 test/apps/passwd/CMakeLists.txt create mode 100644 test/apps/passwd/Makefile create mode 100644 test/apps/passwd/mosq_test_helper.py rename test/apps/{03-passwd-args.py => passwd/passwd-args.py} (100%) rename test/apps/{03-passwd-changes.py => passwd/passwd-changes.py} (100%) create mode 100755 test/apps/passwd/test.py diff --git a/Makefile b/Makefile index 6251b206..565748e2 100644 --- a/Makefile +++ b/Makefile @@ -81,10 +81,10 @@ reallyclean : check : test -test-compile: +test-compile: mosquitto lib $(MAKE) -C test test-compile -test : mosquitto +test : mosquitto lib apps $(MAKE) -C test test ptest : mosquitto diff --git a/test/apps/CMakeLists.txt b/test/apps/CMakeLists.txt index 7aea0bd1..de8285f6 100644 --- a/test/apps/CMakeLists.txt +++ b/test/apps/CMakeLists.txt @@ -1,19 +1,3 @@ -file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) - -set(EXCLUDE_LIST - # none -) - -foreach(PY_TEST_FILE ${PY_TEST_FILES}) - get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE) - if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST) - continue() - endif() - add_test(NAME apps-${PY_TEST_NAME} - COMMAND ${PY_TEST_FILE} - ) - set_tests_properties(apps-${PY_TEST_NAME} - PROPERTIES - ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}" - ) -endforeach() +add_subdirectory(ctrl) +add_subdirectory(db_dump) +add_subdirectory(passwd) diff --git a/test/apps/Makefile b/test/apps/Makefile index e2b19007..57cb859b 100644 --- a/test/apps/Makefile +++ b/test/apps/Makefile @@ -7,25 +7,17 @@ include ${R}/config.mk all : check : test -ptest : test -test : 01 02 03 -01 : - ./01-db-dump-client-stats.py - ./01-db-dump-corrupt.py - ./01-db-dump-print-empty.py - ./01-db-dump-print-v6-all.py - ./01-db-dump-print-v6-mqtt-v5-props.py - ./01-db-dump-stats-current.py - ./01-db-dump-stats.py +test : + $(MAKE) -C db_dump test + $(MAKE) -C ctrl test + $(MAKE) -C passwd test -02 : - ./02-ctrl-args.py - ./02-ctrl-broker.py - ./02-ctrl-dynsec.py +ptest : + $(MAKE) -C db_dump ptest + $(MAKE) -C ctrl ptest + $(MAKE) -C passwd ptest -03 : - ./03-passwd-args.py - ./03-passwd-changes.py - -clean: +reallyclean : clean +clean : + $(MAKE) -C db_dump clean diff --git a/test/apps/ctrl/CMakeLists.txt b/test/apps/ctrl/CMakeLists.txt new file mode 100644 index 00000000..7aea0bd1 --- /dev/null +++ b/test/apps/ctrl/CMakeLists.txt @@ -0,0 +1,19 @@ +file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) + +set(EXCLUDE_LIST + # none +) + +foreach(PY_TEST_FILE ${PY_TEST_FILES}) + get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE) + if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST) + continue() + endif() + add_test(NAME apps-${PY_TEST_NAME} + COMMAND ${PY_TEST_FILE} + ) + set_tests_properties(apps-${PY_TEST_NAME} + PROPERTIES + ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}" + ) +endforeach() diff --git a/test/apps/ctrl/Makefile b/test/apps/ctrl/Makefile new file mode 100644 index 00000000..9ecf2c15 --- /dev/null +++ b/test/apps/ctrl/Makefile @@ -0,0 +1,19 @@ +R=../../.. +include ${R}/config.mk + +.PHONY: all check test ptest clean +.NOTPARALLEL: + +all : + +check : test + +test : + ./ctrl-args.py + ./ctrl-broker.py + ./ctrl-dynsec.py + +ptest: + ./test.py + +clean: diff --git a/test/apps/02-ctrl-args.py b/test/apps/ctrl/ctrl-args.py similarity index 100% rename from test/apps/02-ctrl-args.py rename to test/apps/ctrl/ctrl-args.py diff --git a/test/apps/02-ctrl-broker.py b/test/apps/ctrl/ctrl-broker.py similarity index 100% rename from test/apps/02-ctrl-broker.py rename to test/apps/ctrl/ctrl-broker.py diff --git a/test/apps/02-ctrl-dynsec.py b/test/apps/ctrl/ctrl-dynsec.py similarity index 100% rename from test/apps/02-ctrl-dynsec.py rename to test/apps/ctrl/ctrl-dynsec.py diff --git a/test/apps/ctrl/mosq_test_helper.py b/test/apps/ctrl/mosq_test_helper.py new file mode 100644 index 00000000..ffedfdab --- /dev/null +++ b/test/apps/ctrl/mosq_test_helper.py @@ -0,0 +1,19 @@ +import logging + +import sys +from pathlib import Path + +logging.basicConfig( + level=logging.INFO, + format="%(levelname)s %(asctime)s.%(msecs)03d %(module)s: %(message)s", + datefmt="%H:%M:%S", +) + +current_source_dir = Path(__file__).resolve().parent +test_dir = current_source_dir.parents[1] +if test_dir not in sys.path: + sys.path.insert(0, str(test_dir)) + +import mosq_test +import subprocess +import os diff --git a/test/apps/ctrl/test.py b/test/apps/ctrl/test.py new file mode 100755 index 00000000..94efe9ba --- /dev/null +++ b/test/apps/ctrl/test.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +import mosq_test_helper +import pathlib +import ptest + +tests = [ + (0, './ctrl-args.py'), + (2, './ctrl-broker.py'), + (2, './ctrl-dynsec.py') +] + +ptest.run_tests(tests) diff --git a/test/apps/db_dump/CMakeLists.txt b/test/apps/db_dump/CMakeLists.txt new file mode 100644 index 00000000..7aea0bd1 --- /dev/null +++ b/test/apps/db_dump/CMakeLists.txt @@ -0,0 +1,19 @@ +file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) + +set(EXCLUDE_LIST + # none +) + +foreach(PY_TEST_FILE ${PY_TEST_FILES}) + get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE) + if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST) + continue() + endif() + add_test(NAME apps-${PY_TEST_NAME} + COMMAND ${PY_TEST_FILE} + ) + set_tests_properties(apps-${PY_TEST_NAME} + PROPERTIES + ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}" + ) +endforeach() diff --git a/test/apps/db_dump/Makefile b/test/apps/db_dump/Makefile new file mode 100644 index 00000000..6fa3dea1 --- /dev/null +++ b/test/apps/db_dump/Makefile @@ -0,0 +1,21 @@ +.PHONY: all check test test-compile ptest clean + +all : + +check : test + +test-compile: + +test: + ./db-dump-client-stats.py + ./db-dump-corrupt.py + ./db-dump-print-empty.py + ./db-dump-print-v6-all.py + ./db-dump-print-v6-mqtt-v5-props.py + ./db-dump-stats.py + ./db-dump-stats-current.py + +ptest: + ./test.py + +clean : diff --git a/test/apps/01-db-dump-client-stats.py b/test/apps/db_dump/db-dump-client-stats.py similarity index 78% rename from test/apps/01-db-dump-client-stats.py rename to test/apps/db_dump/db-dump-client-stats.py index 42e0c2e0..e95baf27 100755 --- a/test/apps/01-db-dump-client-stats.py +++ b/test/apps/db_dump/db-dump-client-stats.py @@ -9,10 +9,11 @@ def do_test(file, counts): f"MS: {counts[3]} " + \ f" {counts[4]}\n" - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - '--client-stats', - f'db_dump/{file}' - ] + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + '--client-stats', + f'./{file}' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') if res.stdout != stdout: diff --git a/test/apps/01-db-dump-corrupt.py b/test/apps/db_dump/db-dump-corrupt.py similarity index 87% rename from test/apps/01-db-dump-corrupt.py rename to test/apps/db_dump/db-dump-corrupt.py index b093cf0a..f87f7c60 100755 --- a/test/apps/01-db-dump-corrupt.py +++ b/test/apps/db_dump/db-dump-corrupt.py @@ -4,9 +4,10 @@ from mosq_test_helper import * def do_test(file, stderr, rc_expected): - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'db_dump/{file}' - ] + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + f'./{file}' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') if res.stderr != stderr: @@ -17,7 +18,7 @@ def do_test(file, stderr, rc_expected): print(res.returncode) raise mosq_test.TestError -do_test('missing.test-db', "Error: Unable to open db_dump/missing.test-db\n", 0) +do_test('missing.test-db', "Error: Unable to open ./missing.test-db\n", 0) do_test('bad-magic.test-db', "Error: Unrecognised file format.\n", 1) do_test('short.test-db', "Error: Corrupt persistent database.\n", 1) do_test('bad-dbid-size.test-db', "Error: Incompatible database configuration (dbid size is 5 bytes, expected 8)", 1) diff --git a/test/apps/01-db-dump-print-empty.py b/test/apps/db_dump/db-dump-print-empty.py similarity index 88% rename from test/apps/01-db-dump-print-empty.py rename to test/apps/db_dump/db-dump-print-empty.py index b26f372e..f74312d1 100755 --- a/test/apps/01-db-dump-print-empty.py +++ b/test/apps/db_dump/db-dump-print-empty.py @@ -4,9 +4,10 @@ from mosq_test_helper import * def do_test(file, stdout): - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'db_dump/{file}' - ] + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + f'./{file}' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') if res.stdout != stdout: diff --git a/test/apps/01-db-dump-print-v6-all.py b/test/apps/db_dump/db-dump-print-v6-all.py similarity index 71% rename from test/apps/01-db-dump-print-v6-all.py rename to test/apps/db_dump/db-dump-print-v6-all.py index ed2d8e00..3cf18a27 100755 --- a/test/apps/01-db-dump-print-v6-all.py +++ b/test/apps/db_dump/db-dump-print-v6-all.py @@ -4,13 +4,22 @@ from mosq_test_helper import * def do_test(file, stdout): - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'db_dump/{file}' + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + f'./{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') + if res.stdout != stdout: - print(res.stdout) + read_lines = res.stdout.splitlines() + expected_lines = stdout.splitlines() + for (read,expected) in zip(read_lines,expected_lines): + if read != expected: + print(f"- {expected}") + print(f"+ {read}") + else: + print(f" {read}") raise mosq_test.TestError stdout = """Mosquitto DB dump diff --git a/test/apps/01-db-dump-print-v6-mqtt-v5-props.py b/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py similarity index 93% rename from test/apps/01-db-dump-print-v6-mqtt-v5-props.py rename to test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py index 2e871ed3..312ae193 100755 --- a/test/apps/01-db-dump-print-v6-mqtt-v5-props.py +++ b/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py @@ -4,9 +4,10 @@ from mosq_test_helper import * def do_test(file, stdout): - cmd = [mosq_test.get_build_root() + '/apps/db_dump/mosquitto_db_dump', - f'db_dump/{file}' - ] + cmd = [ + mosq_test.get_build_root() + '/apps/db_dump/mosquitto_db_dump', + f'./{file}' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3, encoding='utf-8') if res.stdout != stdout: diff --git a/test/apps/01-db-dump-stats-current.py b/test/apps/db_dump/db-dump-stats-current.py similarity index 88% rename from test/apps/01-db-dump-stats-current.py rename to test/apps/db_dump/db-dump-stats-current.py index d84f4898..c97d2a41 100755 --- a/test/apps/01-db-dump-stats-current.py +++ b/test/apps/db_dump/db-dump-stats-current.py @@ -20,10 +20,11 @@ def check_db(port, counts): f"DB_CHUNK_SUB: {counts[4]}\n" + \ f"DB_CHUNK_CLIENT: {counts[5]}\n" - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - '--stats', - f'{port}/mosquitto.db' - ] + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + '--stats', + f'{port}/mosquitto.db' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') if res.stdout != stdout: print(res.stdout) @@ -51,24 +52,26 @@ def do_test(counts): } # Set up persistent client session, including a subscription - cmd = [mosq_test.get_build_root()+'/client/mosquitto_sub', + cmd = [ + mosq_test.get_build_root()+'/client/mosquitto_sub', '-c', '-i', 'client-id', '-p', str(port), '-q', '1', '-t', 'sub-topic', '-E' - ] + ] subprocess.run(cmd, timeout=1, env=env) # Publish a retained message which is also queued for the subscriber - cmd = [mosq_test.get_build_root()+'/client/mosquitto_pub', + cmd = [ + mosq_test.get_build_root()+'/client/mosquitto_pub', '-p', str(port), '-q', '1', '-t', 'sub-topic', '-m', 'message', '-r' - ] + ] subprocess.run(cmd, timeout=1, env=env) broker.terminate() diff --git a/test/apps/01-db-dump-stats.py b/test/apps/db_dump/db-dump-stats.py similarity index 91% rename from test/apps/01-db-dump-stats.py rename to test/apps/db_dump/db-dump-stats.py index 417826d1..b29a310c 100755 --- a/test/apps/01-db-dump-stats.py +++ b/test/apps/db_dump/db-dump-stats.py @@ -10,10 +10,11 @@ def do_test(file, counts): f"DB_CHUNK_SUB: {counts[4]}\n" + \ f"DB_CHUNK_CLIENT: {counts[5]}\n" - cmd = [mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', + cmd = [ + mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', '--stats', - f'db_dump/{file}' - ] + f'./{file}' + ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') if res.stdout != stdout: diff --git a/test/apps/db_dump/mosq_test_helper.py b/test/apps/db_dump/mosq_test_helper.py new file mode 100644 index 00000000..fe77c6e0 --- /dev/null +++ b/test/apps/db_dump/mosq_test_helper.py @@ -0,0 +1,18 @@ +import logging +import sys +from pathlib import Path + +logging.basicConfig( + level=logging.INFO, + format="%(levelname)s %(asctime)s.%(msecs)03d %(module)s: %(message)s", + datefmt="%H:%M:%S", +) + +current_source_dir = Path(__file__).resolve().parent +test_dir = current_source_dir.parents[1] +if test_dir not in sys.path: + sys.path.insert(0, str(test_dir)) + +import mosq_test +import subprocess +import os diff --git a/test/apps/db_dump/test.py b/test/apps/db_dump/test.py new file mode 100755 index 00000000..7baee14b --- /dev/null +++ b/test/apps/db_dump/test.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import mosq_test_helper +import pathlib +import ptest + +tests = [] + +for test_file in pathlib.Path('.').glob('db-dump-*.py'): + tests.append((1, test_file.resolve())) + +ptest.run_tests(tests) diff --git a/test/apps/passwd/CMakeLists.txt b/test/apps/passwd/CMakeLists.txt new file mode 100644 index 00000000..7aea0bd1 --- /dev/null +++ b/test/apps/passwd/CMakeLists.txt @@ -0,0 +1,19 @@ +file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) + +set(EXCLUDE_LIST + # none +) + +foreach(PY_TEST_FILE ${PY_TEST_FILES}) + get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE) + if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST) + continue() + endif() + add_test(NAME apps-${PY_TEST_NAME} + COMMAND ${PY_TEST_FILE} + ) + set_tests_properties(apps-${PY_TEST_NAME} + PROPERTIES + ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}" + ) +endforeach() diff --git a/test/apps/passwd/Makefile b/test/apps/passwd/Makefile new file mode 100644 index 00000000..6f665b4e --- /dev/null +++ b/test/apps/passwd/Makefile @@ -0,0 +1,18 @@ +R=../../.. +include ${R}/config.mk + +.PHONY: all check test ptest clean +.NOTPARALLEL: + +all : + +check : test + +test : + ./passwd-args.py + ./passwd-changes.py + +ptest : + ./test.py + +clean: diff --git a/test/apps/passwd/mosq_test_helper.py b/test/apps/passwd/mosq_test_helper.py new file mode 100644 index 00000000..fe77c6e0 --- /dev/null +++ b/test/apps/passwd/mosq_test_helper.py @@ -0,0 +1,18 @@ +import logging +import sys +from pathlib import Path + +logging.basicConfig( + level=logging.INFO, + format="%(levelname)s %(asctime)s.%(msecs)03d %(module)s: %(message)s", + datefmt="%H:%M:%S", +) + +current_source_dir = Path(__file__).resolve().parent +test_dir = current_source_dir.parents[1] +if test_dir not in sys.path: + sys.path.insert(0, str(test_dir)) + +import mosq_test +import subprocess +import os diff --git a/test/apps/03-passwd-args.py b/test/apps/passwd/passwd-args.py similarity index 100% rename from test/apps/03-passwd-args.py rename to test/apps/passwd/passwd-args.py diff --git a/test/apps/03-passwd-changes.py b/test/apps/passwd/passwd-changes.py similarity index 100% rename from test/apps/03-passwd-changes.py rename to test/apps/passwd/passwd-changes.py diff --git a/test/apps/passwd/test.py b/test/apps/passwd/test.py new file mode 100755 index 00000000..0616be50 --- /dev/null +++ b/test/apps/passwd/test.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import mosq_test_helper +import pathlib +import ptest + +tests = [] + +for test_file in pathlib.Path('.').glob('passwd-*.py'): + tests.append((1, test_file.resolve())) + +ptest.run_tests(tests)