]>
git.proxmox.com Git - mirror_frr.git/blob - python/test_xrelfo.py
1 # some basic tests for xrelfo & the python ELF machinery
3 # Copyright (C) 2020 David Lamparter for NetDEF, Inc.
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)
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
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
22 from pprint
import pprint
24 root
= os
.path
.dirname(os
.path
.dirname(__file__
))
25 sys
.path
.append(os
.path
.join(root
, "python"))
28 from clippy
import elf
, uidhash
32 assert uidhash
.uidhash("lib/test_xref.c", "logging call", 3, 0) == "H7KJB-67TBH"
35 def test_xrelfo_other():
38 elf
.ELFUnresolved("somesym", 0),
41 dissect
= xrelfo
.XrefPtr(data
)
44 with pytest
.raises(AttributeError):
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
53 with pytest
.raises(elf
.ELFAccessError
):
57 pprint(xrefs
[0]._data
)
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
65 assert edf
[0:4] == b
"\x7fELF"
68 pprint(xrefs
[0]._data
)