1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/bitops.h>
7 #include <linux/kernel.h>
8 #include <linux/types.h>
12 #include <subcmd/exec-cmd.h>
15 #include "util/build-id.h"
16 #include "util/symbol.h"
21 #ifdef HAVE_LIBBFD_SUPPORT
23 static int run_dir(const char *d
)
25 char filename
[PATH_MAX
];
26 char debugfile
[PATH_MAX
];
28 char debuglink
[PATH_MAX
];
29 char expect_build_id
[] = {
30 0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22,
31 0x4b, 0xa4, 0x7b, 0x62, 0x4c, 0x55, 0xa4, 0x69,
33 char expect_debuglink
[PATH_MAX
] = "pe-file.exe.debug";
38 scnprintf(filename
, PATH_MAX
, "%s/pe-file.exe", d
);
39 ret
= filename__read_build_id(filename
, &bid
);
40 TEST_ASSERT_VAL("Failed to read build_id",
41 ret
== sizeof(expect_build_id
));
42 TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid
.data
, expect_build_id
,
43 sizeof(expect_build_id
)));
45 ret
= filename__read_debuglink(filename
, debuglink
, PATH_MAX
);
46 TEST_ASSERT_VAL("Failed to read debuglink", ret
== 0);
47 TEST_ASSERT_VAL("Wrong debuglink",
48 !strcmp(debuglink
, expect_debuglink
));
50 scnprintf(debugfile
, PATH_MAX
, "%s/%s", d
, debuglink
);
51 ret
= filename__read_build_id(debugfile
, &bid
);
52 TEST_ASSERT_VAL("Failed to read debug file build_id",
53 ret
== sizeof(expect_build_id
));
54 TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid
.data
, expect_build_id
,
55 sizeof(expect_build_id
)));
57 dso
= dso__new(filename
);
58 TEST_ASSERT_VAL("Failed to get dso", dso
);
60 ret
= dso__load_bfd_symbols(dso
, debugfile
);
61 TEST_ASSERT_VAL("Failed to load symbols", ret
== 0);
63 dso__sort_by_name(dso
);
64 sym
= dso__find_symbol_by_name(dso
, "main");
65 TEST_ASSERT_VAL("Failed to find main", sym
);
71 int test__pe_file_parsing(struct test
*test __maybe_unused
,
72 int subtest __maybe_unused
)
75 char path_dir
[PATH_MAX
];
77 /* First try development tree tests. */
78 if (!lstat("./tests", &st
))
79 return run_dir("./tests");
81 /* Then installed path. */
82 snprintf(path_dir
, PATH_MAX
, "%s/tests", get_argv_exec_path());
84 if (!lstat(path_dir
, &st
))
85 return run_dir(path_dir
);
92 int test__pe_file_parsing(struct test
*test __maybe_unused
,
93 int subtest __maybe_unused
)