8
8
import importlib
9
9
import configparser
10
10
import lief
11
+ #import time
11
12
#import filecmp
12
13
import json
13
14
import pytest
26
27
yaml .allow_unicode = True
27
28
yaml .compact (seq_seq = False , seq_map = False )
28
29
from multiprocessing import Pool
29
-
30
+ startpc = '-1'
30
31
31
32
# Misc Helper Functions
32
33
def sanitise_pytest_json (json ):
@@ -197,7 +198,13 @@ def generate_report(output_dir, gen_json_data, target_json_data, ref_json_data,
197
198
html_objects ['num_failed' ] = num_failed
198
199
html_objects ['num_unav' ] = num_unav
199
200
html_objects ['total_instr' ] = total_instr
200
-
201
+ generator_count = {}
202
+ for i in test_dict :
203
+ if test_dict [i ]['generator' ] not in generator_count :
204
+ generator_count [test_dict [i ]['generator' ]] = 1
205
+ else :
206
+ generator_count [test_dict [i ]['generator' ]] += 1
207
+ html_objects ['generator_count' ] = generator_count
201
208
if not os .path .exists (report_dir ):
202
209
os .makedirs (report_dir )
203
210
@@ -413,7 +420,7 @@ def rivercore_generate(config_file, verbosity, filter_testgen):
413
420
414
421
415
422
def rivercore_compile (config_file , test_list , coverage , verbosity , dut_flags ,
416
- ref_flags , compare , process_count , timeout ):
423
+ ref_flags , compare , process_count , timeout , comparestartpc ):
417
424
'''
418
425
419
426
Function to compile generated assembly programs using the plugin as configured in the config.ini.
@@ -446,6 +453,7 @@ def rivercore_compile(config_file, test_list, coverage, verbosity, dut_flags,
446
453
447
454
:type compare: bool
448
455
'''
456
+
449
457
logger .level (verbosity )
450
458
config = configparser .ConfigParser ()
451
459
config .read (config_file )
@@ -627,6 +635,8 @@ def rivercore_compile(config_file, test_list, coverage, verbosity, dut_flags,
627
635
628
636
## Comparing Dumps
629
637
if compare :
638
+ global startpc
639
+ startpc = comparestartpc
630
640
test_dict = utils .load_yaml (test_list )
631
641
gen_json_data = []
632
642
target_json_data = []
@@ -653,7 +663,6 @@ def rivercore_compile(config_file, test_list, coverage, verbosity, dut_flags,
653
663
failed_dict_file = output_dir + '/failed_list.yaml'
654
664
logger .error (f'Saving failed list of tests in { failed_dict_file } ' )
655
665
utils .save_yaml (failed_dict , failed_dict_file )
656
-
657
666
# Start checking things after running the commands
658
667
# Report generation starts here
659
668
# Target
@@ -741,6 +750,116 @@ def rivercore_compile(config_file, test_list, coverage, verbosity, dut_flags,
741
750
return 1
742
751
if not success :
743
752
raise SystemExit (1 )
753
+
754
+ def rivercore_comparison ( test_list ,output_dir , process_count , timeout , comparestartpc ):
755
+ '''
756
+
757
+ Function to compile generated assembly programs using the plugin as configured in the config.ini.
758
+
759
+ :param config_file: Config.ini file for generation
760
+
761
+ :param test_list: Test List exported from generate sub-command
762
+
763
+ :param coverage: Enable coverage merge and stats from the reports
764
+
765
+ :param verbosity: Verbosity level for the framework
766
+
767
+ :param dut_flags: Verbosity level for the framework
768
+
769
+ :param ref_flags: Verbosity level for the framework
770
+
771
+ :param compare: Verbosity level for the framework
772
+
773
+ :type config_file: click.Path
774
+
775
+ :type test_list: click.Path
776
+
777
+ :type coverage: bool
778
+
779
+ :type verbosity: str
780
+
781
+ :type dut_flags: click.Choice
782
+
783
+ :type ref_flags: click.Choice
784
+
785
+ :type compare: bool
786
+ '''
787
+
788
+ logger .info ('****** Compilation Mode ******' )
789
+
790
+ logger .info (
791
+ "The river_core is currently configured to run with following parameters"
792
+ )
793
+ logger .info ("The Output Directory (work_dir) : {0}" .format (output_dir ))
794
+
795
+ # Set default values:
796
+ target_json = None
797
+ ref_json = None
798
+ # Load coverage stats
799
+ if True :
800
+ logger .level ("info" )
801
+ ## Comparing Dumps
802
+ if True :
803
+ global startpc
804
+ startpc = comparestartpc
805
+ test_dict = utils .load_yaml (test_list )
806
+ # parallelized
807
+ success = True
808
+ items = test_dict .items ()
809
+ #start = time.time()
810
+ with Pool (processes = process_count ) as process_pool :
811
+ output = process_pool .map (logcomparison , items ) #Collecting the return values from each process in the Pool
812
+ #stop = time.time()
813
+ #logger.warn(stop - start)
814
+ #Updating values
815
+ for i in output :
816
+ success = success and i [0 ]
817
+ test_dict [i [1 ]]['result' ] = i [2 ]
818
+ test_dict [i [1 ]]['log' ] = i [3 ]
819
+ test_dict [i [1 ]]['num_instr' ] = i [4 ]
820
+ utils .save_yaml (test_dict , output_dir + '/result_list.yaml' )
821
+ failed_dict = {}
822
+ for test , attr in test_dict .items ():
823
+ if attr ['result' ] == 'Failed' or 'Unavailable' in attr ['result' ]:
824
+ failed_dict [test ] = attr
825
+
826
+ if len (failed_dict ) != 0 :
827
+ logger .error (f'Total Tests that Failed :{ len (failed_dict )} ' )
828
+ failed_dict_file = output_dir + '/failed_list.yaml'
829
+ logger .error (f'Saving failed list of tests in { failed_dict_file } ' )
830
+ utils .save_yaml (failed_dict , failed_dict_file )
831
+
832
+ if not success :
833
+ raise SystemExit (1 )
834
+
835
+
836
+ #Helper function for parallel processing
837
+ #Returns success,test,attr['result'],attr['log'],attr['numinstr']
838
+ def logcomparison (item ):
839
+ test , attr = item
840
+ test_wd = attr ['work_dir' ]
841
+ is_self_checking = attr ['self_checking' ]
842
+ if not is_self_checking :
843
+ if not os .path .isfile (test_wd + '/dut.dump' ):
844
+ logger .error (f'{ test :<30} : DUT dump is missing' )
845
+ return False , test , 'Unavailable' , "DUT dump is missing" , None
846
+ if not os .path .isfile (test_wd + '/ref.dump' ):
847
+ logger .error (f'{ test :<30} : REF dump is missing' )
848
+ return False , test , 'Unavailable' , 'REF dump is missing' , None
849
+ compare_start_pc = str (startpc ) if str (startpc )!= '-1' else ''
850
+ result , log , insnsize = utils .compare_dumps (test_wd + '/dut.dump' , test_wd + '/ref.dump' ,compare_start_pc )
851
+ else :
852
+ if not os .path .isfile (test_wd + '/dut.signature' ):
853
+ logger .error (f'{ test :<30} : DUT signature is missing' )
854
+ return False , test , 'Unavailable' ,"DUT signature is missing" , None
855
+ result , log = utils .self_check (test_wd + '/dut.signature' )
856
+ insnsize = utils .get_file_size (test_wd + '/dut.dump' )
857
+ if result == 'Passed' :
858
+ logger .info (f"{ test :<30} : TEST { result .upper ()} " )
859
+ return True , test , result , log , insnsize
860
+ else :
861
+ logger .error (f"{ test :<30} : TEST { result .upper ()} " )
862
+ return False , test , result , log , insnsize
744
863
745
864
746
865
def rivercore_merge (verbosity , db_folders , output , config_file ):
@@ -943,32 +1062,6 @@ def rivercore_merge(verbosity, db_folders, output, config_file):
943
1062
except :
944
1063
logger .info ("Couldn't open the browser" )
945
1064
946
- #Helper function for parallel processing
947
- #Returns success,test,attr['result'],attr['log'],attr['numinstr']
948
- def logcomparison (item ):
949
- test , attr = item
950
- test_wd = attr ['work_dir' ]
951
- is_self_checking = attr ['self_checking' ]
952
- if not is_self_checking :
953
- if not os .path .isfile (test_wd + '/dut.dump' ):
954
- logger .error (f'{ test :<30} : DUT dump is missing' )
955
- return False , test , 'Unavailable' , "DUT dump is missing" , None
956
- if not os .path .isfile (test_wd + '/ref.dump' ):
957
- logger .error (f'{ test :<30} : REF dump is missing' )
958
- return False , test , 'Unavailable' , 'REF dump is missing' , None
959
- result , log , insnsize = utils .compare_dumps (test_wd + '/dut.dump' , test_wd + '/ref.dump' )
960
- else :
961
- if not os .path .isfile (test_wd + '/dut.signature' ):
962
- logger .error (f'{ test :<30} : DUT signature is missing' )
963
- return False , test , 'Unavailable' ,"DUT signature is missing" , None
964
- result , log = utils .self_check (test_wd + '/dut.signature' )
965
- insnsize = utils .get_file_size (test_wd + '/dut.dump' )
966
- if result == 'Passed' :
967
- logger .info (f"{ test :<30} : TEST { result .upper ()} " )
968
- return True , test , result , log , insnsize
969
- else :
970
- logger .error (f"{ test :<30} : TEST { result .upper ()} " )
971
- return False , test , result , log , insnsize
972
1065
def rivercore_setup (config , dut , gen , ref , verbosity ):
973
1066
'''
974
1067
Function to generate sample plugins
0 commit comments