Skip to content

Commit

Permalink
Test case for viewcfg GDB command (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazhuu authored Feb 5, 2022
1 parent a284f06 commit a6b9f12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Pipfile.lock
# Vim files
.*swp
Session.vim
tags

# GDB history
.gdb_history
Expand All @@ -22,3 +23,4 @@ coverage.xml

# Test files
a.out
main.pdf
25 changes: 23 additions & 2 deletions test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,28 @@ def test_savecfg():
'run', 'savecfg']
)
assert os.path.isfile('main.pdf'), result.stdout
# assert 'Saved CFG to a file _start.pdf' in result.stdout, result.stdout
assert 'Saved CFG to a file main.pdf' in result.stdout, result.stdout


def test_viewcfg():
stdout = ''
try:
result = execute_gdb_commands(
['set confirm off', 'set breakpoint pending on',
'file test/fixtures/simple_program/hello', 'b main',
'run', 'viewcfg']
)
stdout = result.stdout
except subprocess.TimeoutExpired as ex:
stdout = str(ex.stdout)
viewcfg_pattern = re.compile(r'Opening a file (.*) with default viewer')
result = viewcfg_pattern.search(stdout)

assert result is not None, stdout

temporary_filename = result.group(1)

assert os.path.isfile(temporary_filename), temporary_filename


def execute_gdb_command(command):
Expand All @@ -72,7 +93,7 @@ def execute_gdb_commands(commands):
gdb_command.append('q')
result = subprocess.run(
gdb_command, stdout=subprocess.PIPE, stdin=None,
stderr=None, timeout=3, check=True, universal_newlines=True,
stderr=None, timeout=2, check=True, universal_newlines=True,
)
return result

Expand Down

0 comments on commit a6b9f12

Please sign in to comment.