Skip to content

Commit

Permalink
[CI] Add extended testing capability (#1156)
Browse files Browse the repository at this point in the history
## Description

Adds Github Actions workflow (`workflow_dispatch` only) and scripts for
running tests in docker on
 - [x] Fedora
 - [x] Debian
 - [x] ArchLinux

Fixes #1152
  • Loading branch information
hugsy authored Nov 13, 2024
1 parent 9f2737a commit 29884e3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 14 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/extended-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Extended Tests


on:
workflow_dispatch:

jobs:
build:
strategy:
fail-fast: false
matrix:
variants:
- { os: fedora, version: 41 }
- { os: debian, version: bookworm }
- { os: archlinux, version: base }

name: "Tests on ${{ matrix.variants }}"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: |
docker run -v ${PWD}:/gef ${{ matrix.variants.os }}:${{ matrix.variants.version }} "bash /gef/tests/extended/${{ matrix.variants.os }}.sh"
32 changes: 18 additions & 14 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,9 +1878,8 @@ def show_last_exception() -> None:
"""Display the last Python exception."""

def _show_code_line(fname: str, idx: int) -> str:
fname = os.path.expanduser(os.path.expandvars(fname))
with open(fname, "r") as f:
_data = f.readlines()
fpath = pathlib.Path(os.path.expanduser(os.path.expandvars(fname)))
_data = fpath.read_text().splitlines()
return _data[idx - 1] if 0 < idx < len(_data) else ""

gef_print("")
Expand Down Expand Up @@ -1912,7 +1911,7 @@ def _show_code_line(fname: str, idx: int) -> str:
lsb_release = which("lsb_release")
gdb.execute(f"!'{lsb_release}' -a")
except FileNotFoundError:
gef_print("lsb_release is missing, cannot collect additional debug information")
pass

gef_print(HORIZONTAL_LINE*80)
gef_print("")
Expand Down Expand Up @@ -4898,17 +4897,22 @@ class VersionCommand(GenericCommand):
def do_invoke(self, argv: list[str]) -> None:
gef_fpath = pathlib.Path(inspect.stack()[0][1]).expanduser().absolute()
gef_dir = gef_fpath.parent
with gef_fpath.open("rb") as f:
gef_hash = hashlib.sha256(f.read()).hexdigest()
gef_hash = hashlib.sha256(gef_fpath.read_bytes()).hexdigest()

if os.access(f"{gef_dir}/.git", os.X_OK):
ver = subprocess.check_output("git log --format='%H' -n 1 HEAD", cwd=gef_dir, shell=True).decode("utf8").strip()
extra = "dirty" if len(subprocess.check_output("git ls-files -m", cwd=gef_dir, shell=True).decode("utf8").strip()) else "clean"
gef_print(f"GEF: rev:{ver} (Git - {extra})")
else:
gef_blob_hash = subprocess.check_output(f"git hash-object {gef_fpath}", shell=True).decode().strip()
gef_print("GEF: (Standalone)")
gef_print(f"Blob Hash({gef_fpath}): {gef_blob_hash}")
try:
git = which("git")
except:
git = None

if git:
if (gef_dir / ".git").is_dir():
ver = subprocess.check_output("git log --format='%H' -n 1 HEAD", cwd=gef_dir, shell=True).decode("utf8").strip()
extra = "dirty" if len(subprocess.check_output("git ls-files -m", cwd=gef_dir, shell=True).decode("utf8").strip()) else "clean"
gef_print(f"GEF: rev:{ver} (Git - {extra})")
else:
gef_blob_hash = subprocess.check_output(f"git hash-object {gef_fpath}", shell=True).decode().strip()
gef_print("GEF: (Standalone)")
gef_print(f"Blob Hash({gef_fpath}): {gef_blob_hash}")
gef_print(f"SHA256({gef_fpath}): {gef_hash}")
gef_print(f"GDB: {gdb.VERSION}")
py_ver = f"{sys.version_info.major:d}.{sys.version_info.minor:d}"
Expand Down
13 changes: 13 additions & 0 deletions tests/extended/archlinux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


#!/bin/bash
set -e
# set -x
# docker run -v /path/to/gef:/gef archlinux:base-20241110.0.278197⁠ "bash /gef/tests/extended/archlinux.sh"
pacman -Suy
pacman -Suy --noconfirm gdb cmake gcc python3 procps file elfutils binutils cmake gcc qemu-user locales git python-pip make
export LANG=en_US.UTF8
export LC_ALL=en_US.UTF8

alias gdb-multiarch=gdb
bash /gef/tests/extended/run_pytest.sh
11 changes: 11 additions & 0 deletions tests/extended/debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
# set -x
# docker run -v /path/to/gef:/gef debian:bookworm "bash /gef/tests/extended/debian.sh"
apt update -qq
apt install -qq -y gdb-multiarch cmake gcc-multilib python3 python3-pip procps file elfutils binutils cmake gcc g++ gdbserver qemu-user locales git
rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
export LANG=en_US.UTF8
export LC_ALL=en_US.UTF8

bash /gef/tests/extended/run_pytest.sh
9 changes: 9 additions & 0 deletions tests/extended/fedora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e
# set -x
# docker run -v /path/to/gef:/gef fedora:41 "bash /gef/tests/extended/fedora.sh"
dnf install -y gdb cmake gcc python3 python3-pip procps file elfutils binutils cmake gcc g++ gdbserver qemu-user git
export LANG=en_US.UTF8
export LC_ALL=en_US.UTF8

bash /gef/tests/extended/run_pytest.sh
10 changes: 10 additions & 0 deletions tests/extended/run_pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

git config --global --add safe.directory /gef
cd /gef
export PY_VER=`gdb-multiarch -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit`
echo Using Python ${PY_VER}
python${PY_VER} -m pip install --user --upgrade -r tests/requirements.txt -r docs/requirements.txt --break-system-packages
make -C tests/binaries -j4
python${PY_VER} -m pytest --forked -n 4 -v -m "not benchmark" tests/

0 comments on commit 29884e3

Please sign in to comment.