media/libyuv/tools/valgrind-libyuv/memcheck/PRESUBMIT.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/tools/valgrind-libyuv/memcheck/PRESUBMIT.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +#!/usr/bin/env python
     1.5 +# Copyright (c) 2012 The LibYuv Project Authors. All rights reserved.
     1.6 +#
     1.7 +# Use of this source code is governed by a BSD-style license
     1.8 +# that can be found in the LICENSE file in the root of the source
     1.9 +# tree. An additional intellectual property rights grant can be found
    1.10 +# in the file PATENTS.  All contributing project authors may
    1.11 +# be found in the AUTHORS file in the root of the source tree.
    1.12 +
    1.13 +"""
    1.14 +Copied from Chrome's src/tools/valgrind/memcheck/PRESUBMIT.py
    1.15 +
    1.16 +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
    1.17 +for more details on the presubmit API built into gcl.
    1.18 +"""
    1.19 +
    1.20 +import os
    1.21 +import re
    1.22 +import sys
    1.23 +
    1.24 +def CheckChange(input_api, output_api):
    1.25 +  """Checks the memcheck suppressions files for bad data."""
    1.26 +
    1.27 +  # Add the path to the Chrome valgrind dir to the import path:
    1.28 +  tools_vg_path = os.path.join(input_api.PresubmitLocalPath(), '..', '..',
    1.29 +                               'valgrind')
    1.30 +  sys.path.append(tools_vg_path)
    1.31 +  import suppressions
    1.32 +
    1.33 +  sup_regex = re.compile('suppressions.*\.txt$')
    1.34 +  suppressions = {}
    1.35 +  errors = []
    1.36 +  check_for_memcheck = False
    1.37 +  # skip_next_line has 3 possible values:
    1.38 +  # - False: don't skip the next line.
    1.39 +  # - 'skip_suppression_name': the next line is a suppression name, skip.
    1.40 +  # - 'skip_param': the next line is a system call parameter error, skip.
    1.41 +  skip_next_line = False
    1.42 +  for f in filter(lambda x: sup_regex.search(x.LocalPath()),
    1.43 +                  input_api.AffectedFiles()):
    1.44 +    for line, line_num in zip(f.NewContents(),
    1.45 +                              xrange(1, len(f.NewContents()) + 1)):
    1.46 +      line = line.lstrip()
    1.47 +      if line.startswith('#') or not line:
    1.48 +        continue
    1.49 +
    1.50 +      if skip_next_line:
    1.51 +        if skip_next_line == 'skip_suppression_name':
    1.52 +          if 'insert_a_suppression_name_here' in line:
    1.53 +            errors.append('"insert_a_suppression_name_here" is not a valid '
    1.54 +                          'suppression name')
    1.55 +          if suppressions.has_key(line):
    1.56 +            if f.LocalPath() == suppressions[line][1]:
    1.57 +              errors.append('suppression with name "%s" at %s line %s '
    1.58 +                            'has already been defined at line %s' %
    1.59 +                            (line, f.LocalPath(), line_num,
    1.60 +                             suppressions[line][1]))
    1.61 +            else:
    1.62 +              errors.append('suppression with name "%s" at %s line %s '
    1.63 +                            'has already been defined at %s line %s' %
    1.64 +                            (line, f.LocalPath(), line_num,
    1.65 +                             suppressions[line][0], suppressions[line][1]))
    1.66 +          else:
    1.67 +            suppressions[line] = (f, line_num)
    1.68 +            check_for_memcheck = True;
    1.69 +        skip_next_line = False
    1.70 +        continue
    1.71 +      if check_for_memcheck:
    1.72 +        if not line.startswith('Memcheck:'):
    1.73 +          errors.append('"%s" should be "Memcheck:..." in %s line %s' %
    1.74 +                        (line, f.LocalPath(), line_num))
    1.75 +        check_for_memcheck = False;
    1.76 +      if line == '{':
    1.77 +        skip_next_line = 'skip_suppression_name'
    1.78 +        continue
    1.79 +      if line == "Memcheck:Param":
    1.80 +        skip_next_line = 'skip_param'
    1.81 +        continue
    1.82 +
    1.83 +      if (line.startswith('fun:') or line.startswith('obj:') or
    1.84 +          line.startswith('Memcheck:') or line == '}' or
    1.85 +          line == '...'):
    1.86 +        continue
    1.87 +      errors.append('"%s" is probably wrong: %s line %s' % (line, f.LocalPath(),
    1.88 +                                                            line_num))
    1.89 +  if errors:
    1.90 +    return [output_api.PresubmitError('\n'.join(errors))]
    1.91 +  return []
    1.92 +
    1.93 +def CheckChangeOnUpload(input_api, output_api):
    1.94 +  return CheckChange(input_api, output_api)
    1.95 +
    1.96 +def CheckChangeOnCommit(input_api, output_api):
    1.97 +  return CheckChange(input_api, output_api)
    1.98 +
    1.99 +def GetPreferredTrySlaves():
   1.100 +  # We don't have any memcheck slaves yet, so there's no use for this method.
   1.101 +  # When we have, the slave name(s) should be put into this list.
   1.102 +  return []

mercurial