From 41f0d34348f378219f1c9af419884260cca1a5ab Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 1 Jun 2023 22:07:37 +0100 Subject: [PATCH] Add mosq_test.env_add_ld_library_path() for tests --- test/apps/ctrl/ctrl-args.py | 3 +-- test/apps/ctrl/ctrl-broker.py | 3 +-- test/apps/ctrl/ctrl-dynsec.py | 3 +-- test/apps/db_dump/db-dump-stats-current.py | 4 +-- test/broker/08-tls-psk-bridge.py | 9 +------ test/broker/08-tls-psk-pub.py | 9 +------ .../02-subscribe-argv-errors-tls-psk.py | 6 ++--- test/client/02-subscribe-argv-errors-tls.py | 6 ++--- .../02-subscribe-argv-errors-without-tls.py | 6 ++--- test/client/02-subscribe-env.py | 2 +- test/client/02-subscribe-filter-out.py | 6 ++--- .../02-subscribe-format-json-properties.py | 6 ++--- test/client/02-subscribe-format-json-qos0.py | 6 ++--- test/client/02-subscribe-format-json-qos1.py | 6 ++--- .../client/02-subscribe-format-json-retain.py | 6 ++--- test/client/02-subscribe-format.py | 6 ++--- test/client/02-subscribe-null.py | 6 ++--- test/client/02-subscribe-qos1-ws.py | 6 ++--- test/client/02-subscribe-qos1.py | 6 ++--- test/client/02-subscribe-verbose.py | 6 ++--- test/client/03-publish-argv-errors-tls-psk.py | 6 ++--- test/client/03-publish-argv-errors-tls.py | 6 ++--- .../03-publish-argv-errors-without-tls.py | 6 ++--- test/client/03-publish-env.py | 3 +-- test/client/03-publish-file-empty.py | 6 ++--- test/client/03-publish-file.py | 7 ++--- test/client/03-publish-options-file.py | 6 ++--- test/client/03-publish-qos0-empty.py | 6 ++--- test/client/03-publish-qos1-properties.py | 6 ++--- test/client/03-publish-qos1-ws-large.py | 6 ++--- test/client/03-publish-qos1-ws.py | 6 ++--- test/client/03-publish-qos1.py | 6 ++--- test/client/03-publish-repeat.py | 6 ++--- test/client/03-publish-socks.py | 6 ++--- test/client/03-publish-stdin-file.py | 6 ++--- test/client/03-publish-stdin-line.py | 6 ++--- test/client/03-publish-url.py | 6 ++--- test/client/04-rr-argv-errors-tls-psk.py | 7 ++--- test/client/04-rr-argv-errors-tls.py | 6 ++--- test/client/04-rr-argv-errors-without-tls.py | 6 ++--- test/client/04-rr-env.py | 2 +- test/client/04-rr-qos1-ws.py | 6 ++--- test/client/04-rr-qos1.py | 6 ++--- test/lib/03-publish-c2b-qos1-disconnect.py | 3 +-- test/lib/03-publish-c2b-qos2-disconnect.py | 3 +-- test/lib/msg_sequence_test.py | 3 +-- test/mosq_test.py | 26 ++++++++++++++++--- test/random/test.py | 4 +-- 48 files changed, 141 insertions(+), 142 deletions(-) diff --git a/test/apps/ctrl/ctrl-args.py b/test/apps/ctrl/ctrl-args.py index ee076dbc..ec8a8dd1 100755 --- a/test/apps/ctrl/ctrl-args.py +++ b/test/apps/ctrl/ctrl-args.py @@ -18,8 +18,7 @@ def do_test(args, rc_expected, response=None): if proc.returncode != rc_expected: raise ValueError(args) -env = dict(os.environ) -env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' +env = mosq_test.env_add_ld_library_path() do_test([], 1) do_test(["broker"], 1) diff --git a/test/apps/ctrl/ctrl-broker.py b/test/apps/ctrl/ctrl-broker.py index e068f0b5..950cfcaa 100755 --- a/test/apps/ctrl/ctrl-broker.py +++ b/test/apps/ctrl/ctrl-broker.py @@ -50,8 +50,7 @@ ports = mosq_test.get_port(2) conf_file = os.path.basename(__file__).replace('.py', '.conf') write_config(conf_file, ports) -env = dict(os.environ) -env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' +env = mosq_test.env_add_ld_library_path() if not os.path.exists(str(ports[0])): os.mkdir(str(ports[0])) diff --git a/test/apps/ctrl/ctrl-dynsec.py b/test/apps/ctrl/ctrl-dynsec.py index be741936..5e5f5282 100755 --- a/test/apps/ctrl/ctrl-dynsec.py +++ b/test/apps/ctrl/ctrl-dynsec.py @@ -60,8 +60,7 @@ ports = mosq_test.get_port(2) conf_file = os.path.basename(__file__).replace('.py', '.conf') write_config(conf_file, ports) -env = dict(os.environ) -env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' +env = mosq_test.env_add_ld_library_path() if not os.path.exists(str(ports[0])): os.mkdir(str(ports[0])) diff --git a/test/apps/db_dump/db-dump-stats-current.py b/test/apps/db_dump/db-dump-stats-current.py index c97d2a41..35ac2b57 100755 --- a/test/apps/db_dump/db-dump-stats-current.py +++ b/test/apps/db_dump/db-dump-stats-current.py @@ -47,9 +47,9 @@ def do_test(counts): try: broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port, use_conf=True) env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', 'XDG_CONFIG_HOME':'/tmp/missing' - } + } + env = mosq_test.env_add_ld_library_path(env) # Set up persistent client session, including a subscription cmd = [ diff --git a/test/broker/08-tls-psk-bridge.py b/test/broker/08-tls-psk-bridge.py index ec7302a8..0c084917 100755 --- a/test/broker/08-tls-psk-bridge.py +++ b/test/broker/08-tls-psk-bridge.py @@ -34,14 +34,7 @@ conf_file2 = "08-tls-psk-bridge.conf2" write_config1(conf_file1, port1, port2) write_config2(conf_file2, port2, port3) -env = dict(os.environ) -env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp' -try: - pp = env['PYTHONPATH'] -except KeyError: - pp = '' -env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp - +env = mosq_test.env_add_ld_library_path() rc = 1 connect_packet = mosq_test.gen_connect("no-psk-test-client") diff --git a/test/broker/08-tls-psk-pub.py b/test/broker/08-tls-psk-pub.py index 5d4ebc58..78b1c3cb 100755 --- a/test/broker/08-tls-psk-pub.py +++ b/test/broker/08-tls-psk-pub.py @@ -22,14 +22,7 @@ def write_config(filename, port1, port2): conf_file = os.path.basename(__file__).replace('.py', '.conf') write_config(conf_file, port1, port2) -env = dict(os.environ) -env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp' -try: - pp = env['PYTHONPATH'] -except KeyError: - pp = '' -env['PYTHONPATH'] = mosq_test.get_build_root() + '/lib/python:'+pp - +env = mosq_test.env_add_ld_library_path() rc = 1 connect_packet = mosq_test.gen_connect("no-psk-test-client") diff --git a/test/client/02-subscribe-argv-errors-tls-psk.py b/test/client/02-subscribe-argv-errors-tls-psk.py index 5577f1e4..a5d1defb 100755 --- a/test/client/02-subscribe-argv-errors-tls-psk.py +++ b/test/client/02-subscribe-argv-errors-tls-psk.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/02-subscribe-argv-errors-tls.py b/test/client/02-subscribe-argv-errors-tls.py index 5c84c8be..14eb2b89 100755 --- a/test/client/02-subscribe-argv-errors-tls.py +++ b/test/client/02-subscribe-argv-errors-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/02-subscribe-argv-errors-without-tls.py b/test/client/02-subscribe-argv-errors-without-tls.py index 06853a4b..413e7e9b 100755 --- a/test/client/02-subscribe-argv-errors-without-tls.py +++ b/test/client/02-subscribe-argv-errors-without-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/02-subscribe-env.py b/test/client/02-subscribe-env.py index a6c5fc2c..d47804e5 100755 --- a/test/client/02-subscribe-env.py +++ b/test/client/02-subscribe-env.py @@ -16,7 +16,7 @@ def do_test(proto_ver, env): else: V = 'mqttv31' - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' + env = mosq_test.env_add_ld_library_path(env) cmd = [mosq_test.get_build_root() + '/client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-filter-out.py b/test/client/02-subscribe-filter-out.py index f8cac07d..9c8abc4c 100755 --- a/test/client/02-subscribe-filter-out.py +++ b/test/client/02-subscribe-filter-out.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '0', diff --git a/test/client/02-subscribe-format-json-properties.py b/test/client/02-subscribe-format-json-properties.py index 63cd0651..934821dc 100755 --- a/test/client/02-subscribe-format-json-properties.py +++ b/test/client/02-subscribe-format-json-properties.py @@ -18,9 +18,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-format-json-qos0.py b/test/client/02-subscribe-format-json-qos0.py index 186735dc..fafa8977 100755 --- a/test/client/02-subscribe-format-json-qos0.py +++ b/test/client/02-subscribe-format-json-qos0.py @@ -18,9 +18,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-F', '%j', diff --git a/test/client/02-subscribe-format-json-qos1.py b/test/client/02-subscribe-format-json-qos1.py index 081d2886..a486ed86 100755 --- a/test/client/02-subscribe-format-json-qos1.py +++ b/test/client/02-subscribe-format-json-qos1.py @@ -18,9 +18,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-format-json-retain.py b/test/client/02-subscribe-format-json-retain.py index 1bbb8ce4..4043a7fa 100755 --- a/test/client/02-subscribe-format-json-retain.py +++ b/test/client/02-subscribe-format-json-retain.py @@ -18,9 +18,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-F', '%j', diff --git a/test/client/02-subscribe-format.py b/test/client/02-subscribe-format.py index 7a997eec..62628cae 100755 --- a/test/client/02-subscribe-format.py +++ b/test/client/02-subscribe-format.py @@ -17,9 +17,9 @@ def do_test(format_str, expected_output, proto_ver=4, payload="message"): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-null.py b/test/client/02-subscribe-null.py index 442ce6db..8afabeed 100755 --- a/test/client/02-subscribe-null.py +++ b/test/client/02-subscribe-null.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-qos1-ws.py b/test/client/02-subscribe-qos1-ws.py index bdc20452..489abda7 100755 --- a/test/client/02-subscribe-qos1-ws.py +++ b/test/client/02-subscribe-qos1-ws.py @@ -25,9 +25,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib:'+ os.getenv("LD_LIBRARY_PATH", ""), - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(ports[0]), '-q', '1', diff --git a/test/client/02-subscribe-qos1.py b/test/client/02-subscribe-qos1.py index f185819c..7831303b 100755 --- a/test/client/02-subscribe-qos1.py +++ b/test/client/02-subscribe-qos1.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/02-subscribe-verbose.py b/test/client/02-subscribe-verbose.py index 33597f8e..76b2d968 100755 --- a/test/client/02-subscribe-verbose.py +++ b/test/client/02-subscribe-verbose.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_sub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-argv-errors-tls-psk.py b/test/client/03-publish-argv-errors-tls-psk.py index 37dc1b4d..6129bdf7 100755 --- a/test/client/03-publish-argv-errors-tls-psk.py +++ b/test/client/03-publish-argv-errors-tls-psk.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub'] + args pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/03-publish-argv-errors-tls.py b/test/client/03-publish-argv-errors-tls.py index f41de1db..967149e0 100755 --- a/test/client/03-publish-argv-errors-tls.py +++ b/test/client/03-publish-argv-errors-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub'] + args pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/03-publish-argv-errors-without-tls.py b/test/client/03-publish-argv-errors-without-tls.py index 43c71c32..8cc92d08 100755 --- a/test/client/03-publish-argv-errors-without-tls.py +++ b/test/client/03-publish-argv-errors-without-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub'] + args pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/03-publish-env.py b/test/client/03-publish-env.py index e8f0ba82..df949d6a 100755 --- a/test/client/03-publish-env.py +++ b/test/client/03-publish-env.py @@ -16,8 +16,7 @@ def do_test(proto_ver, env): else: V = 'mqttv31' - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' - + env = mosq_test.env_add_ld_library_path(env) cmd = [mosq_test.get_build_root() + '/client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-file-empty.py b/test/client/03-publish-file-empty.py index afccd869..42792198 100755 --- a/test/client/03-publish-file-empty.py +++ b/test/client/03-publish-file-empty.py @@ -23,9 +23,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-file.py b/test/client/03-publish-file.py index 35d71af5..0dd6f7bf 100755 --- a/test/client/03-publish-file.py +++ b/test/client/03-publish-file.py @@ -24,9 +24,10 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) + cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-options-file.py b/test/client/03-publish-options-file.py index 330efb42..b860b4ca 100755 --- a/test/client/03-publish-options-file.py +++ b/test/client/03-publish-options-file.py @@ -26,9 +26,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-o', conf_file ] diff --git a/test/client/03-publish-qos0-empty.py b/test/client/03-publish-qos0-empty.py index a52afa30..bee7f4d8 100755 --- a/test/client/03-publish-qos0-empty.py +++ b/test/client/03-publish-qos0-empty.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '0', diff --git a/test/client/03-publish-qos1-properties.py b/test/client/03-publish-qos1-properties.py index a581f783..53482ca6 100755 --- a/test/client/03-publish-qos1-properties.py +++ b/test/client/03-publish-qos1-properties.py @@ -10,9 +10,9 @@ def do_test(proto_ver): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) if proto_ver == 5: V = 'mqttv5' elif proto_ver == 4: diff --git a/test/client/03-publish-qos1-ws-large.py b/test/client/03-publish-qos1-ws-large.py index 1921142d..00b7d37d 100755 --- a/test/client/03-publish-qos1-ws-large.py +++ b/test/client/03-publish-qos1-ws-large.py @@ -25,9 +25,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib:'+ os.getenv("LD_LIBRARY_PATH", ""), - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) payload = "abcdefghijklmnopqrstuvwxyz0123456789"*1821 diff --git a/test/client/03-publish-qos1-ws.py b/test/client/03-publish-qos1-ws.py index b1905e89..21941057 100755 --- a/test/client/03-publish-qos1-ws.py +++ b/test/client/03-publish-qos1-ws.py @@ -25,9 +25,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib:'+ os.getenv("LD_LIBRARY_PATH", ""), - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(ports[0]), '-q', '1', diff --git a/test/client/03-publish-qos1.py b/test/client/03-publish-qos1.py index b8abce2c..d850fa16 100755 --- a/test/client/03-publish-qos1.py +++ b/test/client/03-publish-qos1.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-repeat.py b/test/client/03-publish-repeat.py index 2b0ca152..ead50e98 100755 --- a/test/client/03-publish-repeat.py +++ b/test/client/03-publish-repeat.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-socks.py b/test/client/03-publish-socks.py index 398def87..15157732 100755 --- a/test/client/03-publish-socks.py +++ b/test/client/03-publish-socks.py @@ -36,9 +36,9 @@ def do_test(proto_ver, host): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = [ '../../client/mosquitto_pub', '-h', host, diff --git a/test/client/03-publish-stdin-file.py b/test/client/03-publish-stdin-file.py index 1c01c114..a30d160f 100755 --- a/test/client/03-publish-stdin-file.py +++ b/test/client/03-publish-stdin-file.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '1', diff --git a/test/client/03-publish-stdin-line.py b/test/client/03-publish-stdin-line.py index 9511a9a0..b0457a7a 100755 --- a/test/client/03-publish-stdin-line.py +++ b/test/client/03-publish-stdin-line.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-p', str(port), '-q', '2', diff --git a/test/client/03-publish-url.py b/test/client/03-publish-url.py index 89712a74..577b239c 100755 --- a/test/client/03-publish-url.py +++ b/test/client/03-publish-url.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_pub', '-L', f'mqtt://localhost:{port}/03/pub/url/test', '-m', 'message', diff --git a/test/client/04-rr-argv-errors-tls-psk.py b/test/client/04-rr-argv-errors-tls-psk.py index e58a4008..14629c51 100755 --- a/test/client/04-rr-argv-errors-tls-psk.py +++ b/test/client/04-rr-argv-errors-tls-psk.py @@ -10,9 +10,10 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) + cmd = ['../../client/mosquitto_rr'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/04-rr-argv-errors-tls.py b/test/client/04-rr-argv-errors-tls.py index 4b2c3a73..005b1d7d 100755 --- a/test/client/04-rr-argv-errors-tls.py +++ b/test/client/04-rr-argv-errors-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_rr'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/04-rr-argv-errors-without-tls.py b/test/client/04-rr-argv-errors-without-tls.py index 997c2c1a..9eeb1ed7 100755 --- a/test/client/04-rr-argv-errors-without-tls.py +++ b/test/client/04-rr-argv-errors-without-tls.py @@ -10,9 +10,9 @@ def do_test(args, stderr_expected, rc_expected): port = mosq_test.get_port() env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) cmd = ['../../client/mosquitto_rr'] + args sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) diff --git a/test/client/04-rr-env.py b/test/client/04-rr-env.py index 4a2c5997..bfef387d 100755 --- a/test/client/04-rr-env.py +++ b/test/client/04-rr-env.py @@ -16,7 +16,7 @@ def do_test(proto_ver, env): else: V = 'mqttv31' - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' + env = mosq_test.env_add_ld_library_path(env) payload = "message" cmd = [mosq_test.get_build_root() + '/client/mosquitto_rr', diff --git a/test/client/04-rr-qos1-ws.py b/test/client/04-rr-qos1-ws.py index c886beb0..3a9ac793 100755 --- a/test/client/04-rr-qos1-ws.py +++ b/test/client/04-rr-qos1-ws.py @@ -25,9 +25,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib:'+ os.getenv("LD_LIBRARY_PATH", ""), - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) payload = "message" cmd = ['../../client/mosquitto_rr', '-p', str(ports[0]), diff --git a/test/client/04-rr-qos1.py b/test/client/04-rr-qos1.py index 090721b5..9de5286a 100755 --- a/test/client/04-rr-qos1.py +++ b/test/client/04-rr-qos1.py @@ -17,9 +17,9 @@ def do_test(proto_ver): V = 'mqttv31' env = { - 'LD_LIBRARY_PATH': mosq_test.get_build_root() + '/lib', - 'XDG_CONFIG_HOME':'/tmp/missing' - } + 'XDG_CONFIG_HOME':'/tmp/missing' + } + env = mosq_test.env_add_ld_library_path(env) payload = "message" cmd = ['../../client/mosquitto_rr', '-p', str(port), diff --git a/test/lib/03-publish-c2b-qos1-disconnect.py b/test/lib/03-publish-c2b-qos1-disconnect.py index 79b3719c..8d336c9d 100755 --- a/test/lib/03-publish-c2b-qos1-disconnect.py +++ b/test/lib/03-publish-c2b-qos1-disconnect.py @@ -25,8 +25,7 @@ def do_test(client_cmd): sock.listen(5) client_args = [client_cmd, str(port)] - env = dict(os.environ) - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp' + env = mosq_test.env_add_ld_library_path() client = mosq_test.start_client(filename=client_cmd.replace('/', '-'), cmd=client_args, env=env) diff --git a/test/lib/03-publish-c2b-qos2-disconnect.py b/test/lib/03-publish-c2b-qos2-disconnect.py index 34313375..76f45528 100755 --- a/test/lib/03-publish-c2b-qos2-disconnect.py +++ b/test/lib/03-publish-c2b-qos2-disconnect.py @@ -27,8 +27,7 @@ def do_test(client_cmd): sock.listen(5) client_args = [client_cmd, str(port)] - env = dict(os.environ) - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib:' + mosq_test.get_build_root() + '/lib/cpp' + env = mosq_test.env_add_ld_library_path() client = mosq_test.start_client(filename=client_cmd.replace('/', '-'), cmd=client_args, env=env) diff --git a/test/lib/msg_sequence_test.py b/test/lib/msg_sequence_test.py index 04d5d1ef..c5c5dfe6 100755 --- a/test/lib/msg_sequence_test.py +++ b/test/lib/msg_sequence_test.py @@ -88,8 +88,7 @@ class MsgSequence(object): global vg_index global vg_logfiles - env = {} - env['LD_LIBRARY_PATH'] = mosq_test.get_build_root() + '/lib' + env = mosq_test.env_add_ld_library_path() cmd = [ mosq_test.get_build_root() + '/test/lib/c/fuzzish.test', str(port), str(self.proto_ver), str(self.clean_start) diff --git a/test/mosq_test.py b/test/mosq_test.py index aba4d114..156b0efe 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -30,6 +30,28 @@ def get_build_root(): result = str(Path(__file__).resolve().parents[1]) return result +def env_add_ld_library_path(env=None): + p = ":".join([ + get_build_root() + '/lib', + get_build_root() + '/lib/cpp', + os.getenv("LD_LIBRARY_PATH", "") + ]) + + if env is None: + env = { + 'LD_LIBRARY_PATH': p, + 'DYLIB_LIBRARY_PATH': p, + } + else: + for v in ['LD_LIBRARY_PATH', 'DYLIB_LIBRARY_PATH']: + try: + val = env[v] + env[v] = ":".join([val, p]) + except KeyError: + env[v] = p + + return env + def listen_sock(port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -105,9 +127,7 @@ def start_broker(filename, cmd=None, port=0, use_conf=False, expect_fail=False, def start_client(filename, cmd, env=None): if cmd is None: raise ValueError - if env is None: - env = dict(os.environ) - env['LD_LIBRARY_PATH'] = get_build_root() + '/lib:' + get_build_root() + '/lib/cpp' + env = env_add_ld_library_path(env) if os.environ.get('MOSQ_USE_VALGRIND') is not None: cmd = ['valgrind', '-q', '--log-file='+filename+'.vglog'] + cmd diff --git a/test/random/test.py b/test/random/test.py index 6d058182..373c4593 100755 --- a/test/random/test.py +++ b/test/random/test.py @@ -39,8 +39,6 @@ def run_clients(max_clients): c.wait() -env = {} -env["LD_LIBRARY_PATH"] = "../../lib" - +env = mosq_test.env_add_ld_library_path() #broker = subprocess.Popen(["../../src/mosquitto", "-c", "random.conf"], env=env) run_clients(1000)