@@ -51,24 +51,33 @@ class DifferentialTestingCase:
5151 markers_only_eliminated_by_setting1 : tuple [DCEMarker | VRMarker , ...]
5252 markers_only_eliminated_by_setting2 : tuple [DCEMarker | VRMarker , ...]
5353
54+ def __post_init__ (self ) -> None :
55+ assert set (self .markers_only_eliminated_by_setting1 ).isdisjoint (
56+ self .markers_only_eliminated_by_setting2
57+ )
58+
5459
5560class DifferentialTestingMode (Enum ):
5661 """
57- - Unidirectional: a marker is interesting only if the first
58- compilation setting missed it and the second eliminated
59- - Bidirectional: a marker is interesting if any of the compilation settings
60- missed it and the other found it
62+ - Unidirectional: any marker is interesting only if the first
63+ compilation setting missed it and the second eliminated it
64+ - Bidirectional: any marker is interesting if any of the compilation
65+ settings missed it and the other eliminated it
66+ - MarkerMissedByFirst: a particular marker is interesting if the
67+ first compilation setting missed it and the other eliminated it
6168 """
6269
63- Unidirectional = 0
70+ Unidirectional = 0 # AnyMissedByFirst?
6471 Bidirectional = 1
72+ MarkerMissedByFirst = 2
6573
6674
6775def differential_test (
6876 program : SourceProgram ,
6977 setting1 : CompilationSetting ,
7078 setting2 : CompilationSetting ,
7179 testing_mode : DifferentialTestingMode = DifferentialTestingMode .Bidirectional ,
80+ missed_marker : DCEMarker | VRMarker | None = None ,
7281) -> DifferentialTestingCase | None :
7382 """Instrument `program`, compile it with `setting1` and `setting2` and
7483 check if the set of eliminated markers differ.
@@ -87,11 +96,16 @@ def differential_test(
8796 setting2 (CompilationSetting):
8897 the second compilation setting with which to
8998 compile the instrumented program
90- testing_direction (DifferentialTestingDirection ):
99+ testing_mode (DifferentialTestingMode ):
91100 whether to accept cases whether where any of the two settings miss
92101 at least one marker (Bidirectional), or cases where markers are
93- eliminated by `setting1` and eliminated by `setting2`
94-
102+ missed by `setting1` and eliminated by `setting2` (Unidirectional).
103+ In MarkerMissedByFirst mode, if `missed_marker` is not
104+ missed by the First setting and eliminated by the other,
105+ the case is not interesting and None is returned.
106+ missed_marker (DCEMarker | VRMarker | None):
107+ If `testing_mode` is MarkerMissecByFirst, only `missed_marker` is
108+ checked: it must be missed by the first setting and found by the other.
95109 Returns:
96110 (DifferentialTestingCase | None):
97111 interesting case if found
@@ -103,7 +117,9 @@ def differential_test(
103117
104118 # Instrument program
105119 try :
106- instr_program = instrument_program (program )
120+ instr_program = instrument_program (
121+ setting1 .preprocess_program (program , make_compiler_agnostic = True )
122+ )
107123 except AssertionError :
108124 return None
109125
@@ -114,13 +130,17 @@ def differential_test(
114130 only_eliminated_by_setting2 = tuple (dead_markers2 - dead_markers1 )
115131
116132 # Is the candidate interesting?
117- if not only_eliminated_by_setting1 and not only_eliminated_by_setting2 :
118- return None
119- if testing_mode == DifferentialTestingMode .Unidirectional :
120- if not only_eliminated_by_setting1 :
121- return None
122- else :
123- assert testing_mode == DifferentialTestingMode .Bidirectional
133+ match testing_mode :
134+ case DifferentialTestingMode .Bidirectional :
135+ if not only_eliminated_by_setting1 and not only_eliminated_by_setting2 :
136+ return None
137+ case DifferentialTestingMode .Unidirectional :
138+ if not only_eliminated_by_setting1 :
139+ return None
140+ case DifferentialTestingMode .MarkerMissedByFirst :
141+ assert missed_marker
142+ if missed_marker not in only_eliminated_by_setting2 :
143+ return None
124144
125145 return DifferentialTestingCase (
126146 program = instr_program ,
@@ -131,6 +151,7 @@ def differential_test(
131151 )
132152
133153
154+ # XXX: does this really belong in this module?
134155def generate_and_test (
135156 setting1 : CompilationSetting ,
136157 setting2 : CompilationSetting ,
0 commit comments