Skip to content

Commit

Permalink
Merge branch 'test-update'
Browse files Browse the repository at this point in the history
Updates and fixes for test infrastructure and test cases.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Aug 9, 2018
2 parents e04f916 + 1a8ca37 commit 0e69ab9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
8 changes: 5 additions & 3 deletions arch/x86_64/mcount-dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ static unsigned long get_target_addr(struct mcount_dynamic_info *mdi, unsigned l

static int patch_fentry_func(struct mcount_dynamic_info *mdi, struct sym *sym)
{
unsigned char nop[] = { 0x67, 0x0f, 0x1f, 0x04, 0x00 };
unsigned char nop1[] = { 0x67, 0x0f, 0x1f, 0x04, 0x00 };
unsigned char nop2[] = { 0x0f, 0x1f, 0x44, 0x00, 0x00 };
unsigned char *insn = (void *)sym->addr;
unsigned int target_addr;

/* only support calls to __fentry__ at the beginning */
if (memcmp(insn, nop, sizeof(nop))) {
pr_dbg2("skip non-applicable functions: %s\n", sym->name);
if (memcmp(insn, nop1, sizeof(nop1)) && /* old pattern */
memcmp(insn, nop2, sizeof(nop2))) { /* new pattern */
pr_dbg("skip non-applicable functions: %s\n", sym->name);
return -2;
}

Expand Down
37 changes: 23 additions & 14 deletions tests/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,30 +323,37 @@ def check_perf_paranoid(self):

return True

def run(self, name, cflags, diff):
def run(self, name, cflags, diff, timeout):
ret = TestBase.TEST_SUCCESS

test_cmd = self.runcmd()
self.pr_debug("test command: %s" % test_cmd)

p = sp.Popen(test_cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)

timed_out = False
def timeout(sig, frame):
timed_out = True
class Timeout(Exception):
pass

def timeout_handler(sig, frame):
try:
p.kill()
except:
pass
finally:
raise Timeout

import signal
signal.signal(signal.SIGALRM, timeout)
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(5)

timed_out = False
try:
result_origin = p.communicate()[0].decode(errors='ignore')
except Timeout:
result_origin = ''
timed_out = True
signal.alarm(0)

result_expect = self.sort(self.result)
signal.alarm(5)
result_origin = p.communicate()[0].decode(errors='ignore')
result_tested = self.sort(result_origin) # for python3
signal.alarm(0)

ret = p.wait()
if ret < 0:
Expand Down Expand Up @@ -432,14 +439,14 @@ def timeout(sig, frame):
TestBase.TEST_SUCCESS_FIXED: 'Test succeeded (with some fixup)',
}

def run_single_case(case, flags, opts, diff, dbg):
def run_single_case(case, flags, opts, arg):
result = []

# for python3
_locals = {}
exec("import %s; tc = %s.TestCase()" % (case, case), globals(), _locals)
tc = _locals['tc']
tc.set_debug(dbg)
tc.set_debug(arg.debug)

for flag in flags:
for opt in opts:
Expand All @@ -448,7 +455,7 @@ def run_single_case(case, flags, opts, diff, dbg):
if ret == TestBase.TEST_SUCCESS:
ret = tc.pre()
if ret == TestBase.TEST_SUCCESS:
ret = tc.run(case, cflags, diff)
ret = tc.run(case, cflags, arg.diff, arg.timeout)
ret = tc.post(ret)
result.append(ret)

Expand Down Expand Up @@ -486,6 +493,8 @@ def parse_argument():
help="show internal command and result for debugging")
parser.add_argument("-n", "--no-color", dest='color', action='store_false',
help="suppress color in the output")
parser.add_argument("-t", "--timeout", dest='timeout', default=5,
help="fail test if it runs more than TIMEOUT seconds")

return parser.parse_args()

Expand Down Expand Up @@ -542,7 +551,7 @@ def parse_argument():

for tc in sorted(testcases):
name = tc[:-3] # remove '.py'
result = run_single_case(name, flags, opts.split(), arg.diff, arg.debug)
result = run_single_case(name, flags, opts.split(), arg)
print_test_result(name, result, arg.color)
for r in result:
stats[r] += 1
Expand Down
13 changes: 8 additions & 5 deletions tests/t136_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def __init__(self):
# DURATION TID FUNCTION
62.202 us [28141] | __cxa_atexit();
[28141] | main() {
[28141] | a() {
0.753 us [28141] | getpid();
2.405 us [28141] | } /* a */
2.405 us [28141] | a();
3.005 us [28141] | } /* main */
""")

Expand All @@ -21,7 +19,12 @@ def pre(self):
return TestBase.TEST_SUCCESS

def build(self, name, cflags='', ldflags=''):
return TestBase.build(self, name, '-pg -mfentry -mnop-mcount', ldflags)
cflags += ' -mfentry -mnop-mcount'
cflags += ' -fno-pie -fno-plt' # workaround of build failure
return TestBase.build(self, name, cflags, ldflags)

def runcmd(self):
return '%s -P %s %s' % (TestBase.uftrace_cmd, 'a.?', 't-' + self.name)
uftrace = TestBase.uftrace_cmd
argument = '-P %s --no-libcall' % 'a.?'
program = 't-' + self.name
return '%s %s %s' % (uftrace, argument, program)

0 comments on commit 0e69ab9

Please sign in to comment.