Ejemplo n.º 1
0
def test_main():
    (package, name, launch_arguments, pause, text_mode) = _parse_arguments()
    rocon_launcher = rocon_utilities.find_resource(package, name)  # raises an IO error if there is a problem.
    launchers = rocon_utilities.parse_rocon_launcher(rocon_launcher, launch_arguments)
    results_log_name, results_file = loggers.configure_logging(package, rocon_launcher)

    try:
        test_case = runner.create_unit_rocon_test(rocon_launcher, launchers)
        suite = unittest.TestLoader().loadTestsFromTestCase(test_case)
        if pause:
            runner.set_pause_mode(True)
        if text_mode:
            runner.set_text_mode(True)
            result = unittest.TextTestRunner(verbosity=2).run(suite)
        else:
            xml_runner = rosunit.create_xml_runner(package, results_log_name, \
                                         results_file=results_file, \
                                         is_rostest=True)
            result = xml_runner.run(suite)
    finally:
        # really make sure that all of our processes have been killed (should be automatic though)
        test_parents = runner.get_rocon_test_parents()
        for r in test_parents:
            r.tearDown()
        del test_parents[:]
        pmon_shutdown()
    subtest_results = runner.get_results()

    ################################
    # Post stuff
    ################################
    config = rostest.runner.getConfig()
    if config:
        if config.config_errors:
            print("\n[ROCON_TEST WARNINGS]" + '-' * 62 + '\n', file=sys.stderr)
        for err in config.config_errors:
            print(" * %s" % err, file=sys.stderr)
        print('')

    if not text_mode:
        printRostestSummary(result, subtest_results)
        loggers.printlog("results log file is in %s" % results_file)

    # This is not really a useful log, so dont worry about showing it.
    # if log_name:
    #     loggers.printlog("rocon_test log file is in %s" % log_name)

    if not result.wasSuccessful():
        sys.exit(1)
    elif subtest_results.num_errors or subtest_results.num_failures:
        sys.exit(2)
Ejemplo n.º 2
0
def tearDown(self):
    '''
      Function that becomes TestCase.tearDown()
    '''
    for rocon_launch_configuration in self.rocon_launch_configurations:
        config = rocon_launch_configuration.configuration
        parent = rocon_launch_configuration.parent
        launcher = rocon_launch_configuration.launcher
        if _pause_mode:
            raw_input("Press Enter to continue...")
            set_pause_mode(False)  # only trigger pause once
        printlog("Tear Down - launcher..........................%s" %
                 launcher["path"])
        if config.tests:
            printlog("Tear Down - tests..............................%s" %
                     [test.test_name for test in config.tests])
            if parent:
                parent.tearDown()
                printlog("Tear Down - run id............................%s" %
                         parent.run_id)
        else:
            parent.shutdown()
Ejemplo n.º 3
0
def setUp(self):
    '''
      Function that becomes TestCase.setUp()

      For each launcher representing a launch on a single master in the rocon
      launcher, this makes sure there is an entity that is to be the 'parent'
      who will later be responsible for shutting everything down.

      This could be prone to problems if someone puts multiple test launchers in
      rocon launcher with the same master port (untested).
    '''
    # new parent for each run. we are a bit inefficient as it would be possible to
    # reuse the roslaunch base infrastructure for each test, but the roslaunch code
    # is not abstracted well enough yet
    uuids = {}
    for rocon_launch_configuration in self.rocon_launch_configurations:
        config = rocon_launch_configuration.configuration
        launcher = rocon_launch_configuration.launcher
        o = urlparse(config.master.uri)
        if o.port not in uuids.keys():
            uuids[o.port] = roslaunch.core.generate_run_id()
        if not config.tests:
            rocon_launch_configuration.parent = roslaunch.parent.ROSLaunchParent(
                uuids[o.port], [launcher["path"]],
                is_core=False,
                port=o.port,
                verbose=False,
                force_screen=False,
                is_rostest=False)
            rocon_launch_configuration.parent._load_config()
            rocon_launch_configuration.parent.start()
            printlog("Launch Parent - type ...............ROSLaunchParent")
        else:
            rocon_launch_configuration.parent = RoconTestLaunchParent(
                uuids[o.port], config, [launcher["path"]], port=o.port)
            rocon_launch_configuration.parent.setUp()
            # the config attribute makes it easy for tests to access the ROSLaunchConfig instance
            # Should we do this - it doesn't make a whole lot of sense?
            #rocon_launch_configuration.configuration = rocon_launch_configuration.parent.config
            _add_rocon_test_parent(rocon_launch_configuration.parent)
            printlog("Launch Parent - type ...............ROSTestLaunchParent")
        printlog("Launch Parent - run id..............%s" %
                 rocon_launch_configuration.parent.run_id)
        printlog("Launch Parent - launcher............%s" %
                 rocon_launch_configuration.launcher["path"])
        printlog("Launch Parent - port................%s" % o.port)
        if not config.tests:
            printlog("Launch Parent - tests...............no")
        else:
            printlog("Launch Parent - tests...............yes")
Ejemplo n.º 4
0
    def fn(self):
        printlog("Launching tests")
        done = False
        while not done:
            parent = test_launch_configuration.parent
            self.assert_(parent is not None,
                         "ROSTestParent initialization failed")
            test_name = test.test_name
            printlog("  name..............................%s" % test_name)

            #launch the other nodes
            #for parent in self.parents:
            # DJS - will this mean I miss starting up othe test parents?
            unused_succeeded, failed = parent.launch()
            self.assert_(not failed,
                         "Test Fixture Nodes %s failed to launch" % failed)

            #setup the test
            # - we pass in the output test_file name so we can scrape it
            test_file = rosunit.xml_results_file(test_pkg, test_name, False)
            printlog("  test results file.................%s", test_file)
            if os.path.exists(test_file):
                os.remove(test_file)
                printlog("  clear old test results file.......done")

            # TODO: have to redeclare this due to a bug -- this file
            # needs to be renamed as it aliases the module where the
            # constant is elsewhere defined. The fix is to rename
            # rostest.py
            XML_OUTPUT_FLAG = '--gtest_output=xml:'  # use gtest-compatible flag
            test.args = "%s %s%s" % (test.args, XML_OUTPUT_FLAG, test_file)
            if _text_mode:
                test.output = 'screen'
                test.args = test.args + " --text"

            # run the test, blocks until completion
            printlog("Running test %s" % test_name)
            timeout_failure = False
            try:
                parent.run_test(test)
            except roslaunch.launch.RLTestTimeoutException as unused_e:
                if test.retry:
                    timeout_failure = True
                else:
                    raise

            if not timeout_failure:
                printlog("test finished [%s]" % test_name)
            else:
                printlogerr("test timed out [%s]" % test_name)

            if not _text_mode or timeout_failure:
                if not timeout_failure:
                    self.assert_(
                        os.path.isfile(test_file),
                        "test [%s] did not generate test results" % test_name)
                    printlog("test [%s] results are in [%s]", test_name,
                             test_file)
                    results = rosunit.junitxml.read(test_file, test_name)
                    test_fail = results.num_errors or results.num_failures
                else:
                    test_fail = True
                if test.retry > 0 and test_fail:
                    test.retry -= 1
                    printlog("test [%s] failed, retrying. Retries left: %s" %
                             (test_name, test.retry))
                    self.tearDown()
                    self.setUp()
                else:
                    done = True
                    _accumulate_results(results)
                    printlog(
                        "test [%s] results summary: %s errors, %s failures, %s tests",
                        test_name, results.num_errors, results.num_failures,
                        results.num_tests)
                    #self.assertEquals(0, results.num_errors, "unit test reported errors")
                    #self.assertEquals(0, results.num_failures, "unit test reported failures")
            else:
                if test.retry:
                    printlogerr("retry is disabled in --text mode")
                done = True
        printlog("test done [%s]", test_name)