@@ -51,24 +51,33 @@ class DifferentialTestingCase:
51
51
markers_only_eliminated_by_setting1 : tuple [DCEMarker | VRMarker , ...]
52
52
markers_only_eliminated_by_setting2 : tuple [DCEMarker | VRMarker , ...]
53
53
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
+
54
59
55
60
class DifferentialTestingMode (Enum ):
56
61
"""
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
61
68
"""
62
69
63
- Unidirectional = 0
70
+ Unidirectional = 0 # AnyMissedByFirst?
64
71
Bidirectional = 1
72
+ MarkerMissedByFirst = 2
65
73
66
74
67
75
def differential_test (
68
76
program : SourceProgram ,
69
77
setting1 : CompilationSetting ,
70
78
setting2 : CompilationSetting ,
71
79
testing_mode : DifferentialTestingMode = DifferentialTestingMode .Bidirectional ,
80
+ missed_marker : DCEMarker | VRMarker | None = None ,
72
81
) -> DifferentialTestingCase | None :
73
82
"""Instrument `program`, compile it with `setting1` and `setting2` and
74
83
check if the set of eliminated markers differ.
@@ -87,11 +96,16 @@ def differential_test(
87
96
setting2 (CompilationSetting):
88
97
the second compilation setting with which to
89
98
compile the instrumented program
90
- testing_direction (DifferentialTestingDirection ):
99
+ testing_mode (DifferentialTestingMode ):
91
100
whether to accept cases whether where any of the two settings miss
92
101
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.
95
109
Returns:
96
110
(DifferentialTestingCase | None):
97
111
interesting case if found
@@ -103,7 +117,9 @@ def differential_test(
103
117
104
118
# Instrument program
105
119
try :
106
- instr_program = instrument_program (program )
120
+ instr_program = instrument_program (
121
+ setting1 .preprocess_program (program , make_compiler_agnostic = True )
122
+ )
107
123
except AssertionError :
108
124
return None
109
125
@@ -114,13 +130,17 @@ def differential_test(
114
130
only_eliminated_by_setting2 = tuple (dead_markers2 - dead_markers1 )
115
131
116
132
# 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
124
144
125
145
return DifferentialTestingCase (
126
146
program = instr_program ,
@@ -131,6 +151,7 @@ def differential_test(
131
151
)
132
152
133
153
154
+ # XXX: does this really belong in this module?
134
155
def generate_and_test (
135
156
setting1 : CompilationSetting ,
136
157
setting2 : CompilationSetting ,
0 commit comments