mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-22 16:15:05 +08:00
Command arg tests.
This commit is contained in:
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether command line args are handled
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def start_broker(args):
|
||||
cmd = ['../../src/mosquitto'] + args
|
||||
|
||||
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
|
||||
logfile = filename+'.'+str(vg_index)+'.vglog'
|
||||
if os.environ.get('MOSQ_USE_VALGRIND') == 'callgrind':
|
||||
cmd = ['valgrind', '-q', '--tool=callgrind', '--log-file='+logfile] + cmd
|
||||
elif os.environ.get('MOSQ_USE_VALGRIND') == 'massif':
|
||||
cmd = ['valgrind', '-q', '--tool=massif', '--log-file='+logfile] + cmd
|
||||
else:
|
||||
cmd = ['valgrind', '-q', '--trace-children=yes', '--leak-check=full', '--show-leak-kinds=all', '--log-file='+logfile] + cmd
|
||||
|
||||
return subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
|
||||
|
||||
def do_test(args, rc_expected):
|
||||
rc = 1
|
||||
port = mosq_test.get_port()
|
||||
|
||||
try:
|
||||
broker = start_broker(args)
|
||||
broker.wait(timeout=1)
|
||||
|
||||
if broker.returncode == rc_expected:
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
except subprocess.TimeoutExpired:
|
||||
broker.terminate()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(["-h"], 3)
|
||||
do_test(["-p", "0"], 3) # Port invalid
|
||||
do_test(["-p", "65536"], 3) # Port invalid
|
||||
do_test(["-p"], 3) # Missing port
|
||||
do_test(["-c"], 3) # Missing config
|
||||
do_test(["--tls-keylog"], 3) # Missing filename
|
||||
do_test(["--unknown"], 3) # Unknown option
|
||||
|
||||
exit(0)
|
||||
@@ -5,10 +5,7 @@
|
||||
from mosq_test_helper import *
|
||||
|
||||
def start_broker(filename):
|
||||
if filename is not None:
|
||||
cmd = ['../../src/mosquitto', '-v', '-c', filename]
|
||||
else:
|
||||
cmd = ['../../src/mosquitto', '-h']
|
||||
cmd = ['../../src/mosquitto', '-v', '-c', filename]
|
||||
|
||||
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
|
||||
logfile = filename+'.'+str(vg_index)+'.vglog'
|
||||
@@ -31,11 +28,8 @@ def do_test(config_str, rc_expected):
|
||||
rc = 1
|
||||
port = mosq_test.get_port()
|
||||
|
||||
if config_str is not None:
|
||||
conf_file = os.path.basename(__file__).replace('.py', '.conf')
|
||||
write_config(conf_file, port, config_str)
|
||||
else:
|
||||
conf_file = None
|
||||
conf_file = os.path.basename(__file__).replace('.py', '.conf')
|
||||
write_config(conf_file, port, config_str)
|
||||
|
||||
try:
|
||||
broker = start_broker(conf_file)
|
||||
@@ -50,8 +44,7 @@ def do_test(config_str, rc_expected):
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
if conf_file is not None:
|
||||
os.remove(conf_file)
|
||||
os.remove(conf_file)
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
@@ -59,8 +52,6 @@ def do_test(config_str, rc_expected):
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(None, 3) # Print usage
|
||||
|
||||
do_test("unknown_option unknown\n", 3)
|
||||
|
||||
do_test("user\n", 3) # Empty string, no space
|
||||
|
||||
@@ -260,5 +260,6 @@ endif
|
||||
./15-persist-client-msg-out-v3-1-1.py
|
||||
|
||||
16 :
|
||||
./16-cmd-args.py
|
||||
./16-config-includedir.py
|
||||
./16-config-parse-errors.py
|
||||
|
||||
@@ -219,6 +219,7 @@ tests = [
|
||||
#(1, './15-persist-retain-v3-1-1.py'),
|
||||
#(1, './15-persist-subscription-v3-1-1.py'),
|
||||
|
||||
(1, './16-cmd-args.py'),
|
||||
(1, './16-config-includedir.py'),
|
||||
(1, './16-config-parse-errors.py'),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user