File: TestCommandScriptImmediateOutput.py

package info (click to toggle)
llvm-toolchain-3.8 1%3A3.8.1-24
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 379,280 kB
  • ctags: 388,501
  • sloc: cpp: 2,309,705; ansic: 477,070; objc: 100,918; asm: 97,974; python: 95,911; sh: 18,634; makefile: 7,294; perl: 5,584; ml: 5,460; pascal: 4,661; lisp: 2,548; xml: 686; cs: 350; php: 212; csh: 117
file content (71 lines) | stat: -rw-r--r-- 2,885 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
71
"""
Test that LLDB correctly allows scripted commands to set an immediate output file
"""

from __future__ import print_function



import os, time
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbpexpect import *

class CommandScriptImmediateOutputTestCase (PExpectTest):

    mydir = TestBase.compute_mydir(__file__)

    def setUp(self):
        # Call super's setUp().
        PExpectTest.setUp(self)

    @skipIfRemote # test not remote-ready llvm.org/pr24813
    @expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
    @expectedFlakeyLinux("llvm.org/pr25172")
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    def test_command_script_immediate_output (self):
        """Test that LLDB correctly allows scripted commands to set an immediate output file."""
        self.launch(timeout=60)

        script = os.path.join(os.getcwd(), 'custom_command.py')
        prompt = "\(lldb\) "
                                                                      
        self.sendline('command script import %s' % script, patterns=[prompt])
        self.sendline('command script add -f custom_command.command_function mycommand', patterns=[prompt])
        self.sendline('mycommand', patterns='this is a test string, just a test string')
        self.sendline('command script delete mycommand', patterns=[prompt])

        test_files = {os.path.join(os.getcwd(), 'read.txt')        :'r',
                      os.path.join(os.getcwd(), 'write.txt')       :'w',
                      os.path.join(os.getcwd(), 'append.txt')      :'a',
                      os.path.join(os.getcwd(), 'write_plus.txt')  :'w+',
                      os.path.join(os.getcwd(), 'read_plus.txt')   :'r+',
                      os.path.join(os.getcwd(), 'append_plus.txt') :'a+'}

        starter_string = 'Starter Garbage\n'
        write_string   = 'writing to file with mode: '

        for path, mode in test_files.iteritems():
            with open(path, 'w+') as init:
                init.write(starter_string)

        self.sendline('command script add -f custom_command.write_file mywrite', patterns=[prompt])
        for path, mode in test_files.iteritems():
            command = 'mywrite "' + path + '" ' + mode

            self.sendline(command, patterns=[prompt])

        self.sendline('command script delete mywrite', patterns=[prompt])

        self.quit(gracefully=False)

        for path, mode in test_files.iteritems():
            with open(path, 'r') as result:
                if mode in ['r', 'a', 'a+']:
                    self.assertEquals(result.readline(), starter_string)
                if mode in ['w', 'w+', 'r+', 'a', 'a+']:
                    self.assertEquals(result.readline(), write_string + mode + '\n')

            self.assertTrue(os.path.isfile(path))
            os.remove(path)