4 from pathlib
import Path
13 sys.platform !=
"linux",
14 reason=
"FPE monitoring currently only supported on Linux",
17 "ACTS_SEQUENCER_DISABLE_FPEMON" in os.environ,
18 reason=
"Sequencer is configured to disable FPE monitoring",
24 acts.FpeType.FLTDIV:
"DivByZero",
25 acts.FpeType.FLTOVF:
"Overflow",
26 acts.FpeType.FLTINV:
"Invalid",
31 pytest.param(acts.FpeType.FLTDIV, id=
"FLTDIV"),
32 pytest.param(acts.FpeType.FLTOVF, id=
"FLTOVF"),
33 pytest.param(acts.FpeType.FLTINV, id=
"FLTINV"),
36 _src = (Path(__file__).parent /
"../src/Framework.cpp").resolve()
38 with _src.open()
as fh:
39 _name_to_type = {v.lower(): k
for k, v
in _names.items()}
41 m = re.match(
r".*// ?MARK: (.*)", line)
45 _locs[_name_to_type[name]] = (
str(_src), (i + 1, i + 2))
50 acts.examples.IAlgorithm.__init__(self, name, acts.logging.INFO)
53 i = context.eventNumber % 4
56 acts.FpeMonitor._trigger_divbyzero()
58 acts.FpeMonitor._trigger_overflow()
60 acts.FpeMonitor._trigger_invalid()
62 return acts.examples.ProcessCode.SUCCESS
67 acts.examples.IAlgorithm.__init__(self, name, acts.logging.INFO)
72 return acts.examples.ProcessCode.SUCCESS
75 @pytest.fixture(autouse=
True)
77 prev = acts.logging.getFailureThreshold()
78 acts.logging.setFailureThreshold(acts.logging.MAX)
80 acts.logging.setFailureThreshold(prev)
94 for x
in acts.FpeType.values:
95 assert res.count(x) == 0
98 @pytest.fixture(params=_types)
106 failOnFirstFpe=
False,
113 acts.FpeMonitor, f
"_trigger_{_names[fpe_type].lower()}"
117 with pytest.raises(RuntimeError):
121 for x
in acts.FpeType.values:
122 assert res.count(x) == (s.config.events
if x == fpe_type
else 0)
136 acts.FpeMonitor, f
"_trigger_{_names[fpe_type].lower()}"
141 with pytest.raises(acts.FpeFailure):
145 for x
in acts.FpeType.values:
146 assert res.count(x) == (1
if x == fpe_type
else 0)
150 class Alg(acts.examples.IAlgorithm):
152 acts.examples.IAlgorithm.__init__(self,
"Alg", acts.logging.INFO)
154 def execute(self, context):
155 assert context.fpeMonitor
is None
156 return acts.examples.ProcessCode.SUCCESS
163 s.addAlgorithm(Alg())
168 trigger = getattr(acts.FpeMonitor, f
"_trigger_{_names[fpe_type].lower()}")
170 class Alg(acts.examples.IAlgorithm):
172 acts.examples.IAlgorithm.__init__(self,
"Alg", acts.logging.INFO)
174 def execute(self, context):
175 assert context.fpeMonitor
is not None
177 context.fpeMonitor.rearm()
179 return acts.examples.ProcessCode.SUCCESS
183 failOnFirstFpe=
False,
186 s.addAlgorithm(Alg())
187 with pytest.raises(RuntimeError):
191 for x
in acts.FpeType.values:
192 assert res.count(x) == (s.config.events * 2
if x == fpe_type
else 0)
196 trigger = getattr(acts.FpeMonitor, f
"_trigger_{_names[fpe_type].lower()}")
200 assert context.fpeMonitor
is not None
201 context.fpeMonitor.rearm()
215 s.addAlgorithm(
FuncAlg(
"Alg", func))
217 with pytest.raises(acts.FpeFailure):
231 s.addAlgorithm(
FuncAlg(
"Alg", func))
236 for x
in acts.FpeType.values:
237 assert res.count(x) == (s.config.events * 2
if x == fpe_type
else 0)
243 self.file == other.file
244 and self.lines == other.lines
245 and self.type == other.type
246 and self.count == other.count
256 file = tmp_path /
"fpe_mask.yml"
257 with file.open(
"w")
as fh:
262 assert masks2 == masks
266 trigger = getattr(acts.FpeMonitor, f
"_trigger_{_names[fpe_type].lower()}")
269 with acts.FpeMonitor.context()
as fpe:
278 failOnFirstFpe=
False,
281 s.addAlgorithm(
FuncAlg(
"Invalid",
lambda _: acts.FpeMonitor._trigger_invalid()))
282 with pytest.raises(RuntimeError):
286 for x
in acts.FpeType.values:
287 assert res.count(x) == (s.config.events
if x == acts.FpeType.FLTINV
else 0)