]> git.proxmox.com Git - mirror_frr.git/blob - python/test_xrelfo.py
Merge pull request #8120 from ton31337/feature/bgp_ipv6_default_activated
[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 def test_uidhash():
31 assert uidhash.uidhash("lib/test_xref.c", "logging call", 3, 0) \
32 == 'H7KJB-67TBH'
33
34 def test_xrelfo_other():
35 for data in [
36 elf.ELFNull(),
37 elf.ELFUnresolved('somesym', 0),
38 ]:
39
40 dissect = xrelfo.XrefPtr(data)
41 print(repr(dissect))
42
43 with pytest.raises(AttributeError):
44 dissect.xref
45
46 def test_xrelfo_obj():
47 xrelfo_ = xrelfo.Xrelfo()
48 edf = xrelfo_.load_elf(os.path.join(root, 'lib/.libs/zclient.o'), 'zclient.lo')
49 xrefs = xrelfo_._xrefs
50
51 with pytest.raises(elf.ELFAccessError):
52 edf[0:4]
53
54 pprint(xrefs[0])
55 pprint(xrefs[0]._data)
56
57 def test_xrelfo_bin():
58 xrelfo_ = xrelfo.Xrelfo()
59 edf = xrelfo_.load_elf(os.path.join(root, 'lib/.libs/libfrr.so'), 'libfrr.la')
60 xrefs = xrelfo_._xrefs
61
62 assert edf[0:4] == b'\x7fELF'
63
64 pprint(xrefs[0])
65 pprint(xrefs[0]._data)