blob: 5e6873ad48be57dd03f8ec62ed74e8512c519771 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import signal
Brad Bishopf86d0552018-12-04 14:18:15 -08008from . import OETestDecorator, registerDecorator
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009from oeqa.core.exception import OEQATimeoutError
10
11@registerDecorator
12class OETimeout(OETestDecorator):
13 attrs = ('oetimeout',)
14
15 def setUpDecorator(self):
Brad Bishopf86d0552018-12-04 14:18:15 -080016 timeout = self.oetimeout
17 def _timeoutHandler(signum, frame):
18 raise OEQATimeoutError("Timed out after %s "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019 "seconds of execution" % timeout)
20
Brad Bishopf86d0552018-12-04 14:18:15 -080021 self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout)
22 self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler)
23 signal.alarm(self.oetimeout)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024
25 def tearDownDecorator(self):
Brad Bishopf86d0552018-12-04 14:18:15 -080026 signal.alarm(0)
Andrew Geisslerc926e172021-05-07 16:11:35 -050027 if hasattr(self, 'alarmSignal'):
28 signal.signal(signal.SIGALRM, self.alarmSignal)
29 self.logger.debug("Removed SIGALRM handler")