4 * Babeltrace bt_dwarf (DWARF utilities) tests
6 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
7 * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; under version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <lttng-utils/debug-info/dwarf.h>
34 #define SO_NAME "libhello_so"
35 #define DWARF_DIR_NAME "dwarf_full"
36 #define ELF_DIR_NAME "elf_only"
39 * Test that we fail on an ELF file without DWARF.
42 void test_bt_no_dwarf(const char *data_dir
)
46 Dwarf
*dwarf_info
= NULL
;
48 path
= g_build_filename(data_dir
, ELF_DIR_NAME
, SO_NAME
, NULL
);
50 diag("Failed to allocate memory for path");
54 fd
= open(path
, O_RDONLY
);
55 ok(fd
>= 0, "Open ELF file %s", path
);
57 skip(1, "dwarf_begin failed as expected");
59 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
60 ok(dwarf_info
== NULL
, "dwarf_begin failed as expected");
63 if (dwarf_info
!= NULL
) {
64 dwarf_end(dwarf_info
);
71 * Test with a proper ELF file with DWARF.
74 void test_bt_dwarf(const char *data_dir
)
78 char *die_name
= NULL
;
79 struct bt_dwarf_cu
*cu
= NULL
;
80 struct bt_dwarf_die
*die
= NULL
;
81 Dwarf
*dwarf_info
= NULL
;
83 path
= g_build_filename(data_dir
, DWARF_DIR_NAME
, SO_NAME
, NULL
);
85 diag("Failed to allocate memory for path");
89 fd
= open(path
, O_RDONLY
);
90 ok(fd
>= 0, "Open DWARF file %s", path
);
94 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
95 ok(dwarf_info
!= NULL
, "dwarf_begin successful");
96 cu
= bt_dwarf_cu_create(dwarf_info
);
97 ok(cu
!= NULL
, "bt_dwarf_cu_create successful");
98 ret
= bt_dwarf_cu_next(cu
);
99 ok(ret
== 0, "bt_dwarf_cu_next successful");
100 die
= bt_dwarf_die_create(cu
);
101 ok(die
!= NULL
, "bt_dwarf_die_create successful");
106 * Test bt_dwarf_die_next twice, as the code path is different
107 * for DIEs at depth 0 (just created) and other depths.
109 ret
= bt_dwarf_die_next(die
);
110 ok(ret
== 0, "bt_dwarf_die_next from root DIE successful");
112 "bt_dwarf_die_next from root DIE - correct depth value");
113 ret
= bt_dwarf_die_next(die
);
115 "bt_dwarf_die_next from non-root DIE successful");
117 "bt_dwarf_die_next from non-root DIE - correct depth value");
119 /* Reset DIE to test dwarf_child */
120 bt_dwarf_die_destroy(die
);
121 die
= bt_dwarf_die_create(cu
);
123 diag("Failed to create bt_dwarf_die");
127 ret
= bt_dwarf_die_child(die
);
128 ok(ret
== 0, "bt_dwarf_die_child successful");
129 ok(die
->depth
== 1, "bt_dwarf_die_child - correct depth value");
131 ret
= bt_dwarf_die_get_tag(die
, &tag
);
132 ok(ret
== 0, "bt_dwarf_die_get_tag successful");
133 ok(tag
== DW_TAG_typedef
, "bt_dwarf_die_get_tag - correct tag value");
134 ret
= bt_dwarf_die_get_name(die
, &die_name
);
135 ok(ret
== 0, "bt_dwarf_die_get_name successful");
136 ok(strcmp(die_name
, "size_t") == 0,
137 "bt_dwarf_die_get_name - correct name value");
139 bt_dwarf_die_destroy(die
);
140 bt_dwarf_cu_destroy(cu
);
141 dwarf_end(dwarf_info
);
147 int main(int argc
, char **argv
)
149 const char *data_dir
;
151 plan_tests(NR_TESTS
);
159 test_bt_no_dwarf(data_dir
);
160 test_bt_dwarf(data_dir
);
This page took 0.048715 seconds and 4 git commands to generate.