File: t170_script_filter.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 (53 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

import subprocess as sp

from runtest import TestBase

FILE='script.py'

script = """
UFTRACE_FUNCS = [ "a", "b" ]

def uftrace_entry(ctx):
  print("%s enter" % (ctx["name"]))

def uftrace_exit(ctx):
  print("%s exit" % (ctx["name"]))
"""

class TestCase(TestBase):
    def __init__(self):
        TestBase.__init__(self, 'abc', """
a enter
b enter
b exit
a exit
""")

    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()

        self.subcmd = 'record'
        self.option = ''
        self.exearg = 't-' + self.name

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

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

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