Beispiel #1
0
    def teardown_wrapper(self, func):
        lib.common.test_msg(
            "\n==================== Running Teardown %s    Time: %s ===================="
            % (self.__class__.__name__, now_short(self._format))
        )

        func()
Beispiel #2
0
 def endMarker(self):
     """Prints a banner at the end of a test, including test status, number of attempts (if applicable) and the current time"""
     result = ""
     if self.attempts:
         result = self.result_grade + "(" + str(self.attempts) + "/" + str(
             self.config.retry) + ")"
     lib.common.test_msg(
         "\n==================== End %s   %s   Time: %s =================="
         % (self.__class__.__name__, result, now_short(self._format)))
Beispiel #3
0
    def startMarker(self):
        """Prints a banner at the beginning of a test, including the current time"""
        msg = "==================== Begin %s    Time: %s ====================" \
            % (self.__class__.__name__, now_short(self._format))

        lib.common.test_msg('\n' + msg)
        for c in self.dev.board.consoles:
            if hasattr(c.logfile_read, 'extra_log'):
                c.logfile_read.extra_log(msg)
Beispiel #4
0
    def endMarker(self):
        """Prints a banner at the end of a test, including test status, number of attempts (if applicable) and the current time"""
        result = self.result_grade
        if self.attempts:
            result = self.result_grade + "(" + str(self.attempts) + "/" + str(
                self.config.retry) + ")"
        msg = "==================== End %s   %s   Time: %s ==================" \
                    % (self.__class__.__name__, result, now_short(self._format))

        lib.common.test_msg('\n' + msg)
        for c in self.dev.board.consoles:
            if hasattr(c.logfile_read, 'extra_log'):
                c.logfile_read.extra_log(msg)
Beispiel #5
0
    def testWrapper(self):
        self.start_time = time.time()
        recheck_devices = []

        for d in self.config.devices:
            dev = getattr(self.config, d)
            dev.test_to_log = self
            dev.test_prefix = d.encode("utf8")

        for c in self.dev.board.consoles:
            c.test_to_log = self
            c.test_prefix = 'console-%s' % str(
                self.dev.board.consoles.index(c) + 1)

            if not c.isalive():
                self.result_grade = "SKIP"
                print(
                    "\n\n=========== Test skipped! Board is not alive... ============="
                )
                self.skipTest("Board is not alive")
                raise

        try:
            if hasattr(self.dev, 'wan') and hasattr(self, 'wan_setup'):
                self.wan_setup()
            if hasattr(self.dev, 'lan') and hasattr(self, 'lan_setup'):
                self.lan_setup()
            if hasattr(self.dev, 'wlan') and hasattr(self, 'wlan_setup'):
                self.wlan_setup()

            if self.config.retry and not self.dont_retry:
                retry = self.config.retry
                self.attempts = 1
            else:
                self.attempts = retry = 0

            while retry >= 0:
                try:
                    self.runTest()
                    self.dev.board.touch()
                    break
                except boardfarm.exceptions.SkipTest:
                    raise
                except boardfarm.exceptions.ContingencyCheckError as e:
                    raise
                except Exception as e:
                    retry = retry - 1
                    if (retry > 0):
                        self.attempts = self.config.retry - retry + 1
                        traceback.print_exc(file=sys.stdout)
                        print(
                            "\n\n----------- Test failed! Retrying in 5 seconds... -------------"
                        )
                        self.recover()
                        time.sleep(5)
                        print(
                            "=========== Retry attempt number %s of %s ============="
                            % (self.attempts, self.config.retry))
                    else:
                        raise

            if hasattr(self.dev, 'wan') and hasattr(self, 'wan_cleanup'):
                self.wan_cleanup()
            if hasattr(self.dev, 'lan') and hasattr(self, 'lan_cleanup'):
                self.lan_cleanup()
            if hasattr(self.dev, 'wlan') and hasattr(self, 'wlan_cleanup'):
                self.wlan_cleanup()

            if hasattr(self, 'expected_failure') and self.expected_failure:
                self.result_grade = "Unexp OK"
            else:
                self.result_grade = "OK"

            self.stop_time = time.time()
            self.logged['test_time'] = float(self.stop_time - self.start_time)
        except boardfarm.exceptions.SkipTest as e:
            self.stop_time = time.time()
            self.logged['test_time'] = float(self.stop_time - self.start_time)
            self.result_grade = "SKIP"
            print("\n\nSkipping test: %s" % e)
            print("=========== Test skipped! Moving on... =============")
            return
        except Exception as e:
            self.stop_time = time.time()

            print(
                "\n\n=========== Test: %s failed! running Device status check! Time: %s ==========="
                % (self.__class__.__name__, now_short(self._format)))
            try:
                all_devices = [self.dev.board] + [
                    getattr(self.config, name, None)
                    for name in self.config.devices
                ]
                recheck_devices = check_devices(all_devices)
            except Exception as e:
                print(e)
            print(
                "\n\n=========== Test: %s failed! Device status check done! Time: %s ==========="
                % (self.__class__.__name__, now_short(self._format)))

            self.logged['test_time'] = float(self.stop_time - self.start_time)
            if hasattr(self, 'expected_failure') and self.expected_failure:
                self.result_grade = "Exp FAIL"
            else:
                self.result_grade = "FAIL"
            print(
                "\n\n=========== Test failed! Running recovery Time: %s ==========="
                % now_short(self._format))
            if e.__class__.__name__ == "TIMEOUT":
                print(e.get_trace())
            else:
                print(e)
                traceback.print_exc(file=sys.stdout)

            import os
            if 'BFT_DEBUG' in os.environ:
                print(self)
                for device in self.config.devices:
                    d = getattr(self.config, device)
                    print(d)

            self.recover()
            check_devices(recheck_devices)
            self.endMarker()
            raise
Beispiel #6
0
 def startMarker(self):
     """Prints a banner at the beginning of a test, including the current time"""
     lib.common.test_msg(
         "\n==================== Begin %s    Time: %s ===================="
         % (self.__class__.__name__, now_short(self._format)))
Beispiel #7
0
    def executionWrapper(self):
        self.start_time = time.time()
        recheck_devices = []

        for d in self.config.devices:
            dev = getattr(self.config, d)
            dev.test_to_log = self
            dev.test_prefix = d.encode("utf8")

        for c in self.dev.board.consoles:
            c.test_to_log = self
            c.test_prefix = "console-%s" % str(self.dev.board.consoles.index(c) + 1)

            if not c.isalive():
                self.result_grade = "SKIP"
                print(
                    "\n\n=========== Test skipped! Board is not alive... ============="
                )
                self.skipTest("Board is not alive")
        try:
            if hasattr(self.dev, "wan") and hasattr(self, "wan_setup"):
                self.wan_setup()
            if hasattr(self.dev, "lan") and hasattr(self, "lan_setup"):
                self.lan_setup()
            if hasattr(self.dev, "wlan") and hasattr(self, "wlan_setup"):
                self.wlan_setup()

            if self.config.retry and not self.dont_retry:
                retry = self.config.retry
                self.attempts = 1
            else:
                self.attempts = retry = 0

            # TBC: should the setup and teardown part of the retry?
            func = getattr(self.__class__, "setup_class", None)
            if func and not _using_pytest:
                self.setup_wrapper(func)

            while retry >= 0:
                try:
                    # Pick function to run
                    if hasattr(self, "runTest"):
                        self.runTest()
                    elif hasattr(self, "test_main"):
                        self.test_main()
                    self.dev.board.touch()
                    break
                except boardfarm.exceptions.BftSysExit:
                    logger.critical("received BftSysExit exception, bailing out!")
                    if _using_pytest:
                        pytest.exit(msg="received BftSysExit exception, bailing out!")
                    else:
                        sys.exit(1)
                except boardfarm.exceptions.SkipTest:
                    raise
                except boardfarm.exceptions.ContingencyCheckError:
                    raise
                except Exception:
                    retry = retry - 1
                    if retry > 0:
                        self.attempts = self.config.retry - retry + 1
                        traceback.print_exc(file=sys.stdout)
                        print(
                            "\n\n----------- Test failed! Retrying in 5 seconds... -------------"
                        )
                        debtcollector.deprecate(
                            "Using function/method 'recover()' is deprecated",
                            removal_version="> 1.1.1",
                            category=UserWarning,
                        )
                        self.recover()
                        time.sleep(5)
                        print(
                            "=========== Retry attempt number %s of %s ============="
                            % (self.attempts, self.config.retry)
                        )
                    else:
                        raise

            if hasattr(self.dev, "wan") and hasattr(self, "wan_cleanup"):
                self.wan_cleanup()
            if hasattr(self.dev, "lan") and hasattr(self, "lan_cleanup"):
                self.lan_cleanup()
            if hasattr(self.dev, "wlan") and hasattr(self, "wlan_cleanup"):
                self.wlan_cleanup()

            if hasattr(self, "expected_failure") and self.expected_failure:
                self.result_grade = "Unexp OK"
            else:
                self.result_grade = "OK"

            self.stop_time = time.time()
            self.logged["test_time"] = float(self.stop_time - self.start_time)
        except boardfarm.exceptions.SkipTest as e:
            self.stop_time = time.time()
            self.logged["test_time"] = float(self.stop_time - self.start_time)
            self.result_grade = "SKIP"
            print("\n\nSkipping test: %s" % e)
            print("=========== Test skipped! Moving on... =============")
            return
        except boardfarm.exceptions.ContingencyCheckError as e:
            self.stop_time = time.time()
            self.logged["test_time"] = float(self.stop_time - self.start_time)
            self.result_grade = "CC FAIL"
            print("\n\nContingency check failed: %s" % e)
            print(
                "=========== Test skipped as contingency check failed! Moving on... ============="
            )
            return
        except Exception as e:
            self.stop_time = time.time()

            print(
                "\n\n=========== Test: %s failed! running Device status check! Time: %s ==========="
                % (self.__class__.__name__, now_short(self._format))
            )

            print(
                "\n\n=========== Test: %s failed! Device status check done! Time: %s ==========="
                % (self.__class__.__name__, now_short(self._format))
            )

            self.logged["test_time"] = float(self.stop_time - self.start_time)
            if hasattr(self, "expected_failure") and self.expected_failure:
                self.result_grade = "Exp FAIL"
            else:
                self.result_grade = "FAIL"
            print(
                "\n\n=========== Test failed! Running recovery Time: %s ==========="
                % now_short(self._format)
            )
            if e.__class__.__name__ == "TIMEOUT":
                print(e.get_trace())
            else:
                print(e)
                traceback.print_exc(file=sys.stdout)

            try:
                all_devices = [self.dev.board] + [
                    getattr(self.config, name, None) for name in self.config.devices
                ]
                recheck_devices = check_devices(all_devices)
            except Exception as e:
                print(e)

            import os

            if "BFT_DEBUG" in os.environ:
                print(self)
                for device in self.config.devices:
                    try:
                        d = getattr(self.config, device)
                        print(d)
                    except Exception:
                        traceback.print_exc(file=sys.stdout)

            debtcollector.deprecate(
                "Using function/method 'recover()' is deprecated",
                removal_version="> 1.1.1",
                category=UserWarning,
            )

            try:
                self.recover()
                check_devices(recheck_devices)
            except Exception:
                print(
                    "These are maintenance functions, these should not throw an exception"
                )
                traceback.print_exc(file=sys.stdout)

            raise
Beispiel #8
0
    def testWrapper(self):
        self.start_time = time.time()

        for d in self.config.devices:
            dev = getattr(self.config, d)
            dev.test_to_log = self
            dev.test_prefix = d.encode("utf8")

        for c in board.consoles:
            c.test_to_log = self
            c.test_prefix = 'console-%s' % str(board.consoles.index(c) + 1)

            if not c.isalive():
                self.result_grade = "SKIP"
                print(
                    "\n\n=========== Test skipped! Board is not alive... ============="
                )
                self.skipTest("Board is not alive")
                raise

        try:
            if wan and hasattr(self, 'wan_setup'):
                self.wan_setup()
            if lan and hasattr(self, 'lan_setup'):
                self.lan_setup()
            if wlan and hasattr(self, 'wlan_setup'):
                self.wlan_setup()

            if self.config.retry and not self.dont_retry:
                retry = self.config.retry
            else:
                retry = 0

            while retry >= 0:
                try:
                    self.runTest()
                    board.touch()
                    retry = -1
                except Exception as e:
                    retry = retry - 1
                    if (retry > 0):
                        if hasattr(e, 'get_trace'):
                            print(e.get_trace())
                        else:
                            print("Exception has no trace, type = %s" %
                                  type(e))
                        print(
                            "\n\n----------- Test failed! Retrying in 5 seconds... -------------"
                        )
                        time.sleep(5)
                    else:
                        raise

            if wan and hasattr(self, 'wan_cleanup'):
                self.wan_cleanup()
            if lan and hasattr(self, 'lan_cleanup'):
                self.lan_cleanup()
            if wlan and hasattr(self, 'wlan_cleanup'):
                self.wlan_cleanup()

            if hasattr(self, 'expected_failure') and self.expected_failure:
                self.result_grade = "Unexp OK"
            else:
                self.result_grade = "OK"

            self.stop_time = time.time()
            self.logged['test_time'] = float(self.stop_time - self.start_time)
        except unittest2.case.SkipTest:
            self.stop_time = time.time()
            self.logged['test_time'] = float(self.stop_time - self.start_time)
            self.result_grade = "SKIP"
            print("\n\n=========== Test skipped! Moving on... =============")
            raise
        except Exception as e:
            self.stop_time = time.time()
            self.logged['test_time'] = float(self.stop_time - self.start_time)
            if hasattr(self, 'expected_failure') and self.expected_failure:
                self.result_grade = "Exp FAIL"
            else:
                self.result_grade = "FAIL"
            print(
                "\n\n=========== Test failed! Running recovery Time: %s ==========="
                % now_short(self._format))
            if e.__class__.__name__ == "TIMEOUT":
                print(e.get_trace())
            else:
                print(e)
                traceback.print_exc(file=sys.stdout)

            import os
            if 'BFT_DEBUG' in os.environ:
                print(self)
                for device in self.config.devices:
                    d = getattr(self.config, device)
                    print(d)

            self.recover()
            raise
Beispiel #9
0
 def tearDown(self):
     lib.common.test_msg(
         "\n==================== End %s      Time: %s ======================"
         % (self.__class__.__name__, now_short(self._format)))
Beispiel #10
0
 def setUp(self):
     lib.common.test_msg(
         "\n==================== Begin %s    Time: %s ===================="
         % (self.__class__.__name__, now_short(self._format)))