]> git.proxmox.com Git - mirror_frr.git/blob - python/test_xrelfo.py
3379959dc134d60bd25d74ddb4f8e76cb1c307a2
[mirror_frr.git] / python / test_xrelfo.py
1 # some basic tests for xrelfo & the python ELF machinery
2 #
3 # Copyright (C) 2020 David Lamparter for NetDEF, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; see the file COPYING; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 import sys
20 import os
21 import pytest
22 from pprint import pprint
23
24 root = os.path.dirname(os.path.dirname(__file__))
25 sys.path.append(os.path.join(root, "python"))
26
27 import xrelfo
28 from clippy import elf, uidhash
29
30
31 def test_uidhash():
32 assert uidhash.uidhash("lib/test_xref.c", "logging call", 3, 0) == "H7KJB-67TBH"
33
34
35 def test_xrelfo_other():
36 for data in [
37 elf.ELFNull(),
38 elf.ELFUnresolved("somesym", 0),
39 ]:
40
41 dissect = xrelfo.XrefPtr(data)
42 print(repr(dissect))
43
44 with pytest.raises(AttributeError):
45 dissect.xref
46
47
48 def test_xrelfo_obj():
49 xrelfo_ = xrelfo.Xrelfo()
50 edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/zclient.o"), "zclient.lo")
51 xrefs = xrelfo_._xrefs
52
53 with pytest.raises(elf.ELFAccessError):
54 edf[0:4]
55
56 pprint(xrefs[0])
57 pprint(xrefs[0]._data)
58
59
60 def test_xrelfo_bin():
61 xrelfo_ = xrelfo.Xrelfo()
62 edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/libfrr.so"), "libfrr.la")
63 xrefs = xrelfo_._xrefs
64
65 assert edf[0:4] == b"\x7fELF"
66
67 pprint(xrefs[0])
68 pprint(xrefs[0]._data)