Пример #1
0
def rostestmain():
    import roslaunch.rlutil
    
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog [options] [package] <filename>", prog=_NAME)
    parser.add_option("-t", "--text",
                      action="store_true", dest="text_mode", default=False,
                      help="Run with stdout output instead of XML output")
    parser.add_option("--pkgdir", metavar="PKG_DIR",
                      dest="pkg_dir", default=None,
                      help="package dir")
    parser.add_option("--package", metavar="PACKAGE",
                      dest="package", default=None,
                      help="package")
    parser.add_option("--results-filename", metavar="RESULTS_FILENAME",
                      dest="results_filename", default=None,
                      help="results_filename")
    (options, args) = parser.parse_args()
    try:
        args = roslaunch.rlutil.resolve_launch_arguments(args)
    except roslaunch.core.RLException as e:
        print(str(e), file=sys.stderr)
        sys.exit(1)

    # make sure all loggers are configured properly
    logfile_name = configure_logging()
    logger = logging.getLogger('rostest')
    import roslaunch.core
    roslaunch.core.add_printlog_handler(logger.info)
    roslaunch.core.add_printerrlog_handler(logger.error)        
        
    logger.info('rostest starting with options %s, args %s'%(options, args))
    if len(args) == 0:
        parser.error("You must supply a test file argument to rostest.")
    if len(args) != 1:
        parser.error("rostest only accepts a single test file")

    # compute some common names we'll be using to generate test names and files
    test_file = args[0]
    if options.pkg_dir and options.package:  
        # rosbuild2: the build system knows what package and directory, so let it tell us,
        # instead of shelling back out to rospack
        pkg_dir, pkg = options.pkg_dir, options.package
    else:
        pkg = rospkg.get_package_name(test_file)
        r = rospkg.RosPack()
        pkg_dir = r.get_path(pkg)

    if options.results_filename:
        outname = options.results_filename
        if '.' in outname:
            outname = outname[:outname.rfind('.')]
    else:
        outname = rostest_name_from_path(pkg_dir, test_file)

    # #1140
    if not os.path.isfile(test_file):
        results_file = xmlResultsFile(pkg, outname, True)
        write_bad_filename_failure(test_file, results_file, outname)
        parser.error("test file is invalid. Generated failure case result file in %s"%results_file)
        
    try:
        testCase = rostest.runner.createUnitTest(pkg, test_file)
        suite = unittest.TestLoader().loadTestsFromTestCase(testCase)

        if options.text_mode:
            rostest.runner.setTextMode(True)
            result = unittest.TextTestRunner(verbosity=2).run(suite)
        else:
            is_rostest = True
            results_file = xmlResultsFile(pkg, outname, is_rostest)        
            xml_runner = createXMLRunner(pkg, outname, \
                                             results_file=results_file, \
                                             is_rostest=is_rostest)
            result = xml_runner.run(suite)
    finally:
        # really make sure that all of our processes have been killed
        test_parents = rostest.runner.getRostestParents()
        for r in test_parents:
            logger.info("finally rostest parent tearDown [%s]", r)
            r.tearDown()
        del test_parents[:]
        from roslaunch.pmon import pmon_shutdown
        logger.info("calling pmon_shutdown")
        pmon_shutdown()
        logger.info("... done calling pmon_shutdown")

    # print config errors after test has run so that we don't get caught up in .xml results
    config = rostest.runner.getConfig()
    if config:
        if config.config_errors:
            print("\n[ROSTEST WARNINGS]"+'-'*62+'\n', file=sys.stderr)
        for err in config.config_errors:
            print(" * %s"%err, file=sys.stderr)
        print('')

    # summary is worthless if textMode is on as we cannot scrape .xml results
    subtest_results = rostest.runner.getResults()
    if not options.text_mode:
        printRostestSummary(result, subtest_results)
    else:
        print("WARNING: overall test result is not accurate when --text is enabled")

    if logfile_name:
        print("rostest log file is in %s"%logfile_name)
        
    if not result.wasSuccessful():
        sys.exit(1)
    elif subtest_results.num_errors or subtest_results.num_failures:
        sys.exit(2)
Пример #2
0
def rostestmain():
    import roslaunch.rlutil
    
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog [options] [package] <filename>", prog=_NAME)
    parser.add_option("-t", "--text",
                      action="store_true", dest="text_mode", default=False,
                      help="Run with stdout output instead of XML output")
    parser.add_option("--pkgdir", metavar="PKG_DIR",
                      dest="pkg_dir", default=None,
                      help="package dir")
    parser.add_option("--package", metavar="PACKAGE",
                      dest="package", default=None,
                      help="package")
    parser.add_option("--results-filename", metavar="RESULTS_FILENAME",
                      dest="results_filename", default=None,
                      help="results_filename")
    parser.add_option("--results-base-dir", metavar="RESULTS_BASE_DIR",
                      help="The base directory of the test results. The test result file is " +
                           "created in a subfolder name PKG_DIR.")
    (options, args) = parser.parse_args()
    try:
        args = roslaunch.rlutil.resolve_launch_arguments(args)
    except roslaunch.core.RLException as e:
        print(str(e), file=sys.stderr)
        sys.exit(1)

    # make sure all loggers are configured properly
    logfile_name = configure_logging()
    logger = logging.getLogger('rostest')
    import roslaunch.core
    roslaunch.core.add_printlog_handler(logger.info)
    roslaunch.core.add_printerrlog_handler(logger.error)        
        
    logger.info('rostest starting with options %s, args %s'%(options, args))
    if len(args) == 0:
        parser.error("You must supply a test file argument to rostest.")
    if len(args) != 1:
        parser.error("rostest only accepts a single test file")

    # compute some common names we'll be using to generate test names and files
    test_file = args[0]
    if options.pkg_dir and options.package:  
        # rosbuild2: the build system knows what package and directory, so let it tell us,
        # instead of shelling back out to rospack
        pkg_dir, pkg = options.pkg_dir, options.package
    else:
        pkg = rospkg.get_package_name(test_file)
        r = rospkg.RosPack()
        pkg_dir = r.get_path(pkg)

    if options.results_filename:
        outname = options.results_filename
        if '.' in outname:
            outname = outname[:outname.rfind('.')]
    else:
        outname = rostest_name_from_path(pkg_dir, test_file)

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

    # #1140
    if not os.path.isfile(test_file):
        results_file = xmlResultsFile(pkg, outname, True, env=env)
        write_bad_filename_failure(test_file, results_file, outname)
        parser.error("test file is invalid. Generated failure case result file in %s"%results_file)
        
    try:
        testCase = rostest.runner.createUnitTest(pkg, test_file)
        suite = unittest.TestLoader().loadTestsFromTestCase(testCase)

        if options.text_mode:
            rostest.runner.setTextMode(True)
            result = unittest.TextTestRunner(verbosity=2).run(suite)
        else:
            is_rostest = True
            results_file = xmlResultsFile(pkg, outname, is_rostest, env=env)
            xml_runner = createXMLRunner(pkg, outname, \
                                             results_file=results_file, \
                                             is_rostest=is_rostest)
            result = xml_runner.run(suite)
    finally:
        # really make sure that all of our processes have been killed
        test_parents = rostest.runner.getRostestParents()
        for r in test_parents:
            logger.info("finally rostest parent tearDown [%s]", r)
            r.tearDown()
        del test_parents[:]
        from roslaunch.pmon import pmon_shutdown
        logger.info("calling pmon_shutdown")
        pmon_shutdown()
        logger.info("... done calling pmon_shutdown")

    # print config errors after test has run so that we don't get caught up in .xml results
    config = rostest.runner.getConfig()
    if config:
        if config.config_errors:
            print("\n[ROSTEST WARNINGS]"+'-'*62+'\n', file=sys.stderr)
        for err in config.config_errors:
            print(" * %s"%err, file=sys.stderr)
        print('')

    # summary is worthless if textMode is on as we cannot scrape .xml results
    subtest_results = rostest.runner.getResults()
    if not options.text_mode:
        printRostestSummary(result, subtest_results)
    else:
        print("WARNING: overall test result is not accurate when --text is enabled")

    if logfile_name:
        print("rostest log file is in %s"%logfile_name)
        
    if not result.wasSuccessful():
        sys.exit(1)
    elif subtest_results.num_errors or subtest_results.num_failures:
        sys.exit(2)
Пример #3
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)
Пример #4
0
    def runTest(self):
        self.failIf(self.package is None, "unable to determine package of executable")
            
        done = False
        while not done:
            test_name = self.test_name

            printlog("Running test [%s]", test_name)

            #setup the test
            # - we pass in the output test_file name so we can scrape it
            test_file = xmlResultsFile(self.package, test_name, False)
            if os.path.exists(test_file):
                printlog("removing previous test results file [%s]", test_file)
                os.remove(test_file)

            self.args.append('--gtest_output=xml:%s'%test_file)

            # run the test, blocks until completion
            printlog("running test %s"%test_name)
            timeout_failure = False

            run_id = None
            #TODO: really need different, non-node version of LocalProcess instead of these extra args
            process = roslaunch.nodeprocess.LocalProcess(run_id, self.package, self.test_name, self.args, os.environ, False, cwd='cwd', is_node=False)

            pm = self.pmon
            pm.register(process)
            success = process.start()
            self.assert_(success, "test failed to start")

            #poll until test terminates or alloted time exceed
            timeout_t = time.time() + self.time_limit
            try:
                while pm.mainthread_spin_once() and process.is_alive():
                    #test fails on timeout
                    if time.time() > timeout_t:
                        raise roslaunch.launch.RLTestTimeoutException("test max time allotted")
                    time.sleep(0.1)
                
            except roslaunch.launch.RLTestTimeoutException, e:
                if self.retry:
                    timeout_failure = True
                else:
                    raise

            if not timeout_failure:
                printlog("test [%s] finished"%test_name)
            else:
                printlogerr("test [%s] timed out"%test_name)                
        
            # load in test_file
            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 self.retry > 0 and test_fail:
                self.retry -= 1
                printlog("test [%s] failed, retrying. Retries left: %s"%(test_name, self.retry))
            else:
                done = True
                self.results.accumulate(results)
                printlog("test [%s] results summary: %s errors, %s failures, %s tests",
                         test_name, results.num_errors, results.num_failures, results.num_tests)
Пример #5
0
        sys.exit(1)

    logger.info('rostest starting with options %s, args %s' % (options, args))
    if len(args) == 0:
        parser.error("You must supply a test file argument to rostest.")
    if len(args) != 1 and not options.bare:
        parser.error("rostest only accepts a single test file")

    # compute some common names we'll be using to generate test names and files
    test_file = args[0]
    pkg_dir, pkg = roslib.packages.get_dir_pkg(test_file)
    outname = rostest_name_from_path(pkg_dir, test_file)

    # #1140
    if not options.bare and not os.path.isfile(test_file):
        results_file = xmlResultsFile(pkg, outname, True)
        write_bad_filename_failure(test_file, results_file, outname)
        parser.error(
            "test file is invalid. Generated failure case result file in %s" %
            results_file)

    try:
        if options.bare:
            # TODO: does bare-retry make sense?
            time_limit = float(
                options.bare_limit) if options.bare_limit else None
            testCase = rostest.baretest.BareTestCase(
                test_file,
                args[1:],
                rostest.runner.getResults(),
                retry=0,
Пример #6
0
    def runTest(self):
        self.failIf(self.package is None,
                    "unable to determine package of executable")

        done = False
        while not done:
            test_name = self.test_name

            printlog("Running test [%s]", test_name)

            #setup the test
            # - we pass in the output test_file name so we can scrape it
            test_file = xmlResultsFile(self.package, test_name, False)
            if os.path.exists(test_file):
                printlog("removing previous test results file [%s]", test_file)
                os.remove(test_file)

            self.args.append('--gtest_output=xml:%s' % test_file)

            # run the test, blocks until completion
            printlog("running test %s" % test_name)
            timeout_failure = False

            run_id = None
            #TODO: really need different, non-node version of LocalProcess instead of these extra args
            process = roslaunch.nodeprocess.LocalProcess(run_id,
                                                         self.package,
                                                         self.test_name,
                                                         self.args,
                                                         os.environ,
                                                         False,
                                                         cwd='cwd',
                                                         is_node=False)

            pm = self.pmon
            pm.register(process)
            success = process.start()
            self.assert_(success, "test failed to start")

            #poll until test terminates or alloted time exceed
            timeout_t = time.time() + self.time_limit
            try:
                while pm.mainthread_spin_once() and process.is_alive():
                    #test fails on timeout
                    if time.time() > timeout_t:
                        raise roslaunch.launch.RLTestTimeoutException(
                            "test max time allotted")
                    time.sleep(0.1)

            except roslaunch.launch.RLTestTimeoutException, e:
                if self.retry:
                    timeout_failure = True
                else:
                    raise

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

            # load in test_file
            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 = rostest.xmlresults.read(test_file, test_name)
                test_fail = results.num_errors or results.num_failures
            else:
                test_fail = True

            if self.retry > 0 and test_fail:
                self.retry -= 1
                printlog("test [%s] failed, retrying. Retries left: %s" %
                         (test_name, self.retry))
            else:
                done = True
                self.results.accumulate(results)
                printlog(
                    "test [%s] results summary: %s errors, %s failures, %s tests",
                    test_name, results.num_errors, results.num_failures,
                    results.num_tests)
Пример #7
0
        parser.error("rostest only accepts a single test file")

    # compute some common names we'll be using to generate test names and files
    test_file = args[0]
    if options.pkg_dir and options.package:  
        # rosbuild2: the build system knows what package and directory, so let it tell us,
        # instead of shelling back out to rospack
        pkg_dir, pkg = options.pkg_dir, options.package
    else:
        pkg_dir, pkg = roslib.packages.get_dir_pkg(test_file)

    outname = rostest_name_from_path(pkg_dir, test_file)

    # #1140
    if not options.bare and not os.path.isfile(test_file):
        results_file = xmlResultsFile(pkg, outname, True)
        write_bad_filename_failure(test_file, results_file, outname)
        parser.error("test file is invalid. Generated failure case result file in %s"%results_file)
        
    try:
        if options.bare:
            # TODO: does bare-retry make sense?
            time_limit = float(options.bare_limit) if options.bare_limit else None
            testCase = rostest.baretest.BareTestCase(test_file, args[1:], 
                                                     rostest.runner.getResults(), retry=0, 
                                                     time_limit=time_limit, test_name=options.bare_name,
                                                     package=pkg)
            suite = unittest.TestSuite()
            suite.addTest(testCase)

            # override outname