diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index bc39864e..1121841e 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,2 +1,3 @@ +add_subdirectory(db_dump) add_subdirectory(mosquitto_ctrl) add_subdirectory(mosquitto_passwd) diff --git a/apps/db_dump/CMakeLists.txt b/apps/db_dump/CMakeLists.txt new file mode 100644 index 00000000..cea18246 --- /dev/null +++ b/apps/db_dump/CMakeLists.txt @@ -0,0 +1,33 @@ +add_executable(mosquitto_db_dump + db_dump.c + print.c + stubs.c + + ../../lib/memory_mosq.c + ../../lib/packet_datatypes.c + ../../lib/property_mosq.c + ../../lib/utf8_mosq.c + + ../../src/memory_public.c + ../../src/persist_read.c + ../../src/persist_read_v234.c + ../../src/persist_read_v5.c + ../../src/topic_tok.c +) + +target_compile_definitions(mosquitto_db_dump PRIVATE + WITH_BROKER + WITH_PERSISTENCE +) + +target_include_directories(mosquitto_db_dump PRIVATE + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/common" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/src" +) + +install(TARGETS mosquitto_db_dump + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9489ccb3..3068a2b5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(apps) add_subdirectory(broker) add_subdirectory(client) add_subdirectory(lib) diff --git a/test/apps/ctrl/CMakeLists.txt b/test/apps/ctrl/CMakeLists.txt index 7aea0bd1..b1919463 100644 --- a/test/apps/ctrl/CMakeLists.txt +++ b/test/apps/ctrl/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) +file(GLOB PY_TEST_FILES ctrl-*.py) set(EXCLUDE_LIST # none diff --git a/test/apps/ctrl/ctrl-args.py b/test/apps/ctrl/ctrl-args.py index 8b793518..ee076dbc 100755 --- a/test/apps/ctrl/ctrl-args.py +++ b/test/apps/ctrl/ctrl-args.py @@ -26,18 +26,18 @@ do_test(["broker"], 1) do_test(["-A"], 1, response="Error: -A argument given but no address specified.\n\n") do_test(["-A", "127.0.0.1"], 1) # Gives generic help do_test(["--cafile"], 1, response="Error: --cafile argument given but no file specified.\n\n") -do_test(["--cafile", mosq_test.get_build_root()+"/test/ssl/all-ca.crt"], 1) # Gives generic help +do_test(["--cafile", ssl_dir / "all-ca.crt"], 1) # Gives generic help do_test(["--capath"], 1, response="Error: --capath argument given but no directory specified.\n\n") -do_test(["--capath", mosq_test.get_build_root()+"/test/ssl"], 1) # Gives generic help +do_test(["--capath", ssl_dir], 1) # Gives generic help do_test(["--cert"], 1, response="Error: --cert argument given but no file specified.\n\n") -do_test(["--cert", mosq_test.get_build_root()+"/test/ssl/client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n") +do_test(["--cert", ssl_dir / "client.crt"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n") do_test(["--key"], 1, response="Error: --key argument given but no file specified.\n\n") -do_test(["--key", mosq_test.get_build_root()+"/test/ssl/client.key"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n") +do_test(["--key", ssl_dir / "client.key"], 1, response="Error: Both certfile and keyfile must be provided if one of them is set.\n") do_test(["--ciphers"], 1, response="Error: --ciphers argument given but no ciphers specified.\n\n") do_test(["--ciphers", "DEFAULT"], 1) # Gives generic help do_test(["--debug"], 1) # Gives generic help do_test(["-f"], 1, response="Error: -f argument given but no data file specified.\n\n") -do_test(["-f", mosq_test.get_build_root()+"/test/ssl/test"], 1) # Gives generic help +do_test(["-f", ssl_dir / "test"], 1) # Gives generic help do_test(["--help"], 1) # Gives generic help do_test(["--host"], 1, response="Error: -h argument given but no host specified.\n\n") do_test(["--host", "127.0.0.1"], 1) # Gives generic help diff --git a/test/apps/ctrl/ctrl-broker.py b/test/apps/ctrl/ctrl-broker.py index c12c1bb3..e068f0b5 100755 --- a/test/apps/ctrl/ctrl-broker.py +++ b/test/apps/ctrl/ctrl-broker.py @@ -14,8 +14,8 @@ def write_config(filename, ports): f.write("allow_anonymous false\n") f.write(f"listener {ports[0]}\n") f.write(f"listener {ports[1]}\n") - f.write(f"certfile {mosq_test.get_build_root()}/test/ssl/server.crt\n") - f.write(f"keyfile {mosq_test.get_build_root()}/test/ssl/server.key\n") + f.write(f"certfile {ssl_dir}/server.crt\n") + f.write(f"keyfile {ssl_dir}/server.key\n") def ctrl_cmd(cmd, args, ports, response=None): opts = ["-u", "admin", @@ -30,7 +30,7 @@ def ctrl_cmd(cmd, args, ports, response=None): capture_output = False else: opts += ["-p", str(ports[1])] - opts += ["--cafile", f"{mosq_test.get_build_root()}/test/ssl/all-ca.crt"] + opts += ["--cafile", f"{ssl_dir}/all-ca.crt"] capture_output = True proc = subprocess.run([mosq_test.get_build_root()+"/apps/mosquitto_ctrl/mosquitto_ctrl"] diff --git a/test/apps/ctrl/ctrl-dynsec.py b/test/apps/ctrl/ctrl-dynsec.py index a0fe0d6a..be741936 100755 --- a/test/apps/ctrl/ctrl-dynsec.py +++ b/test/apps/ctrl/ctrl-dynsec.py @@ -11,8 +11,8 @@ def write_config(filename, ports): f.write("allow_anonymous false\n") f.write(f"listener {ports[0]}\n") f.write(f"listener {ports[1]}\n") - f.write(f"certfile {mosq_test.get_build_root()}/test/ssl/server.crt\n") - f.write(f"keyfile {mosq_test.get_build_root()}/test/ssl/server.key\n") + f.write(f"certfile {ssl_dir}/server.crt\n") + f.write(f"keyfile {ssl_dir}/server.key\n") def ctrl_dynsec_cmd(args, ports, response=None, input=None): opts = ["-u", "admin", @@ -25,7 +25,7 @@ def ctrl_dynsec_cmd(args, ports, response=None, input=None): ] else: opts += ["-p", str(ports[1])] - opts += ["--cafile", f"{mosq_test.get_build_root()}/test/ssl/all-ca.crt"] + opts += ["--cafile", f"{ssl_dir}/all-ca.crt"] proc = subprocess.run([mosq_test.get_build_root()+"/apps/mosquitto_ctrl/mosquitto_ctrl"] + opts + ["dynsec"] + args, diff --git a/test/apps/ctrl/mosq_test_helper.py b/test/apps/ctrl/mosq_test_helper.py index ffedfdab..0a5ebc94 100644 --- a/test/apps/ctrl/mosq_test_helper.py +++ b/test/apps/ctrl/mosq_test_helper.py @@ -14,6 +14,8 @@ test_dir = current_source_dir.parents[1] if test_dir not in sys.path: sys.path.insert(0, str(test_dir)) +ssl_dir = test_dir / "ssl" + import mosq_test import subprocess import os diff --git a/test/apps/db_dump/CMakeLists.txt b/test/apps/db_dump/CMakeLists.txt index 7aea0bd1..2c899b0d 100644 --- a/test/apps/db_dump/CMakeLists.txt +++ b/test/apps/db_dump/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) +file(GLOB PY_TEST_FILES db-dump-*.py) set(EXCLUDE_LIST # none diff --git a/test/apps/db_dump/db-dump-client-stats.py b/test/apps/db_dump/db-dump-client-stats.py index e95baf27..00d05ca2 100755 --- a/test/apps/db_dump/db-dump-client-stats.py +++ b/test/apps/db_dump/db-dump-client-stats.py @@ -12,7 +12,7 @@ def do_test(file, counts): cmd = [ mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', '--client-stats', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') diff --git a/test/apps/db_dump/db-dump-corrupt.py b/test/apps/db_dump/db-dump-corrupt.py index f87f7c60..3362d32a 100755 --- a/test/apps/db_dump/db-dump-corrupt.py +++ b/test/apps/db_dump/db-dump-corrupt.py @@ -6,7 +6,7 @@ def do_test(file, stderr, rc_expected): cmd = [ mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') @@ -18,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 ./missing.test-db\n", 0) +do_test('missing.test-db', f"Error: Unable to open {test_dir}/apps/db_dump/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/db_dump/db-dump-print-empty.py b/test/apps/db_dump/db-dump-print-empty.py index f74312d1..2c85bacc 100755 --- a/test/apps/db_dump/db-dump-print-empty.py +++ b/test/apps/db_dump/db-dump-print-empty.py @@ -6,7 +6,7 @@ def do_test(file, stdout): cmd = [ mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') diff --git a/test/apps/db_dump/db-dump-print-v6-all.py b/test/apps/db_dump/db-dump-print-v6-all.py index 3cf18a27..caf50b5c 100755 --- a/test/apps/db_dump/db-dump-print-v6-all.py +++ b/test/apps/db_dump/db-dump-print-v6-all.py @@ -6,11 +6,11 @@ def do_test(file, stdout): cmd = [ mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') - + if res.stdout != stdout: read_lines = res.stdout.splitlines() expected_lines = stdout.splitlines() diff --git a/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py b/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py index 312ae193..e043db8f 100755 --- a/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py +++ b/test/apps/db_dump/db-dump-print-v6-mqtt-v5-props.py @@ -6,7 +6,7 @@ def do_test(file, stdout): cmd = [ mosq_test.get_build_root() + '/apps/db_dump/mosquitto_db_dump', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3, encoding='utf-8') diff --git a/test/apps/db_dump/db-dump-stats.py b/test/apps/db_dump/db-dump-stats.py index b29a310c..72169848 100755 --- a/test/apps/db_dump/db-dump-stats.py +++ b/test/apps/db_dump/db-dump-stats.py @@ -13,7 +13,7 @@ def do_test(file, counts): cmd = [ mosq_test.get_build_root()+'/apps/db_dump/mosquitto_db_dump', '--stats', - f'./{file}' + f'{test_dir}/apps/db_dump/{file}' ] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8') diff --git a/test/apps/db_dump/mosq_test_helper.py b/test/apps/db_dump/mosq_test_helper.py index fe77c6e0..6581b51a 100644 --- a/test/apps/db_dump/mosq_test_helper.py +++ b/test/apps/db_dump/mosq_test_helper.py @@ -13,6 +13,8 @@ test_dir = current_source_dir.parents[1] if test_dir not in sys.path: sys.path.insert(0, str(test_dir)) +ssl_dir = test_dir / "ssl" + import mosq_test import subprocess import os diff --git a/test/apps/passwd/CMakeLists.txt b/test/apps/passwd/CMakeLists.txt index 7aea0bd1..59a8b274 100644 --- a/test/apps/passwd/CMakeLists.txt +++ b/test/apps/passwd/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB PY_TEST_FILES [0-9][0-9]-*.py) +file(GLOB PY_TEST_FILES passwd-*.py) set(EXCLUDE_LIST # none diff --git a/test/apps/passwd/mosq_test_helper.py b/test/apps/passwd/mosq_test_helper.py index fe77c6e0..6581b51a 100644 --- a/test/apps/passwd/mosq_test_helper.py +++ b/test/apps/passwd/mosq_test_helper.py @@ -13,6 +13,8 @@ test_dir = current_source_dir.parents[1] if test_dir not in sys.path: sys.path.insert(0, str(test_dir)) +ssl_dir = test_dir / "ssl" + import mosq_test import subprocess import os