diff --git a/test/broker/Makefile b/test/broker/Makefile index 76448dfe..28473325 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -13,7 +13,7 @@ test-compile : $(MAKE) -C c ptest : test-compile - ./ptest.py + ./test.py test : test-compile 01 02 03 04 05 06 07 08 09 10 11 12 diff --git a/test/broker/ptest.py b/test/broker/test.py similarity index 71% rename from test/broker/ptest.py rename to test/broker/test.py index df029c1e..200cf55b 100755 --- a/test/broker/ptest.py +++ b/test/broker/test.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 -import subprocess -import time -import sys +import mosq_test_helper +import ptest -max_running = 10 tests = [ #(ports required, 'path'), (1, './01-connect-bad-packet.py'), @@ -145,75 +143,4 @@ tests = [ (1, './12-prop-response-topic-correlation-data.py'), ] -minport = 1888 -ports = list(range(minport, minport+max_running+1)) - -def next_test(tests, ports): - if len(tests) == 0 or len(ports) == 0: - return - - test = tests.pop() - proc_ports = () - - if len(ports) < test[0]: - tests.insert(0, test) - return None - else: - args = [test[1]] - - for i in range(0, test[0]): - proc_port = ports.pop() - proc_ports = proc_ports + (proc_port,) - args.append(str(proc_port)) - - proc = subprocess.Popen(args) - proc.start_time = time.time() - proc.mosq_port = proc_ports - return proc - - -def run_tests(tests, ports): - passed = 0 - failed = 0 - - failed_tests = [] - - running_tests = [] - while len(tests) > 0 or len(running_tests) > 0: - if len(running_tests) <= max_running: - t = next_test(tests, ports) - if t is None: - time.sleep(0.1) - else: - running_tests.append(t) - - for t in running_tests: - t.poll() - if t.returncode is not None: - running_tests.remove(t) - if isinstance(t.mosq_port, tuple): - for portret in t.mosq_port: - ports.append(portret) - else: - ports.append(t.mosq_port) - t.terminate() - t.wait() - runtime = time.time() - t.start_time - #(stdo, stde) = t.communicate() - if t.returncode == 1: - print("%0.3fs : \033[31m%s\033[0m" % (runtime, t.args[0])) - failed = failed + 1 - failed_tests.append(t.args[0]) - else: - passed = passed + 1 - print("%0.3fs : \033[32m%s\033[0m" % (runtime, t.args[0])) - - print("Passed: %d\nFailed: %d\nTotal: %d" % (passed, failed, passed+failed)) - if failed > 0: - print("Failing tests:") - for f in failed_tests: - print(f) - sys.exit(1) - - -run_tests(tests, ports) +ptest.run_tests(tests) diff --git a/test/lib/Makefile b/test/lib/Makefile index 49f3088b..d88f58a1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -8,7 +8,7 @@ LD_LIBRARY_PATH=../../lib all : ptest : test-compile - ./ptest.py + ./test.py test : c cpp diff --git a/test/lib/ptest.py b/test/lib/ptest.py deleted file mode 100755 index c12142a1..00000000 --- a/test/lib/ptest.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess -import time -import sys - -max_running = 10 -tests = [ - ('./01-con-discon-success.py', 'c/01-con-discon-success.test'), - ('./01-keepalive-pingreq.py', 'c/01-keepalive-pingreq.test'), - ('./01-server-keepalive-pingreq.py', 'c/01-server-keepalive-pingreq.test'), - ('./01-no-clean-session.py', 'c/01-no-clean-session.test'), - ('./01-unpwd-set.py', 'c/01-unpwd-set.test'), - ('./01-will-set.py', 'c/01-will-set.test'), - ('./01-will-unpwd-set.py', 'c/01-will-unpwd-set.test'), - ('./02-subscribe-qos0.py', 'c/02-subscribe-qos0.test'), - ('./02-subscribe-qos1.py', 'c/02-subscribe-qos1.test'), - ('./02-subscribe-qos2.py', 'c/02-subscribe-qos2.test'), - ('./02-unsubscribe.py', 'c/02-unsubscribe.test'), - ('./03-publish-b2c-qos1.py', 'c/03-publish-b2c-qos1.test'), - ('./03-publish-b2c-qos2.py', 'c/03-publish-b2c-qos2.test'), - ('./03-publish-c2b-qos1-len.py', 'c/03-publish-c2b-qos1-len.test'), - ('./03-publish-c2b-qos2-len.py', 'c/03-publish-c2b-qos2-len.test'), - ('./03-publish-b2c-qos2-len.py', 'c/03-publish-b2c-qos2-len.test'), - ('./03-publish-c2b-qos1-disconnect.py', 'c/03-publish-c2b-qos1-disconnect.test'), - ('./03-publish-c2b-qos2-disconnect.py', 'c/03-publish-c2b-qos2-disconnect.test'), - ('./03-publish-c2b-qos2.py', 'c/03-publish-c2b-qos2.test'), - ('./03-publish-c2b-qos1-receive-maximum.py', 'c/03-publish-c2b-qos1-receive-maximum.test'), - ('./03-publish-c2b-qos2-receive-maximum-1.py', 'c/03-publish-c2b-qos2-receive-maximum-1.test'), - ('./03-publish-c2b-qos2-receive-maximum-2.py', 'c/03-publish-c2b-qos2-receive-maximum-2.test'), - ('./03-publish-c2b-qos2-pubrec-error.py', 'c/03-publish-c2b-qos2-pubrec-error.test'), - ('./03-publish-c2b-qos2-maximum-qos-0.py', 'c/03-publish-c2b-qos2-maximum-qos-0.test'), - ('./03-publish-c2b-qos2-maximum-qos-1.py', 'c/03-publish-c2b-qos2-maximum-qos-1.test'), - ('./03-publish-qos0-no-payload.py', 'c/03-publish-qos0-no-payload.test'), - ('./03-publish-qos0.py', 'c/03-publish-qos0.test'), - ('./03-request-response.py', 'c/03-request-response.test'), - ('./03-request-response-correlation.py', 'c/03-request-response-correlation.test'), - ('./04-retain-qos0.py', 'c/04-retain-qos0.test'), - ('./08-ssl-bad-cacert.py', 'c/08-ssl-bad-cacert.test'), - ('./08-ssl-connect-cert-auth-enc.py', 'c/08-ssl-connect-cert-auth-enc.test'), - ('./08-ssl-connect-cert-auth.py', 'c/08-ssl-connect-cert-auth.test'), - ('./08-ssl-connect-no-auth.py', 'c/08-ssl-connect-no-auth.test'), - ('./09-util-topic-tokenise.py', 'c/09-util-topic-tokenise.test'), - ('./11-prop-send-payload-format.py', 'c/11-prop-send-payload-format.test'), - ('./11-prop-send-content-type.py', 'c/11-prop-send-content-type.test'), - - ('./01-con-discon-success.py', 'cpp/01-con-discon-success.test'), - ('./01-keepalive-pingreq.py', 'cpp/01-keepalive-pingreq.test'), - ('./01-no-clean-session.py', 'cpp/01-no-clean-session.test'), - ('./01-unpwd-set.py', 'cpp/01-unpwd-set.test'), - ('./01-will-set.py', 'cpp/01-will-set.test'), - ('./01-will-unpwd-set.py', 'cpp/01-will-unpwd-set.test'), - ('./02-subscribe-qos0.py', 'cpp/02-subscribe-qos0.test'), - ('./02-subscribe-qos1.py', 'cpp/02-subscribe-qos1.test'), - ('./02-subscribe-qos2.py', 'cpp/02-subscribe-qos2.test'), - ('./02-unsubscribe.py', 'cpp/02-unsubscribe.test'), - ('./03-publish-b2c-qos1.py', 'cpp/03-publish-b2c-qos1.test'), - ('./03-publish-b2c-qos2.py', 'cpp/03-publish-b2c-qos2.test'), - ('./03-publish-c2b-qos1-disconnect.py', 'cpp/03-publish-c2b-qos1-disconnect.test'), - ('./03-publish-c2b-qos2-disconnect.py', 'cpp/03-publish-c2b-qos2-disconnect.test'), - ('./03-publish-c2b-qos2.py', 'cpp/03-publish-c2b-qos2.test'), - ('./03-publish-qos0-no-payload.py', 'cpp/03-publish-qos0-no-payload.test'), - ('./03-publish-qos0.py', 'cpp/03-publish-qos0.test'), - ('./04-retain-qos0.py', 'cpp/04-retain-qos0.test'), - ('./08-ssl-bad-cacert.py', 'cpp/08-ssl-bad-cacert.test'), - ('./08-ssl-connect-cert-auth-enc.py', 'cpp/08-ssl-connect-cert-auth-enc.test'), - ('./08-ssl-connect-cert-auth.py', 'cpp/08-ssl-connect-cert-auth.test'), - ('./08-ssl-connect-no-auth.py', 'cpp/08-ssl-connect-no-auth.test'), - ('./09-util-topic-tokenise.py', 'cpp/09-util-topic-tokenise.test'), - ] - -minport = 1888 -ports = list(range(minport, minport+max_running+1)) - -def next_test(tests, ports): - if len(tests) == 0 or len(ports) == 0: - return - - test = tests.pop() - port = ports.pop() - p = subprocess.Popen([test[0], test[1], str(port)]) - p.mosq_port = port - return p - -def run_tests(tests, ports): - passed = 0 - failed = 0 - - failed_tests = [] - - running_tests = [] - while len(tests) > 0 or len(running_tests) > 0: - if len(running_tests) <= max_running: - t = next_test(tests, ports) - if t is None: - time.sleep(0.1) - else: - running_tests.append(t) - - for t in running_tests: - t.poll() - if t.returncode is not None: - running_tests.remove(t) - if isinstance(t.mosq_port, tuple): - for portret in t.mosq_port: - ports.append(portret) - else: - ports.append(t.mosq_port) - t.terminate() - t.wait() - #(stdo, stde) = t.communicate() - if t.returncode == 1: - print("\033[31m %s %s\033[0m" % (t.args[0], t.args[1])) - failed = failed + 1 - else: - passed = passed + 1 - print("\033[32m %s %s\033[0m" % (t.args[0], t.args[1])) - - print("Passed: %d\nFailed: %d\nTotal: %d" % (passed, failed, passed+failed)) - if failed > 0: - sys.exit(1) - - -run_tests(tests, ports) diff --git a/test/lib/test.py b/test/lib/test.py new file mode 100755 index 00000000..76d7dc0d --- /dev/null +++ b/test/lib/test.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +import mosq_test_helper +import ptest + +tests = [ + (1, ['./01-con-discon-success.py', 'c/01-con-discon-success.test']), + (1, ['./01-keepalive-pingreq.py', 'c/01-keepalive-pingreq.test']), + (1, ['./01-server-keepalive-pingreq.py', 'c/01-server-keepalive-pingreq.test']), + (1, ['./01-no-clean-session.py', 'c/01-no-clean-session.test']), + (1, ['./01-unpwd-set.py', 'c/01-unpwd-set.test']), + (1, ['./01-will-set.py', 'c/01-will-set.test']), + (1, ['./01-will-unpwd-set.py', 'c/01-will-unpwd-set.test']), + (1, ['./02-subscribe-qos0.py', 'c/02-subscribe-qos0.test']), + (1, ['./02-subscribe-qos1.py', 'c/02-subscribe-qos1.test']), + (1, ['./02-subscribe-qos2.py', 'c/02-subscribe-qos2.test']), + (1, ['./02-unsubscribe.py', 'c/02-unsubscribe.test']), + (1, ['./03-publish-b2c-qos1.py', 'c/03-publish-b2c-qos1.test']), + (1, ['./03-publish-b2c-qos2.py', 'c/03-publish-b2c-qos2.test']), + (1, ['./03-publish-c2b-qos1-len.py', 'c/03-publish-c2b-qos1-len.test']), + (1, ['./03-publish-c2b-qos2-len.py', 'c/03-publish-c2b-qos2-len.test']), + (1, ['./03-publish-b2c-qos2-len.py', 'c/03-publish-b2c-qos2-len.test']), + (1, ['./03-publish-c2b-qos1-disconnect.py', 'c/03-publish-c2b-qos1-disconnect.test']), + (1, ['./03-publish-c2b-qos2-disconnect.py', 'c/03-publish-c2b-qos2-disconnect.test']), + (1, ['./03-publish-c2b-qos2.py', 'c/03-publish-c2b-qos2.test']), + (1, ['./03-publish-c2b-qos1-receive-maximum.py', 'c/03-publish-c2b-qos1-receive-maximum.test']), + (1, ['./03-publish-c2b-qos2-receive-maximum-1.py', 'c/03-publish-c2b-qos2-receive-maximum-1.test']), + (1, ['./03-publish-c2b-qos2-receive-maximum-2.py', 'c/03-publish-c2b-qos2-receive-maximum-2.test']), + (1, ['./03-publish-c2b-qos2-pubrec-error.py', 'c/03-publish-c2b-qos2-pubrec-error.test']), + (1, ['./03-publish-c2b-qos2-maximum-qos-0.py', 'c/03-publish-c2b-qos2-maximum-qos-0.test']), + (1, ['./03-publish-c2b-qos2-maximum-qos-1.py', 'c/03-publish-c2b-qos2-maximum-qos-1.test']), + (1, ['./03-publish-qos0-no-payload.py', 'c/03-publish-qos0-no-payload.test']), + (1, ['./03-publish-qos0.py', 'c/03-publish-qos0.test']), + (1, ['./03-request-response.py', 'c/03-request-response.test']), + (1, ['./03-request-response-correlation.py', 'c/03-request-response-correlation.test']), + (1, ['./04-retain-qos0.py', 'c/04-retain-qos0.test']), + (1, ['./08-ssl-bad-cacert.py', 'c/08-ssl-bad-cacert.test']), + (1, ['./08-ssl-connect-cert-auth-enc.py', 'c/08-ssl-connect-cert-auth-enc.test']), + (1, ['./08-ssl-connect-cert-auth.py', 'c/08-ssl-connect-cert-auth.test']), + (1, ['./08-ssl-connect-no-auth.py', 'c/08-ssl-connect-no-auth.test']), + (1, ['./09-util-topic-tokenise.py', 'c/09-util-topic-tokenise.test']), + (1, ['./11-prop-send-payload-format.py', 'c/11-prop-send-payload-format.test']), + (1, ['./11-prop-send-content-type.py', 'c/11-prop-send-content-type.test']), + + (1, ['./01-con-discon-success.py', 'cpp/01-con-discon-success.test']), + (1, ['./01-keepalive-pingreq.py', 'cpp/01-keepalive-pingreq.test']), + (1, ['./01-no-clean-session.py', 'cpp/01-no-clean-session.test']), + (1, ['./01-unpwd-set.py', 'cpp/01-unpwd-set.test']), + (1, ['./01-will-set.py', 'cpp/01-will-set.test']), + (1, ['./01-will-unpwd-set.py', 'cpp/01-will-unpwd-set.test']), + (1, ['./02-subscribe-qos0.py', 'cpp/02-subscribe-qos0.test']), + (1, ['./02-subscribe-qos1.py', 'cpp/02-subscribe-qos1.test']), + (1, ['./02-subscribe-qos2.py', 'cpp/02-subscribe-qos2.test']), + (1, ['./02-unsubscribe.py', 'cpp/02-unsubscribe.test']), + (1, ['./03-publish-b2c-qos1.py', 'cpp/03-publish-b2c-qos1.test']), + (1, ['./03-publish-b2c-qos2.py', 'cpp/03-publish-b2c-qos2.test']), + (1, ['./03-publish-c2b-qos1-disconnect.py', 'cpp/03-publish-c2b-qos1-disconnect.test']), + (1, ['./03-publish-c2b-qos2-disconnect.py', 'cpp/03-publish-c2b-qos2-disconnect.test']), + (1, ['./03-publish-c2b-qos2.py', 'cpp/03-publish-c2b-qos2.test']), + (1, ['./03-publish-qos0-no-payload.py', 'cpp/03-publish-qos0-no-payload.test']), + (1, ['./03-publish-qos0.py', 'cpp/03-publish-qos0.test']), + (1, ['./04-retain-qos0.py', 'cpp/04-retain-qos0.test']), + (1, ['./08-ssl-bad-cacert.py', 'cpp/08-ssl-bad-cacert.test']), + (1, ['./08-ssl-connect-cert-auth-enc.py', 'cpp/08-ssl-connect-cert-auth-enc.test']), + (1, ['./08-ssl-connect-cert-auth.py', 'cpp/08-ssl-connect-cert-auth.test']), + (1, ['./08-ssl-connect-no-auth.py', 'cpp/08-ssl-connect-no-auth.test']), + (1, ['./09-util-topic-tokenise.py', 'cpp/09-util-topic-tokenise.test']), + ] + + +ptest.run_tests(tests) diff --git a/test/ptest.py b/test/ptest.py new file mode 100755 index 00000000..233f609e --- /dev/null +++ b/test/ptest.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +import subprocess +import time +import sys + +def next_test(tests, ports): + if len(tests) == 0 or len(ports) == 0: + return + + test = tests.pop() + proc_ports = () + + if len(ports) < test[0]: + tests.insert(0, test) + return None + else: + if isinstance(test[1], (list,)): + args = test[1] + else: + args = [test[1]] + + for i in range(0, test[0]): + proc_port = ports.pop() + proc_ports = proc_ports + (proc_port,) + args.append(str(proc_port)) + + proc = subprocess.Popen(args) + proc.start_time = time.time() + proc.mosq_port = proc_ports + return proc + + +def run_tests(tests, minport=1888, max_running=20): + ports = list(range(minport, minport+max_running+1)) + start_time = time.time() + passed = 0 + failed = 0 + + failed_tests = [] + + running_tests = [] + while len(tests) > 0 or len(running_tests) > 0: + if len(running_tests) <= max_running: + t = next_test(tests, ports) + if t is None: + time.sleep(0.1) + else: + running_tests.append(t) + + for t in running_tests: + t.poll() + if t.returncode is not None: + running_tests.remove(t) + if isinstance(t.mosq_port, tuple): + for portret in t.mosq_port: + ports.append(portret) + else: + ports.append(t.mosq_port) + t.terminate() + t.wait() + runtime = time.time() - t.start_time + #(stdo, stde) = t.communicate() + if t.returncode == 1: + print("%0.3fs : \033[31m%s\033[0m" % (runtime, t.args[0])) + failed = failed + 1 + failed_tests.append(t.args[0]) + else: + passed = passed + 1 + print("%0.3fs : \033[32m%s\033[0m" % (runtime, t.args[0])) + + print("Passed: %d\nFailed: %d\nTotal: %d\nTotal time: %0.2f" % (passed, failed, passed+failed, time.time()-start_time)) + if failed > 0: + print("Failing tests:") + for f in failed_tests: + print(f) + sys.exit(1) +