]>
Commit | Line | Data |
---|---|---|
36a8fdfd DL |
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__)) | |
00f0c399 | 25 | sys.path.append(os.path.join(root, "python")) |
36a8fdfd DL |
26 | |
27 | import xrelfo | |
28 | from clippy import elf, uidhash | |
29 | ||
00f0c399 | 30 | |
36a8fdfd | 31 | def test_uidhash(): |
00f0c399 DL |
32 | assert uidhash.uidhash("lib/test_xref.c", "logging call", 3, 0) == "H7KJB-67TBH" |
33 | ||
36a8fdfd DL |
34 | |
35 | def test_xrelfo_other(): | |
36 | for data in [ | |
00f0c399 DL |
37 | elf.ELFNull(), |
38 | elf.ELFUnresolved("somesym", 0), | |
39 | ]: | |
36a8fdfd DL |
40 | |
41 | dissect = xrelfo.XrefPtr(data) | |
42 | print(repr(dissect)) | |
43 | ||
44 | with pytest.raises(AttributeError): | |
45 | dissect.xref | |
46 | ||
00f0c399 | 47 | |
36a8fdfd DL |
48 | def test_xrelfo_obj(): |
49 | xrelfo_ = xrelfo.Xrelfo() | |
00f0c399 | 50 | edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/zclient.o"), "zclient.lo") |
36a8fdfd DL |
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 | ||
00f0c399 | 59 | |
36a8fdfd DL |
60 | def test_xrelfo_bin(): |
61 | xrelfo_ = xrelfo.Xrelfo() | |
00f0c399 | 62 | edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/libfrr.so"), "libfrr.la") |
36a8fdfd DL |
63 | xrefs = xrelfo_._xrefs |
64 | ||
00f0c399 | 65 | assert edf[0:4] == b"\x7fELF" |
36a8fdfd DL |
66 | |
67 | pprint(xrefs[0]) | |
68 | pprint(xrefs[0]._data) |