blob: a247583f7f124148187256b61dd5a3308c3dcddb [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004import signal
Brad Bishopf86d0552018-12-04 14:18:15 -08005from . import OETestDecorator, registerDecorator
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006from oeqa.core.exception import OEQATimeoutError
7
8@registerDecorator
9class OETimeout(OETestDecorator):
10 attrs = ('oetimeout',)
11
12 def setUpDecorator(self):
Brad Bishopf86d0552018-12-04 14:18:15 -080013 timeout = self.oetimeout
14 def _timeoutHandler(signum, frame):
15 raise OEQATimeoutError("Timed out after %s "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 "seconds of execution" % timeout)
17
Brad Bishopf86d0552018-12-04 14:18:15 -080018 self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout)
19 self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler)
20 signal.alarm(self.oetimeout)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021
22 def tearDownDecorator(self):
Brad Bishopf86d0552018-12-04 14:18:15 -080023 signal.alarm(0)
24 signal.signal(signal.SIGALRM, self.alarmSignal)
25 self.logger.debug("Removed SIGALRM handler")