aboutsummaryrefslogtreecommitdiff
path: root/debug_info_test/debug_info_test.py
blob: 4839e69cd0cff7debc5ef454b46c4cdcccf217fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python2

# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import subprocess
import sys

import check_icf
import check_cus
import check_exist

elf_checks = [check_exist.check_exist_all,
              check_cus.check_compile_units,
              check_icf.check_identical_code_folding]

def scanelf(root):
    """find ELFs in root

    Args:
        root: root dir to start with the search.
    Returns:
        Filenames of ELFs in root.
    """
    p = subprocess.Popen(['scanelf', '-y', '-B', '-F', '%F', '-R', root],
                         stdout=subprocess.PIPE)
    return [l.strip() for l in p.stdout]

def Main(argv):
    if len(argv) < 2:
        print('usage: %s [file|dir]')
        return 1

    files = []
    cand = argv[1]
    if os.path.isfile(cand):
        files = [cand]
    elif os.path.isdir(cand):
        files = scanelf(cand)
    else:
        print('usage: %s [file|dir]')
        return 1

    failed = False
    for f in files:
        for c in elf_checks:
            if not c(f):
                failed = True

    if failed:
        return 1
    return 0

if __name__ == '__main__':
    sys.exit(Main(sys.argv))