예제 #1
0
def prepare_launch_configurations(turtles):
    """
    :param Turtle[] turtles:
    """
    port = 11
    launch_text = '<concert>\n'
    for turtle in turtles:
        launch_text += '  <launch title="%s:114%s" package="concert_service_turtlesim" name="turtle.launch" port="114%s">\n' % (
            turtle.unique_name, str(port), str(port))
        launch_text += '    <arg name="turtle_name" value="%s"/>\n' % turtle.unique_name
        launch_text += '    <arg name="turtle_concert_whitelist" value="%s"/>\n' % str(
            turtle.concert_whitelist
        )  # e.g. [Turtle Concert, Turtle Teleop Concert, Concert Tutorial]
        launch_text += '    <arg name="turtle_rapp_whitelist" value="%s"/>\n' % str(
            turtle.rapp_whitelist)  # e.g. [rocon_apps, turtle_concert]
        launch_text += '  </launch>\n'
        port = port + 1
    launch_text += '</concert>\n'
    temp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
    #print("\n" + console.green + rocon_launch_text + console.reset)
    temp.write(launch_text)
    #rospy.logwarn("Turtle Herder: rocon launch text\n%s" % launch_text)
    temp.close()  # unlink it later
    launch_configurations = rocon_launch.parse_rocon_launcher(
        temp.name, "--screen")
    try:
        os.unlink(temp.name)
    except OSError:
        rospy.logerr("Turtle Herder : failed to unlink the rocon launcher.")
    return launch_configurations
    def _launch_robot_clients(self, robots):
        """
        Spawn concert clients for given named robot.

        :param robot_names str[]: Names of all robots.
        """
        # spawn the concert clients
        rocon_launch_text = self._prepare_rocon_launch_text(robots)
        self.loginfo("constructing robot client rocon launcher")
        #print("\n" + console.green + rocon_launch_text + console.reset)
        temp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
        temp.write(rocon_launch_text)
        temp.close()
        launch_configurations = rocon_launch.parse_rocon_launcher(
            temp.name, "--screen")
        try:
            os.unlink(temp.name)
        except OSError:
            self.logerr("failed to unlink the rocon launcher.")

        for launch_configuration in launch_configurations:
            self.loginfo(
                "launching concert client %s on port %s" %
                (launch_configuration.name, launch_configuration.port))
            #print("%s" % launch_configuration)
            process, meta_roslauncher = self._terminal.spawn_roslaunch_window(
                launch_configuration)
            self._processes.append(process)
            self._temporary_files.append(meta_roslauncher)
예제 #3
0
def prepare_launch_configurations(turtles):
    """
    :param Turtle[] turtles:
    """
    port = 11
    launch_text = "<concert>\n"
    for turtle in turtles:
        launch_text += '  <launch title="%s:114%s" package="rostful_examples" name="turtle.launch" port="114%s">\n' % (
            turtle.unique_name,
            str(port),
            str(port),
        )
        launch_text += '    <arg name="turtle_name" value="%s"/>\n' % turtle.unique_name
        launch_text += '    <arg name="turtle_concert_whitelist" value="%s"/>\n' % str(
            turtle.concert_whitelist
        )  # e.g. [Turtle Concert, Turtle Teleop Concert, Concert Tutorial]
        launch_text += '    <arg name="turtle_rapp_whitelist" value="%s"/>\n' % str(
            turtle.rapp_whitelist
        )  # e.g. [rocon_apps, turtle_concert]
        launch_text += '    <arg name="disable_zeroconf" value="%s"/>\n' % str(
            turtle.disable_zeroconf
        )  # e.g. [True, False]
        launch_text += '    <arg name="rostful_port" value="%s"/>\n' % str(turtle.rostful_port)  # e.g. [True, False]
        launch_text += '    <arg name="rosbridge_port" value="%s"/>\n' % str(
            turtle.rosbridge_port
        )  # e.g. [True, False]
        launch_text += "  </launch>\n"
        port = port + 1
    launch_text += "</concert>\n"
    temp = tempfile.NamedTemporaryFile(mode="w+t", delete=False)
    # print("\n" + console.green + rocon_launch_text + console.reset)
    temp.write(launch_text)
    # rospy.logwarn("Turtle Herder: rocon launch text\n%s" % launch_text)
    temp.close()  # unlink it later
    launch_configurations = rocon_launch.parse_rocon_launcher(temp.name, "--screen")
    try:
        os.unlink(temp.name)
    except OSError:
        rospy.logerr("Turtle Herder : failed to unlink the rocon launcher.")
    return launch_configurations
예제 #4
0
def test_main():
    (package, name, launch_arguments, pause, text_mode, results_filename,
     results_base_dir) = _parse_arguments()

    if os.path.isabs(name):
        if os.path.exists(name):
            rocon_launcher = name
        else:
            raise IOError("cannot locate [%s]" % name)
    else:
        rocon_launcher = rocon_python_utils.ros.find_resource(
            package, name)  # raises an IO error if there is a problem.

    env = None
    if results_base_dir:
        env = {ROS_TEST_RESULTS_DIR: results_base_dir}

    if results_filename:
        results_log_name = results_filename
        if '.' in results_log_name:
            results_log_name = results_log_name[:results_log_name.rfind('.')]
        results_log_file = xmlResultsFile(package,
                                          results_log_name,
                                          is_rostest=True,
                                          env=env)
        results_log_file = results_log_file.replace("rostest", "rocon_test")
    else:
        results_log_name, results_log_file = loggers.configure_logging(
            package, rocon_launcher)

    # launchers is of type rocon_launch.RosLaunchConfiguration[]
    launchers = rocon_launch.parse_rocon_launcher(rocon_launcher,
                                                  launch_arguments,
                                                  args_mappings={})

    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_log_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_log_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)