File: t052_nested_func.py

package info (click to toggle)
uftrace 0.6.0.20161014-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,940 kB
  • ctags: 3,404
  • sloc: ansic: 24,586; python: 3,663; makefile: 585; asm: 242; sh: 135; cpp: 117
file content (46 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download
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
#!/usr/bin/env python

import re
from runtest import TestBase

class TestCase(TestBase):
    def __init__(self):
        TestBase.__init__(self, 'nested', result="""
# DURATION    TID     FUNCTION
            [13348] | main() {
            [13348] |   foo() {
   0.170 us [13348] |     foo_internal.2406();
   0.650 us [13348] |   } /* foo */
            [13348] |   bar() {
            [13348] |     qsort() {
   0.120 us [13348] |       compar.2414();
   0.093 us [13348] |       compar.2414();
   0.092 us [13348] |       compar.2414();
   2.479 us [13348] |     } /* qsort */
   3.462 us [13348] |   } /* bar */
   3.623 us [13348] | } /* main */
""")

    def sort(self, output, ignore_children=False):
        """ This function post-processes output of the test to be compared .
            It ignores blank and comment (#) lines and remaining functions.  """
        before_main = True
        funcs = []
        for ln in output.split('\n'):
            if ln.find(' | main()') > 0:
                before_main = False
            if before_main:
                continue
            # ignore result of remaining functions which follows a blank line
            if ln.strip() == '':
                break;

            try:
                func = ln.split('|', 1)[-1]
                # ignore function suffix after '.'
                funcs.append(func.split('.',1)[0])
            except:
                pass

        result = '\n'.join(funcs)
        return result