File: debuginfod.test

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (77 lines) | stat: -rw-r--r-- 2,846 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# REQUIRES: curl
# RUN: rm -rf %t
# RUN: mkdir %t
# # Query the python server for artifacts
# RUN: DEBUGINFOD_CACHE_PATH=%t %python %s --server-path %S/Inputs \
# RUN:   --tool-cmd 'llvm-debuginfod-find --dump --executable abcdef' | \
# RUN:   FileCheck %s --check-prefix=EXECUTABLE
# RUN: DEBUGINFOD_CACHE_PATH=%t %python %s --server-path %S/Inputs \
# RUN:   --tool-cmd 'llvm-debuginfod-find --dump --source=/directory/file.c abcdef' | \
# RUN:   FileCheck %s --check-prefix=SOURCE
# RUN: DEBUGINFOD_CACHE_PATH=%t %python %s --server-path %S/Inputs \
# RUN:   --tool-cmd 'llvm-debuginfod-find --dump --debuginfo abcdef' | \
# RUN:   FileCheck %s --check-prefix=DEBUGINFO

# EXECUTABLE: fake_executable
# SOURCE: int foo = 0;
# DEBUGINFO: fake_debuginfo

# # The artifacts should still be present in the cache without needing to query
# # the server.
# RUN: DEBUGINFOD_CACHE_PATH=%t llvm-debuginfod-find --dump --executable abcdef | \
# RUN:   FileCheck %s --check-prefix=EXECUTABLE
# RUN: DEBUGINFOD_CACHE_PATH=%t llvm-debuginfod-find --dump \
# RUN:   --source=/directory/file.c abcdef | \
# RUN:   FileCheck %s --check-prefix=SOURCE
# RUN: DEBUGINFOD_CACHE_PATH=%t llvm-debuginfod-find --dump --debuginfo abcdef | \
# RUN:   FileCheck %s --check-prefix=DEBUGINFO


# This script is used to test the debuginfod client within a host tool.
# It first stands up a Python HTTP static file server and then executes the tool.
# This way the tool can make debuginfod HTTP requests to the static file server.
import argparse
import threading
import http.server
import functools
import subprocess
import sys
import os


# Serves files at the server_path, then runs the tool with specified args.
# Sets the DEBUGINFOD_CACHE_PATH env var to point at the given cache_directory.
# Sets the DEBUGINFOD_URLS env var to point at the local server.
def test_tool(server_path, tool_args):
    httpd = http.server.ThreadingHTTPServer(
        ('',0), functools.partial(
            http.server.SimpleHTTPRequestHandler,
            directory=server_path))
    port = httpd.server_port
    thread = threading.Thread(target=httpd.serve_forever)
    try:
        thread.start()
        env = os.environ
        env['DEBUGINFOD_URLS'] = 'http://localhost:%s' % port
        process = subprocess.Popen(
            tool_args, env=env)
        code = process.wait()
        if code != 0:
            print('nontrivial return code %s' % code)
            return 1
    finally:
        httpd.shutdown()
        thread.join()
    return 0

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--server-path', default='./')
    parser.add_argument('--tool-cmd', required=True, type=str)
    args = parser.parse_args()
    result = test_tool(args.server_path,
        args.tool_cmd.split())
    sys.exit(result)

if __name__ == '__main__':
    main()