[go: up one dir, main page]

File: t271_script_event.py

package info (click to toggle)
uftrace 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,212 kB
  • sloc: ansic: 53,313; python: 9,846; makefile: 838; asm: 703; cpp: 602; sh: 560; javascript: 191
file content (55 lines) | stat: -rw-r--r-- 1,344 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
#!/usr/bin/env python

import os
import subprocess as sp

from runtest import TestBase

FILE='script.py'

script = """
def uftrace_entry(ctx):
  pass
def uftrace_exit(ctx):
  pass
def uftrace_event(ctx):
  args = ''
  if "args" in ctx:
    for kv in ctx["args"].split(" "):
      args += ' ' + kv.split("=")[0]
  print(ctx["name"] + args)
"""

class TestCase(TestBase):
    def __init__(self):
        TestBase.__init__(self, 'abc', """
read:proc/statm vmsize vmrss shared
diff:proc/statm vmsize vmrss shared
""")

    def prerun(self, timeout):
        script_cmd = '%s script' % (TestBase.uftrace_cmd)
        p = sp.Popen(script_cmd.split(), stdout=sp.PIPE, stderr=sp.PIPE)
        if p.communicate()[1].decode(errors='ignore').startswith('WARN:'):
            return TestBase.TEST_SKIP

        f = open(FILE, 'w')
        f.write(script)
        f.close()

        TestBase.default_opt = TestBase.default_opt.replace('--no-event', '')

        self.subcmd = 'record'
        self.option = '-T a@read=proc/statm'
        record_cmd = self.runcmd()

        self.pr_debug("prerun command: " + record_cmd)
        sp.call(record_cmd.split(), stdout=sp.PIPE)
        return TestBase.TEST_SUCCESS

    def setup(self):
        self.subcmd = 'script'
        self.option = '-S ' + FILE

    def sort(self, output):
        return output.strip()