[Fuego] [PATCH 2/2] ftc: add support for all fuego flags

Tim Bird tbird20d at gmail.com
Fri Aug 17 01:07:21 UTC 2018


Applied and pushed.

Thanks,
 -- Tim

On Thu, Aug 2, 2018 at 11:39 PM, Daniel Sangorrin
<daniel.sangorrin at toshiba.co.jp> wrote:
> This patch allows passing fuego flags such as reboot, rebuild,
> pre/post cleanup, and timeout to ftc run-test and add-jobs.
>
> Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
> ---
>  engine/scripts/ftc | 177 +++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 146 insertions(+), 31 deletions(-)
>
> diff --git a/engine/scripts/ftc b/engine/scripts/ftc
> index 73f2870..57328d2 100755
> --- a/engine/scripts/ftc
> +++ b/engine/scripts/ftc
> @@ -25,7 +25,6 @@
>  # - add do_run_request - to run a job request from the server
>  #    if no arguments, run the next available request on the server
>  # - finish do_run_test
> -#    - support flags: Reboot, Target_Cleanup, Rebuild
>  #    - get log results into file (switch to subprocess?)
>  #    - make Jenkins recognize ftc test result
>  # - finish do_set
> @@ -92,10 +91,17 @@ where_help = \
>  # format for command_help mapping with: key=name, value=(summary, long description)
>  command_help = {
>  "add-jobs": ("Adds jobs to Jenkins.",
> -    """Usage: ftc add-jobs -b <board>[,board2...] [-p <testplan> | -t <testcase> -s <testspec> [-k <kill timeout>] [--rebuild <true|false>]
> +    """Usage: ftc add-jobs -b <board>[,board2...] [-p <testplan> | -t <testcase> -s <testspec>]
> +       [-k <kill timeout>] [--rebuild <true|false>] [--reboot <true|false>]
> +       [--precleanup <true|false>] [--postcleanup <true|false>]
>    Example: ftc add-jobs -b docker -p testplan_docker
>    Example: ftc add-jobs -b docker -t Benchmark.Dhrystone -k 5m --rebuild false
> -  Use list-plans to see the available test plans.
> +  board,testplan,testpec: use list-board/plans/specs to see the available ones.
> +  timeout: integer with a suffix from 'smhd' (seconds, minutes, hours, days).
> +  rebuild: if true rebuild the test source even if it was already built.
> +  reboot: if true reboot the board before the test.
> +  precleanup: if true clean the board's test folder before the test.
> +  postcleanup: if true clean the board's test folder after the test.
>
>    Note that you can specify more than one board using a comma-separated
>    list for the <board> argument. e.g.
> @@ -226,9 +232,18 @@ You can obtain a list of run_ids for runs on the local system with
>
>  "run-test": ("Run a test on a board.",
>      """Usage: ftc run-test -b <board> -t <test> [-s <spec>] [-p <phases>]
> +    [-k <kill timeout>] [--rebuild <true|false>] [--reboot <true|false>]
> +    [--precleanup <true|false>] [--postcleanup <true|false>]
>  Run the indicated test on the specified board.  Use the
>  indicated spec, if one is provided.
>
> +board,spec: use list-board/specs to see the available ones.
> +timeout: integer with a suffix from 'smhd' (seconds, minutes, hours, days).
> +rebuild: if true rebuild the test source even if it was already built.
> +reboot: if true reboot the board before the test.
> +precleanup: if true clean the board's test folder before the test.
> +postcleanup: if true clean the board's test folder after the test.
> +
>  A list of phase characters may be provided, to execute only those phases
>    p = pre_test, c=pre_check, b=build, d=deploy, r=run,
>    t = post_test, a=processing
> @@ -722,7 +737,7 @@ class run_class:
>          # FIXTHIS - in run_class, convert build.xml startTime from seconds to timestamp
>
>          # lower-case some things:
> -        for key in ["TESTPLAN", "Reboot", "Rebuild", "Target_Cleanup", "Device"]:
> +        for key in ["TESTPLAN", "Reboot", "Rebuild", "Target_PreCleanup", "Target_PostCleanup", "Device"]:
>              lkey = key.lower()
>              try:
>                  self.__dict__[lkey] = self.__dict__[key]
> @@ -751,7 +766,8 @@ class run_class:
>                  ("testplan_name", "testplan"),
>                  ("reboot_flag", "reboot"),
>                  ("rebuild_flag", "rebuild"),
> -                ("target_cleanup_flag", "target_cleanup"),
> +                ("precleanup_flag", "precleanup"),
> +                ("postcleanup_flag", "postcleanup"),
>                  ("board_name", "device"),
>          ]
>
> @@ -775,7 +791,7 @@ class run_class:
>          self.files = ["devlog.txt", "syslog.before.txt", "syslog.after.txt",
>              "testlog.txt", "consolelog.txt", "build.xml"]
>          keylist = ["test_name", "timestamp", "num", "host", "board",
> -            "result", "device", "reboot", "rebuild", "testplan", "target_cleanup",
> +            "result", "device", "reboot", "rebuild", "testplan", "precleanup", "postcleanup",
>              "start_time", "description", "duration", "charset", "keep_log",
>              "built_on", "workspace", "cause",
>              "files"]
> @@ -1477,6 +1493,39 @@ def do_add_jobs(conf, options):
>      else:
>          error_out('No testplan (-p) or test (-t) supplied.')
>
> +    if '--reboot' in options:
> +        try:
> +            reboot = options[options.index('--reboot') + 1]
> +        except IndexError:
> +            error_out('Reboot option not provided after --reboot')
> +        if reboot not in ['true', 'false']:
> +            error_out("Invalid reboot option '%s'" % reboot)
> +        options.remove(reboot)
> +        options.remove('--reboot')
> +        test_dict["reboot"] = reboot
> +
> +    if '--precleanup' in options:
> +        try:
> +            precleanup = options[options.index('--precleanup') + 1]
> +        except IndexError:
> +            error_out('Precleanup option not provided after --precleanup')
> +        if precleanup not in ['true', 'false']:
> +            error_out("Invalid precleanup option '%s'" % precleanup)
> +        options.remove(precleanup)
> +        options.remove('--precleanup')
> +        test_dict["precleanup"] = precleanup
> +
> +    if '--postcleanup' in options:
> +        try:
> +            postcleanup = options[options.index('--postcleanup') + 1]
> +        except IndexError:
> +            error_out('Postcleanup option not provided after --postcleanup')
> +        if postcleanup not in ['true', 'false']:
> +            error_out("Invalid postcleanup option '%s'" % postcleanup)
> +        options.remove(postcleanup)
> +        options.remove('--postcleanup')
> +        test_dict["postcleanup"] = postcleanup
> +
>      if '-s' in options:
>          if test_name is None:
>              error_out("-s option requires the test option (-t) to be set")
> @@ -2662,7 +2711,7 @@ def do_run_request(conf, options):
>      except:
>          error_out("Request %s has invalid board %s" % (req_id, board_name))
>
> -    # FIXTHIS - run_request: should process Reboot, Rebuild and Target_cleanup flags
> +    # FIXTHIS - run_request: should process Reboot, Rebuild and Pre/Post cleanup flags
>      print("Executing test %s on board %s (using %s)" % (test_name, board_name, testplan))
>      do_run_test(conf, ['-b', board_name, '-t', test_name, '-p', testplan])
>
> @@ -2726,11 +2775,11 @@ class data_class:
>          else:
>              return item
>
> -
> +# FIXTHIS: this is dead code
>  def write_run_build_xml_file(run_dir, build_data):
>      ### the format str needs build_data to have the following attributes:
>      # board_name
> -    # reboot_flag, rebuild_flag, target_cleanup_flag
> +    # reboot_flag, rebuild_flag, precleanup_flag, postcleanup_flag
>      #    the flags must be one of (lower case) 'true' or 'false'
>      # testplan_name
>      # build_number
> @@ -2768,9 +2817,14 @@ def write_run_build_xml_file(run_dir, build_data):
>            <value>%(rebuild_flag)s</value>
>          </hudson.model.BooleanParameterValue>
>          <hudson.model.BooleanParameterValue>
> -          <name>Target_Cleanup</name>
> +          <name>Target_PreCleanup</name>
> +          <description></description>
> +          <value>%(precleanup_flag)s</value>
> +        </hudson.model.BooleanParameterValue>
> +        <hudson.model.BooleanParameterValue>
> +          <name>Target_PostCleanup</name>
>            <description></description>
> -          <value>true</value>
> +          <value>%(postcleanup_flag)s</value>
>          </hudson.model.BooleanParameterValue>
>          <hudson.model.StringParameterValue>
>            <name>TESTPLAN</name>
> @@ -2816,7 +2870,7 @@ def write_run_build_xml_file(run_dir, build_data):
>  def write_build_xml_file(run_dir, build_data):
>      ### the format str needs build_data to have the following attributes:
>      # board_name
> -    # reboot_flag, rebuild_flag, target_cleanup_flag
> +    # reboot_flag, rebuild_flag, precleanup_flag, postcleanup_flag
>      #    the flags must be one of (lower case) 'true' or 'false'
>      # testplan_name
>      # build_number
> @@ -2854,9 +2908,14 @@ def write_build_xml_file(run_dir, build_data):
>            <value>%(rebuild_flag)s</value>
>          </hudson.model.BooleanParameterValue>
>          <hudson.model.BooleanParameterValue>
> -          <name>Target_Cleanup</name>
> +          <name>Target_PreCleanup</name>
>            <description></description>
> -          <value>true</value>
> +          <value>%(precleanup_flag)s</value>
> +        </hudson.model.BooleanParameterValue>
> +        <hudson.model.BooleanParameterValue>
> +          <name>Target_PostCleanup</name>
> +          <description></description>
> +          <value>%(postcleanup_flag)s</value>
>          </hudson.model.BooleanParameterValue>
>          <hudson.model.StringParameterValue>
>            <name>TESTPLAN</name>
> @@ -2935,7 +2994,14 @@ def ftc_exec_command(command, timeout):
>
>      # specify timeout for command operation
>      signal.signal(signal.SIGALRM, alarm_handler)
> -    signal.alarm(timeout)
> +
> +    # timeout is passed as integer[dhms] (dhms: days, hours, minutes, seconds)
> +    print "timeout is: " + timeout
> +    units = timeout[:-1]
> +    multiplier = {"d": 24*60*60, "h": 60*60, "m": 60, "s": 1}
> +    time = int(units)*multiplier[timeout[-1]]
> +    print "setting alarm to: " + str(time) + " seconds"
> +    signal.alarm(time)
>
>      try:
>          # p.poll returns exit code when process completes
> @@ -3008,7 +3074,8 @@ def do_put_request(conf, options):
>              "board": board,
>              "reboot": reboot,
>              "rebuild": "False",
> -            "target_cleanup": "False",
> +            "precleanup": "True",
> +            "postcleanup": "True",
>              "testplan": plan,
>              "requestor": "Tim",
>              }
> @@ -3140,6 +3207,61 @@ def do_run_test(conf, options):
>          options.remove('-s')
>          test_dict["spec"] = spec_name
>
> +    if '-k' in options:
> +        try:
> +            timeout = options[options.index('-k') + 1]
> +        except IndexError:
> +            error_out('No timeout specified after -k')
> +        if re.match('^\d+[dhms]', timeout) is None:
> +            error_out('%s: Timeout format not supported.' % timeout)
> +        options.remove('-k')
> +        options.remove(timeout)
> +        test_dict["timeout"] = timeout
> +
> +    if '--rebuild' in options:
> +        try:
> +            rebuild = options[options.index('--rebuild') + 1]
> +        except IndexError:
> +            error_out('Rebuild option not provided after --rebuild')
> +        if rebuild not in ['true', 'false']:
> +            error_out("Invalid rebuild option '%s'" % rebuild)
> +        options.remove(rebuild)
> +        options.remove('--rebuild')
> +        test_dict["rebuild"] = rebuild
> +
> +    if '--reboot' in options:
> +        try:
> +            reboot = options[options.index('--reboot') + 1]
> +        except IndexError:
> +            error_out('Reboot option not provided after --reboot')
> +        if reboot not in ['true', 'false']:
> +            error_out("Invalid reboot option '%s'" % reboot)
> +        options.remove(reboot)
> +        options.remove('--reboot')
> +        test_dict["reboot"] = reboot
> +
> +    if '--precleanup' in options:
> +        try:
> +            precleanup = options[options.index('--precleanup') + 1]
> +        except IndexError:
> +            error_out('Precleanup option not provided after --precleanup')
> +        if precleanup not in ['true', 'false']:
> +            error_out("Invalid precleanup option '%s'" % precleanup)
> +        options.remove(precleanup)
> +        options.remove('--precleanup')
> +        test_dict["precleanup"] = precleanup
> +
> +    if '--postcleanup' in options:
> +        try:
> +            postcleanup = options[options.index('--postcleanup') + 1]
> +        except IndexError:
> +            error_out('Postcleanup option not provided after --postcleanup')
> +        if postcleanup not in ['true', 'false']:
> +            error_out("Invalid postcleanup option '%s'" % postcleanup)
> +        options.remove(postcleanup)
> +        options.remove('--postcleanup')
> +        test_dict["postcleanup"] = postcleanup
> +
>      # apply defaults for test flags that were not specified on the command line
>      test = test_class(test_dict=test_dict)
>
> @@ -3209,12 +3331,10 @@ def do_run_test(conf, options):
>      build_data.job_name = "%s.%s.%s" % (board_name, test.spec, test_name)
>      build_data.workspace = conf.FUEGO_RW+"/buildzone"
>      build_data.start_time = long(time.time() * 1000)
> -
> -    # force these for now, but
> -    # FIXTHIS - do_run_test: read flag options (e.g. reboot) from command line (from 'options')
> -    build_data.reboot_flag = "false"
> -    build_data.rebuild_flag = "false"
> -    build_data.target_cleanup_flag = "true"
> +    build_data.reboot_flag = test.reboot
> +    build_data.rebuild_flag = test.rebuild
> +    build_data.precleanup_flag = test.precleanup
> +    build_data.postcleanup_flag = test.postcleanup
>
>      # FIXTHIS - do_run_test: set job description
>      # set job description in run json file
> @@ -3290,9 +3410,8 @@ def do_run_test(conf, options):
>
>      os.environ["Reboot"] = build_data.reboot_flag
>      os.environ["Rebuild"] = build_data.rebuild_flag
> -    # FIXTHIS - do_run_test: support separate pre and post cleanup flags
> -    os.environ["Target_PreCleanup"] = build_data.target_cleanup_flag
> -    os.environ["Target_PostCleanup"] = build_data.target_cleanup_flag
> +    os.environ["Target_PreCleanup"] = build_data.precleanup_flag
> +    os.environ["Target_PostCleanup"] = build_data.postcleanup_flag
>
>      # cd to buildzone directory
>      saved_cur_dir = os.getcwd()
> @@ -3300,9 +3419,7 @@ def do_run_test(conf, options):
>
>      print("Running remotely on '%(board_name)s' in workspace %(workspace)s" % build_data)
>
> -    # FIXTHIS - do_run_test - get timeout from testplan
> -    # FIXTHIS - do_run_test - handle timeout myself in ftc_exec_command
> -    command = "timeout --signal=9 30m /bin/bash $FUEGO_CORE/engine/scripts/main.sh"
> +    command = "/bin/bash $FUEGO_CORE/engine/scripts/main.sh"
>      pvar("command")
>
>      # write command to temp file, and execute that with
> @@ -3330,9 +3447,7 @@ def do_run_test(conf, options):
>      fcntl.fcntl(tail_fd, fcntl.F_SETFL, flag | os.O_NONBLOCK)
>
>      command = "/bin/bash -xe %s" % (tempfilename)
> -    # FIXTHIS - in do_run_test: timeout is hardcoded to 5 minutes
> -    timeout = 300    # 5 minutes
> -    rcode = ftc_exec_command(command, timeout)
> +    rcode = ftc_exec_command(command, test.timeout)
>      log.flush()
>
>      build_data.result = "UNKNOWN"
> --
> 2.7.4
>
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego



-- 
 -- Tim Bird
Senior Staff Software Engineer, Sony Corporation
Architecture Group Chair, Core Embedded Linux Project, Linux Foundation


More information about the Fuego mailing list