Skip to content

Commit

Permalink
test: Add test cases for advanced python script testing
Browse files Browse the repository at this point in the history
Curiously some tests are failed when run together, but running the
failed test alone always succeeded.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Sep 9, 2017
1 parent 6811ef2 commit 00f38d0
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/t169_script_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

from runtest import TestBase
import subprocess as sp

TDIR='xxx'
FILE='script.py'

script = """
def uftrace_entry(ctx):
if "args" in ctx:
print("%s(%s)" % (ctx["name"], ctx["args"][0]))
def uftrace_exit(ctx):
pass
"""

class TestCase(TestBase):
def __init__(self):
TestBase.__init__(self, 'openclose', 'fopen(/dev/null)')

def pre(self):
f = open(FILE, 'w')
f.write(script)
f.close()

uftrace = TestBase.ftrace
options = '-A fopen@arg1/s'
program = 't-' + self.name
record_cmd = '%s record -d %s %s %s' % (uftrace, TDIR, options, program)

self.pr_debug("record command: %s" % record_cmd)
sp.call(record_cmd.split())
return TestBase.TEST_SUCCESS

def runcmd(self):
uftrace = TestBase.ftrace
options = '-S ' + FILE
return '%s script -d %s %s' % (uftrace, TDIR, options)

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

def post(self, ret):
sp.call(['rm', '-rf', TDIR, FILE])
return ret
51 changes: 51 additions & 0 deletions tests/t170_script_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

from runtest import TestBase
import subprocess as sp

TDIR='xxx'
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 pre(self):
f = open(FILE, 'w')
f.write(script)
f.close()

uftrace = TestBase.ftrace
program = 't-' + self.name
record_cmd = '%s record -d %s %s' % (uftrace, TDIR, program)

self.pr_debug("record command: %s" % record_cmd)
sp.call(record_cmd.split())
return TestBase.TEST_SUCCESS

def runcmd(self):
uftrace = TestBase.ftrace
options = '-S ' + FILE
return '%s script -d %s %s' % (uftrace, TDIR, options)

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

def post(self, ret):
sp.call(['rm', '-rf', TDIR, FILE])
return ret
40 changes: 40 additions & 0 deletions tests/t171_script_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python

from runtest import TestBase
import subprocess as sp

FILE='script.py'

script = """
# uftrace-option: -A fopen@arg1/s
def uftrace_entry(ctx):
if "args" in ctx:
print("%s(%s)" % (ctx["name"], ctx["args"][0]))
def uftrace_exit(ctx):
pass
"""

class TestCase(TestBase):
def __init__(self):
TestBase.__init__(self, 'openclose', 'fopen(/dev/null)')

def pre(self):
f = open(FILE, 'w')
f.write(script)
f.close()
return TestBase.TEST_SUCCESS

def runcmd(self):
uftrace = TestBase.ftrace
options = '-S ' + FILE
program = 't-' + self.name
return '%s %s %s' % (uftrace, options, program)

def sort(self, output):
return output.strip().split('\n')[0]

def post(self, ret):
sp.call(['rm', '-f', FILE])
return ret

0 comments on commit 00f38d0

Please sign in to comment.