Skip to content

Commit

Permalink
selftest: contrib: Add some GDB startup tests
Browse files Browse the repository at this point in the history
These tests should catch a couple of edge-cases of GDB startup where
tbot is supposed to properly throw a certain exception.

Signed-off-by: Harald Seiler <[email protected]>
  • Loading branch information
Rahix committed Apr 13, 2023
1 parent a8ed7b9 commit 9d8425e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions selftest/tests/contrib/test_gdb.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
import re
from typing import Tuple, Type

import pytest
import testmachines

import tbot
import tbot_contrib.gdb
from tbot.machine import linux

RESULT_PATTERN = re.compile(r"\$\d+ = 0x[0-9a-f]+ (?:<.*> )?\"(.*)\"")


@pytest.mark.parametrize( # type: ignore
"failure_mode",
[
("true", linux.CommandEndedException),
("false", tbot.error.CommandFailure),
],
ids=lambda failure_mode: failure_mode[1].__name__,
)
def test_gdb_start_crash(
tbot_context: tbot.Context, failure_mode: Tuple[str, Type[Exception]]
) -> None:
command, exception = failure_mode
with tbot_context.request(testmachines.Localhost) as lh:
with pytest.raises(exception):
# Run `echo` instead of GDB to force an initialization error
with tbot_contrib.gdb.GDB(lh, gdb=command) as gdb:
gdb.exec("help")

lh.exec0("uname", "-r")


def test_gdb_init_hang(tbot_context: tbot.Context) -> None:
with tbot_context.request(testmachines.Localhost) as lh:
with pytest.raises(TimeoutError):
# Run `echo` instead of GDB to force and hack in a sleep
# to let the initialization hang forever
with tbot_contrib.gdb.GDB(lh, linux.Then, "sleep", "30", gdb="echo") as gdb: # type: ignore
gdb.exec("help")

lh.exec0("uname", "-r")


def test_gdb_machine(tbot_context: tbot.Context) -> None:
with tbot_context.request(testmachines.Localhost) as lh:
program = lh.exec0("which", "echo").strip()
Expand Down

0 comments on commit 9d8425e

Please sign in to comment.