1# 2# Copyright (C) 2016 Intel Corporation 3# 4# SPDX-License-Identifier: MIT 5# 6 7import signal 8from . import OETestDecorator, registerDecorator 9from oeqa.core.exception import OEQATimeoutError 10 11@registerDecorator 12class OETimeout(OETestDecorator): 13 attrs = ('oetimeout',) 14 15 def setUpDecorator(self): 16 timeout = self.oetimeout 17 def _timeoutHandler(signum, frame): 18 raise OEQATimeoutError("Timed out after %s " 19 "seconds of execution" % timeout) 20 21 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) 24 25 def tearDownDecorator(self): 26 signal.alarm(0) 27 signal.signal(signal.SIGALRM, self.alarmSignal) 28 self.logger.debug("Removed SIGALRM handler") 29