File: t103_dump_kernel.py

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (93 lines) | stat: -rw-r--r-- 4,038 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3

import os
import subprocess as sp

from runtest import TestBase

class TestCase(TestBase):
    def __init__(self):
        TestBase.__init__(self, 'getids', serial=True, result="""
{"traceEvents":[
{"ts":14510734170,"ph":"M","pid":32687,"name":"process_name","args":{"name": "[32687] t-getids"}},
{"ts":14510734170,"ph":"M","pid":32687,"name":"thread_name","args":{"name": "[32687] t-getids"}},
{"ts":14510734172,"ph":"B","pid":32687,"name":"main"},
{"ts":14510734172,"ph":"B","pid":32687,"name":"getpid"},
{"ts":14510734173,"ph":"E","pid":32687,"name":"getpid"},
{"ts":14510734176,"ph":"B","pid":32687,"name":"getppid"},
{"ts":14510734177,"ph":"B","pid":32687,"name":"sys_getppid"},
{"ts":14510734177,"ph":"E","pid":32687,"name":"sys_getppid"},
{"ts":14510734178,"ph":"E","pid":32687,"name":"getppid"},
{"ts":14510734178,"ph":"B","pid":32687,"name":"getpgid"},
{"ts":14510734179,"ph":"B","pid":32687,"name":"sys_getpgid"},
{"ts":14510734180,"ph":"E","pid":32687,"name":"sys_getpgid"},
{"ts":14510734180,"ph":"E","pid":32687,"name":"getpgid"},
{"ts":14510734180,"ph":"B","pid":32687,"name":"getsid"},
{"ts":14510734181,"ph":"B","pid":32687,"name":"sys_getsid"},
{"ts":14510734182,"ph":"E","pid":32687,"name":"sys_getsid"},
{"ts":14510734182,"ph":"E","pid":32687,"name":"getsid"},
{"ts":14510734182,"ph":"B","pid":32687,"name":"getuid"},
{"ts":14510734183,"ph":"B","pid":32687,"name":"sys_getuid"},
{"ts":14510734183,"ph":"E","pid":32687,"name":"sys_getuid"},
{"ts":14510734184,"ph":"E","pid":32687,"name":"getuid"},
{"ts":14510734184,"ph":"B","pid":32687,"name":"geteuid"},
{"ts":14510734184,"ph":"B","pid":32687,"name":"sys_geteuid"},
{"ts":14510734185,"ph":"E","pid":32687,"name":"sys_geteuid"},
{"ts":14510734185,"ph":"E","pid":32687,"name":"geteuid"},
{"ts":14510734185,"ph":"B","pid":32687,"name":"getgid"},
{"ts":14510734186,"ph":"B","pid":32687,"name":"sys_getgid"},
{"ts":14510734187,"ph":"E","pid":32687,"name":"sys_getgid"},
{"ts":14510734187,"ph":"E","pid":32687,"name":"getgid"},
{"ts":14510734187,"ph":"B","pid":32687,"name":"getegid"},
{"ts":14510734188,"ph":"B","pid":32687,"name":"sys_getegid"},
{"ts":14510734188,"ph":"E","pid":32687,"name":"sys_getegid"},
{"ts":14510734188,"ph":"E","pid":32687,"name":"getegid"},
{"ts":14510734189,"ph":"E","pid":32687,"name":"main"}
], "metadata": {
"command_line":"uftrace record -k -d xxx t-getids ",
"recorded_time":"Sun Oct  2 20:52:31 2016"
} }
""", sort='chrome')

    def prerun(self, timeout):
        if os.geteuid() != 0:
            return TestBase.TEST_SKIP
        if os.path.exists('/.dockerenv'):
            return TestBase.TEST_SKIP

        self.subcmd = 'record'
        self.option = '-k -F main'
        record_cmd = self.runcmd()
        sp.call(record_cmd.split())
        return TestBase.TEST_SUCCESS

    def setup(self):
        self.subcmd = 'dump'
        self.option = '-k --chrome'

    def fixup(self, cflags, result):
        result = result.replace("""\
{"ts":14510734172,"ph":"B","pid":32687,"name":"getpid"},
{"ts":14510734173,"ph":"E","pid":32687,"name":"getpid"},\
""",
"""\
{"ts":14510734172,"ph":"B","pid":32687,"name":"getpid"},
{"ts":14510734172,"ph":"B","pid":32687,"name":"sys_getpid"},
{"ts":14510734172,"ph":"E","pid":32687,"name":"sys_getpid"},
{"ts":14510734173,"ph":"E","pid":32687,"name":"getpid"},\
""")
        uname = os.uname()

        # Later version changed syscall routines
        major, minor, release = uname[2].split('.', 2)
        if uname[0] == 'Linux' and uname[4] == 'x86_64':
            if int(major) == 6 and int(minor) >= 9:
                import re
                result = re.sub(r'sys_get[a-z]*', 'x64_sys_call', result)
            elif int(major) >= 5 or (int(major) == 4 and int(minor) >= 17):
                result = result.replace('sys_get', '__x64_sys_get')
        if uname[0] == 'Linux' and uname[4] == 'aarch64' and \
           int(major) >= 5 or (int(major) == 4 and int(minor) >= 19):
            result = result.replace('sys_get', '__arm64_sys_get')

        return result