Skip to content

Commit

Permalink
test: Add a test case for signal trigger
Browse files Browse the repository at this point in the history
  $ uftrace -a --signal SIGUSR1@finish tests/t-signal
  # DURATION     TID     FUNCTION
              [ 13635] | main(1, 0x7ffd5c074428) {
     0.245 us [ 13635] |   foo() = 0;
     1.572 us [ 13635] |   signal(SIGUSR1, &sighandler) = 0x7f20827b9fd0;
              [ 13635] |   raise() {
              [ 13635] |     sighandler(10) {
     0.102 us [ 13635] |       bar(10);
              [ 13635] |       /* linux:task-exit */
     4.376 us [ 13635] |     } /* sighandler */

  uftrace stopped tracing with remaining functions
  ================================================
  task: 13635
  [2] sighandler
  [1] raise
  [0] main

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Jan 16, 2019
1 parent 33a2496 commit 770faff
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
30 changes: 30 additions & 0 deletions libmcount/mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1844,4 +1844,34 @@ TEST_CASE(mcount_thread_data)
return TEST_OK;
}

TEST_CASE(mcount_signal_setup)
{
struct signal_trigger_item *item;
struct uftrace_filter_setting setting = {
.ptype = PATT_NONE,
};

/* it signal triggers are maintained in a stack (LIFO) */
mcount_signal_init("SIGUSR1@traceon;USR2@traceoff;RTMIN+3@finish",
&setting);

item = list_first_entry(&siglist, typeof(*item), list);
TEST_EQ(item->sig, SIGRTMIN + 3);
TEST_EQ(item->tr.flags, TRIGGER_FL_FINISH);

item = list_next_entry(item, list);
TEST_EQ(item->sig, SIGUSR2);
TEST_EQ(item->tr.flags, TRIGGER_FL_TRACE_OFF);

item = list_next_entry(item, list);
TEST_EQ(item->sig, SIGUSR1);
TEST_EQ(item->tr.flags, TRIGGER_FL_TRACE_ON);

mcount_signal_finish();

TEST_EQ(list_empty(&siglist), true);

return TEST_OK;
}

#endif /* UNIT_TEST */
2 changes: 1 addition & 1 deletion tests/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def task_sort(self, output, ignore_children=False):
# ignore result of remaining functions which follows a blank line
if ln.strip() == '':
break
pid_patt = re.compile('[^[]*\[ *(\d+)\] |')
pid_patt = re.compile('[^[]+\[ *(\d+)\] |')
m = pid_patt.match(ln)
try:
pid = int(m.group(1))
Expand Down
15 changes: 9 additions & 6 deletions tests/s-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

volatile int dummy;

void foo(void)
typedef void (*sighandler_t)(int sig);
sighandler_t old_handler;

int foo(void)
{
if (dummy == 0)
dummy = 1;
else
dummy = 0;
return dummy;
}

void bar(int n)
Expand All @@ -19,6 +19,9 @@ void bar(int n)
void sighandler(int sig)
{
bar(sig);

if (old_handler != SIG_DFL)
old_handler(sig);
}

int main(int argc, char *argv[])
Expand All @@ -29,7 +32,7 @@ int main(int argc, char *argv[])
sig = atoi(argv[1]);

foo();
signal(sig, sighandler);
old_handler = signal(sig, sighandler);
raise(sig);
foo();

Expand Down
34 changes: 34 additions & 0 deletions tests/t214_signal_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

from runtest import TestBase

class TestCase(TestBase):
def __init__(self):
TestBase.__init__(self, 'signal', """
# DURATION TID FUNCTION
[ 11892] | main() {
0.241 us [ 11892] | foo();
1.611 us [ 11892] | signal();
[ 11892] | raise() {
[ 11892] | sighandler() {
0.120 us [ 11892] | bar();
2.315 us [ 11892] | } /* sighandler */
uftrace stopped tracing with remaining functions
================================================
task: 11892
[2] sighandler
[1] raise
[0] main
""")

def runcmd(self):
uftrace = TestBase.uftrace_cmd
options = "--signal SIGUSR1@finish"
program = 't-' + self.name

return "%s %s %s" % (uftrace, options, program)

def fixup(self, cflags, result):
return result.replace(""" } /* sighandler */
""", "")

0 comments on commit 770faff

Please sign in to comment.