<commit_before>"""
Test lldb-mi startup options.
"""

import lldbmi_testcase
from lldbtest import *
import unittest2

class MiStartupOptionsTestCase(lldbmi_testcase.MiTestCaseBase):

    mydir = TestBase.compute_mydir(__file__)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_file(self):
        """Test that 'lldb-mi --interpreter %s' loads executable file."""

        self.spawnLldbMi(args = "%s" % self.myexe)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified
        self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_unknown_file(self):
        """Test that 'lldb-mi --interpreter %s' fails on unknown executable file."""

        # Prepare path to executable
        path = "unknown_file"

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable isn't loaded when unknown file was specified
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_absolute_path(self):
        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via absolute path."""

        # Prepare path to executable
        import os
        path = os.path.join(os.getcwd(), self.myexe)

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified using absolute path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_relative_path(self):
        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via relative path."""

        # Prepare path to executable
        path = "./%s" % self.myexe

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified using relative path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_unknown_path(self):
        """Test that 'lldb-mi --interpreter %s' fails on executable file which is specified via unknown path."""

        # Prepare path to executable
        path = "unknown_dir/%s" % self.myexe

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable isn't loaded when file was specified using unknown path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    def test_lldbmi_source_option_start_script(self):
        """Test that 'lldb-mi --interpreter' can execute user's commands after initial commands were executed."""

        # Prepared source file
        sourceFile = "start_script"

        self.spawnLldbMi(args = "--source %s" % sourceFile)

        # After '-file-exec-and-symbols a.out'
        self.expect("-file-exec-and-symbols %s" % self.myexe)
        self.expect("\^done")

        # After '-break-insert -f main'
        self.expect("-break-insert -f main")
        self.expect("\^done,bkpt={number=\"1\"")

        # After '-exec-run'
        self.expect("-exec-run")
        self.expect("\^running")

        # After '-break-insert main.cpp:BP_return'
        line = line_number('main.cpp', '//BP_return')
        self.expect("-break-insert main.cpp:%d" % line)
        self.expect("\^done,bkpt={number=\"2\"")

        # After '-exec-continue'
        self.expect("-exec-continue")
        self.expect("\^running")

        # Test that lldb-mi is ready after execution of --source start_script
        self.expect(self.child_prompt, exactly = True)

        # Try to evaluate 'a' expression
        self.runCmd("-data-evaluate-expression a")
        self.expect("\^done,value=\"10\"")
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    def test_lldbmi_source_option_start_script_exit(self):
        """Test that 'lldb-mi --interpreter' can execute a prepared file which passed via --source option."""

        # Prepared source file
        sourceFile = "start_script_exit"

        self.spawnLldbMi(args = "--source %s" % sourceFile)<commit_msg>Skip few MiStartupOptionsTestCase tests to get Linux build green<commit_after>"""
Test lldb-mi startup options.
"""

import lldbmi_testcase
from lldbtest import *
import unittest2

class MiStartupOptionsTestCase(lldbmi_testcase.MiTestCaseBase):

    mydir = TestBase.compute_mydir(__file__)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_file(self):
        """Test that 'lldb-mi --interpreter %s' loads executable file."""

        self.spawnLldbMi(args = "%s" % self.myexe)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified
        self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_unknown_file(self):
        """Test that 'lldb-mi --interpreter %s' fails on unknown executable file."""

        # Prepare path to executable
        path = "unknown_file"

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable isn't loaded when unknown file was specified
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_absolute_path(self):
        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via absolute path."""

        # Prepare path to executable
        import os
        path = os.path.join(os.getcwd(), self.myexe)

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified using absolute path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_relative_path(self):
        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via relative path."""

        # Prepare path to executable
        path = "./%s" % self.myexe

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable is loaded when file was specified using relative path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^done")

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

        # Run
        self.runCmd("-exec-run")
        self.expect("\^running")
        self.expect("\*stopped,reason=\"exited-normally\"")

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
    def test_lldbmi_executable_option_unknown_path(self):
        """Test that 'lldb-mi --interpreter %s' fails on executable file which is specified via unknown path."""

        # Prepare path to executable
        path = "unknown_dir/%s" % self.myexe

        self.spawnLldbMi(args = "%s" % path)

        # Test that lldb-mi is ready after startup
        self.expect(self.child_prompt, exactly = True)

        # Test that the executable isn't loaded when file was specified using unknown path
        self.expect("-file-exec-and-symbols \"%s\"" % path)
        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))

        # Test that lldb-mi is ready when executable was loaded
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
    def test_lldbmi_source_option_start_script(self):
        """Test that 'lldb-mi --interpreter' can execute user's commands after initial commands were executed."""

        # Prepared source file
        sourceFile = "start_script"

        self.spawnLldbMi(args = "--source %s" % sourceFile)

        # After '-file-exec-and-symbols a.out'
        self.expect("-file-exec-and-symbols %s" % self.myexe)
        self.expect("\^done")

        # After '-break-insert -f main'
        self.expect("-break-insert -f main")
        self.expect("\^done,bkpt={number=\"1\"")

        # After '-exec-run'
        self.expect("-exec-run")
        self.expect("\^running")

        # After '-break-insert main.cpp:BP_return'
        line = line_number('main.cpp', '//BP_return')
        self.expect("-break-insert main.cpp:%d" % line)
        self.expect("\^done,bkpt={number=\"2\"")

        # After '-exec-continue'
        self.expect("-exec-continue")
        self.expect("\^running")

        # Test that lldb-mi is ready after execution of --source start_script
        self.expect(self.child_prompt, exactly = True)

        # Try to evaluate 'a' expression
        self.runCmd("-data-evaluate-expression a")
        self.expect("\^done,value=\"10\"")
        self.expect(self.child_prompt, exactly = True)

    @lldbmi_test
    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
    @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
    def test_lldbmi_source_option_start_script_exit(self):
        """Test that 'lldb-mi --interpreter' can execute a prepared file which passed via --source option."""

        # Prepared source file
        sourceFile = "start_script_exit"

        self.spawnLldbMi(args = "--source %s" % sourceFile)
{'fraction_non_alphanumeric': 0.11733445213621425, 'fraction_numerical': 0.00978952520802741, 'mean_word_length': 2.841525651356433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4330577', 'n_tokens_mistral': 4509, 'n_tokens_neox': 4275, 'n_words': 1161}