Skip to content

Commit

Permalink
Use unittest for ebpf & add disasm test (#58)
Browse files Browse the repository at this point in the history
* use unittest for ebpf & add disasm test

* lint

* oops! fogot that
  • Loading branch information
xxr0ss authored Nov 30, 2023
1 parent cfcb77e commit 5884f37
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions tests/test_ebpf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import unittest
from pathlib import Path

import angr
from angr_platforms.ebpf import ArchExtendedBPF
from angr_platforms.ebpf import ArchExtendedBPF, LifterEbpf


TEST_PROGRAMS_BASE = Path(__file__).parent.parent / "test_programs" / "ebpf"


def test_prog_always_returns_42(filename: str) -> None:
proj = angr.Project(TEST_PROGRAMS_BASE / filename)
assert isinstance(proj.arch, ArchExtendedBPF)
Expand All @@ -17,19 +20,25 @@ def test_prog_always_returns_42(filename: str) -> None:
assert state.solver.eval_exact(simgr.deadended[0].regs.R0, 1) == [42]


def test_trivial_return():
test_prog_always_returns_42("return_42.o")

class TestEbpf(unittest.TestCase):
# pylint:disable=missing-class-docstring,no-self-use
def test_trivial_return(self):
test_prog_always_returns_42("return_42.o")

def test_branched_return():
test_prog_always_returns_42("return_if.o")
def test_branched_return(self):
test_prog_always_returns_42("return_if.o")

def test_get_ns(self):
test_prog_always_returns_42("get_ns.o")

def test_get_ns():
test_prog_always_returns_42("get_ns.o")
def test_ebpf_lift(self):
proj = angr.Project(TEST_PROGRAMS_BASE / "return_42.o")
state = proj.factory.entry_state()
block = proj.factory.block(state.addr)
lifter = LifterEbpf(proj.arch, block.addr)
lifter.lift(block.bytes)
assert len(lifter.disassemble()) == 2


if __name__ == "__main__":
test_trivial_return()
test_branched_return()
test_get_ns()
unittest.main()

0 comments on commit 5884f37

Please sign in to comment.