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.
28 #include <lttng-utils/debug-info/dwarf.h>
33 #define SO_NAME "libhello_so"
34 #define DWARF_DIR_NAME "dwarf_full"
37 void test_bt_dwarf(const char *data_dir
)
41 char *die_name
= NULL
;
42 struct bt_dwarf_cu
*cu
= NULL
;
43 struct bt_dwarf_die
*die
= NULL
;
44 Dwarf
*dwarf_info
= NULL
;
46 path
= g_build_filename(data_dir
, DWARF_DIR_NAME
, SO_NAME
, NULL
);
51 fd
= open(path
, O_RDONLY
);
52 ok(fd
>= 0, "Open DWARF file %s", path
);
56 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
57 ok(dwarf_info
!= NULL
, "dwarf_begin successful");
58 cu
= bt_dwarf_cu_create(dwarf_info
);
59 ok(cu
!= NULL
, "bt_dwarf_cu_create successful");
60 ret
= bt_dwarf_cu_next(cu
);
61 ok(ret
== 0, "bt_dwarf_cu_next successful");
62 die
= bt_dwarf_die_create(cu
);
63 ok(die
!= NULL
, "bt_dwarf_die_create successful");
68 * Test bt_dwarf_die_next twice, as the code path is different
69 * for DIEs at depth 0 (just created) and other depths.
71 ret
= bt_dwarf_die_next(die
);
72 ok(ret
== 0, "bt_dwarf_die_next from root DIE successful");
74 "bt_dwarf_die_next from root DIE - correct depth value");
75 ret
= bt_dwarf_die_next(die
);
77 "bt_dwarf_die_next from non-root DIE successful");
79 "bt_dwarf_die_next from non-root DIE - correct depth value");
81 /* Reset DIE to test dwarf_child */
82 bt_dwarf_die_destroy(die
);
83 die
= bt_dwarf_die_create(cu
);
85 diag("Failed to create bt_dwarf_die");
89 ret
= bt_dwarf_die_child(die
);
90 ok(ret
== 0, "bt_dwarf_die_child successful");
91 ok(die
->depth
== 1, "bt_dwarf_die_child - correct depth value");
93 ret
= bt_dwarf_die_get_tag(die
, &tag
);
94 ok(ret
== 0, "bt_dwarf_die_get_tag successful");
95 ok(tag
== DW_TAG_typedef
, "bt_dwarf_die_get_tag - correct tag value");
96 ret
= bt_dwarf_die_get_name(die
, &die_name
);
97 ok(ret
== 0, "bt_dwarf_die_get_name successful");
98 ok(strcmp(die_name
, "size_t") == 0,
99 "bt_dwarf_die_get_name - correct name value");
101 bt_dwarf_die_destroy(die
);
102 bt_dwarf_cu_destroy(cu
);
103 dwarf_end(dwarf_info
);
109 int main(int argc
, char **argv
)
111 const char *data_dir
;
113 plan_tests(NR_TESTS
);
121 test_bt_dwarf(data_dir
);
This page took 0.044211 seconds and 4 git commands to generate.