22
33from includes import *
44import os
5+ from functools import wraps
56
67'''
78python -m RLTest --test tests_llapi.py --module path/to/redisai.so
89'''
910
10- goal_dir = os .path .join (os .getcwd (), "../module/LLAPI.so" )
11- TEST_MODULE_PATH = os .path .abspath (goal_dir )
1211
12+ def ensure_test_module_loaded (f ):
13+ @wraps (f )
14+ def wrapper (env , * args , ** kwargs ):
15+ goal_dir = os .path .join (os .getcwd (), "../module/LLAPI.so" )
16+ TEST_MODULE_PATH = os .path .abspath (goal_dir )
17+ con = env .getConnection ()
18+ modules = con .execute_command ("MODULE" , "LIST" )
19+ if b'RAI_llapi' in [module [1 ] for module in modules ]:
20+ return f (env , * args , ** kwargs )
21+ try :
22+ ret = con .execute_command ('MODULE' , 'LOAD' , TEST_MODULE_PATH )
23+ env .assertEqual (ret , b'OK' )
24+ return f (env , * args , ** kwargs )
25+ except Exception as e :
26+ env .assertFalse (True )
27+ env .debugPrint (str (e ), force = True )
28+ return
29+ return wrapper
1330
31+
32+ @ensure_test_module_loaded
1433def test_basic_check (env ):
1534
1635 con = env .getConnection ()
17- ret = con .execute_command ("MODULE" , "LOAD" , TEST_MODULE_PATH )
18- env .assertEqual (ret , b'OK' )
1936 ret = con .execute_command ("RAI_llapi.basic_check" )
2037 env .assertEqual (ret , b'OK' )
2138
2239
40+ @ensure_test_module_loaded
2341def test_model_run_async (env ):
2442
2543 con = env .getConnection ()
26- ret = con .execute_command ("MODULE" , "LOAD" , TEST_MODULE_PATH )
27- env .assertEqual (ret , b'OK' )
28-
2944 test_data_path = os .path .join (os .path .dirname (__file__ ), 'test_data' )
3045 model_filename = os .path .join (test_data_path , 'graph.pb' )
3146
@@ -39,3 +54,25 @@ def test_model_run_async(env):
3954 con .execute_command ('AI.TENSORSET' , 'b{1}' , 'FLOAT' , 2 , 2 , 'VALUES' , 2 , 3 , 2 , 3 )
4055 ret = con .execute_command ("RAI_llapi.modelRun" )
4156 env .assertEqual (ret , b'Async run success' )
57+
58+
59+ @ensure_test_module_loaded
60+ def test_script_run_async (env ):
61+
62+ con = env .getConnection ()
63+ test_data_path = os .path .join (os .path .dirname (__file__ ), 'test_data' )
64+ script_filename = os .path .join (test_data_path , 'script.txt' )
65+
66+ with open (script_filename , 'rb' ) as f :
67+ script = f .read ()
68+
69+ ret = con .execute_command ('AI.SCRIPTSET' , 'myscript{1}' , DEVICE , 'TAG' , 'version1' , 'SOURCE' , script )
70+ env .assertEqual (ret , b'OK' )
71+
72+ ret = con .execute_command ('AI.TENSORSET' , 'a{1}' , 'FLOAT' , 2 , 2 , 'VALUES' , 2 , 3 , 2 , 3 )
73+ env .assertEqual (ret , b'OK' )
74+ ret = con .execute_command ('AI.TENSORSET' , 'b{1}' , 'FLOAT' , 2 , 2 , 'VALUES' , 2 , 3 , 2 , 3 )
75+ env .assertEqual (ret , b'OK' )
76+
77+ ret = con .execute_command ("RAI_llapi.scriptRun" )
78+ env .assertEqual (ret , b'Async run success' )
0 commit comments