]> git.proxmox.com Git - mirror_frr.git/blob - python/test_xrelfo.py
Merge pull request #12780 from opensourcerouting/spdx-license-id
[mirror_frr.git] / python / test_xrelfo.py
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 # some basic tests for xrelfo & the python ELF machinery
3 #
4 # Copyright (C) 2020 David Lamparter for NetDEF, Inc.
5
6 import sys
7 import os
8 import pytest
9 from pprint import pprint
10
11 root = os.path.dirname(os.path.dirname(__file__))
12 sys.path.append(os.path.join(root, "python"))
13
14 import xrelfo
15 from clippy import elf, uidhash
16
17
18 def test_uidhash():
19 assert uidhash.uidhash("lib/test_xref.c", "logging call", 3, 0) == "H7KJB-67TBH"
20
21
22 def test_xrelfo_other():
23 for data in [
24 elf.ELFNull(),
25 elf.ELFUnresolved("somesym", 0),
26 ]:
27
28 dissect = xrelfo.XrefPtr(data)
29 print(repr(dissect))
30
31 with pytest.raises(AttributeError):
32 dissect.xref
33
34
35 def test_xrelfo_obj():
36 xrelfo_ = xrelfo.Xrelfo()
37 edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/zclient.o"), "zclient.lo")
38 xrefs = xrelfo_._xrefs
39
40 with pytest.raises(elf.ELFAccessError):
41 edf[0:4]
42
43 pprint(xrefs[0])
44 pprint(xrefs[0]._data)
45
46
47 def test_xrelfo_bin():
48 xrelfo_ = xrelfo.Xrelfo()
49 edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/libfrr.so"), "libfrr.la")
50 xrefs = xrelfo_._xrefs
51
52 assert edf[0:4] == b"\x7fELF"
53
54 pprint(xrefs[0])
55 pprint(xrefs[0]._data)