mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-05-21 12:24:29 +02:00
Moved python tests inside test/apps to subfolder per app
Signed-off-by: Norbert Heusser <norbert.heusser@cedalo.com>
This commit is contained in:
parent
e4c252b781
commit
8a07110cef
4
Makefile
4
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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
19
test/apps/ctrl/CMakeLists.txt
Normal file
19
test/apps/ctrl/CMakeLists.txt
Normal file
|
|
@ -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()
|
||||
19
test/apps/ctrl/Makefile
Normal file
19
test/apps/ctrl/Makefile
Normal file
|
|
@ -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:
|
||||
19
test/apps/ctrl/mosq_test_helper.py
Normal file
19
test/apps/ctrl/mosq_test_helper.py
Normal file
|
|
@ -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
|
||||
13
test/apps/ctrl/test.py
Executable file
13
test/apps/ctrl/test.py
Executable file
|
|
@ -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)
|
||||
19
test/apps/db_dump/CMakeLists.txt
Normal file
19
test/apps/db_dump/CMakeLists.txt
Normal file
|
|
@ -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()
|
||||
21
test/apps/db_dump/Makefile
Normal file
21
test/apps/db_dump/Makefile
Normal file
|
|
@ -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 :
|
||||
|
|
@ -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:
|
||||
|
|
@ -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)
|
||||
|
|
@ -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:
|
||||
|
|
@ -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
|
||||
|
|
@ -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:
|
||||
|
|
@ -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()
|
||||
|
|
@ -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:
|
||||
18
test/apps/db_dump/mosq_test_helper.py
Normal file
18
test/apps/db_dump/mosq_test_helper.py
Normal file
|
|
@ -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
|
||||
12
test/apps/db_dump/test.py
Executable file
12
test/apps/db_dump/test.py
Executable file
|
|
@ -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)
|
||||
19
test/apps/passwd/CMakeLists.txt
Normal file
19
test/apps/passwd/CMakeLists.txt
Normal file
|
|
@ -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()
|
||||
18
test/apps/passwd/Makefile
Normal file
18
test/apps/passwd/Makefile
Normal file
|
|
@ -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:
|
||||
18
test/apps/passwd/mosq_test_helper.py
Normal file
18
test/apps/passwd/mosq_test_helper.py
Normal file
|
|
@ -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
|
||||
12
test/apps/passwd/test.py
Executable file
12
test/apps/passwd/test.py
Executable file
|
|
@ -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)
|
||||
Loading…
Reference in a new issue