-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test cases for advanced python script testing
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
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |