summaryrefslogtreecommitdiffstats
path: root/lldb/test/process_io/TestProcessIO.py
blob: 518d674d8a518e177cc1ab6e00ef0c1f87c39bec (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Test lldb process IO launch flags..
"""

import os, time
import unittest2
import lldb
from lldbtest import *

class ProcessLaunchIOTestCase(TestBase):

    mydir = "process_io"

    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
    def test_with_dsym (self):
        self.buildDsym ()
        self.process_io_test ()

    def test_with_dwarf (self):
        self.buildDwarf ()
        self.process_io_test ()

    def do_nothing (self):
        i = 1

    def process_io_test (self):
        exe = os.path.join (os.getcwd(), "a.out")
        self.expect("file " + exe,
                    patterns = [ "Current executable set to .*a.out" ])


        in_file = os.path.join (os.getcwd(), "input-file.txt")
        out_file = os.path.join (os.getcwd(), "output-test.out")
        err_file = os.path.join (os.getcwd(), "output-test.err")


        # Make sure the output files do not exist before launching the process
        try:
            os.remove (out_file)
        except OSError:
            # do_nothing (self)
            i = 1

        try:
            os.remove (err_file)
        except OSError:
            # do_nothing (self)
            i = 1

        launch_command = "process launch -i " + in_file + " -o " + out_file + " -e " + err_file
        
        self.expect (launch_command,
                     patterns = [ "Process .* launched: .*a.out" ])


        success = True
        err_msg = ""

        # Check to see if the 'stdout' file was created
        try:
            out_f = open (out_file)
        except IOError:
            success = False
            err_msg = err_msg + "   ERROR: stdout file was not created.\n"
        else:
            # Check to see if the 'stdout' file contains the right output
            line = out_f.readline ();
            if line != "This should go to stdout.\n":
                success = False
                err_msg = err_msg + "    ERROR: stdout file does not contain correct output.\n"
                out_f.close();
            
        # Try to delete the 'stdout' file
        try:
            os.remove (out_file)
        except OSError:
            # do_nothing (self)
            i = 1

        # Check to see if the 'stderr' file was created
        try:
            err_f = open (err_file)
        except IOError:
            success = False
            err_msg = err_msg + "     ERROR:  stderr file was not created.\n"
        else:
            # Check to see if the 'stderr' file contains the right output
            line = err_f.readline ()
            if line != "This should go to stderr.\n":
                success = False
                err_msg = err_msg + "    ERROR: stderr file does not contain correct output.\n\
"
                err_f.close()

        # Try to delete the 'stderr' file
        try:
            os.remove (err_file)
        except OSError:
            # do_nothing (self)
            i = 1

        if not success:
            self.fail (err_msg)

if __name__ == '__main__':
    import atexit
    lldb.SBDebugger.Initialize()
    atexit.register(lambda: lldb.SBDebugger.Terminate())
    unittest2.main()

OpenPOWER on IntegriCloud