diff options
| author | Arthur Hanson Rasmusson <arthur@vgpu.io> | 2026-10-02 10:58:21 -0400 |
|---|---|---|
| committer | Arthur Hanson Rasmusson <arthur@vgpu.io> | 2026-10-02 10:58:21 -0400 |
| commit | f909a5f822c5c4a4e9526b861d4171f8925f5113 (patch) | |
| tree | ed362021c83569f49b48079a774f05775e84b0bd /debug/risc-v-gsp-rm-vm/tests/test_core.py | |
| parent | 09f241601423b1ae98e97846ee451768ff8a0a9e (diff) | |
| download | open-iov-f909a5f822c5c4a4e9526b861d4171f8925f5113.tar.gz open-iov-f909a5f822c5c4a4e9526b861d4171f8925f5113.zip | |
debug: green-eye wave 3 - RM harness, local simulator, device map, MCP plugin, value-validation demos, CI pipeline, toolchain docs; add host RM tools rmtool/rmtop
Diffstat (limited to 'debug/risc-v-gsp-rm-vm/tests/test_core.py')
| -rw-r--r-- | debug/risc-v-gsp-rm-vm/tests/test_core.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/debug/risc-v-gsp-rm-vm/tests/test_core.py b/debug/risc-v-gsp-rm-vm/tests/test_core.py index 907a2eb..f02b2e6 100644 --- a/debug/risc-v-gsp-rm-vm/tests/test_core.py +++ b/debug/risc-v-gsp-rm-vm/tests/test_core.py @@ -3,10 +3,12 @@ from __future__ import annotations import json import os +import struct import tempfile import unittest -from greeneye.elf import EM_RISCV, parse_elf, load_elf +from greeneye.elf import EM_RISCV, parse_elf, load_elf, write_relocated_elf +from greeneye.errors import GreenEyeError from greeneye.structs import Field, Schema, decode, render, schema_from_json from greeneye.symbols import Symbol, SymbolDB @@ -36,6 +38,19 @@ class ElfTests(unittest.TestCase): with self.assertRaises(Exception): parse_elf(b"not an elf") + def test_write_relocated_elf(self): + if not os.path.exists(DEMO_ELF): + self.skipTest("demo firmware not built") + image = load_elf(DEMO_ELF) + with tempfile.TemporaryDirectory(prefix="greeneye-reloc-") as tmp: + out = os.path.join(tmp, "relocated.elf") + path = write_relocated_elf(DEMO_ELF, out, 0x1000) + with open(path, "rb") as fh: + data = fh.read() + self.assertEqual(struct.unpack_from("<Q", data, 24)[0], image.entry + 0x1000) + moved = parse_elf(data) + self.assertEqual(moved.entry, image.entry + 0x1000) + class SymbolTests(unittest.TestCase): def setUp(self): @@ -50,6 +65,11 @@ class SymbolTests(unittest.TestCase): self.assertEqual(self.db.annotate(0x1010), "0x1010 alpha+0x10") self.assertEqual(self.db.lookup("beta"), 0x1200) + def test_by_subsystem(self): + self.db.add(Symbol(addr=0x2000, name="gamma", size=8, source="test", subsystem="core")) + self.assertEqual([s.name for s in self.db.by_subsystem("core")], ["gamma"]) + self.assertEqual(self.db.by_subsystem("nope"), []) + def test_names_tsv(self): with tempfile.NamedTemporaryFile("w", suffix=".tsv", delete=False) as fh: fh.write("# comment\n0x00279000\t_DT_INIT\tghidra\n0x00279020\tFUN_x\n") @@ -89,6 +109,26 @@ class SymbolTests(unittest.TestCase): finally: os.unlink(path) + def test_json_list_payload(self): + with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as fh: + json.dump([{"addr": "0x2000", "name": "listed", "size": 4}], fh) + path = fh.name + try: + self.assertEqual(self.db.load_json(path), 1) + self.assertEqual(self.db.lookup("listed"), 0x2000) + finally: + os.unlink(path) + + def test_json_bad_input_raises_greeneye_error(self): + with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as fh: + fh.write("not json") + path = fh.name + try: + with self.assertRaises(GreenEyeError): + self.db.load_json(path) + finally: + os.unlink(path) + class StructTests(unittest.TestCase): SCHEMA = { |
