4444from soundfile import read , write
4545
4646RM_INSTALL_DIR = "RM_install_dir"
47+ CONFORMANCE_PATH_KEY = "conformance_path"
4748ENCODER_PATH_KEY = "encoder_path"
4849DECODER_PATH_KEY = "decoder_path"
4950SYNTHESIZER_PATH_KEY = "synthesizer_path"
5960CONFORMANCE_FILES_KEY = "conformance_files"
6061CONFORMANCE_TEST_SET_KEYS = [
6162 "schemas_checks" ,
62- "semantic_checks"
63+ "semantic_checks" ,
64+ "hmpg_compatibility_checks" ,
65+ "hmpg_conformance_checks"
6366]
67+ CONFORMANCE_TEST_SET_KEY = "conversion_checks"
6468
6569def checkSoftwarePath (config : dict ):
6670 def _check_software (dir_key : str ,path_key : str ):
@@ -71,6 +75,7 @@ def _check_software(dir_key: str,path_key: str):
7175 assert os .path .exists (config_file ), f"{ path_key } should be an existing file"
7276 assert os .access (config_file , os .X_OK ), f"{ path_key } should be executable"
7377
78+ _check_software (RM_INSTALL_DIR , CONFORMANCE_PATH_KEY )
7479 _check_software (RM_INSTALL_DIR , ENCODER_PATH_KEY )
7580 _check_software (RM_INSTALL_DIR , DECODER_PATH_KEY )
7681 _check_software (RM_INSTALL_DIR , SYNTHESIZER_PATH_KEY )
@@ -85,15 +90,13 @@ def main():
8590 if os .path .exists (output_folder ):
8691 shutil .rmtree (output_folder )
8792
88-
89- #text_file = open("testlog.txt", "w")
93+ print ("####### HJIF Conformance Tests" )
9094 nb_tests = 0
9195 nb_success = 0
9296 check_fails = []
9397 for conformance_check_type in CONFORMANCE_TEST_SET_KEYS :
9498 print ("\n ****** " ,conformance_check_type ," ******" )
9599 test_number = 1 ;
96- #text_file.write("****** "+conformance_check_type+" ******\n")
97100 for conformance_check in config [CONFORMANCE_FILES_KEY ][conformance_check_type ]:
98101 input_file_path = conformance_check [HAPTIC_FILE_PATH_KEY ]
99102 if MAIN_FOLDER_KEY in config [CONFORMANCE_FILES_KEY ]:
@@ -105,27 +108,64 @@ def main():
105108 input_file_path = os .path .join (config [CONFORMANCE_FILES_KEY ][MAIN_FOLDER_KEY ], input_file_path )
106109 if (not os .path .exists (input_file_path )):
107110 print (f"FILE NOT FOUND: { input_file_path } " )
111+ nb_tests += 1
112+ test_number += 1
108113 continue
109- #print("\n",conformance_check[NAME_KEY])
110- #print(datetime.now().strftime(f"[ %Hh : %Mm : %Ss ] => Encoder on : {input_file_path}"))
111- result = subprocess .run (f"{ os .path .join (config [RM_INSTALL_DIR ], config [ENCODER_PATH_KEY ])} -f { input_file_path } -o test.hjif" ,shell = True , capture_output = True , text = True )
112- valid = result .stderr .splitlines ()== conformance_check [EXPECTED_OUTPUT_KEY ].splitlines ()
114+ result = subprocess .run (f"{ os .path .join (config [RM_INSTALL_DIR ], config [CONFORMANCE_PATH_KEY ])} -f { input_file_path } " ,shell = True , capture_output = True , text = True )
115+ expected_output = conformance_check [EXPECTED_OUTPUT_KEY ].replace ("{main_folder}" ,config [CONFORMANCE_FILES_KEY ][MAIN_FOLDER_KEY ])
116+ valid = result .stderr .splitlines ()== expected_output .splitlines ()
113117 if (not valid ):
114- check_fails .append ("********* \n " + conformance_check_type + " #" + str (test_number )+ " failed: " + conformance_check [NAME_KEY ]+ "\n " )
118+ check_fails .append ("\n --------------------- \n " + conformance_check_type + " #" + str (test_number )+ " failed: " + conformance_check [NAME_KEY ]+ "\n " )
115119 check_fails .append ("- Output : \n " + result .stderr )
116- check_fails .append ("- Expected output: \n " + conformance_check [ EXPECTED_OUTPUT_KEY ] )
120+ check_fails .append ("- Expected output: \n " + expected_output )
117121 print ("Test #" ,test_number ,":\t " ,valid ,"\t |\t " ,conformance_check [NAME_KEY ])
118122 nb_tests += 1
119123 test_number += 1
120124 if (valid ):
121125 nb_success += 1
122- #text_file.write('\\n'.join(result.stderr.replace("\\","\\\\").splitlines())+"\n\n")
123- #text_file.close()
124- print ("####### Conformance Results" )
125- if (nb_success == nb_tests ):
126- print ("SUCCESS: " ,nb_success ,"/" ,nb_tests ," valid tests" )
126+ if (nb_success == nb_tests ):
127+ print ("\n SUCCESS: " ,nb_success ,"/" ,nb_tests ," valid tests" )
128+ else :
129+ print ("\n FAIL: " ,nb_success ,"/" ,nb_tests ," valid tests" )
130+ print ("The following tests failed:" )
131+ print ("\n " .join (check_fails ))
132+
133+ check_fails = []
134+ test_number = 1 ;
135+ nb_success = 0 ;
136+ nb_tests = 0 ;
137+
138+ print ("\n ####### Conversion Conformance Tests\n " )
139+ for conversion_check in config [CONFORMANCE_FILES_KEY ][CONFORMANCE_TEST_SET_KEY ]:
140+ input_file_path = conversion_check [HAPTIC_FILE_PATH_KEY ]
141+ if MAIN_FOLDER_KEY in config [CONFORMANCE_FILES_KEY ]:
142+ if (input_file_path == "" ):
143+ print ("Conversion Test " ,conversion_check [NAME_KEY ],"TO DO\t " )
144+ test_number += 1
145+ continue
146+ input_file_path = os .path .join (config [CONFORMANCE_FILES_KEY ][MAIN_FOLDER_KEY ], input_file_path )
147+ if (not os .path .exists (input_file_path )):
148+ print (f"FILE NOT FOUND: { input_file_path } " )
149+ test_number += 1
150+ continue
151+ binary_encoding_result = subprocess .run (f"{ os .path .join (config [RM_INSTALL_DIR ], config [ENCODER_PATH_KEY ])} -f { input_file_path } -o test.hmpg -b" ,shell = True , capture_output = True , text = True )
152+ decoding_result = subprocess .run (f"{ os .path .join (config [RM_INSTALL_DIR ], config [DECODER_PATH_KEY ])} -f test.hmpg -o testDecoded.hjif" ,shell = True , capture_output = True , text = True )
153+ comparison = subprocess .run (f"{ os .path .join (config [RM_INSTALL_DIR ], config [CONFORMANCE_PATH_KEY ])} -f { input_file_path } -c testDecoded.hjif" ,shell = True , capture_output = True , text = True )
154+ expected_output = conversion_check [EXPECTED_OUTPUT_KEY ].replace ("{main_folder}" ,config [CONFORMANCE_FILES_KEY ][MAIN_FOLDER_KEY ])
155+ valid = comparison .stderr .splitlines ()== expected_output .splitlines ()
156+ if (not valid ):
157+ check_fails .append ("\n ---------------------\n \n Conversion #" + str (test_number )+ " failed: " + conversion_check [NAME_KEY ]+ "\n " )
158+ check_fails .append ("- Output : \n " + comparison .stderr )
159+ check_fails .append ("- Expected output: \n " + expected_output )
160+ else :
161+ nb_success += 1
162+ print ("Test #" ,test_number ,":\t " ,valid ,"\t |\t " ,conversion_check [NAME_KEY ])
163+ test_number += 1
164+
165+ if (nb_success == test_number - 1 ):
166+ print ("\n SUCCESS: " ,nb_success ,"/" ,test_number - 1 ," valid tests" )
127167 else :
128- print ("FAIL : " ,nb_success ,"/" ,nb_tests ," valid tests" )
168+ print ("\n FAIL : " ,nb_success ,"/" ,test_number - 1 ," valid tests" )
129169 print ("The following test failed:" )
130170 print ("\n " .join (check_fails ))
131171
0 commit comments