Skip to content

Commit

Permalink
Add session.root tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Oct 10, 2022
1 parent c0b26de commit 353126b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/api/gef_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
"""


from logging import root
import subprocess
import os
from tests.utils import (
TMPDIR,
gdb_test_python_method,
_target,
GefUnitTestGeneric,
gdbserver_session,
gdb_run_cmd,
qemuuser_session
)

GDBSERVER_PREFERED_HOST = "localhost"
GDBSERVER_PREFERED_PORT = 1234

class GefSessionApi(GefUnitTestGeneric):
"""`gef.session` test module."""
Expand Down Expand Up @@ -40,3 +47,30 @@ def test_func_auxiliary_vector(self):
self.assertTrue("'AT_PLATFORM'" in res)
self.assertTrue("'AT_EXECFN':" in res)
self.assertFalse("'AT_WHATEVER':" in res)

def test_root_dir(self):
func = "(s.st_dev, s.st_ino)"
res = gdb_test_python_method(func, target=_target("default"), before="s=os.stat(gef.session.root)")
self.assertNoException(res)
st_dev, st_ino = eval(res.split("\n")[-1])
stat_root = os.stat("/")
# Check that the `/` directory and the `session.root` directory are the same
assert (stat_root.st_dev == st_dev) and (stat_root.st_ino == st_ino)

port = GDBSERVER_PREFERED_PORT + 1
before = [f"gef-remote {GDBSERVER_PREFERED_HOST} {port}",
"pi s = os.stat(gef.session.root)"]
with gdbserver_session(port=port) as _:
res = gdb_run_cmd(f"pi {func}", target=_target("default"), before=before)
self.assertNoException(res)
st_dev, st_ino = eval(res.split("\n")[-1])
assert (stat_root.st_dev == st_dev) and (stat_root.st_ino == st_ino)

port = GDBSERVER_PREFERED_PORT + 2
with qemuuser_session(port=port) as _:
target = _target("default")
before = [
f"gef-remote --qemu-user --qemu-binary {target} {GDBSERVER_PREFERED_HOST} {port}"]
res = gdb_run_cmd(f"pi gef.session.root", target=_target("default"), before=before)
self.assertNoException(res)
assert "/proc/1/root" in res

0 comments on commit 353126b

Please sign in to comment.