]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
36a8fdfd DL |
2 | # some basic tests for xrelfo & the python ELF machinery |
3 | # | |
4 | # Copyright (C) 2020 David Lamparter for NetDEF, Inc. | |
36a8fdfd DL |
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__)) | |
00f0c399 | 12 | sys.path.append(os.path.join(root, "python")) |
36a8fdfd DL |
13 | |
14 | import xrelfo | |
15 | from clippy import elf, uidhash | |
16 | ||
00f0c399 | 17 | |
36a8fdfd | 18 | def test_uidhash(): |
00f0c399 DL |
19 | assert uidhash.uidhash("lib/test_xref.c", "logging call", 3, 0) == "H7KJB-67TBH" |
20 | ||
36a8fdfd DL |
21 | |
22 | def test_xrelfo_other(): | |
23 | for data in [ | |
00f0c399 DL |
24 | elf.ELFNull(), |
25 | elf.ELFUnresolved("somesym", 0), | |
26 | ]: | |
36a8fdfd DL |
27 | |
28 | dissect = xrelfo.XrefPtr(data) | |
29 | print(repr(dissect)) | |
30 | ||
31 | with pytest.raises(AttributeError): | |
32 | dissect.xref | |
33 | ||
00f0c399 | 34 | |
36a8fdfd DL |
35 | def test_xrelfo_obj(): |
36 | xrelfo_ = xrelfo.Xrelfo() | |
00f0c399 | 37 | edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/zclient.o"), "zclient.lo") |
36a8fdfd DL |
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 | ||
00f0c399 | 46 | |
36a8fdfd DL |
47 | def test_xrelfo_bin(): |
48 | xrelfo_ = xrelfo.Xrelfo() | |
00f0c399 | 49 | edf = xrelfo_.load_elf(os.path.join(root, "lib/.libs/libfrr.so"), "libfrr.la") |
36a8fdfd DL |
50 | xrefs = xrelfo_._xrefs |
51 | ||
00f0c399 | 52 | assert edf[0:4] == b"\x7fELF" |
36a8fdfd DL |
53 | |
54 | pprint(xrefs[0]) | |
55 | pprint(xrefs[0]._data) |