99c584fbf1f21c2333c8daa9932a146bfc3e24ce
2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2015 EfficiOS Inc. and Linux Foundation
5 * Copyright (C) 2015 Antoine Busque <abusque@efficios.com>
7 * Babeltrace bt_dwarf (DWARF utilities) tests
16 #include <lttng-utils/debug-info/dwarf.h>
21 #define SO_NAME "libhello_so"
22 #define DWARF_DIR_NAME "dwarf_full"
23 #define ELF_DIR_NAME "elf_only"
26 * Test that we fail on an ELF file without DWARF.
29 void test_bt_no_dwarf(const char *data_dir
)
33 Dwarf
*dwarf_info
= NULL
;
35 path
= g_build_filename(data_dir
, ELF_DIR_NAME
, SO_NAME
, NULL
);
37 diag("Failed to allocate memory for path");
41 fd
= open(path
, O_RDONLY
);
42 ok(fd
>= 0, "Open ELF file %s", path
);
44 skip(1, "dwarf_begin failed as expected");
46 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
47 ok(!dwarf_info
, "dwarf_begin failed as expected");
51 dwarf_end(dwarf_info
);
61 * Test with a proper ELF file with DWARF.
64 void test_bt_dwarf(const char *data_dir
)
68 char *die_name
= NULL
;
69 struct bt_dwarf_cu
*cu
= NULL
;
70 struct bt_dwarf_die
*die
= NULL
;
71 Dwarf
*dwarf_info
= NULL
;
73 path
= g_build_filename(data_dir
, DWARF_DIR_NAME
, SO_NAME
, NULL
);
75 diag("Failed to allocate memory for path");
79 fd
= open(path
, O_RDONLY
);
80 ok(fd
>= 0, "Open DWARF file %s", path
);
84 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
85 ok(dwarf_info
, "dwarf_begin successful");
86 cu
= bt_dwarf_cu_create(dwarf_info
);
87 ok(cu
, "bt_dwarf_cu_create successful");
88 ret
= bt_dwarf_cu_next(cu
);
89 ok(ret
== 0, "bt_dwarf_cu_next successful");
90 die
= bt_dwarf_die_create(cu
);
91 ok(die
, "bt_dwarf_die_create successful");
96 * Test bt_dwarf_die_next twice, as the code path is different
97 * for DIEs at depth 0 (just created) and other depths.
99 ret
= bt_dwarf_die_next(die
);
100 ok(ret
== 0, "bt_dwarf_die_next from root DIE successful");
102 "bt_dwarf_die_next from root DIE - correct depth value");
103 ret
= bt_dwarf_die_next(die
);
105 "bt_dwarf_die_next from non-root DIE successful");
107 "bt_dwarf_die_next from non-root DIE - correct depth value");
109 /* Reset DIE to test dwarf_child */
110 bt_dwarf_die_destroy(die
);
111 die
= bt_dwarf_die_create(cu
);
113 diag("Failed to create bt_dwarf_die");
117 ret
= bt_dwarf_die_child(die
);
118 ok(ret
== 0, "bt_dwarf_die_child successful");
119 ok(die
->depth
== 1, "bt_dwarf_die_child - correct depth value");
121 ret
= bt_dwarf_die_get_tag(die
, &tag
);
122 ok(ret
== 0, "bt_dwarf_die_get_tag successful");
123 ok(tag
== DW_TAG_typedef
, "bt_dwarf_die_get_tag - correct tag value");
124 ret
= bt_dwarf_die_get_name(die
, &die_name
);
125 ok(ret
== 0, "bt_dwarf_die_get_name successful");
126 ok(strcmp(die_name
, "size_t") == 0,
127 "bt_dwarf_die_get_name - correct name value");
129 bt_dwarf_die_destroy(die
);
130 bt_dwarf_cu_destroy(cu
);
131 dwarf_end(dwarf_info
);
137 int main(int argc
, char **argv
)
139 const char *data_dir
;
141 plan_tests(NR_TESTS
);
149 test_bt_no_dwarf(data_dir
);
150 test_bt_dwarf(data_dir
);
152 return exit_status();
This page took 0.033326 seconds and 3 git commands to generate.