diff --git a/tai_mux/.gitignore b/tai_mux/.gitignore index 0378430..dda0fa8 100644 --- a/tai_mux/.gitignore +++ b/tai_mux/.gitignore @@ -1,3 +1,4 @@ *.so test/test build +__pycache__ diff --git a/tai_mux/oopt-tai b/tai_mux/oopt-tai index ba4b1ba..3448aca 160000 --- a/tai_mux/oopt-tai +++ b/tai_mux/oopt-tai @@ -1 +1 @@ -Subproject commit ba4b1ba6a68be8cec28801c7c85a4573c25a1565 +Subproject commit 3448aca2a1e71825005b9127dc815bdeea367d8d diff --git a/tai_mux/tests/Makefile b/tai_mux/tests/Makefile index 5458afd..5e4aabc 100644 --- a/tai_mux/tests/Makefile +++ b/tai_mux/tests/Makefile @@ -6,9 +6,12 @@ ifndef TAI_LIB_DIR TAI_LIB_DIR := $(TAI_DIR)/tools/framework endif -all: libtai.so static.json libtai-a.so libtai-b.so +all: exec-pa TAI_MUX_STATIC_CONFIG_FILE=$(abspath static.json) TAI_TEST_TARGET=$(abspath libtai.so) $(MAKE) -C $(TAI_DIR)/tests +exec-pa: libtai.so static.json libtai-a.so libtai-b.so + TAI_MUX_PLATFORM_ADAPTER="exec" TAI_MUX_EXEC_SCRIPT=$(abspath exec.py) LD_LIBRARY_PATH=. python -m unittest -vf + libtai.so: $(MAKE) -C .. ln -sf ../$@ $@ diff --git a/tai_mux/tests/exec.py b/tai_mux/tests/exec.py new file mode 100755 index 0000000..cf4a3b0 --- /dev/null +++ b/tai_mux/tests/exec.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import sys +import time + + +def main(): + if len(sys.argv) != 2: + sys.exit(1) + + arg = sys.argv[1] + + if arg == "list": + print("\n".join(str(v) for v in range(1, 8))) + return + + time.sleep(.5) + + print("libtai-a.so") + + +if __name__ == "__main__": + main() diff --git a/tai_mux/tests/test.py b/tai_mux/tests/test.py new file mode 100644 index 0000000..d83ef48 --- /dev/null +++ b/tai_mux/tests/test.py @@ -0,0 +1,56 @@ +import unittest +import subprocess as sp +import threading +import os +import time +import taish +import asyncio + +TAI_TEST_MODULE_LOCATION = os.environ.get("TAI_TEST_MODULE_LOCATION", "") +if not TAI_TEST_MODULE_LOCATION: + TAI_TEST_MODULE_LOCATION = "0" + +TAI_TEST_TAISH_SERVER_ADDRESS = os.environ.get("TAI_TEST_TAISH_SERVER_ADDRESS", "") +if not TAI_TEST_TAISH_SERVER_ADDRESS: + TAI_TEST_TAISH_SERVER_ADDRESS = taish.DEFAULT_SERVER_ADDRESS + +TAI_TEST_TAISH_SERVER_PORT = os.environ.get("TAI_TEST_TAISH_SERVER_PORT", "") +if not TAI_TEST_TAISH_SERVER_PORT: + TAI_TEST_TAISH_SERVER_PORT = taish.DEFAULT_SERVER_PORT + +TAI_TEST_NO_LOCAL_TAISH_SERVER = ( + True if os.environ.get("TAI_TEST_NO_LOCAL_TAISH_SERVER", "") else False +) + + +def output_reader(proc): + for line in iter(proc.stdout.readline, b""): + print("taish-server: {}".format(line.decode("utf-8")), end="") + + +class TestTAI(unittest.IsolatedAsyncioTestCase): + def setUp(self): + if TAI_TEST_NO_LOCAL_TAISH_SERVER: + return + proc = sp.Popen(["taish_server", "-v", "-n"], stderr=sp.STDOUT, stdout=sp.PIPE) + self.d = threading.Thread(target=output_reader, args=(proc,)) + self.d.start() + self.proc = proc + time.sleep(1) # wait for the server to be ready + + def tearDown(self): + if TAI_TEST_NO_LOCAL_TAISH_SERVER: + return + self.proc.terminate() + self.proc.wait(timeout=0.2) + self.d.join() + self.proc.stdout.close() + + async def test_create_and_remove(self): + cli = taish.AsyncClient( + TAI_TEST_TAISH_SERVER_ADDRESS, TAI_TEST_TAISH_SERVER_PORT + ) + m = await cli.list() + v = await asyncio.gather(*(cli.create_module(k) for k in m.keys())) + await asyncio.gather(*(cli.remove(v.oid) for v in v)) + cli.close()