@@ -35,20 +35,22 @@ def print_version():
3535
3636def print_models ():
3737 print list_fastmodels ()
38- self_test ( )
38+ print "Import PyCADI Test ... {}" . format ( "PASSED" if check_import () else "FAILED" )
3939
4040def self_test ():
41- if check_import ():
42- print "Self Test ... Passed"
43- else :
44- print "Self Test ... Failed"
41+ print list_fastmodels (check_models = True )
42+ print "Import PyCADI Test ... {}" .format ("PASSED" if check_import () else "FAILED" )
4543
46- def list_fastmodels ():
44+ def list_fastmodels (check_models = False ):
4745 """! List all models and configs in fm_agent"""
46+
4847 resource = FastmodelAgent ()
4948 model_dict = resource .list_avaliable_models ()
5049
5150 columns = ['MODEL NAME' , "MODEL LIB full path" , 'CONFIG NAME' , 'CONFIG FILE' , 'AVAILABILITY' ]
51+ if check_models :
52+ columns .append ('SELF TEST' )
53+
5254 pt = PrettyTable (columns )
5355 pt .hrules = 1
5456
@@ -61,6 +63,8 @@ def list_fastmodels():
6163 c_names_cell = []
6264 c_files_cell = []
6365 c_avail_cell = []
66+ if check_models :
67+ c_test_cell = []
6468
6569 for config_name , config_file in sorted (configs .items ()):
6670 c_names_cell .append (config_name )
@@ -69,22 +73,39 @@ def list_fastmodels():
6973 for file in c_files_cell :
7074 if not os .path .exists (lib_path ):
7175 c_avail_cell .append ("NO 'MODEL LIB' NOT EXIST" )
76+ if check_models :
77+ c_test_cell .append ("SKIPPED" )
7278 elif resource .check_config_exist (file ):
7379 c_avail_cell .append ("YES" )
80+ if check_models :
81+ try :
82+ resource .setup_simulator (model_name ,config_name )
83+ resource .start_simulator ()
84+ c_test_cell .append ("PASSED" if resource .is_simulator_alive () else "FAILED" )
85+ resource .shutdown_simulator ()
86+ except Exception as e :
87+ print str (e )
88+ c_test_cell .append ("FAILED" )
7489 else :
7590 c_avail_cell .append ("NO 'CONFIG FILE' NOT EXIST" )
91+ if check_models :
92+ c_test_cell .append ("SKIPPED" )
7693
7794 MAX_WIDTH = 60
7895 lib_path_cell = [lib_path [i :i + MAX_WIDTH ] for i in range (0 , len (lib_path ), MAX_WIDTH )]
7996
8097 padding_lines_col1 = "\n " * ((len (c_names_cell )- 1 ) // 2 )
8198 padding_lines_col2 = "\n " * ((len (c_names_cell )- len (lib_path_cell )) // 2 )
8299
83- pt . add_row ( [padding_lines_col1 + model_name ,
100+ row_list = [padding_lines_col1 + model_name ,
84101 padding_lines_col2 + "\n " .join (lib_path_cell ),
85102 "\n " .join (c_names_cell ),
86103 "\n " .join (c_files_cell ),
87- "\n " .join (c_avail_cell )])
104+ "\n " .join (c_avail_cell )]
105+ if check_models :
106+ row_list .append ("\n " .join (c_test_cell ))
107+
108+ pt .add_row (row_list )
88109
89110 return pt .get_string ()
90111
@@ -97,7 +118,7 @@ def cli_parser(in_args):
97118 help = 'print package version and exit' )
98119 parser .add_argument ('-t' , '--self-test' , dest = 'command' ,
99120 action = 'store_const' , const = self_test ,
100- help = 'self-test if fast model product been installed successfully' )
121+ help = 'self-test if fast model can be launch successfully' )
101122 out_args = parser .parse_args (in_args )
102123 return out_args
103124
0 commit comments