From b40406336202fc7193585aff45f038532b052bb7 Mon Sep 17 00:00:00 2001 From: alonre24 Date: Mon, 1 Mar 2021 18:29:30 +0200 Subject: [PATCH 1/2] Use Cmakelist instead of makefile for test module --- CMakeLists.txt | 1 + tests/flow/tests.sh | 1 - tests/flow/tests_llapi.py | 4 ++-- tests/module/CMakeLists.txt | 5 +++++ tests/module/Makefile | 39 ------------------------------------- 5 files changed, 8 insertions(+), 42 deletions(-) create mode 100644 tests/module/CMakeLists.txt delete mode 100644 tests/module/Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 32125a33d..5b57cab5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,7 @@ ENDIF() #---------------------------------------------------------------------------------------------- ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(tests/module) ADD_LIBRARY(redisai SHARED $) TARGET_LINK_LIBRARIES(redisai ${CMAKE_DL_LIBS}) diff --git a/tests/flow/tests.sh b/tests/flow/tests.sh index b296b2cab..993f93d0f 100755 --- a/tests/flow/tests.sh +++ b/tests/flow/tests.sh @@ -92,7 +92,6 @@ valgrind_summary() { #---------------------------------------------------------------------------------------------- run_tests() { - make -C ../module local title="$1" [[ ! -z $title ]] && { $ROOT/opt/readies/bin/sep -0; printf "Tests with $title:\n\n"; } cd $ROOT/tests/flow diff --git a/tests/flow/tests_llapi.py b/tests/flow/tests_llapi.py index 1abadf868..405d0baa6 100644 --- a/tests/flow/tests_llapi.py +++ b/tests/flow/tests_llapi.py @@ -12,8 +12,8 @@ def ensure_test_module_loaded(f): @wraps(f) def wrapper(env, *args, **kwargs): - goal_dir = os.path.join(os.path.dirname(__file__), "../module/LLAPI.so") - TEST_MODULE_PATH = os.path.abspath(goal_dir) + #goal_dir = os.path.join(os.path.dirname(__file__), "../module/testmod.so") + TEST_MODULE_PATH = "{ROOT}/bin/linux-x64-release/src/tests/module/testmod.so".format(ROOT=ROOT) con = env.getConnection() modules = con.execute_command("MODULE", "LIST") if b'RAI_llapi' in [module[1] for module in modules]: diff --git a/tests/module/CMakeLists.txt b/tests/module/CMakeLists.txt new file mode 100644 index 000000000..734b3ae6d --- /dev/null +++ b/tests/module/CMakeLists.txt @@ -0,0 +1,5 @@ +ADD_LIBRARY(testmod SHARED LLAPI.c DAG_utils.c) + +INCLUDE_DIRECTORIES(../../src) +SET_TARGET_PROPERTIES(testmod PROPERTIES PREFIX "") +SET_TARGET_PROPERTIES(testmod PROPERTIES SUFFIX ".so") diff --git a/tests/module/Makefile b/tests/module/Makefile deleted file mode 100644 index 2ad5b1984..000000000 --- a/tests/module/Makefile +++ /dev/null @@ -1,39 +0,0 @@ - -# find the OS -uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') - -# if DEBUG env var is set, we compile with "debug" cflags -DEBUGFLAGS = -g -ggdb -O3 -ifeq ($(DEBUG), 1) - DEBUGFLAGS = -fno-omit-frame-pointer -g -ggdb -O0 -endif - -# Compile flags for linux / osx -ifeq ($(uname_S),Linux) - SHOBJ_CFLAGS ?= -W -Wall -fno-common -g -ggdb -std=c99 -O2 - SHOBJ_LDFLAGS ?= -shared -else - SHOBJ_CFLAGS ?= -W -Wall -dynamic -fno-common -g -ggdb -std=c99 -O2 - SHOBJ_LDFLAGS ?= -bundle -undefined dynamic_lookup -endif - -TEST_MODULES = LLAPI.so - -.PHONY: all - -all: $(TEST_MODULES) - -32bit: - $(MAKE) CFLAGS="-m32" LDFLAGS="-melf_i386" - -%.o: %.c - $(CC) $(DEBUGFLAGS) -I../../src -DREDIS_MODULE_TARGET -DREDISMODULE_EXPERIMENTAL_API $(SHOBJ_CFLAGS) -fPIC -c $< -o $@ - -%.so: %.o DAG_utils.o - $(CC) -o $@ $^ $(SHOBJ_LDFLAGS) -lc -lm - chmod +x LLAPI.so - -.PHONY: clean - -clean: - rm -f $(TEST_MODULES) $(TEST_MODULES:.so=.xo) From 30c2d484693b3d276510a93884f81a39ca8e2df6 Mon Sep 17 00:00:00 2001 From: alonre24 Date: Tue, 2 Mar 2021 15:44:22 +0200 Subject: [PATCH 2/2] Send the path of test module .so to tests.sh and use it in tests_llapi.py to load the module. --- opt/Makefile | 1 + tests/flow/includes.py | 4 +--- tests/flow/tests.sh | 5 +++++ tests/flow/tests_llapi.py | 17 +++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/opt/Makefile b/opt/Makefile index 272173c0c..5d5fcaa06 100755 --- a/opt/Makefile +++ b/opt/Makefile @@ -276,6 +276,7 @@ test: build $(SHOW)\ DEVICE=$(DEVICE) \ MODULE=$(realpath $(INSTALLED_TARGET)) \ + TESTMOD=$(realpath $(BINDIR)/tests/module/testmod.so) \ CLUSTER=$(CLUSTER) \ GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \ VALGRIND=$(VALGRIND) \ diff --git a/tests/flow/includes.py b/tests/flow/includes.py index 31255c5d6..fb1d04590 100755 --- a/tests/flow/includes.py +++ b/tests/flow/includes.py @@ -15,9 +15,7 @@ import paella ROOT = os.environ.get("ROOT", None) -if ROOT is None: - sys.stderr.write("ROOT was not defined in the environment.\n") - sys.exit(1) +TESTMOD_PATH = os.environ.get("TESTMOD", None) MAX_ITERATIONS = 2 if os.environ.get("MAX_ITERATIONS") == None else os.environ.get("MAX_ITERATIONS") TEST_TF = os.environ.get("TEST_TF") != "0" and os.environ.get("WITH_TF") != "0" TEST_TFLITE = os.environ.get("TEST_TFLITE") != "0" and os.environ.get("WITH_TFLITE") != "0" diff --git a/tests/flow/tests.sh b/tests/flow/tests.sh index 993f93d0f..0d30ff509 100755 --- a/tests/flow/tests.sh +++ b/tests/flow/tests.sh @@ -28,6 +28,9 @@ help() { Argument variables: VERBOSE=1 Print commands IGNERR=1 Do not abort on error + + MODULE=path Path to redisai.so + TESTMOD=path Path to LLAPI module DEVICE=cpu|gpu Device for testing GEN=0|1 General tests @@ -115,6 +118,8 @@ OP="" MODULE=${MODULE:-$1} [[ -z $MODULE || ! -f $MODULE ]] && { echo "Module not found at ${MODULE}. Aborting."; exit 1; } +TESTMOD=${TESTMOD} +echo "Test module path is ${TESTMOD}" [[ $VALGRIND == 1 || $VGD == 1 ]] && valgrind_config diff --git a/tests/flow/tests_llapi.py b/tests/flow/tests_llapi.py index 405d0baa6..57d6a666b 100644 --- a/tests/flow/tests_llapi.py +++ b/tests/flow/tests_llapi.py @@ -8,18 +8,15 @@ python -m RLTest --test tests_llapi.py --module path/to/redisai.so ''' - -def ensure_test_module_loaded(f): +def with_test_module(f): @wraps(f) def wrapper(env, *args, **kwargs): - #goal_dir = os.path.join(os.path.dirname(__file__), "../module/testmod.so") - TEST_MODULE_PATH = "{ROOT}/bin/linux-x64-release/src/tests/module/testmod.so".format(ROOT=ROOT) con = env.getConnection() modules = con.execute_command("MODULE", "LIST") if b'RAI_llapi' in [module[1] for module in modules]: return f(env, *args, **kwargs) try: - ret = con.execute_command('MODULE', 'LOAD', TEST_MODULE_PATH) + ret = con.execute_command('MODULE', 'LOAD', TESTMOD_PATH) env.assertEqual(ret, b'OK') except Exception as e: env.assertFalse(True) @@ -29,7 +26,7 @@ def wrapper(env, *args, **kwargs): return wrapper -@ensure_test_module_loaded +@with_test_module def test_basic_check(env): con = env.getConnection() @@ -37,7 +34,7 @@ def test_basic_check(env): env.assertEqual(ret, b'OK') -@ensure_test_module_loaded +@with_test_module def test_model_run_async(env): con = env.getConnection() @@ -56,7 +53,7 @@ def test_model_run_async(env): env.assertEqual(ret, b'Async run success') -@ensure_test_module_loaded +@with_test_module def test_script_run_async(env): con = env.getConnection() @@ -78,7 +75,7 @@ def test_script_run_async(env): env.assertEqual(ret, b'Async run success') -@ensure_test_module_loaded +@with_test_module def test_dag_build_and_run(env): con = env.getConnection() @@ -105,7 +102,7 @@ def test_dag_build_and_run(env): env.assertEqual(ret, b'DAG run success') -@ensure_test_module_loaded +@with_test_module def test_dagrun_multidevice_resnet(env): con = env.getConnection()