File: t222_external_data.py

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (70 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3

import os.path
import subprocess as sp

from runtest import TestBase

class TestCase(TestBase):
    def __init__(self):
        TestBase.__init__(self, 'abc', """
# DURATION    TID     FUNCTION
            [28141] | main() {
            [28141] | /* external-data: user message */
            [28141] |   a() {
            [28141] |     b() {
            [28141] |       c() {
   0.753 us [28141] |         getpid();
   1.430 us [28141] |       } /* c */
   1.915 us [28141] |     } /* b */
   2.405 us [28141] |   } /* a */
   3.005 us [28141] | } /* main */
""")

    def prerun(self, timeout):
        self.subcmd = 'record'
        self.option = ''
        self.exearg = 't-' + self.name

        record_cmd = TestBase.runcmd(self)
        self.pr_debug("prerun command: " + record_cmd)
        sp.call(record_cmd.split())

        self.subcmd = 'replay'
        self.option = '-F main -f time'
        self.exearg = ''
        replay_cmd = TestBase.runcmd(self)
        self.pr_debug("prerun command: " + replay_cmd)

        p = sp.Popen(replay_cmd.split(), stdout=sp.PIPE)
        if p.wait() != 0:
            return TestBase.TEST_NONZERO_RETURN

        output = p.communicate()[0].decode(errors='ignore')
        for l in output.split('\n'):
            if l.startswith('#'):
                continue;
            # parse first line to get the timestamp
            t = l.split(' | ')[0].strip()
            point = t.find('.')
            if point < 0:
                return TestBase.TEST_DIFF_RESULT
            nsec = int(t[point+1:point+10])

            # add the external data right after the first line
            msg = '%s.%09d %s\n' % (t[:point], nsec + 1, 'user message')

            data_file = open(os.path.join('uftrace.data', 'extern.dat'), 'w')
            data_file.write(msg)
            data_file.close()
            break
        return TestBase.TEST_SUCCESS

    def setup(self):
        self.subcmd = 'replay'
        self.option = ''
        self.exearg = ''

    def runcmd(self):
        cmd = TestBase.runcmd(self)
        return cmd.replace('--no-event', '')