Home | History | Annotate | Download | only in tools
      1 #!/usr/bin/env python2.7
      2 
      3 # Copyright 2016, VIXL authors
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions are met:
      8 #
      9 #   * Redistributions of source code must retain the above copyright notice,
     10 #     this list of conditions and the following disclaimer.
     11 #   * Redistributions in binary form must reproduce the above copyright notice,
     12 #     this list of conditions and the following disclaimer in the documentation
     13 #     and/or other materials provided with the distribution.
     14 #   * Neither the name of ARM Limited nor the names of its contributors may be
     15 #     used to endorse or promote products derived from this software without
     16 #     specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
     19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
     22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 
     29 import os
     30 import sys
     31 import argparse
     32 import re
     33 import util
     34 
     35 
     36 def BuildOptions(root):
     37   result = argparse.ArgumentParser(
     38       description = 'Generate reference output for TRACE_* tests')
     39   result.add_argument('--runner', action='store',
     40                       default=os.path.join(root, 'obj/latest/test/test-runner'),
     41                       help='The test executable to run.')
     42   result.add_argument('--outdir', action='store',
     43                       default='test/test-trace-reference/')
     44   return result.parse_args()
     45 
     46 if __name__ == '__main__':
     47   root_dir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
     48   os.chdir(root_dir)
     49 
     50   args = BuildOptions(root_dir)
     51 
     52   # Run each trace test (TRACE_*) with the --generate_test_trace option, and
     53   # use the output to create the reference traces (in --outdir).
     54 
     55   # Find the trace tests.
     56   status, output = util.getstatusoutput(args.runner + ' --list')
     57   if status != 0: util.abort('Failed to list all tests')
     58   tests = filter(lambda t: 'TRACE_' in t, output.split())
     59   tests.sort()
     60 
     61   if not os.path.exists(args.outdir):
     62     os.makedirs(args.outdir)
     63 
     64   for test in tests:
     65     # Run each test.
     66     print 'Generating trace for ' + test;
     67     cmd = ' '.join([args.runner, '--generate_test_trace', test])
     68     status, output = util.getstatusoutput(cmd)
     69     if status != 0: util.abort('Failed to run ' + cmd + '.')
     70 
     71     # Create a new trace header file.
     72     trace_filename = 'log-' + test.replace('TRACE_', '').lower().replace('_', '-')
     73     trace_f =  open(os.path.join(args.outdir, trace_filename), 'w')
     74     trace_f.write(output)
     75     # `getstatusoutput` removes the trailing newline. Put it back, but only if
     76     # the output was not empty.
     77     if len(output) > 0: trace_f.write('\n')
     78