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 <babeltrace/dwarf.h>
34 void test_bt_dwarf(const char *data_dir
)
38 char *die_name
= NULL
;
39 struct bt_dwarf_cu
*cu
= NULL
;
40 struct bt_dwarf_die
*die
= NULL
;
41 Dwarf
*dwarf_info
= NULL
;
43 snprintf(path
, PATH_MAX
, "%s/libhello.so", data_dir
);
45 fd
= open(path
, O_RDONLY
);
46 ok(fd
>= 0, "Open DWARF file %s", path
);
47 dwarf_info
= dwarf_begin(fd
, DWARF_C_READ
);
48 ok(dwarf_info
!= NULL
, "dwarf_begin successful");
49 cu
= bt_dwarf_cu_create(dwarf_info
);
50 ok(cu
!= NULL
, "bt_dwarf_cu_create successful");
51 ret
= bt_dwarf_cu_next(cu
);
52 ok(ret
== 0, "bt_dwarf_cu_next successful");
53 die
= bt_dwarf_die_create(cu
);
54 ok(die
!= NULL
, "bt_dwarf_die_create successful");
56 * Test bt_dwarf_die_next twice, as the code path is different
57 * for DIEs at depth 0 (just created) and other depths.
59 ret
= bt_dwarf_die_next(die
);
60 ok(ret
== 0, "bt_dwarf_die_next from root DIE successful");
62 "bt_dwarf_die_next from root DIE - correct depth value");
63 ret
= bt_dwarf_die_next(die
);
65 "bt_dwarf_die_next from non-root DIE successful");
67 "bt_dwarf_die_next from non-root DIE - correct depth value");
69 /* Reset DIE to test dwarf_child */
70 bt_dwarf_die_destroy(die
);
71 die
= bt_dwarf_die_create(cu
);
73 ret
= bt_dwarf_die_child(die
);
74 ok(ret
== 0, "bt_dwarf_die_child successful");
75 ok(die
->depth
== 1, "bt_dwarf_die_child - correct depth value");
77 ret
= bt_dwarf_die_get_tag(die
, &tag
);
78 ok(ret
== 0, "bt_dwarf_die_get_tag successful");
79 ok(tag
== DW_TAG_typedef
, "bt_dwarf_die_get_tag - correct tag value");
80 ret
= bt_dwarf_die_get_name(die
, &die_name
);
81 ok(ret
== 0, "bt_dwarf_die_get_name successful");
82 ok(strcmp(die_name
, "size_t") == 0,
83 "bt_dwarf_die_get_name - correct name value");
85 bt_dwarf_die_destroy(die
);
86 bt_dwarf_cu_destroy(cu
);
87 dwarf_end(dwarf_info
);
92 int main(int argc
, char **argv
)
104 test_bt_dwarf(data_dir
);
This page took 0.03234 seconds and 4 git commands to generate.