summaryrefslogtreecommitdiff
path: root/test/libdwarf/ts
diff options
context:
space:
mode:
authorKai Wang <kaiw@FreeBSD.org>2014-01-15 08:43:20 +0000
committerKai Wang <kaiw@FreeBSD.org>2014-01-15 08:43:20 +0000
commit5265ace0e440a23fb522c516f4ee20f43eaed2b3 (patch)
tree13068447bb61372f7540b168e913b8eb88ef7578 /test/libdwarf/ts
Notes
Diffstat (limited to 'test/libdwarf/ts')
-rw-r--r--test/libdwarf/ts/Makefile25
-rw-r--r--test/libdwarf/ts/Makefile.tset56
-rw-r--r--test/libdwarf/ts/README34
-rwxr-xr-xtest/libdwarf/ts/bin/count-ic38
-rw-r--r--test/libdwarf/ts/common/die_traverse.c104
-rw-r--r--test/libdwarf/ts/common/driver.c890
-rw-r--r--test/libdwarf/ts/common/driver.h172
-rwxr-xr-xtest/libdwarf/ts/common/object/dt32-g1.gzbin0 -> 9724 bytes
-rwxr-xr-xtest/libdwarf/ts/common/object/dt64-g1.gzbin0 -> 9841 bytes
-rwxr-xr-xtest/libdwarf/ts/common/object/dt64-g3.gzbin0 -> 30254 bytes
-rw-r--r--test/libdwarf/ts/common/object/dto64-g1.gzbin0 -> 7880 bytes
-rwxr-xr-xtest/libdwarf/ts/common/object/ec32-g1.gzbin0 -> 277478 bytes
-rwxr-xr-xtest/libdwarf/ts/common/object/ec64-g1.gzbin0 -> 301342 bytes
-rwxr-xr-xtest/libdwarf/ts/common/object/ec64-g3.gzbin0 -> 323788 bytes
-rw-r--r--test/libdwarf/ts/dwarf_abbrev/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_abbrev/dt32-g1.xml.gzbin0 -> 1328 bytes
-rw-r--r--test/libdwarf/ts/dwarf_abbrev/dto64-g1.xml.gzbin0 -> 1334 bytes
-rw-r--r--test/libdwarf/ts/dwarf_abbrev/dwarf_abbrev.c125
-rw-r--r--test/libdwarf/ts/dwarf_abbrev/ec64-g1.xml.gzbin0 -> 8447 bytes
-rw-r--r--test/libdwarf/ts/dwarf_arange/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_arange/dt32-g1.xml.gzbin0 -> 198 bytes
-rw-r--r--test/libdwarf/ts/dwarf_arange/dt64-g1.xml.gzbin0 -> 197 bytes
-rw-r--r--test/libdwarf/ts/dwarf_arange/dwarf_arange.c127
-rw-r--r--test/libdwarf/ts/dwarf_arange/ec32-g1.xml.gzbin0 -> 328 bytes
-rw-r--r--test/libdwarf/ts/dwarf_arange/ec64-g1.xml.gzbin0 -> 316 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attr/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_attr/dt32-g1.xml.gzbin0 -> 1463 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attr/dt64-g1.xml.gzbin0 -> 1468 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attr/dto64-g1.xml.gzbin0 -> 1470 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attr/dwarf_attr.c198
-rw-r--r--test/libdwarf/ts/dwarf_attr/ec32-g1.xml.gzbin0 -> 14221 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attr/ec64-g1.xml.gzbin0 -> 14231 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/dt32-g1.xml.gzbin0 -> 750 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/dt64-g1.xml.gzbin0 -> 753 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/dwarf_attrlist.c129
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/ec32-g1.xml.gzbin0 -> 5465 bytes
-rw-r--r--test/libdwarf/ts/dwarf_attrlist/ec64-g1.xml.gzbin0 -> 5475 bytes
-rw-r--r--test/libdwarf/ts/dwarf_child/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_child/dt32-g1.xml.gzbin0 -> 135 bytes
-rw-r--r--test/libdwarf/ts/dwarf_child/dt64-g1.xml.gzbin0 -> 136 bytes
-rw-r--r--test/libdwarf/ts/dwarf_child/dwarf_child.c138
-rw-r--r--test/libdwarf/ts/dwarf_child/ec32-g1.xml.gzbin0 -> 138 bytes
-rw-r--r--test/libdwarf/ts/dwarf_child/ec64-g1.xml.gzbin0 -> 138 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/dt32-g1.xml.gzbin0 -> 822 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/dt64-g1.xml.gzbin0 -> 819 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/dwarf_die_convenience.c242
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/ec32-g1.xml.gzbin0 -> 5960 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_convenience/ec64-g1.xml.gzbin0 -> 5935 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/dt32-g1.xml.gzbin0 -> 1791 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/dt64-g1.xml.gzbin0 -> 1797 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/dwarf_die_offset.c190
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/ec32-g1.xml.gzbin0 -> 19169 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_offset/ec64-g1.xml.gzbin0 -> 19118 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_query/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_die_query/dt32-g1.xml.gzbin0 -> 1461 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_query/dt64-g1.xml.gzbin0 -> 1459 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_query/dto64-g1.xml.gzbin0 -> 1458 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_query/dwarf_die_query.c154
-rw-r--r--test/libdwarf/ts/dwarf_die_query/ec32-g1.xml.gzbin0 -> 12687 bytes
-rw-r--r--test/libdwarf/ts/dwarf_die_query/ec64-g1.xml.gzbin0 -> 12685 bytes
-rw-r--r--test/libdwarf/ts/dwarf_form/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_form/dt32-g1.xml.gzbin0 -> 8114 bytes
-rw-r--r--test/libdwarf/ts/dwarf_form/dt64-g1.xml.gzbin0 -> 8140 bytes
-rw-r--r--test/libdwarf/ts/dwarf_form/dwarf_form.c270
-rw-r--r--test/libdwarf/ts/dwarf_form/ec32-g1.xml.gzbin0 -> 89574 bytes
-rw-r--r--test/libdwarf/ts/dwarf_form/ec64-g1.xml.gzbin0 -> 89610 bytes
-rw-r--r--test/libdwarf/ts/dwarf_frame/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_frame/dt64-g1.xml.gzbin0 -> 10646 bytes
-rw-r--r--test/libdwarf/ts/dwarf_frame/dto64-g1.xml.gzbin0 -> 5059 bytes
-rw-r--r--test/libdwarf/ts/dwarf_frame/dwarf_frame.c498
-rw-r--r--test/libdwarf/ts/dwarf_frame/ec32-g1.xml.gzbin0 -> 104318 bytes
-rw-r--r--test/libdwarf/ts/dwarf_get_address_size/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_get_address_size/dt32-g1.xml.gzbin0 -> 127 bytes
-rw-r--r--test/libdwarf/ts/dwarf_get_address_size/dt64-g1.xml.gzbin0 -> 128 bytes
-rw-r--r--test/libdwarf/ts/dwarf_get_address_size/dwarf_get_address_size.c87
-rw-r--r--test/libdwarf/ts/dwarf_init/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_init/dt32-g1.xml.gzbin0 -> 90 bytes
-rw-r--r--test/libdwarf/ts/dwarf_init/dt64-g1.xml.gzbin0 -> 90 bytes
-rw-r--r--test/libdwarf/ts/dwarf_init/dwarf_init.c82
-rw-r--r--test/libdwarf/ts/dwarf_init/ec32-g1.xml.gzbin0 -> 90 bytes
-rw-r--r--test/libdwarf/ts/dwarf_init/ec64-g1.xml.gzbin0 -> 90 bytes
-rw-r--r--test/libdwarf/ts/dwarf_lineno/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_lineno/dt32-g1.xml.gzbin0 -> 1478 bytes
-rw-r--r--test/libdwarf/ts/dwarf_lineno/dt64-g1.xml.gzbin0 -> 1470 bytes
-rw-r--r--test/libdwarf/ts/dwarf_lineno/dto64-g1.xml.gzbin0 -> 1446 bytes
-rw-r--r--test/libdwarf/ts/dwarf_lineno/dwarf_lineno.c278
-rw-r--r--test/libdwarf/ts/dwarf_lineno/ec32-g1.xml.gzbin0 -> 17688 bytes
-rw-r--r--test/libdwarf/ts/dwarf_lineno/ec64-g1.xml.gzbin0 -> 17539 bytes
-rw-r--r--test/libdwarf/ts/dwarf_loclist/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_loclist/dt32-g1.xml.gzbin0 -> 3672 bytes
-rw-r--r--test/libdwarf/ts/dwarf_loclist/dt64-g1.xml.gzbin0 -> 3298 bytes
-rw-r--r--test/libdwarf/ts/dwarf_loclist/dwarf_loclist.c234
-rw-r--r--test/libdwarf/ts/dwarf_loclist/ec32-g1.xml.gzbin0 -> 30295 bytes
-rw-r--r--test/libdwarf/ts/dwarf_loclist/ec64-g1.xml.gzbin0 -> 32586 bytes
-rw-r--r--test/libdwarf/ts/dwarf_macinfo/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_macinfo/dt64-g1.xml.gzbin0 -> 129 bytes
-rw-r--r--test/libdwarf/ts/dwarf_macinfo/dt64-g3.xml.gzbin0 -> 94883 bytes
-rw-r--r--test/libdwarf/ts/dwarf_macinfo/dwarf_macinfo.c137
-rw-r--r--test/libdwarf/ts/dwarf_macinfo/ec64-g3.xml.gzbin0 -> 263347 bytes
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/dt32-g1.xml.gzbin0 -> 244 bytes
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/dt64-g1.xml.gzbin0 -> 246 bytes
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/dwarf_next_cu_header.c149
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/ec32-g1.xml.gzbin0 -> 352 bytes
-rw-r--r--test/libdwarf/ts/dwarf_next_cu_header/ec64-g1.xml.gzbin0 -> 358 bytes
-rw-r--r--test/libdwarf/ts/dwarf_pubnames/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_pubnames/dt32-g1.xml.gzbin0 -> 177 bytes
-rw-r--r--test/libdwarf/ts/dwarf_pubnames/dwarf_pubnames.c114
-rw-r--r--test/libdwarf/ts/dwarf_pubnames/ec64-g1.xml.gzbin0 -> 604 bytes
-rw-r--r--test/libdwarf/ts/dwarf_ranges/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_ranges/dt32-g1.xml.gzbin0 -> 759 bytes
-rw-r--r--test/libdwarf/ts/dwarf_ranges/dwarf_ranges.c102
-rw-r--r--test/libdwarf/ts/dwarf_ranges/ec64-g1.xml.gzbin0 -> 4492 bytes
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/Makefile8
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/dt32-g1.xml.gzbin0 -> 137 bytes
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/dt64-g1.xml.gzbin0 -> 138 bytes
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/dwarf_siblingof.c160
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/ec32-g1.xml.gzbin0 -> 140 bytes
-rw-r--r--test/libdwarf/ts/dwarf_siblingof/ec64-g1.xml.gzbin0 -> 140 bytes
122 files changed, 4885 insertions, 0 deletions
diff --git a/test/libdwarf/ts/Makefile b/test/libdwarf/ts/Makefile
new file mode 100644
index 0000000000000..84d6e2404b142
--- /dev/null
+++ b/test/libdwarf/ts/Makefile
@@ -0,0 +1,25 @@
+#
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+#
+
+SUBDIR+= dwarf_init
+SUBDIR+= dwarf_next_cu_header
+SUBDIR+= dwarf_get_address_size
+SUBDIR+= dwarf_siblingof
+SUBDIR+= dwarf_child
+SUBDIR+= dwarf_die_query
+SUBDIR+= dwarf_die_offset
+SUBDIR+= dwarf_die_convenience
+SUBDIR+= dwarf_attr
+SUBDIR+= dwarf_attrlist
+SUBDIR+= dwarf_form
+SUBDIR+= dwarf_loclist
+SUBDIR+= dwarf_lineno
+SUBDIR+= dwarf_frame
+SUBDIR+= dwarf_arange
+SUBDIR+= dwarf_abbrev
+SUBDIR+= dwarf_pubnames
+SUBDIR+= dwarf_macinfo
+SUBDIR+= dwarf_ranges
+
+.include <bsd.subdir.mk>
diff --git a/test/libdwarf/ts/Makefile.tset b/test/libdwarf/ts/Makefile.tset
new file mode 100644
index 0000000000000..af0f82a10dbc1
--- /dev/null
+++ b/test/libdwarf/ts/Makefile.tset
@@ -0,0 +1,56 @@
+# $Id: Makefile.tset 2198 2011-11-23 16:13:45Z jkoshy $
+
+.include "${TOP}/mk/elftoolchain.os.mk"
+
+# libdwarf test suite uses libdwarf in /usr/local (i.e. SGI libdwarf),
+# if TCGEN is defined.
+.if defined(TCGEN)
+DWARF_INC?= /usr/local/include
+DWARF_LIBS?= /usr/local/lib
+CFLAGS+= -DTCGEN -I${DWARF_INC}
+LDADD+= -L${DWARF_LIBS}
+.endif
+LDADD+= -ldwarf
+
+DPADD+= ${LIBELF}
+LDADD+= -lelf
+
+# Determine the location of the XML handling library.
+.if ${OS_HOST} == FreeBSD
+LDADD+= -lbsdxml
+.else
+.if ${OS_HOST} == DragonFly || ${OS_HOST} == NetBSD
+CFLAGS+= -I/usr/pkg/include
+LDADD+= -L/usr/pkg/lib
+.endif
+LDADD+= -lexpat
+.endif
+
+.if !defined(TCGEN)
+TS_SRCS+= ${.OBJDIR}/ic_count.c
+${.OBJDIR}/ic_count.c:
+ ${TS_ROOT}/bin/count-ic ${.OBJDIR}
+CLEANFILES+= ${.OBJDIR}/ic_count.c
+.endif
+
+.for f in ${TS_DATA}
+CLEANFILES+= ${f}.xml
+.endfor
+
+# Copy test objects(binaries) to the build directory.
+.for f in ${TS_DATA}
+.if !exists(${f:R})
+${f}: ${TS_OBJROOT}/common/object/${f}.gz
+ cp ${.ALLSRC} ${.TARGET}.gz
+ gunzip ${.TARGET}.gz
+.endif
+.endfor
+
+# NetBSD turns on -Wstrict-prototypes for WARNS>0; however
+# TET 3.8's headers do not compile with -Wstrict-prototypes.
+.if ${OS_HOST} != NetBSD
+WARNS?= 2
+.endif
+
+# Test cases do not have manual pages.
+NOMAN= noman
diff --git a/test/libdwarf/ts/README b/test/libdwarf/ts/README
new file mode 100644
index 0000000000000..b163c50a7ccd9
--- /dev/null
+++ b/test/libdwarf/ts/README
@@ -0,0 +1,34 @@
+: $Id: README 2084 2011-10-27 04:48:12Z jkoshy $
+
+Libdwarf test suite use XML files to describe test case, invocable
+component and test purpose.
+
+Each test case can have several XML files, and each XML file
+corresponds to exact one invocable component.
+
+For example, test case dwarf_get_address_size contains following
+XML file:
+
+<ic file='dt32-g1'>
+ <tp func='tp_dwarf_get_address_size'>
+ <vc var='addr_size' type='uint'>4</vc>
+ </tp>
+</ic>
+
+Element 'ic' defines invocable component, in libdwarf test suite, one
+invocable component can be invoked on only one test object (dt32-g1 in
+this case). Element 'tp' defines a test purpose. A 'ic' can have
+multiple 'tp' (only one in this case). Element 'vc' defines a
+"variable check", which means verify varible's value against constant.
+In this example, test purpose tp_dwarf_get_address_size will verify
+that variable addr_size has value 4.
+
+When a test case is compiled nomarlly, during test case startup, the
+test driver will parse the XML files and report to TET how many IC and
+TP this test case have. When each TP is executed, test driver will
+verify variable values according to the list of VC defined in that TP.
+
+When a test case is compiled with 'make TCGEN=yes', it will instead
+link with SGI libdwarf and genearte XML files during TP execution.
+These generated XML files can then be used directly to test this
+libdwarf implementation.
diff --git a/test/libdwarf/ts/bin/count-ic b/test/libdwarf/ts/bin/count-ic
new file mode 100755
index 0000000000000..8c3c249a80925
--- /dev/null
+++ b/test/libdwarf/ts/bin/count-ic
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# $Id: count-ic 2084 2011-10-27 04:48:12Z jkoshy $
+#
+# This shell script generates ic_count.c which contains a single
+# variable definition `ic_count'. Variable `ic_count' is assigned
+# the number of IC (invocable components) in the directory `dir'.
+# The script count IC number by simply counting the number
+# of .xml.gz files contained in the `dir', based on the fact that
+# one .xml.gz file defines exactly one IC.
+
+usage()
+{
+ echo "usage:" `basename $0` "dir"
+}
+
+
+if [ $# -ne 1 ]; then
+ usage
+ exit 1
+fi
+
+dir=$1
+
+if [ ! -d ${dir} ]; then
+ echo "${dir} does not exist or is not a directory"
+ exit 1
+fi
+
+count=`ls ${dir}/*.xml.gz | wc -l | awk '{print $1}'`
+output="${dir}/ic_count.c"
+
+exec > ${output}
+echo "
+/* WARNING GENERATED FILE */
+
+int ic_count = ${count};
+"
diff --git a/test/libdwarf/ts/common/die_traverse.c b/test/libdwarf/ts/common/die_traverse.c
new file mode 100644
index 0000000000000..0dde964f15220
--- /dev/null
+++ b/test/libdwarf/ts/common/die_traverse.c
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: die_traverse.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <libdwarf.h>
+
+#include "driver.h"
+
+static int die_cnt;
+
+/*
+ * DIE traverse function shared by test cases.
+ */
+
+static void
+_die_traverse_recursive(Dwarf_Debug dbg, Dwarf_Die die,
+ void (*die_callback)(Dwarf_Die die))
+{
+ Dwarf_Die die0;
+ Dwarf_Off offset;
+ Dwarf_Half tag;
+ Dwarf_Error de;
+ const char *tagname;
+ int r;
+
+ assert(dbg != NULL && die != NULL && die_callback != NULL);
+
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ tagname = NULL;
+ if (dwarf_get_TAG_name(tag, &tagname) != DW_DLV_OK) {
+ tet_infoline("dwarf_get_TAG_name failed");
+ result = TET_FAIL;
+ }
+ offset = 0;
+ if (dwarf_dieoffset(die, &offset, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_dieoffset failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ tet_printf("DIE #%d (%s) [%#x]\n", die_cnt++, tagname, offset);
+
+ die_callback(die);
+
+ /* Search children. */
+ r = dwarf_child(die, &die0, &de);
+ if (r == DW_DLV_ERROR)
+ tet_printf("%s: dwarf_child failed: %s", __func__,
+ dwarf_errmsg(de));
+ else if (r == DW_DLV_OK)
+ _die_traverse_recursive(dbg, die0, die_callback);
+
+ /* Search sibling. */
+ r = dwarf_siblingof(dbg, die, &die0, &de);
+ if (r == DW_DLV_ERROR)
+ tet_printf("%s: dwarf_siblingof failed: %s", __func__,
+ dwarf_errmsg(de));
+ else if (r == DW_DLV_OK)
+ _die_traverse_recursive(dbg, die0, die_callback);
+}
+
+static void
+_die_traverse(Dwarf_Debug dbg, void (*die_callback)(Dwarf_Die die))
+{
+ Dwarf_Die die;
+ Dwarf_Error de;
+ Dwarf_Unsigned cu_next_offset;
+
+ assert(dbg != NULL && die_callback != NULL);
+
+ die_cnt = 0;
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_siblingof(dbg, NULL, &die, &de) != DW_DLV_OK)
+ break;
+ _die_traverse_recursive(dbg, die, die_callback);
+ }
+}
diff --git a/test/libdwarf/ts/common/driver.c b/test/libdwarf/ts/common/driver.c
new file mode 100644
index 0000000000000..2a4a2945fd8e1
--- /dev/null
+++ b/test/libdwarf/ts/common/driver.c
@@ -0,0 +1,890 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: driver.c 2121 2011-11-09 08:43:56Z jkoshy $
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+#include <unistd.h>
+#ifdef __FreeBSD__
+#include <bsdxml.h>
+#else
+#include <expat.h>
+#endif
+
+#include "driver.h"
+#include "tet_api.h"
+
+#ifndef TCGEN
+#define _XML_BUFSIZE 8192
+#define _XML_DATABUFSZ 65536
+struct _drv_vc {
+ const char *var;
+ union {
+ uint64_t u64;
+ int64_t i64;
+ char *str;
+ struct {
+ char *data;
+ int len;
+ } b;
+ } v;
+ enum {
+ _VTYPE_NONE,
+ _VTYPE_INT,
+ _VTYPE_UINT,
+ _VTYPE_STRING,
+ _VTYPE_BLOCK,
+ } vt;
+ enum {
+ _OP_EQ,
+ _OP_NE,
+ } op;
+ enum {
+ _FAIL_CONTINUE,
+ _FAIL_ABORT,
+ } fail;
+ STAILQ_ENTRY(_drv_vc) next;
+};
+struct _drv_tp {
+ struct dwarf_tp *dtp;
+ int testnum;
+ STAILQ_HEAD(, _drv_vc) vclist;
+ STAILQ_ENTRY(_drv_tp) next;
+};
+struct _drv_ic {
+ const char *file;
+ int tpcnt;
+ STAILQ_HEAD(, _drv_tp) tplist;
+ STAILQ_ENTRY(_drv_ic) next;
+};
+extern int ic_count;
+static STAILQ_HEAD(, _drv_ic) _iclist;
+static struct _drv_ic *_cur_ic = NULL;
+static struct _drv_tp *_cur_tp = NULL;
+static struct _drv_vc *_cur_vc = NULL;
+static char _xml_buf[_XML_BUFSIZE];
+static char _xml_data[_XML_DATABUFSZ];
+static int _xml_data_pos = 0;
+static int _test_cnt = 0;
+#else
+FILE *_cur_fp = NULL;
+#endif /* !TCGEN */
+
+/* The name of the file currently being processed. */
+const char *_cur_file = NULL;
+
+static void driver_startup(void);
+static void driver_cleanup(void);
+static __attribute__ ((unused)) char * driver_string_encode(const char *str);
+#ifndef TCGEN
+static void driver_base64_decode(const char *code, int codesize, char **plain,
+ int *plainsize);
+#else
+static __attribute__ ((unused)) void driver_base64_encode(const char *plain,
+ int plainsize, char **code, int *codesize);
+#endif /* !TCGEN */
+
+void (*tet_startup)(void) = driver_startup;
+void (*tet_cleanup)(void) = driver_cleanup;
+
+/*
+ * Functions used by TCM for supporting a dynamic test case.
+ */
+
+#ifndef TCGEN
+static struct _drv_ic *
+_find_ic(int icnum)
+{
+ struct _drv_ic *ic;
+ int i;
+
+ for (i = 1, ic = STAILQ_FIRST(&_iclist);
+ i < icnum && ic != NULL;
+ i++, ic = STAILQ_NEXT(ic, next))
+ ;
+
+ return (ic);
+}
+
+static struct _drv_tp *
+_find_tp(int icnum, int tpnum)
+{
+ struct _drv_ic *ic;
+ struct _drv_tp *tp;
+ int i;
+
+ ic = _find_ic(icnum);
+ assert(ic != NULL);
+ for (i = 1, tp = STAILQ_FIRST(&ic->tplist);
+ i < tpnum && tp != NULL;
+ i++, tp = STAILQ_NEXT(tp, next))
+ ;
+
+ return (tp);
+}
+#endif /* !TCGEN */
+
+int
+tet_getminic(void)
+{
+
+ return (1); /* IC start with 1. */
+}
+
+int
+tet_getmaxic(void)
+{
+
+#ifdef TCGEN
+ return (1);
+#else
+ return (ic_count);
+#endif /* TCGEN */
+}
+
+int
+tet_isdefic(int icnum)
+{
+
+#ifdef TCGEN
+ assert(icnum == 1);
+ return (1);
+#else
+ if (icnum >= 1 && icnum <= ic_count)
+ return (1);
+
+ return (0);
+#endif /* TCGEN */
+}
+
+int
+tet_gettpcount(int icnum)
+{
+#ifdef TCGEN
+ assert(icnum == 1);
+ return (1);
+#else
+ struct _drv_ic *ic;
+
+ ic = _find_ic(icnum);
+ assert(ic != NULL);
+
+ return (ic->tpcnt);
+#endif /* TCGEN */
+}
+
+int
+tet_gettestnum(int icnum, int tpnum)
+{
+#ifdef TCGEN
+ assert(icnum == 1 && tpnum == 1);
+ return (1);
+#else
+ struct _drv_tp *tp;
+
+ tp = _find_tp(icnum, tpnum);
+ assert(tp != NULL);
+
+ return (tp->testnum);
+#endif /* TCGEN */
+}
+
+int
+tet_invoketp(int icnum, int tpnum)
+{
+#ifdef TCGEN
+ assert(icnum == 1 && tpnum == 1);
+ return (0);
+#else
+ struct _drv_ic *ic;
+ struct _drv_tp *tp;
+
+ ic = _find_ic(icnum);
+ assert(ic != NULL);
+ _cur_ic = ic;
+ _cur_file = _cur_ic->file;
+ tp = _find_tp(icnum, tpnum);
+ assert(tp != NULL && tp->dtp != NULL);
+ tet_printf("Start Test Purpose <%s> on <%s>\n", tp->dtp->tp_name,
+ _cur_ic->file);
+ _cur_vc = STAILQ_FIRST(&tp->vclist);
+ tp->dtp->tp_func();
+
+ return (0);
+#endif /* TCGEN */
+}
+
+#ifndef TCGEN
+static void
+_xml_start_cb(void *data, const char *el, const char **attr)
+{
+ XML_Parser p;
+ int i, j;
+
+ p = data;
+
+ if (!strcmp(el, "ic")) {
+ if (_cur_ic != NULL)
+ errx(EXIT_FAILURE, "Nested IC at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ _cur_ic = calloc(1, sizeof(*_cur_ic));
+ STAILQ_INIT(&_cur_ic->tplist);
+ if (_cur_ic == NULL)
+ err(EXIT_FAILURE, "calloc");
+ for (i = 0; attr[i]; i += 2) {
+ if (!strcmp(attr[i], "file")) {
+ _cur_ic->file = strdup(attr[i + 1]);
+ if (_cur_ic->file == NULL)
+ err(EXIT_FAILURE, "strdup");
+ break;
+ }
+ }
+ if (_cur_ic->file == NULL)
+ errx(EXIT_FAILURE, "IC without 'file' attribute "
+ "at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+
+ } else if (!strcmp(el, "tp")) {
+ if (_cur_ic == NULL)
+ errx(EXIT_FAILURE, "TP without containing IC at "
+ "line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ if (_cur_tp != NULL)
+ errx(EXIT_FAILURE, "Nested TP at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ _cur_tp = calloc(1, sizeof(*_cur_tp));
+ STAILQ_INIT(&_cur_tp->vclist);
+ if (_cur_tp == NULL)
+ err(EXIT_FAILURE, "calloc");
+ for (i = 0; attr[i]; i += 2) {
+ if (!strcmp(attr[i], "func")) {
+ for (j = 0; dwarf_tp_array[j].tp_name != NULL;
+ j++)
+ if (!strcmp(attr[i + 1],
+ dwarf_tp_array[j].tp_name)) {
+ _cur_tp->dtp =
+ &dwarf_tp_array[j];
+ break;
+ }
+ if (_cur_tp->dtp == NULL)
+ errx(EXIT_FAILURE,
+ "TP function '%s' not found",
+ attr[i]);
+ break;
+ }
+ }
+ if (_cur_tp->dtp == NULL)
+ errx(EXIT_FAILURE,
+ "TP without 'func' attribute at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+
+ } else if (!strcmp(el, "vc")) {
+ if (_cur_tp == NULL)
+ errx(EXIT_FAILURE,
+ "VC without containing IC at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ if (_cur_vc != NULL)
+ errx(EXIT_FAILURE, "Nested VC at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ _cur_vc = calloc(1, sizeof(*_cur_vc));
+
+ _cur_vc->op = _OP_EQ;
+ _cur_vc->fail = _FAIL_CONTINUE;
+ if (_cur_vc == NULL)
+ err(EXIT_FAILURE, "calloc");
+ for (i = 0; attr[i]; i += 2) {
+ if (!strcmp(attr[i], "var")) {
+ _cur_vc->var = strdup(attr[i + 1]);
+ if (_cur_vc->var == NULL)
+ err(EXIT_FAILURE, "strdup");
+ } else if (!strcmp(attr[i], "type")) {
+ if (!strcmp(attr[i + 1], "int"))
+ _cur_vc->vt = _VTYPE_INT;
+ else if (!strcmp(attr[i + 1], "uint"))
+ _cur_vc->vt = _VTYPE_UINT;
+ else if (!strcmp(attr[i + 1], "str"))
+ _cur_vc->vt = _VTYPE_STRING;
+ else if (!strcmp(attr[i + 1], "block"))
+ _cur_vc->vt = _VTYPE_BLOCK;
+ else
+ errx(EXIT_FAILURE,
+ "Unknown value type %s at "
+ "line %jd", attr[i + 1],
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ } else if (!strcmp(attr[i], "op")) {
+ if (!strcmp(attr[i + 1], "ne"))
+ _cur_vc->op = _OP_NE;
+ } else if (!strcmp(attr[i], "fail")) {
+ if (!strcmp(attr[i + 1], "abort"))
+ _cur_vc->fail = _FAIL_ABORT;
+ } else
+ errx(EXIT_FAILURE,
+ "Unknown attr %s at line %jd",
+ attr[i],
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ }
+ if (_cur_vc->var == NULL || _cur_vc->vt == _VTYPE_NONE)
+ errx(EXIT_FAILURE,
+ "VC without 'var' or 'type' attribute at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ } else
+ errx(EXIT_FAILURE, "Unknown element %s at line %jd", el,
+ (intmax_t) XML_GetCurrentLineNumber(p));
+}
+
+static void
+_xml_end_cb(void *data, const char *el)
+{
+ XML_Parser p;
+
+ p = data;
+
+ if (!strcmp(el, "ic")) {
+ if (_cur_ic == NULL)
+ errx(EXIT_FAILURE, "bogus IC end tag at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ STAILQ_INSERT_TAIL(&_iclist, _cur_ic, next);
+ _cur_ic = NULL;
+ } else if (!strcmp(el, "tp")) {
+ if (_cur_tp == NULL)
+ errx(EXIT_FAILURE, "bogus TP end tag at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ assert(_cur_ic != NULL);
+ _test_cnt++;
+ _cur_tp->testnum = _test_cnt;
+ STAILQ_INSERT_TAIL(&_cur_ic->tplist, _cur_tp, next);
+ _cur_ic->tpcnt++;
+ _cur_tp = NULL;
+ } else if (!strcmp(el, "vc")) {
+ if (_cur_vc == NULL)
+ errx(EXIT_FAILURE, "bogus VC end tag at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ if (_xml_data_pos == 0 && _cur_vc->vt != _VTYPE_STRING)
+ errx(EXIT_FAILURE,
+ "VC element without value defined at line %jd",
+ (intmax_t) XML_GetCurrentLineNumber(p));
+ _xml_data[_xml_data_pos] = '\0';
+ switch (_cur_vc->vt) {
+ case _VTYPE_INT:
+ _cur_vc->v.i64 = strtoimax(_xml_data, NULL, 0);
+ break;
+ case _VTYPE_UINT:
+ _cur_vc->v.u64 = strtoumax(_xml_data, NULL, 0);
+ break;
+ case _VTYPE_STRING:
+ _cur_vc->v.str = strdup(_xml_data);
+ if (_cur_vc->v.str == NULL)
+ err(EXIT_FAILURE, "strdup");
+ break;
+ case _VTYPE_BLOCK:
+ driver_base64_decode(_xml_data, _xml_data_pos,
+ &_cur_vc->v.b.data, &_cur_vc->v.b.len);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ _xml_data_pos = 0;
+
+ assert(_cur_tp != NULL);
+ STAILQ_INSERT_TAIL(&_cur_tp->vclist, _cur_vc, next);
+ _cur_vc = NULL;
+ }
+}
+
+#define _VALUE_BUFSIZE 1024
+
+static void
+_xml_data_cb(void *data, const char *s, int len)
+{
+
+ (void) data;
+
+ if (_cur_vc != NULL) {
+ if (_xml_data_pos + len >= _XML_DATABUFSZ) {
+ warnx("_xml_data overflowed, data(%d) discarded", len);
+ return;
+ }
+ memcpy(&_xml_data[_xml_data_pos], s, len);
+ _xml_data_pos += len;
+ }
+}
+
+#define _CMD_SIZE 256
+
+static void
+driver_parse_ic_desc(const char *fname)
+{
+ XML_Parser p;
+ ssize_t bytes;
+ int fd, final;
+ char *xml_name, *ext, *fname0;
+ char cmd[_CMD_SIZE];
+
+ if ((fname0 = strdup(fname)) == NULL)
+ err(EXIT_FAILURE, "strdup");
+ fname0[strlen(fname) - 3] = '\0';
+ snprintf(cmd, _CMD_SIZE, "gunzip -f -c %s > %s", fname, fname0);
+ if (system(cmd) < 0)
+ err(EXIT_FAILURE, "system");
+
+ if ((xml_name = strdup(fname)) == NULL)
+ err(EXIT_FAILURE, "strdup");
+ ext = strrchr(xml_name, '.');
+ assert(ext != NULL);
+ *ext = '\0';
+
+ if ((p = XML_ParserCreate(NULL)) == NULL)
+ errx(EXIT_FAILURE, "XML_ParserCreate failed");
+ XML_SetUserData(p, p);
+ XML_SetElementHandler(p, _xml_start_cb, _xml_end_cb);
+ XML_SetCharacterDataHandler(p, _xml_data_cb);
+
+ if ((fd = open(xml_name, O_RDONLY)) < 0)
+ err(EXIT_FAILURE, "open %s failed", xml_name);
+
+ final = 0;
+ for (;;) {
+ bytes = read(fd, _xml_buf, _XML_BUFSIZE);
+ if (bytes < 0)
+ err(EXIT_FAILURE, "read %s failed", xml_name);
+ if (bytes == 0)
+ final = 1;
+ if (!XML_Parse(p, _xml_buf, (int) bytes, final))
+ errx(EXIT_FAILURE, "XML_Parse error at line %jd: %s\n",
+ (intmax_t) XML_GetCurrentLineNumber(p),
+ XML_ErrorString(XML_GetErrorCode(p)));
+ if (final)
+ break;
+ }
+
+ free(xml_name);
+}
+
+static void
+driver_parse_ic(void)
+{
+ struct dirent *dp;
+ DIR *dirp;
+
+ if ((dirp = opendir(".")) == NULL)
+ err(EXIT_FAILURE, "opendir");
+ while ((dp = readdir(dirp)) != NULL) {
+ if (strlen(dp->d_name) <= 7)
+ continue;
+ if (!strcmp(&dp->d_name[strlen(dp->d_name) - 7], ".xml.gz"))
+ driver_parse_ic_desc(dp->d_name);
+ }
+ (void) closedir(dirp);
+}
+
+#else /* !TCGEN */
+
+static void
+driver_gen_tp(FILE *fp, const char *file)
+{
+ int i;
+
+ assert(fp != NULL);
+ for (i = 0; dwarf_tp_array[i].tp_name != NULL; i++) {
+ fprintf(fp, " <tp func='%s'>\n", dwarf_tp_array[i].tp_name);
+ _cur_file = file;
+ _cur_fp = fp;
+ dwarf_tp_array[i].tp_func();
+ fprintf(fp, " </tp>\n");
+ }
+}
+
+#define _FILENAME_BUFSIZE 1024
+#define _CMD_SIZE 256
+
+static void
+driver_gen_ic(void)
+{
+ char *flist, *token;
+ FILE *fp;
+ char nbuf[_FILENAME_BUFSIZE], cmd[_CMD_SIZE];
+
+ flist = getenv("ICLIST");
+ if (flist == NULL)
+ errx(EXIT_FAILURE,
+ "Driver in TCGEN mode but ICLIST env is not defined");
+ if ((flist = strdup(flist)) == NULL)
+ err(EXIT_FAILURE, "strdup");
+ while ((token = strsep(&flist, ":")) != NULL) {
+ snprintf(nbuf, sizeof(nbuf), "%s.xml", token);
+ if ((fp = fopen(nbuf, "w")) == NULL)
+ err(EXIT_FAILURE, "fopen %s failed", nbuf);
+ fprintf(fp, "<ic file='%s'>\n", token);
+ driver_gen_tp(fp, token);
+ fprintf(fp, "</ic>\n");
+ fclose(fp);
+ snprintf(cmd, _CMD_SIZE, "gzip -f %s", nbuf);
+ if (system(cmd) < 0)
+ err(EXIT_FAILURE, "system");
+ }
+ free(flist);
+}
+
+#endif /* !TCGEN */
+
+#define _MAX_STRING_SIZE 65535
+
+static char *
+driver_string_encode(const char *str)
+{
+ static char enc[_MAX_STRING_SIZE];
+ size_t len;
+ int pos;
+
+#define _ENCODE_STRING(S) do { \
+ len = strlen(S); \
+ if (pos + len < _MAX_STRING_SIZE) { \
+ strncpy(enc + pos, S, len); \
+ pos += len; \
+ } else { \
+ assert(0); \
+ return (NULL); \
+ } \
+ } while(0)
+
+ pos = 0;
+ for (; *str != '\0'; str++) {
+ switch (*str) {
+ case '"':
+ _ENCODE_STRING("&quot;");
+ break;
+ case '\'':
+ _ENCODE_STRING("&apos;");
+ break;
+ case '<':
+ _ENCODE_STRING("&lt;");
+ break;
+ case '>':
+ _ENCODE_STRING("&gt;");
+ break;
+ case '&':
+ _ENCODE_STRING("&amp;");
+ break;
+ default:
+ /* Normal chars. */
+ if (pos < _MAX_STRING_SIZE - 1)
+ enc[pos++] = *str;
+ else {
+ enc[pos] = '\0';
+ assert(0);
+ return (NULL);
+ }
+ break;
+ }
+ }
+ enc[pos] = '\0';
+
+ return (enc);
+#undef _ENCODE_STRING
+}
+
+static void
+driver_startup(void)
+{
+
+#ifdef TCGEN
+ driver_gen_ic();
+#else
+ STAILQ_INIT(&_iclist);
+ driver_parse_ic();
+#endif
+}
+
+static void
+driver_cleanup(void)
+{
+
+}
+
+/*
+ * Base64 encode/decode utility modified from libb64 project. It's been
+ * placed in the public domain. Note that this modified version doesn't
+ * emit newline during encoding.
+ */
+
+#ifdef TCGEN
+
+typedef enum
+{
+ step_A, step_B, step_C
+} base64_encodestep;
+
+typedef struct
+{
+ base64_encodestep step;
+ char result;
+} base64_encodestate;
+
+static void
+base64_init_encodestate(base64_encodestate* state_in)
+{
+ state_in->step = step_A;
+ state_in->result = 0;
+}
+
+static char
+base64_encode_value(char value_in)
+{
+ static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ if (value_in > 63)
+ return '=';
+
+ return encoding[(int)value_in];
+}
+
+static int
+base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
+ base64_encodestate* state_in)
+{
+ const char* plainchar = plaintext_in;
+ const char* const plaintextend = plaintext_in + length_in;
+ char* codechar = code_out;
+ char res;
+ char fragment;
+
+ res = state_in->result;
+
+ switch (state_in->step)
+ {
+ while (1)
+ {
+ case step_A:
+ if (plainchar == plaintextend)
+ {
+ state_in->result = res;
+ state_in->step = step_A;
+ return codechar - code_out;
+ }
+ fragment = *plainchar++;
+ res = (fragment & 0x0fc) >> 2;
+ *codechar++ = base64_encode_value(res);
+ res = (fragment & 0x003) << 4;
+ case step_B:
+ if (plainchar == plaintextend)
+ {
+ state_in->result = res;
+ state_in->step = step_B;
+ return codechar - code_out;
+ }
+ fragment = *plainchar++;
+ res |= (fragment & 0x0f0) >> 4;
+ *codechar++ = base64_encode_value(res);
+ res = (fragment & 0x00f) << 2;
+ case step_C:
+ if (plainchar == plaintextend)
+ {
+ state_in->result = res;
+ state_in->step = step_C;
+ return codechar - code_out;
+ }
+ fragment = *plainchar++;
+ res |= (fragment & 0x0c0) >> 6;
+ *codechar++ = base64_encode_value(res);
+ res = (fragment & 0x03f) >> 0;
+ *codechar++ = base64_encode_value(res);
+ }
+ }
+ /* control should not reach here */
+ return codechar - code_out;
+}
+
+static int
+base64_encode_blockend(char* code_out, base64_encodestate* state_in)
+{
+ char* codechar = code_out;
+
+ switch (state_in->step)
+ {
+ case step_B:
+ *codechar++ = base64_encode_value(state_in->result);
+ *codechar++ = '=';
+ *codechar++ = '=';
+ break;
+ case step_C:
+ *codechar++ = base64_encode_value(state_in->result);
+ *codechar++ = '=';
+ break;
+ case step_A:
+ break;
+ }
+
+ return codechar - code_out;
+}
+
+static void
+driver_base64_encode(const char *plain, int plainsize, char **code,
+ int *codesize)
+{
+ base64_encodestate state;
+
+ assert(plain != NULL && plainsize > 0);
+
+ *code = malloc(sizeof(char) * plainsize * 2);
+ if (*code == NULL)
+ err(EXIT_FAILURE, "malloc");
+
+ base64_init_encodestate(&state);
+
+ *codesize = base64_encode_block(plain, plainsize, *code, &state);
+ *codesize += base64_encode_blockend(*code + *codesize, &state);
+}
+
+#else /* TCGEN */
+
+typedef enum
+{
+ step_a, step_b, step_c, step_d
+} base64_decodestep;
+
+typedef struct
+{
+ base64_decodestep step;
+ char plainchar;
+} base64_decodestate;
+
+static int
+base64_decode_value(int value_in)
+{
+ static const char decoding[] = { 62,-1,-1,-1,63,52,53,54,55,56,57,58,
+ 59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,
+ 3,4,5,6,7,8,9,10,11,12,13,14,15,16,
+ 17,18,19,20,21,22,23,24,25,-1,-1,-1,
+ -1,-1,-1,26,27,28,29,30,31,32,33,34,
+ 35,36,37,38,39,40,41,42,43,44,45,46,
+ 47,48,49,50,51 };
+ static const int decoding_size = sizeof(decoding);
+
+ value_in -= 43;
+ if (value_in < 0 || value_in > decoding_size)
+ return -1;
+
+ return decoding[value_in];
+}
+
+static void
+base64_init_decodestate(base64_decodestate* state_in)
+{
+ state_in->step = step_a;
+ state_in->plainchar = 0;
+}
+
+static int
+base64_decode_block(const char* code_in, const int length_in,
+ char* plaintext_out, base64_decodestate* state_in)
+{
+ const char* codechar = code_in;
+ char* plainchar = plaintext_out;
+ char fragment;
+
+ *plainchar = state_in->plainchar;
+
+ switch (state_in->step)
+ {
+ while (1) {
+ case step_a:
+ do {
+ if (codechar == code_in+length_in)
+ {
+ state_in->step = step_a;
+ state_in->plainchar = *plainchar;
+ return plainchar - plaintext_out;
+ }
+ fragment = (char)base64_decode_value(*codechar++);
+ } while (fragment < 0);
+ *plainchar = (fragment & 0x03f) << 2;
+ case step_b:
+ do {
+ if (codechar == code_in+length_in)
+ {
+ state_in->step = step_b;
+ state_in->plainchar = *plainchar;
+ return plainchar - plaintext_out;
+ }
+ fragment = (char)base64_decode_value(*codechar++);
+ } while (fragment < 0);
+ *plainchar++ |= (fragment & 0x030) >> 4;
+ *plainchar = (fragment & 0x00f) << 4;
+ case step_c:
+ do {
+ if (codechar == code_in+length_in)
+ {
+ state_in->step = step_c;
+ state_in->plainchar = *plainchar;
+ return plainchar - plaintext_out;
+ }
+ fragment = (char)base64_decode_value(*codechar++);
+ } while (fragment < 0);
+ *plainchar++ |= (fragment & 0x03c) >> 2;
+ *plainchar = (fragment & 0x003) << 6;
+ case step_d:
+ do {
+ if (codechar == code_in+length_in)
+ {
+ state_in->step = step_d;
+ state_in->plainchar = *plainchar;
+ return plainchar - plaintext_out;
+ }
+ fragment = (char)base64_decode_value(*codechar++);
+ } while (fragment < 0);
+ *plainchar++ |= (fragment & 0x03f);
+ }
+ }
+ /* control should not reach here */
+ return plainchar - plaintext_out;
+}
+
+static void
+driver_base64_decode(const char *code, int codesize, char **plain, int *plainsize)
+{
+ base64_decodestate state;
+
+ assert(code != NULL && codesize > 0);
+
+ *plain = malloc(sizeof(char) * codesize);
+ if (*plain == NULL)
+ err(EXIT_FAILURE, "malloc");
+
+ base64_init_decodestate(&state);
+
+ *plainsize = base64_decode_block(code, codesize, *plain, &state);
+}
+#endif /* TCGEN */
diff --git a/test/libdwarf/ts/common/driver.h b/test/libdwarf/ts/common/driver.h
new file mode 100644
index 0000000000000..7d84a017e386c
--- /dev/null
+++ b/test/libdwarf/ts/common/driver.h
@@ -0,0 +1,172 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: driver.h 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#ifndef _DRIVER_H_
+#define _DRIVER_H_
+
+struct dwarf_tp {
+ const char *tp_name;
+ void (*tp_func)(void);
+};
+
+#define TS_DWARF_INIT(D,FD,DE) do { \
+ (D) = NULL; \
+ if (((FD) = open(_cur_file, O_RDONLY)) < 0) { \
+ tet_printf("open %s failed; %s", _cur_file, \
+ strerror(errno)); \
+ result = TET_FAIL; \
+ goto done; \
+ } \
+ if (dwarf_init((FD), DW_DLC_READ, NULL, NULL, &(D), &(DE)) != \
+ DW_DLV_OK) { \
+ tet_printf("dwarf_init failed: %s", dwarf_errmsg((DE)));\
+ result = TET_FAIL; \
+ goto done; \
+ } \
+ } while (0)
+
+#define TS_DWARF_FINISH(D,DE) do { \
+ if (dwarf_finish((D), &(DE)) != DW_DLV_OK) { \
+ tet_printf("dwarf_finish failed: %s", \
+ dwarf_errmsg((DE))); \
+ result = TET_FAIL; \
+ } \
+ } while (0)
+
+#define TS_DWARF_CU_FOREACH(D,N,DE) \
+ while (dwarf_next_cu_header((D), NULL, NULL, NULL, NULL, &(N), \
+ &(DE)) == DW_DLV_OK)
+
+#define TS_DWARF_DIE_TRAVERSE(D, CB) \
+ _die_traverse((D), (CB))
+
+#ifndef TCGEN
+
+#define _TS_CHECK_VAR(X,S) do { \
+ struct _drv_vc *_next_vc; \
+ int skip = 0; \
+ if (strcmp(_cur_vc->var, S)) { \
+ tet_printf("VC var(%s) does not match %s, possibly" \
+ " caused by the skip of previous VCs, try finding" \
+ " the next var with maching name", _cur_vc->var, \
+ S); \
+ _next_vc = _cur_vc; \
+ do { \
+ _next_vc = STAILQ_NEXT(_next_vc, next); \
+ skip++; \
+ if (!strcmp(_next_vc->var, S)) \
+ break; \
+ } while (_next_vc != NULL); \
+ if (_next_vc != NULL) { \
+ tet_printf("skipped %d VC(s)\n", skip); \
+ _cur_vc = _next_vc; \
+ } \
+ } \
+ } while (0)
+
+#define TS_CHECK_INT(X) do { \
+ assert(_cur_vc != NULL); \
+ _TS_CHECK_VAR(X,#X); \
+ if (X != _cur_vc->v.i64) { \
+ tet_printf("assertion %s(%jd) == %jd failed", \
+ _cur_vc->var, (intmax_t) (X), \
+ (intmax_t) _cur_vc->v.i64); \
+ result = TET_FAIL; \
+ } \
+ _cur_vc = STAILQ_NEXT(_cur_vc, next); \
+ } while (0)
+
+#define TS_CHECK_UINT(X) do { \
+ assert(_cur_vc != NULL); \
+ _TS_CHECK_VAR(X,#X); \
+ if (X != _cur_vc->v.u64) { \
+ tet_printf("assertion %s(%ju) == %ju failed", \
+ _cur_vc->var, (uintmax_t) (X), \
+ (uintmax_t) _cur_vc->v.u64); \
+ result = TET_FAIL; \
+ } \
+ _cur_vc = STAILQ_NEXT(_cur_vc, next); \
+ } while (0)
+
+#define TS_CHECK_STRING(X) do { \
+ assert(_cur_vc != NULL); \
+ _TS_CHECK_VAR(X,#X); \
+ if (strcmp(X, _cur_vc->v.str)) { \
+ tet_printf("assertion %s('%s') == '%s' failed", \
+ _cur_vc->var, (X), _cur_vc->v.str); \
+ result = TET_FAIL; \
+ } \
+ _cur_vc = STAILQ_NEXT(_cur_vc, next); \
+ } while (0)
+
+#define TS_CHECK_BLOCK(B,S) do { \
+ assert(_cur_vc != NULL); \
+ _TS_CHECK_VAR(B,#B); \
+ if ((S) != _cur_vc->v.b.len || \
+ memcmp((B), _cur_vc->v.b.data, _cur_vc->v.b.len)) { \
+ tet_printf("assertion block %s failed\n", _cur_vc->var);\
+ result = TET_FAIL; \
+ } \
+ _cur_vc = STAILQ_NEXT(_cur_vc, next); \
+ } while (0)
+
+#define TS_RESULT(X) tet_result(X)
+
+#else /* !TCGEN */
+
+#define TS_CHECK_INT(X) do { \
+ fprintf(_cur_fp, " <vc var='%s' type='int'>%jd</vc>\n", #X, \
+ (intmax_t) (X)); \
+ } while (0)
+
+#define TS_CHECK_UINT(X) do { \
+ fprintf(_cur_fp, " <vc var='%s' type='uint'>%ju</vc>\n", #X, \
+ (uintmax_t)(X)); \
+ } while (0)
+
+#define TS_CHECK_STRING(X) do { \
+ fprintf(_cur_fp, " <vc var='%s' type='str'>%s</vc>\n", #X, \
+ driver_string_encode(X)); \
+ } while (0)
+
+#define TS_CHECK_BLOCK(B,S) do { \
+ char *code; \
+ int codesize; \
+ size_t wsize; \
+ fprintf(_cur_fp, " <vc var='%s' type='block'>", #B); \
+ driver_base64_encode((char *) (B), (S), &code, &codesize); \
+ wsize = fwrite(code, 1, (size_t) codesize, _cur_fp); \
+ assert(wsize == (size_t) codesize); \
+ fprintf(_cur_fp, "</vc>\n"); \
+ free(code); \
+ } while (0)
+
+#define TS_RESULT(X)
+
+#endif /* !TCGEN */
+#endif /* !_DRIVER_H_ */
diff --git a/test/libdwarf/ts/common/object/dt32-g1.gz b/test/libdwarf/ts/common/object/dt32-g1.gz
new file mode 100755
index 0000000000000..8c5f75d9c11d6
--- /dev/null
+++ b/test/libdwarf/ts/common/object/dt32-g1.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/dt64-g1.gz b/test/libdwarf/ts/common/object/dt64-g1.gz
new file mode 100755
index 0000000000000..462c1750ce36c
--- /dev/null
+++ b/test/libdwarf/ts/common/object/dt64-g1.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/dt64-g3.gz b/test/libdwarf/ts/common/object/dt64-g3.gz
new file mode 100755
index 0000000000000..ab04c6559689a
--- /dev/null
+++ b/test/libdwarf/ts/common/object/dt64-g3.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/dto64-g1.gz b/test/libdwarf/ts/common/object/dto64-g1.gz
new file mode 100644
index 0000000000000..09be38b32cb82
--- /dev/null
+++ b/test/libdwarf/ts/common/object/dto64-g1.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/ec32-g1.gz b/test/libdwarf/ts/common/object/ec32-g1.gz
new file mode 100755
index 0000000000000..140dbd03b7d69
--- /dev/null
+++ b/test/libdwarf/ts/common/object/ec32-g1.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/ec64-g1.gz b/test/libdwarf/ts/common/object/ec64-g1.gz
new file mode 100755
index 0000000000000..553cc9dcf9f53
--- /dev/null
+++ b/test/libdwarf/ts/common/object/ec64-g1.gz
Binary files differ
diff --git a/test/libdwarf/ts/common/object/ec64-g3.gz b/test/libdwarf/ts/common/object/ec64-g3.gz
new file mode 100755
index 0000000000000..d3dc21715bfaf
--- /dev/null
+++ b/test/libdwarf/ts/common/object/ec64-g3.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_abbrev/Makefile b/test/libdwarf/ts/dwarf_abbrev/Makefile
new file mode 100644
index 0000000000000..58757edc2f1be
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_abbrev/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_abbrev.c
+TS_DATA= dt32-g1 ec64-g1 dto64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_abbrev/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_abbrev/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..5c1f982810dbe
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_abbrev/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_abbrev/dto64-g1.xml.gz b/test/libdwarf/ts/dwarf_abbrev/dto64-g1.xml.gz
new file mode 100644
index 0000000000000..a96259b3c5f33
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_abbrev/dto64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_abbrev/dwarf_abbrev.c b/test/libdwarf/ts/dwarf_abbrev/dwarf_abbrev.c
new file mode 100644
index 0000000000000..130cc46029455
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_abbrev/dwarf_abbrev.c
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_abbrev.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf address range API.
+ */
+static void tp_dwarf_abbrev(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_abbrev", tp_dwarf_abbrev},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+static void
+tp_dwarf_abbrev(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Abbrev ab;
+ Dwarf_Unsigned off, length, attr_count, code;
+ Dwarf_Signed children_flag, form;
+ Dwarf_Half tag, attr_num;
+ Dwarf_Off attr_off;
+ Dwarf_Error de;
+ int fd, r_abbrev, r_abbrev_entry, i;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ off = 0;
+ for (;;) {
+ tet_printf("check abbrev at offset(%ju):\n", (uintmax_t) off);
+ r_abbrev = dwarf_get_abbrev(dbg, off, &ab, &length,
+ &attr_count, &de);
+ off += length;
+ TS_CHECK_INT(r_abbrev);
+ if (r_abbrev != DW_DLV_OK)
+ break;
+ TS_CHECK_UINT(length);
+ TS_CHECK_UINT(attr_count);
+ if (dwarf_get_abbrev_tag(ab, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_abbrev_tag failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(tag);
+ if (dwarf_get_abbrev_code(ab, &code, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_abbrev_code failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(code);
+ if (dwarf_get_abbrev_children_flag(ab, &children_flag, &de) !=
+ DW_DLV_OK) {
+ tet_printf("dwarf_get_abbrev_children_flag failed: "
+ "%s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(children_flag);
+ for (i = 0; i < attr_count; i++) {
+ tet_printf("check attr %d:\n", i);
+ if (dwarf_get_abbrev_entry(ab, i, &attr_num, &form,
+ &attr_off, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_abbrev_entry failed: "
+ "%s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(attr_num);
+ TS_CHECK_INT(form);
+ TS_CHECK_INT(attr_off);
+ }
+ /* Invalid index. */
+ r_abbrev_entry = dwarf_get_abbrev_entry(ab, i + 10, &attr_num,
+ &form, &attr_off, &de);
+ TS_CHECK_INT(r_abbrev_entry);
+ }
+ if (r_abbrev == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_abbrev failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_abbrev/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_abbrev/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..d061687855a0a
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_abbrev/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_arange/Makefile b/test/libdwarf/ts/dwarf_arange/Makefile
new file mode 100644
index 0000000000000..4bd20cea526bf
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_arange.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_arange/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_arange/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..16a1cef7b8e7b
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_arange/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_arange/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..7adcf11af5156
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_arange/dwarf_arange.c b/test/libdwarf/ts/dwarf_arange/dwarf_arange.c
new file mode 100644
index 0000000000000..c03d93cda9f14
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/dwarf_arange.c
@@ -0,0 +1,127 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_arange.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf address range API.
+ */
+static void tp_dwarf_arange(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_arange", tp_dwarf_arange},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+static void
+tp_dwarf_arange(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Arange *aranges;
+ Dwarf_Arange arange;
+ Dwarf_Signed arange_cnt;
+ Dwarf_Off cu_die_offset, cu_die_offset2, cu_header_offset;
+ Dwarf_Addr start;
+ Dwarf_Unsigned length;
+ Dwarf_Error de;
+ int fd, i, r_aranges, r_arange;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ r_aranges = dwarf_get_aranges(dbg, &aranges, &arange_cnt, &de);
+ TS_CHECK_INT(r_aranges);
+ if (r_aranges == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_aranges failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (r_aranges == DW_DLV_OK) {
+ for (i = 0; i < arange_cnt; i++) {
+ if (dwarf_get_cu_die_offset(aranges[i], &cu_die_offset,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_cu_die_offset failed:"
+ " %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_INT(cu_die_offset);
+ if (dwarf_get_arange_cu_header_offset(aranges[i],
+ &cu_header_offset, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_arange_cu_header_offset"
+ "failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_INT(cu_header_offset);
+ if (dwarf_get_arange_info(aranges[i], &start, &length,
+ &cu_die_offset2, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_arange_info failed:%s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(start);
+ TS_CHECK_UINT(length);
+ TS_CHECK_UINT(cu_die_offset2);
+ r_arange = dwarf_get_arange(aranges, arange_cnt, start,
+ &arange, &de);
+ TS_CHECK_INT(r_arange);
+ r_arange = dwarf_get_arange(aranges, arange_cnt,
+ start + 1, &arange, &de);
+ TS_CHECK_INT(r_arange);
+ r_arange = dwarf_get_arange(aranges, arange_cnt,
+ start + length, &arange, &de);
+ TS_CHECK_INT(r_arange);
+ r_arange = dwarf_get_arange(aranges, arange_cnt,
+ start + length + 1, &arange, &de);
+ TS_CHECK_INT(r_arange);
+ r_arange = dwarf_get_arange(aranges, arange_cnt,
+ start + length - 1, &arange, &de);
+ TS_CHECK_INT(r_arange);
+ }
+ }
+
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_arange/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_arange/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..ff13e0c1d74ea
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_arange/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_arange/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..0cca099f4fa4e
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_arange/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attr/Makefile b/test/libdwarf/ts/dwarf_attr/Makefile
new file mode 100644
index 0000000000000..e416176011a44
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_attr.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1 dto64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_attr/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_attr/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..5e999ae993726
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attr/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_attr/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..3cb66127dd7ef
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attr/dto64-g1.xml.gz b/test/libdwarf/ts/dwarf_attr/dto64-g1.xml.gz
new file mode 100644
index 0000000000000..b046103890c26
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/dto64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attr/dwarf_attr.c b/test/libdwarf/ts/dwarf_attr/dwarf_attr.c
new file mode 100644
index 0000000000000..f6566916e9efa
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/dwarf_attr.c
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_attr.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf_attr, dwarf_hasattr and dwarf_whatattr etc.
+ */
+static void tp_dwarf_attr(void);
+static void tp_dwarf_attr_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_attr", tp_dwarf_attr},
+ {"tp_dwarf_attr_sanity", tp_dwarf_attr_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static Dwarf_Half attr_array[] = { DW_AT_ordering,
+ DW_AT_bit_offset,
+ DW_AT_bit_size,
+ DW_AT_byte_size,
+ DW_AT_high_pc,
+ DW_AT_low_pc,
+ DW_AT_language,
+ DW_AT_name,
+ DW_AT_data_member_location,
+ DW_AT_producer,
+ DW_AT_comp_dir,
+ DW_AT_location,
+ DW_AT_decl_file,
+ DW_AT_decl_line };
+static int attr_array_size = sizeof(attr_array) / sizeof(Dwarf_Half);
+
+static void
+_dwarf_attr(Dwarf_Die die)
+{
+ Dwarf_Attribute at;
+ Dwarf_Bool has_attr;
+ Dwarf_Half attr;
+ Dwarf_Error de;
+ const char *attr_name;
+ int i, r;
+
+ for (i = 0; i < attr_array_size; i++) {
+ if (dwarf_hasattr(die, attr_array[i], &has_attr, &de) !=
+ DW_DLV_OK) {
+ tet_printf("dwarf_hasattr failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(has_attr);
+
+ if (has_attr) {
+ if (dwarf_get_AT_name(attr_array[i], &attr_name) !=
+ DW_DLV_OK) {
+ tet_printf("dwarf_get_AT_name failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ if (attr_name == NULL) {
+ tet_infoline("dwarf_get_AT_name returned "
+ "DW_DLV_OK but didn't return string");
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_STRING(attr_name);
+
+ tet_printf("DIE #%d has attribute '%s'\n", die_cnt,
+ attr_name);
+
+ r = dwarf_attr(die, attr_array[i], &at, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_attr failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ } else if (r == DW_DLV_NO_ENTRY) {
+ tet_infoline("dwarf_hasattr returned true for "
+ "attribute '%s', while dwarf_attr returned"
+ " DW_DLV_NO_ENTRY for the same attr");
+ result = TET_FAIL;
+ continue;
+ }
+ if (dwarf_whatattr(at, &attr, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_whatattr failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ if (attr != attr_array[i]) {
+ tet_infoline("attr returned by dwarf_whatattr"
+ " != attr_array[i]");
+ result = TET_FAIL;
+ continue;
+ }
+ }
+ }
+}
+
+static void
+tp_dwarf_attr(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_attr);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_attr_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Bool has_attr;
+ Dwarf_Half attr;
+ Dwarf_Attribute at;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_hasattr(NULL, DW_AT_name, &has_attr, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_hasattr didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_attr(NULL, DW_AT_name, &at, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_attr didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_whatattr(NULL, &attr, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_whatattr didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_attr/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_attr/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..b8ea5a2247651
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attr/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_attr/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..44d581a3755c9
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attr/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attrlist/Makefile b/test/libdwarf/ts/dwarf_attrlist/Makefile
new file mode 100644
index 0000000000000..29cc2480527b8
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_attrlist.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_attrlist/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_attrlist/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..9757123b7b2c5
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attrlist/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_attrlist/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..e4cf1c592c6d9
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attrlist/dwarf_attrlist.c b/test/libdwarf/ts/dwarf_attrlist/dwarf_attrlist.c
new file mode 100644
index 0000000000000..fa6818ec1dcce
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/dwarf_attrlist.c
@@ -0,0 +1,129 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_attrlist.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf_attrlist and dwarf_whatattr etc.
+ */
+static void tp_dwarf_attrlist(void);
+static void tp_dwarf_attrlist_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_attrlist", tp_dwarf_attrlist},
+ {"tp_dwarf_attrlist_sanity", tp_dwarf_attrlist_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_attrlist(Dwarf_Die die)
+{
+ Dwarf_Attribute *attrlist;
+ Dwarf_Signed attrcount;
+ Dwarf_Half attr;
+ Dwarf_Error de;
+ int i, r;
+
+ r = dwarf_attrlist(die, &attrlist, &attrcount, &de);
+ TS_CHECK_INT(r);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_attrlist failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ } else if (r == DW_DLV_NO_ENTRY)
+ return;
+
+ TS_CHECK_INT(attrcount);
+ for (i = 0; i < attrcount; i++) {
+ if (dwarf_whatattr(attrlist[i], &attr, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_whatattr failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(attr);
+ }
+}
+
+static void
+tp_dwarf_attrlist(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_attrlist);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_attrlist_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Attribute *attrlist;
+ Dwarf_Signed attrcount;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_attrlist(NULL, &attrlist, &attrcount, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_attrlist didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_attrlist/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_attrlist/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..3408f55c6e59d
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_attrlist/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_attrlist/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..13581a27d24c9
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_attrlist/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_child/Makefile b/test/libdwarf/ts/dwarf_child/Makefile
new file mode 100644
index 0000000000000..60dd68f07bb27
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_child.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_child/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_child/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..0510e6afc1fe7
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_child/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_child/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..202c9cc13c795
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_child/dwarf_child.c b/test/libdwarf/ts/dwarf_child/dwarf_child.c
new file mode 100644
index 0000000000000..045fdac816ca0
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/dwarf_child.c
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_child.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+static void tp_dwarf_child_first(void);
+static void tp_dwarf_child_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_child_first", tp_dwarf_child_first},
+ {"tp_dwarf_child_sanity", tp_dwarf_child_sanity},
+ {NULL, NULL},
+};
+#include "driver.c"
+
+static void
+tp_dwarf_child_first(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Die die, die0;
+ Dwarf_Unsigned cu_next_offset;
+ int r, fd, result, die_cnt;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ tet_infoline("count the number of children of compilation unit DIE");
+
+ die_cnt = 0;
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ r = dwarf_siblingof(dbg, NULL, &die, &de);
+ if (r == DW_DLV_OK) {
+ r = dwarf_child(die, &die0, &de);
+ while (r == DW_DLV_OK) {
+ if (die0 == NULL) {
+ tet_infoline("dwarf_child or "
+ "dwarf_siblingof return "
+ "DW_DLV_OK while argument die0 "
+ "is not filled in");
+ result = TET_FAIL;
+ goto done;
+ }
+ die_cnt++;
+ die = die0;
+ r = dwarf_siblingof(dbg, die, &die0, &de);
+ }
+ }
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof or dwarf_child failed:"
+ " %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ TS_CHECK_INT(die_cnt);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_child_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Die die;
+ Dwarf_Unsigned cu_next_offset;
+ int fd, result;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_child(NULL, &die, &de) != DW_DLV_ERROR ||
+ dwarf_child(NULL, NULL, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_child didn't return DW_DLV_ERROR when"
+ " called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+
+ }
+
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_child(NULL, &die, &de) != DW_DLV_ERROR ||
+ dwarf_child(NULL, NULL, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_child didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_child/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_child/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..355cacbb614d4
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_child/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_child/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..3ad7586bf2cff
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_child/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_convenience/Makefile b/test/libdwarf/ts/dwarf_die_convenience/Makefile
new file mode 100644
index 0000000000000..4819d237c39c0
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_die_convenience.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_die_convenience/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_convenience/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..d69ae6e2bdf13
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_convenience/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_convenience/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..c115a1fe868fa
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_convenience/dwarf_die_convenience.c b/test/libdwarf/ts/dwarf_die_convenience/dwarf_die_convenience.c
new file mode 100644
index 0000000000000..7471762103763
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/dwarf_die_convenience.c
@@ -0,0 +1,242 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_die_convenience.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for a few convenience functions used to retrieve certain
+ * attribute values from DIE.
+ */
+
+static void tp_dwarf_die_convenience(void);
+static void tp_dwarf_die_convenience_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_die_convenience", tp_dwarf_die_convenience},
+ {"tp_dwarf_die_convenience_sanity", tp_dwarf_die_convenience_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_die_convenience(Dwarf_Die die)
+{
+ Dwarf_Error de;
+ Dwarf_Addr highpc, lowpc;
+ Dwarf_Unsigned arrayorder, bitoffset, bitsize, bytesize;
+ Dwarf_Unsigned srclang;
+ int r_arrayorder, r_bitoffset, r_bitsize, r_bytesize;
+ int r_highpc, r_lowpc, r_srclang;
+
+ r_arrayorder = dwarf_arrayorder(die, &arrayorder, &de);
+ TS_CHECK_INT(r_arrayorder);
+ if (r_arrayorder == DW_DLV_ERROR) {
+ tet_printf("dwarf_arrayorder failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_arrayorder == DW_DLV_OK)
+ TS_CHECK_UINT(arrayorder);
+
+ r_bitoffset = dwarf_bitoffset(die, &bitoffset, &de);
+ TS_CHECK_INT(r_bitoffset);
+ if (r_bitoffset == DW_DLV_ERROR) {
+ tet_printf("dwarf_bitoffset failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_bitoffset == DW_DLV_OK)
+ TS_CHECK_UINT(bitoffset);
+
+ r_bitsize = dwarf_bitsize(die, &bitsize, &de);
+ TS_CHECK_INT(r_bitsize);
+ if (r_bitsize == DW_DLV_ERROR) {
+ tet_printf("dwarf_bitsize failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_bitsize == DW_DLV_OK)
+ TS_CHECK_UINT(bitsize);
+
+ r_bytesize = dwarf_bytesize(die, &bytesize, &de);
+ TS_CHECK_INT(r_bytesize);
+ if (r_bytesize == DW_DLV_ERROR) {
+ tet_printf("dwarf_bytesize failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_bytesize == DW_DLV_OK)
+ TS_CHECK_UINT(bytesize);
+
+ r_highpc = dwarf_highpc(die, &highpc, &de);
+ TS_CHECK_INT(r_highpc);
+ if (r_highpc == DW_DLV_ERROR) {
+ tet_printf("dwarf_highpc failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_highpc == DW_DLV_OK)
+ TS_CHECK_UINT(highpc);
+
+ r_lowpc = dwarf_lowpc(die, &lowpc, &de);
+ TS_CHECK_INT(r_lowpc);
+ if (r_lowpc == DW_DLV_ERROR) {
+ tet_printf("dwarf_lowpc failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_lowpc == DW_DLV_OK)
+ TS_CHECK_UINT(lowpc);
+
+ r_srclang = dwarf_srclang(die, &srclang, &de);
+ TS_CHECK_INT(r_srclang);
+ if (r_srclang == DW_DLV_ERROR) {
+ tet_printf("dwarf_srclang failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (r_srclang == DW_DLV_OK)
+ TS_CHECK_UINT(srclang);
+}
+
+static void
+tp_dwarf_die_convenience(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_die_convenience);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_die_convenience_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Die die;
+ Dwarf_Addr highpc, lowpc;
+ Dwarf_Unsigned arrayorder, bitoffset, bitsize, bytesize;
+ Dwarf_Unsigned srclang, cu_next_offset;
+ int r, fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_siblingof(dbg, NULL, &die, &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_arrayorder(NULL, &arrayorder, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_arrayorder didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_bitoffset(NULL, &bitoffset, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_bitoffset didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_bitsize(NULL, &bitsize, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_bitsize didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_bytesize(NULL, &bytesize, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_bytesize didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_highpc(NULL, &highpc, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_highpc didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ r = dwarf_highpc(die, &highpc, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_highpc failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ } else if (r == DW_DLV_OK)
+ TS_CHECK_UINT(highpc);
+
+ if (dwarf_lowpc(NULL, &lowpc, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_lowpc didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ r = dwarf_lowpc(die, &lowpc, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_lowpc failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ } else if (r == DW_DLV_OK)
+ TS_CHECK_UINT(lowpc);
+
+ if (dwarf_srclang(NULL, &srclang, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_srclang didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ r = dwarf_srclang(die, &srclang, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_srclang failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ } else if (r == DW_DLV_OK)
+ TS_CHECK_UINT(srclang);
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_die_convenience/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_convenience/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..b2c04b5c6f8e9
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_convenience/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_convenience/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..a4d2ea5d60a67
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_convenience/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_offset/Makefile b/test/libdwarf/ts/dwarf_die_offset/Makefile
new file mode 100644
index 0000000000000..f54104a049df2
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_die_offset.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_die_offset/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_offset/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..cd6b2a3d74d22
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_offset/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_offset/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..89cc4546efcc6
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_offset/dwarf_die_offset.c b/test/libdwarf/ts/dwarf_die_offset/dwarf_die_offset.c
new file mode 100644
index 0000000000000..087b175f2742b
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/dwarf_die_offset.c
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_die_offset.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for DIE offset query functions: dwarf_die_CU_offset,
+ * dwarf_die_CU_offset_range, dwarf_dieoffset and
+ * dwarf_get_cu_die_offset_given_cu_header_offset.
+ */
+
+static void tp_dwarf_die_offset(void);
+static void tp_dwarf_die_offset_given_cu(void);
+static void tp_dwarf_die_offset_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_die_offset", tp_dwarf_die_offset},
+ {"tp_dwarf_die_offset_given_cu", tp_dwarf_die_offset_given_cu},
+ {"tp_dwarf_die_offset_sanity", tp_dwarf_die_offset_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_die_offset(Dwarf_Die die)
+{
+ Dwarf_Off rel_off, die_off, cu_off, cu_len;
+ Dwarf_Error de;
+
+ if (dwarf_die_CU_offset(die, &rel_off, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_die_CU_offset failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(rel_off);
+
+ if (dwarf_die_CU_offset_range(die, &cu_off, &cu_len, &de) !=
+ DW_DLV_OK) {
+ tet_printf("dwarf_die_CU_offset_range failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(cu_off);
+ TS_CHECK_INT(cu_len);
+
+ if (dwarf_dieoffset(die, &die_off, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_dieoffset failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(die_off);
+}
+
+static void
+tp_dwarf_die_offset(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_die_offset);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_die_offset_given_cu(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Off cu_offset, cu_dieoff;
+ Dwarf_Unsigned cu_next_offset;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ cu_offset = 0;
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_get_cu_die_offset_given_cu_header_offset(dbg,
+ cu_offset, &cu_dieoff, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_cu_die_offset_given_cu_header"
+ "_offset failed: %s", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ TS_CHECK_INT(cu_dieoff);
+ cu_offset = cu_next_offset;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_die_offset_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Die die;
+ Dwarf_Error de;
+ Dwarf_Off rel_off, die_off, cu_off, cu_len;
+ Dwarf_Unsigned cu_next_offset;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_siblingof(dbg, NULL, &die, &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_die_CU_offset(NULL, &rel_off, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_die_CU_offset didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_die_CU_offset_range(NULL, &cu_off, &cu_len, &de) !=
+ DW_DLV_ERROR) {
+ tet_infoline("dwarf_die_CU_offset_range didn't return"
+ " DW_DLV_ERROR when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_dieoffset(NULL, &die_off, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_dieoffset didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_die_offset/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_offset/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..335c6c61b95b8
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_offset/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_offset/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..fd6f9eac7d050
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_offset/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_query/Makefile b/test/libdwarf/ts/dwarf_die_query/Makefile
new file mode 100644
index 0000000000000..efcf1bc97c4e0
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_die_query.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1 dto64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_die_query/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_query/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..2cda689a79455
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_query/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_query/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..211645acbf436
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_query/dto64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_query/dto64-g1.xml.gz
new file mode 100644
index 0000000000000..7b2d38d04585e
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/dto64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_query/dwarf_die_query.c b/test/libdwarf/ts/dwarf_die_query/dwarf_die_query.c
new file mode 100644
index 0000000000000..45b9c44d1abef
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/dwarf_die_query.c
@@ -0,0 +1,154 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_die_query.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for DIE query functions: dwarf_tag, dwarf_die_abbrev_code,
+ * dwarf_diename and dwarf_dieoffset.
+ */
+
+static void tp_dwarf_die_query(void);
+static void tp_dwarf_die_query_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_die_query", tp_dwarf_die_query},
+ {"tp_dwarf_die_query_sanity", tp_dwarf_die_query_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_die_query(Dwarf_Die die)
+{
+ Dwarf_Half tag;
+ Dwarf_Error de;
+ char *die_name;
+ int abbrev_code, dwarf_diename_ret;
+
+ /* Check DIE abbreviation code. */
+ abbrev_code = dwarf_die_abbrev_code(die);
+ TS_CHECK_INT(abbrev_code);
+
+ /* Check DIE tag. */
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(tag);
+
+ /* Check DIE name. */
+ dwarf_diename_ret = dwarf_diename(die, &die_name, &de);
+ TS_CHECK_INT(dwarf_diename_ret);
+ if (dwarf_diename_ret == DW_DLV_ERROR) {
+ tet_printf("dwarf_diename failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ } else if (dwarf_diename_ret == DW_DLV_OK)
+ TS_CHECK_STRING(die_name);
+}
+
+static void
+tp_dwarf_die_query(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_die_query);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_die_query_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Die die;
+ Dwarf_Error de;
+ Dwarf_Half tag;
+ Dwarf_Unsigned cu_next_offset;
+ char *die_name;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_siblingof(dbg, NULL, &die, &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_tag(NULL, &tag, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_tag didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ TS_CHECK_UINT(tag);
+
+ if (dwarf_diename(NULL, &die_name, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_diename didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_die_query/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_die_query/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..d54847f126eaa
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_die_query/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_die_query/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..21559130a6793
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_die_query/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_form/Makefile b/test/libdwarf/ts/dwarf_form/Makefile
new file mode 100644
index 0000000000000..a64bd6f6f2ba2
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_form.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_form/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_form/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..b15226e85f107
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_form/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_form/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..62b6aa2687306
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_form/dwarf_form.c b/test/libdwarf/ts/dwarf_form/dwarf_form.c
new file mode 100644
index 0000000000000..8567b5a14491f
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/dwarf_form.c
@@ -0,0 +1,270 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_form.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for DWARF attribute query functions.
+ */
+static void tp_dwarf_form(void);
+static void tp_dwarf_form_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_form", tp_dwarf_form},
+ {"tp_dwarf_form_sanity", tp_dwarf_form_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_form(Dwarf_Die die)
+{
+ Dwarf_Attribute *attrlist, at;
+ Dwarf_Signed attrcount;
+ Dwarf_Half form, direct_form;
+ Dwarf_Off offset;
+ Dwarf_Addr addr;
+ Dwarf_Bool flag, hasform;
+ Dwarf_Unsigned uvalue;
+ Dwarf_Signed svalue;
+ Dwarf_Block *block;
+ Dwarf_Error de;
+ char *str;
+ int i, r;
+ int r_formref, r_global_formref, r_formaddr, r_formflag;
+ int r_formudata, r_formsdata, r_formblock, r_formstring;
+
+ r = dwarf_attrlist(die, &attrlist, &attrcount, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_attrlist failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ } else if (r == DW_DLV_NO_ENTRY)
+ return;
+
+ for (i = 0; i < attrcount; i++) {
+ at = attrlist[i];
+ if (dwarf_whatform(at, &form, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_whatform failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(form);
+ if (dwarf_hasform(at, form, &hasform, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_hasform failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ if (!hasform) {
+ tet_infoline("dwarf_hasform contradicts with"
+ " dwarf_whatform");
+ result = TET_FAIL;
+ }
+ if (dwarf_whatform_direct(at, &direct_form, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_whatform_direct failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(direct_form);
+
+ r_formref = dwarf_formref(at, &offset, &de);
+ TS_CHECK_INT(r_formref);
+ if (r_formref == DW_DLV_OK)
+ TS_CHECK_INT(offset);
+
+ r_global_formref = dwarf_global_formref(at, &offset, &de);
+ TS_CHECK_INT(r_global_formref);
+ if (r_global_formref == DW_DLV_OK)
+ TS_CHECK_INT(offset);
+
+ r_formaddr = dwarf_formaddr(at, &addr, &de);
+ TS_CHECK_INT(r_formaddr);
+ if (r_formaddr == DW_DLV_OK)
+ TS_CHECK_UINT(addr);
+
+ r_formflag = dwarf_formflag(at, &flag, &de);
+ TS_CHECK_INT(r_formflag);
+ if (r_formflag == DW_DLV_OK)
+ TS_CHECK_INT(flag);
+
+ r_formudata = dwarf_formudata(at, &uvalue, &de);
+ TS_CHECK_INT(r_formudata);
+ if (r_formudata == DW_DLV_OK)
+ TS_CHECK_UINT(uvalue);
+
+ r_formsdata = dwarf_formsdata(at, &svalue, &de);
+ TS_CHECK_INT(r_formsdata);
+ if (r_formsdata == DW_DLV_OK)
+ TS_CHECK_INT(svalue);
+
+ r_formblock = dwarf_formblock(at, &block, &de);
+ TS_CHECK_INT(r_formblock);
+ if (r_formblock == DW_DLV_OK)
+ TS_CHECK_BLOCK(block->bl_data, block->bl_len);
+
+ r_formstring = dwarf_formstring(at, &str, &de);
+ TS_CHECK_INT(r_formstring);
+ if (r_formstring == DW_DLV_OK)
+ TS_CHECK_STRING(str);
+ }
+}
+
+static void
+tp_dwarf_form(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_form);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_form_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Half form, direct_form;
+ Dwarf_Off offset;
+ Dwarf_Addr addr;
+ Dwarf_Bool flag, hasform;
+ Dwarf_Unsigned uvalue;
+ Dwarf_Signed svalue;
+ Dwarf_Block *block;
+ char *str;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_whatform(NULL, &form, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_whatform didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_whatform_direct(NULL, &direct_form, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_whatform_direct didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_hasform(NULL, DW_FORM_indirect, &hasform, &de) !=
+ DW_DLV_ERROR) {
+ tet_infoline("dwarf_hasform didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formref(NULL, &offset, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formref didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_global_formref(NULL, &offset, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_global_formref didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formaddr(NULL, &addr, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formaddr didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formflag(NULL, &flag, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formflag didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formudata(NULL, &uvalue, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formudata didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formsdata(NULL, &svalue, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formsdata didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formblock(NULL, &block, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formblock didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_formstring(NULL, &str, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_formstring didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_form/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_form/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..8342c21cf7e12
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_form/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_form/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..b046c5b902374
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_form/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_frame/Makefile b/test/libdwarf/ts/dwarf_frame/Makefile
new file mode 100644
index 0000000000000..118bd3f5e0b1f
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_frame/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_frame.c
+TS_DATA= dt64-g1 ec32-g1 dto64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_frame/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_frame/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..b053c9d0de2b9
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_frame/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_frame/dto64-g1.xml.gz b/test/libdwarf/ts/dwarf_frame/dto64-g1.xml.gz
new file mode 100644
index 0000000000000..c6512db46f58b
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_frame/dto64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_frame/dwarf_frame.c b/test/libdwarf/ts/dwarf_frame/dwarf_frame.c
new file mode 100644
index 0000000000000..3c5ed4d99ccef
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_frame/dwarf_frame.c
@@ -0,0 +1,498 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_frame.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf line informatio API.
+ */
+static void tp_dwarf_frame2(void);
+static void tp_dwarf_frame3(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_frame2",tp_dwarf_frame2},
+ {"tp_dwarf_frame3",tp_dwarf_frame3},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+#define _MAX_REG_NUM 10
+
+static void
+_frame2_test(Dwarf_Debug dbg, Dwarf_Fde fde, Dwarf_Addr pc,
+ Dwarf_Unsigned func_len, Dwarf_Unsigned caf)
+{
+ Dwarf_Signed offset_relevant, register_num, offset;
+ Dwarf_Addr pc_end, row_pc;
+ Dwarf_Regtable reg_table;
+ Dwarf_Error de;
+ int i, cnt;
+
+ (void) dwarf_set_frame_cfa_value(dbg, DW_FRAME_CFA_COL);
+
+ /* Sanity check for invalid table_column. */
+ if (dwarf_get_fde_info_for_reg(fde, 9999, 0, &offset_relevant,
+ &register_num, &offset, &row_pc, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_get_fde_info_for_reg didn't return"
+ " DW_DLV_ERROR when called with invalid table_column"
+ " value");
+ result = TET_FAIL;
+ return;
+ }
+
+ cnt = 0;
+ pc_end = pc + func_len;
+ while (pc < pc_end && cnt < 16) {
+ tet_printf("query CFA register pc %#jx\n", (uintmax_t) pc);
+ /*
+ * XXX If application want to use DW_FRAME_CFA_COL for CFA,
+ * it should call dwarf_set_frame_cfa_value() to set that
+ * explicitly. So here DW_FRAME_CFA_COL might not be refering
+ * to the CFA at all, depends on whether CFA(0) is set by
+ * dwarf_set_frame_cfa_value.
+ */
+ if (dwarf_get_fde_info_for_reg(fde, DW_FRAME_CFA_COL,
+ pc, &offset_relevant, &register_num, &offset,
+ &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_reg(cfa) failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ }
+ TS_CHECK_INT(offset_relevant);
+ TS_CHECK_INT(offset);
+ TS_CHECK_INT(register_num);
+ TS_CHECK_UINT(row_pc);
+ for (i = 1; i < _MAX_REG_NUM; i++) {
+ tet_printf("query register %d\n", i);
+ if (dwarf_get_fde_info_for_reg(fde, i, pc,
+ &offset_relevant, &register_num, &offset,
+ &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_reg(%d)"
+ " failed: %s", i, dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto next;
+ }
+ TS_CHECK_INT(offset_relevant);
+ TS_CHECK_INT(offset);
+ TS_CHECK_INT(register_num);
+ TS_CHECK_UINT(row_pc);
+ }
+ tet_infoline("query all register");
+ if (dwarf_get_fde_info_for_all_regs(fde, pc, &reg_table,
+ &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_all_regs failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto next;
+ }
+ TS_CHECK_UINT(row_pc);
+ for (i = 0; i < _MAX_REG_NUM; i++) {
+ tet_printf("check reg_table[%d]\n", i);
+ TS_CHECK_UINT(reg_table.rules[i].dw_offset_relevant);
+ TS_CHECK_UINT(reg_table.rules[i].dw_regnum);
+ TS_CHECK_UINT(reg_table.rules[i].dw_offset);
+ }
+
+ next:
+ pc += caf;
+ cnt++;
+ }
+}
+
+static void
+_frame3_test(Dwarf_Debug dbg, Dwarf_Fde fde, Dwarf_Addr pc,
+ Dwarf_Unsigned func_len, Dwarf_Unsigned caf)
+{
+ Dwarf_Signed offset_relevant, register_num, offset_or_block_len;
+ Dwarf_Addr pc_end, row_pc;
+ Dwarf_Ptr block_ptr;
+ Dwarf_Regtable3 reg_table3;
+ Dwarf_Small value_type;
+ Dwarf_Error de;
+ int i, cnt;
+
+ /* Initialise regster table (DWARF3). */
+ reg_table3.rt3_reg_table_size = DW_REG_TABLE_SIZE;
+ reg_table3.rt3_rules = calloc(reg_table3.rt3_reg_table_size,
+ sizeof(Dwarf_Regtable_Entry3));
+ if (reg_table3.rt3_rules == NULL) {
+ tet_infoline("calloc failed when initialising reg_table3");
+ result = TET_FAIL;
+ return;
+ }
+
+ /* Sanity check for invalid table_column. */
+ if (dwarf_get_fde_info_for_reg3(fde, 9999, 0, &value_type,
+ &offset_relevant, &register_num, &offset_or_block_len, &block_ptr,
+ &row_pc, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_get_fde_info_for_reg3 didn't return"
+ " DW_DLV_ERROR when called with invalid table_column"
+ " value");
+ result = TET_FAIL;
+ return;
+ }
+
+ cnt = 0;
+ pc_end = pc + func_len;
+ while (pc < pc_end && cnt < 16) {
+ tet_printf("query CFA(3) register pc %#jx\n", (uintmax_t) pc);
+ if (dwarf_get_fde_info_for_cfa_reg3(fde, pc, &value_type,
+ &offset_relevant, &register_num, &offset_or_block_len,
+ &block_ptr, &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_reg3(cfa) failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ }
+ TS_CHECK_INT(value_type);
+ TS_CHECK_INT(offset_relevant);
+ TS_CHECK_INT(offset_or_block_len);
+ TS_CHECK_INT(register_num);
+ TS_CHECK_UINT(row_pc);
+ if (value_type == DW_EXPR_EXPRESSION ||
+ value_type == DW_EXPR_VAL_EXPRESSION)
+ TS_CHECK_BLOCK(block_ptr, offset_or_block_len);
+ for (i = 1; i < _MAX_REG_NUM; i++) {
+ tet_printf("query register(3) %d\n", i);
+ if (dwarf_get_fde_info_for_reg3(fde, i, pc, &value_type,
+ &offset_relevant, &register_num,
+ &offset_or_block_len, &block_ptr,
+ &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_reg3(%d)"
+ " failed: %s", i, dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto next;
+ }
+ TS_CHECK_INT(value_type);
+ TS_CHECK_INT(offset_relevant);
+ TS_CHECK_INT(offset_or_block_len);
+ TS_CHECK_INT(register_num);
+ TS_CHECK_UINT(row_pc);
+ if (value_type == DW_EXPR_EXPRESSION ||
+ value_type == DW_EXPR_VAL_EXPRESSION)
+ TS_CHECK_BLOCK(block_ptr, offset_or_block_len);
+ }
+ tet_infoline("query all register(3)");
+ if (dwarf_get_fde_info_for_all_regs3(fde, pc, &reg_table3,
+ &row_pc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_info_for_all_regs failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto next;
+ }
+ TS_CHECK_UINT(row_pc);
+
+#define CFA3 reg_table3.rt3_cfa_rule
+#define RT3 reg_table3.rt3_rules
+ TS_CHECK_UINT(CFA3.dw_offset_relevant);
+ TS_CHECK_UINT(CFA3.dw_value_type);
+ TS_CHECK_UINT(CFA3.dw_regnum);
+ TS_CHECK_UINT(CFA3.dw_offset_or_block_len);
+ if (CFA3.dw_value_type == DW_EXPR_EXPRESSION ||
+ CFA3.dw_value_type == DW_EXPR_VAL_EXPRESSION)
+ TS_CHECK_BLOCK(CFA3.dw_block_ptr,
+ CFA3.dw_offset_or_block_len);
+ for (i = 0; i < _MAX_REG_NUM; i++) {
+ tet_printf("check reg_table3[%d]\n", i);
+ TS_CHECK_UINT(RT3[i].dw_offset_relevant);
+ TS_CHECK_UINT(RT3[i].dw_value_type);
+ TS_CHECK_UINT(RT3[i].dw_regnum);
+ TS_CHECK_UINT(RT3[i].dw_offset_or_block_len);
+ if (RT3[i].dw_value_type == DW_EXPR_EXPRESSION ||
+ RT3[i].dw_value_type == DW_EXPR_VAL_EXPRESSION)
+ TS_CHECK_BLOCK(RT3[i].dw_block_ptr,
+ RT3[i].dw_offset_or_block_len);
+ }
+#undef CFA3
+#undef RT3
+
+ next:
+ pc += caf;
+ cnt++;
+ }
+}
+
+static void
+_dwarf_cie_fde_test(Dwarf_Debug dbg, int eh, void (*_frame_test)(Dwarf_Debug,
+ Dwarf_Fde, Dwarf_Addr, Dwarf_Unsigned, Dwarf_Unsigned))
+{
+ Dwarf_Cie *cielist, cie;
+ Dwarf_Fde *fdelist, fde;
+ Dwarf_Frame_Op *oplist;
+ Dwarf_Signed ciecnt, fdecnt;
+ Dwarf_Addr low_pc, high_pc;
+ Dwarf_Unsigned func_len, fde_byte_len, fde_inst_len, bytes_in_cie;
+ Dwarf_Unsigned cie_caf, cie_daf, cie_inst_len;
+ Dwarf_Signed cie_index, opcnt;
+ Dwarf_Off cie_offset, fde_offset;
+ Dwarf_Ptr fde_bytes, fde_inst, cie_initinst;
+ Dwarf_Half cie_ra;
+ Dwarf_Small cie_version;
+ Dwarf_Error de;
+ const char *cfa_str;
+ char *cie_augmenter;
+ int i, j, r_fde_at_pc;
+
+ if (eh) {
+ if (dwarf_get_fde_list_eh(dbg, &cielist, &ciecnt, &fdelist,
+ &fdecnt, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_list_eh failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ } else {
+ if (dwarf_get_fde_list(dbg, &cielist, &ciecnt, &fdelist,
+ &fdecnt, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_list failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+ TS_CHECK_INT(ciecnt);
+ TS_CHECK_INT(fdecnt);
+
+ /*
+ * Test dwarf_get_fde_at_pc using hard-coded PC values.
+ */
+
+ tet_infoline("attempt to get fde at 0x08082a30");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x08082a30, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ tet_infoline("attempt to get fde at 0x08083087");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x08083087, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ tet_infoline("attempt to get fde at 0x080481f0");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x080481f0, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ tet_infoline("attempt to get fde at 0x08048564");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x08048564, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ tet_infoline("attempt to get fde at 0x00401280");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x00401280, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ tet_infoline("attempt to get fde at 0x004012b1");
+ r_fde_at_pc = dwarf_get_fde_at_pc(fdelist, 0x004012b1, &fde, &low_pc,
+ &high_pc, &de);
+ TS_CHECK_INT(r_fde_at_pc);
+ if (r_fde_at_pc == DW_DLV_OK) {
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(high_pc);
+ }
+
+ /*
+ * Test each FDE contained in the FDE list.
+ */
+
+ for (i = 0; i < fdecnt; i++) {
+ if (dwarf_get_fde_n(fdelist, i, &fde, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_n(%d) failed: %s\n", i,
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ if (dwarf_get_fde_range(fde, &low_pc, &func_len, &fde_bytes,
+ &fde_byte_len, &cie_offset, &cie_index, &fde_offset,
+ &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_fde_range(%d) failed: %s\n", i,
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(low_pc);
+ TS_CHECK_UINT(func_len);
+ TS_CHECK_UINT(fde_byte_len);
+ if (fde_byte_len > 0)
+ TS_CHECK_BLOCK(fde_bytes, fde_byte_len);
+ TS_CHECK_INT(cie_offset);
+ TS_CHECK_INT(cie_index);
+ TS_CHECK_INT(fde_offset);
+ if (dwarf_get_cie_of_fde(fde, &cie, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_cie_of_fde(%d) failed: %s\n", i,
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ if (dwarf_get_cie_index(cie, &cie_index, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_cie_index(%d) failed: %s\n", i,
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_INT(cie_index);
+ if (dwarf_get_cie_info(cie, &bytes_in_cie, &cie_version,
+ &cie_augmenter, &cie_caf, &cie_daf, &cie_ra, &cie_initinst,
+ &cie_inst_len, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_cie_info(%d) failed: %s\n", i,
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(bytes_in_cie);
+ TS_CHECK_UINT(cie_version);
+ TS_CHECK_STRING(cie_augmenter);
+ TS_CHECK_UINT(cie_caf);
+ TS_CHECK_UINT(cie_daf);
+ TS_CHECK_UINT(cie_ra);
+ TS_CHECK_UINT(cie_inst_len);
+ if (cie_inst_len > 0)
+ TS_CHECK_BLOCK(cie_initinst, cie_inst_len);
+ if (dwarf_get_fde_instr_bytes(fde, &fde_inst, &fde_inst_len,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_fde_instr_bytes(%d) failed: %s\n",
+ i, dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(fde_inst_len);
+ if (fde_inst_len > 0) {
+ TS_CHECK_BLOCK(fde_inst, fde_inst_len);
+ if (dwarf_expand_frame_instructions(cie, fde_inst,
+ fde_inst_len, &oplist, &opcnt, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_expand_frame_instructions(%d)"
+ " failed: %s\n", i, dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_INT(opcnt);
+ for (j = 0; j < opcnt; j++) {
+ TS_CHECK_UINT(oplist[j].fp_base_op);
+ if (oplist[j].fp_base_op != 0) {
+ if (dwarf_get_CFA_name(
+ oplist[j].fp_base_op << 6,
+ &cfa_str) != DW_DLV_OK) {
+ tet_printf("dwarf_get_CFA_name"
+ " failed\n");
+ continue;
+ }
+ TS_CHECK_STRING(cfa_str);
+ }
+ TS_CHECK_UINT(oplist[j].fp_extended_op);
+ if (oplist[j].fp_extended_op != 0) {
+ if (dwarf_get_CFA_name(
+ oplist[j].fp_extended_op,
+ &cfa_str) != DW_DLV_OK) {
+ tet_printf("dwarf_get_CFA_name"
+ " failed\n");
+ continue;
+ }
+ TS_CHECK_STRING(cfa_str);
+ }
+ TS_CHECK_UINT(oplist[j].fp_register);
+ TS_CHECK_INT(oplist[j].fp_offset);
+ TS_CHECK_INT(oplist[j].fp_instr_offset);
+ }
+ }
+ _frame_test(dbg, fde, low_pc, func_len, cie_caf);
+ }
+
+done:
+ return;
+}
+
+static void
+tp_dwarf_frame2(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ _dwarf_cie_fde_test(dbg, 0, _frame2_test);
+ _dwarf_cie_fde_test(dbg, 1, _frame2_test);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_frame3(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ _dwarf_cie_fde_test(dbg, 0, _frame3_test);
+ _dwarf_cie_fde_test(dbg, 1, _frame3_test);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_frame/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_frame/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..a63c1e222eb5b
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_frame/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_get_address_size/Makefile b/test/libdwarf/ts/dwarf_get_address_size/Makefile
new file mode 100644
index 0000000000000..30349b750fd34
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_get_address_size/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_get_address_size.c
+TS_DATA= dt32-g1 dt64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_get_address_size/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_get_address_size/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..4317b6bdad4a7
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_get_address_size/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_get_address_size/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_get_address_size/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..b16cb3614e8b4
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_get_address_size/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_get_address_size/dwarf_get_address_size.c b/test/libdwarf/ts/dwarf_get_address_size/dwarf_get_address_size.c
new file mode 100644
index 0000000000000..be9a10f0bb106
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_get_address_size/dwarf_get_address_size.c
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_get_address_size.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+static void tp_dwarf_get_address_size(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_get_address_size", tp_dwarf_get_address_size},
+ {NULL, NULL},
+};
+#include "driver.c"
+
+static void
+tp_dwarf_get_address_size(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Half addr_size;
+ int fd, result;
+
+ dbg = NULL;
+ result = TET_UNRESOLVED;
+
+ if (dwarf_get_address_size(NULL, &addr_size, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_get_adderss_size NULL 'dbg' test failed");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_get_address_size(dbg, NULL, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_get_adderss_size NULL 'addr_size' test "
+ "failed");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_get_address_size(dbg, &addr_size, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_get_address_size failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+
+ TS_CHECK_UINT(addr_size);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_init/Makefile b/test/libdwarf/ts/dwarf_init/Makefile
new file mode 100644
index 0000000000000..316f5c27f1cca
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_init.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_init/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_init/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..2ae60f2388eba
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_init/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_init/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..ee7365f486194
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_init/dwarf_init.c b/test/libdwarf/ts/dwarf_init/dwarf_init.c
new file mode 100644
index 0000000000000..73fa7cca1bbf6
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/dwarf_init.c
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_init.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+static void tp_dwarf_init(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_init", tp_dwarf_init},
+ {NULL, NULL},
+};
+#include "driver.c"
+
+static void
+tp_dwarf_init(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd, result;
+
+ result = TET_UNRESOLVED;
+
+ assert(_cur_file != NULL);
+ dbg = NULL;
+ if ((fd = open(_cur_file, O_RDONLY)) < 0) {
+ tet_printf("open %s failed: %s", _cur_file, strerror(errno));
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_init failed: %s", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_init(-1, DW_DLC_READ, NULL, NULL, &dbg, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_init didn't return DW_DLV_ERROR when"
+ " called with fd(-1)");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_init/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_init/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..32a51f94b9808
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_init/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_init/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..caceadb417ec4
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_init/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_lineno/Makefile b/test/libdwarf/ts/dwarf_lineno/Makefile
new file mode 100644
index 0000000000000..756e5059335f0
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_lineno.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1 dto64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_lineno/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_lineno/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..e71efb4cd21c2
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_lineno/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_lineno/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..7dbb07d1de503
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_lineno/dto64-g1.xml.gz b/test/libdwarf/ts/dwarf_lineno/dto64-g1.xml.gz
new file mode 100644
index 0000000000000..24fe7b01b6f99
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/dto64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_lineno/dwarf_lineno.c b/test/libdwarf/ts/dwarf_lineno/dwarf_lineno.c
new file mode 100644
index 0000000000000..322031e808939
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/dwarf_lineno.c
@@ -0,0 +1,278 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_lineno.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf line informatio API.
+ */
+static void tp_dwarf_lineno(void);
+static void tp_dwarf_srcfiles(void);
+static void tp_dwarf_lineno_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_lineno", tp_dwarf_lineno},
+ {"tp_dwarf_srcfiles", tp_dwarf_srcfiles},
+ {"tp_dwarf_lineno_sanity", tp_dwarf_lineno_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_lineno(Dwarf_Die die)
+{
+ Dwarf_Line *linebuf, ln;
+ Dwarf_Signed linecount, lineoff;
+ Dwarf_Unsigned lineno, srcfileno;
+ Dwarf_Addr lineaddr;
+ Dwarf_Half tag;
+ Dwarf_Error de;
+ Dwarf_Bool linebeginstatement, lineendsequence, lineblock;
+ char *linesrc;
+ int r_srclines;
+ int i;
+
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ }
+
+ r_srclines = dwarf_srclines(die, &linebuf, &linecount, &de);
+ TS_CHECK_INT(r_srclines);
+
+ if (r_srclines == DW_DLV_ERROR) {
+ tet_printf("dwarf_srclines should not fail but still failed:",
+ " %s", dwarf_errmsg(de));
+ return;
+ }
+
+ if (r_srclines != DW_DLV_OK)
+ return;
+
+ for (i = 0; i < linecount; i++) {
+
+ ln = linebuf[i];
+
+ if (dwarf_linebeginstatement(ln, &linebeginstatement,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_linebeginstatement failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(linebeginstatement);
+
+ if (dwarf_linebeginstatement(ln, &linebeginstatement,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_linebeginstatement failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(linebeginstatement);
+
+ if (dwarf_lineendsequence(ln, &lineendsequence,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_lineendsequence failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(lineendsequence);
+
+ if (dwarf_lineno(ln, &lineno, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_lineno failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(lineno);
+
+ if (dwarf_line_srcfileno(ln, &srcfileno, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_line_srcfileno failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(srcfileno);
+
+ if (dwarf_lineaddr(ln, &lineaddr, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_lineaddr failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_UINT(lineaddr);
+
+ if (dwarf_lineoff(ln, &lineoff, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_lineoff failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(lineoff);
+
+ if (dwarf_linesrc(ln, &linesrc, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_linesrc failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_STRING(linesrc);
+
+ if (dwarf_lineblock(ln, &lineblock, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_lineblock failed: %s",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(lineblock);
+ }
+}
+
+static void
+tp_dwarf_lineno(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_lineno);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+_dwarf_srcfiles(Dwarf_Die die)
+{
+ Dwarf_Half tag;
+ Dwarf_Error de;
+ Dwarf_Signed srccount;
+ char **srcfiles;
+ int r_srcfiles, i;
+
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ }
+
+ r_srcfiles = dwarf_srcfiles(die, &srcfiles, &srccount, &de);
+ TS_CHECK_INT(r_srcfiles);
+
+ if (r_srcfiles == DW_DLV_ERROR) {
+ tet_printf("dwarf_srcfiles should not fail but still failed:",
+ " %s", dwarf_errmsg(de));
+ return;
+ }
+
+ if (r_srcfiles != DW_DLV_OK)
+ return;
+
+ if (dwarf_srcfiles(die, &srcfiles, &srccount, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_srcfiles failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ }
+
+ TS_CHECK_INT(srccount);
+ for (i = 0; i < srccount; i++) {
+ if (srcfiles[i] == NULL) {
+ tet_printf("dwarf_srcfiles returned NULL pointer"
+ " srcfiles[%d]\n", i);
+ result = TET_FAIL;
+ } else
+ TS_CHECK_STRING(srcfiles[i]);
+ }
+}
+
+static void
+tp_dwarf_srcfiles(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_srcfiles);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_lineno_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Line *linebuf;
+ Dwarf_Signed linecount;
+ Dwarf_Signed srccount;
+ char **srcfiles;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_srclines(NULL, &linebuf, &linecount, &de) !=
+ DW_DLV_ERROR) {
+ tet_infoline("dwarf_srclines didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ }
+
+ if (dwarf_srcfiles(NULL, &srcfiles, &srccount, &de) !=
+ DW_DLV_ERROR) {
+ tet_infoline("dwarf_srcfiles didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_lineno/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_lineno/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..a8ed45fce4923
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_lineno/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_lineno/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..94a9822388127
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_lineno/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_loclist/Makefile b/test/libdwarf/ts/dwarf_loclist/Makefile
new file mode 100644
index 0000000000000..0d3d98554c3fb
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_loclist.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_loclist/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_loclist/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..008fdd98b84d3
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_loclist/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_loclist/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..b7beeaf6fb1af
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_loclist/dwarf_loclist.c b/test/libdwarf/ts/dwarf_loclist/dwarf_loclist.c
new file mode 100644
index 0000000000000..8ea768948341e
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/dwarf_loclist.c
@@ -0,0 +1,234 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_loclist.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for DWARF loclist query functions.
+ */
+static void tp_dwarf_loclist(void);
+static void tp_dwarf_loclist_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_loclist", tp_dwarf_loclist},
+ {"tp_dwarf_loclist_sanity", tp_dwarf_loclist_sanity},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+#include "die_traverse.c"
+
+static void
+_dwarf_loclist(Dwarf_Die die)
+{
+ Dwarf_Attribute *attrlist, at;
+ Dwarf_Signed attrcount;
+ Dwarf_Half attr;
+ Dwarf_Locdesc **llbuf, *llbuf0;
+ Dwarf_Loc *loc;
+ Dwarf_Signed listlen;
+ Dwarf_Error de;
+ const char *atname;
+ int r, i, j, k;
+ int r_loclist, r_loclist_n;
+
+ r = dwarf_attrlist(die, &attrlist, &attrcount, &de);
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_attrlist failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ return;
+ } else if (r == DW_DLV_NO_ENTRY)
+ return;
+
+ for (i = 0; i < attrcount; i++) {
+ at = attrlist[i];
+ if (dwarf_whatattr(at, &attr, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_whatattr failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ continue;
+ }
+ TS_CHECK_UINT(attr);
+ switch (attr) {
+ case DW_AT_location:
+ case DW_AT_string_length:
+ case DW_AT_return_addr:
+ case DW_AT_data_member_location:
+ case DW_AT_frame_base:
+ case DW_AT_segment:
+ case DW_AT_static_link:
+ case DW_AT_use_location:
+ case DW_AT_vtable_elem_location:
+ break;
+ default:
+ continue;
+ }
+
+ atname = NULL;
+ if (dwarf_get_AT_name(attr, &atname) != DW_DLV_OK) {
+ tet_printf("dwarf_get_AT_name failed\n");
+ result = TET_FAIL;
+ }
+ tet_printf("process attribute %s\n", atname);
+
+ r_loclist_n = dwarf_loclist_n(at, &llbuf, &listlen, &de);
+ TS_CHECK_INT(r_loclist_n);
+ if (r_loclist_n == DW_DLV_OK){
+#ifndef TCGEN
+ /*
+ * XXX SGI libdwarf do not return the End-List-Indicator
+ * to the application (when loclist is in .debug_loc .i.e,
+ * listen > 1), while our libdwarf does. Workaround this
+ * by decreasing listlen by 1 when TCGEN is not defined,
+ * so this test case can work.
+ */
+ if (listlen > 1)
+ listlen--;
+#endif
+ TS_CHECK_INT(listlen);
+ for (j = 0; j < listlen; j++) {
+ tet_printf("process loclist[%d]\n", j);
+ TS_CHECK_UINT(llbuf[j]->ld_lopc);
+ TS_CHECK_UINT(llbuf[j]->ld_hipc);
+ TS_CHECK_UINT(llbuf[j]->ld_cents);
+ for (k = 0; k < llbuf[j]->ld_cents; k++) {
+ tet_printf("process ld_s[%d]\n", k);
+ loc = &llbuf[j]->ld_s[k];
+ TS_CHECK_UINT(loc->lr_atom);
+ TS_CHECK_UINT(loc->lr_number);
+ TS_CHECK_UINT(loc->lr_number2);
+#ifndef TCGEN
+ /*
+ * XXX SGI libdwarf defined that
+ * lr_offset is lr_atom's offset + 1.
+ */
+ loc->lr_offset++;
+#endif
+ TS_CHECK_UINT(loc->lr_offset);
+#ifndef TCGEN
+ loc->lr_offset--;
+#endif
+ }
+ }
+ }
+
+ r_loclist = dwarf_loclist(at, &llbuf0, &listlen, &de);
+ TS_CHECK_INT(r_loclist);
+ if (r_loclist == DW_DLV_OK) {
+ if (listlen != 1) {
+ tet_printf("listlen(%d) returned by"
+ " dwarf_loclist must be 1", listlen);
+ result = TET_FAIL;
+ }
+ tet_printf("process the only loclist\n");
+ TS_CHECK_UINT(llbuf0->ld_lopc);
+ TS_CHECK_UINT(llbuf0->ld_hipc);
+ TS_CHECK_UINT(llbuf0->ld_cents);
+ for (k = 0; k < llbuf0->ld_cents; k++) {
+ tet_printf("process ld_s[%d]\n", k);
+ loc = &llbuf0->ld_s[k];
+ TS_CHECK_UINT(loc->lr_atom);
+ TS_CHECK_UINT(loc->lr_number);
+ TS_CHECK_UINT(loc->lr_number2);
+#ifndef TCGEN
+ /*
+ * XXX SGI libdwarf defined that
+ * lr_offset is lr_atom's offset + 1.
+ */
+ loc->lr_offset++;
+#endif
+ TS_CHECK_UINT(loc->lr_offset);
+#ifndef TCGEN
+ loc->lr_offset--;
+#endif
+ }
+ }
+ }
+}
+
+static void
+tp_dwarf_loclist(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ TS_DWARF_DIE_TRAVERSE(dbg, _dwarf_loclist);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_loclist_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Locdesc **llbuf, *llbuf0;
+ Dwarf_Signed listlen;
+ int fd;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_loclist_n(NULL, &llbuf, &listlen, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_loclist_n didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (dwarf_loclist(NULL, &llbuf0, &listlen, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_loclist didn't return DW_DLV_ERROR"
+ " when called with NULL arguments");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_loclist/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_loclist/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..2849eb8b0bfe1
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_loclist/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_loclist/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..b6ff7dbb5d8e1
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_loclist/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_macinfo/Makefile b/test/libdwarf/ts/dwarf_macinfo/Makefile
new file mode 100644
index 0000000000000..bd9d82f516d6f
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_macinfo/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_macinfo.c
+TS_DATA= dt64-g1 dt64-g3 ec64-g3
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_macinfo/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_macinfo/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..3e1a4673683d6
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_macinfo/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_macinfo/dt64-g3.xml.gz b/test/libdwarf/ts/dwarf_macinfo/dt64-g3.xml.gz
new file mode 100644
index 0000000000000..28a458355ef10
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_macinfo/dt64-g3.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_macinfo/dwarf_macinfo.c b/test/libdwarf/ts/dwarf_macinfo/dwarf_macinfo.c
new file mode 100644
index 0000000000000..bf4201f206752
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_macinfo/dwarf_macinfo.c
@@ -0,0 +1,137 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_macinfo.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf macro information API.
+ */
+static void tp_dwarf_macinfo(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_macinfo", tp_dwarf_macinfo},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+static void
+_check_details(Dwarf_Macro_Details *details, Dwarf_Signed entry_count)
+{
+ char *macro_value;
+ int i;
+
+ for (i = 0; i < entry_count; i++) {
+ tet_printf("check macro details entry %d:\n", i);
+ TS_CHECK_INT(details[i].dmd_offset);
+ TS_CHECK_UINT(details[i].dmd_type);
+ TS_CHECK_INT(details[i].dmd_lineno);
+ TS_CHECK_INT(details[i].dmd_fileindex);
+ if (details[i].dmd_macro != NULL) {
+ TS_CHECK_STRING(details[i].dmd_macro);
+ macro_value = dwarf_find_macro_value_start(details[i].dmd_macro);
+ if (macro_value != NULL)
+ TS_CHECK_STRING(macro_value);
+ }
+ }
+}
+
+static void
+_get_macinfo(Dwarf_Debug dbg, Dwarf_Off macro_offset, Dwarf_Unsigned max_count)
+{
+ Dwarf_Macro_Details *details;
+ Dwarf_Signed entry_count;
+ Dwarf_Error de;
+ int r_details;
+
+ r_details = dwarf_get_macro_details(dbg, macro_offset, max_count,
+ &entry_count, &details, &de);
+ TS_CHECK_INT(r_details);
+ if (r_details != DW_DLV_OK) {
+ if (r_details == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_macro_details failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ return;
+ }
+ TS_CHECK_UINT(entry_count);
+ _check_details(details, entry_count);
+}
+
+static void
+_get_all_macinfo(Dwarf_Debug dbg)
+{
+ Dwarf_Macro_Details *details;
+ Dwarf_Signed entry_count;
+ Dwarf_Off off;
+ Dwarf_Error de;
+ int r_details;
+
+ off = 0;
+ while ((r_details = dwarf_get_macro_details(dbg, off, 0, &entry_count,
+ &details, &de)) == DW_DLV_OK) {
+ TS_CHECK_UINT(entry_count);
+ _check_details(details, entry_count);
+ off = details[entry_count - 1].dmd_offset + 1;
+ }
+ TS_CHECK_INT(r_details);
+}
+
+static void
+tp_dwarf_macinfo(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int fd;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ /* Get all Dwarf_Macro_Details entries in the first CU. */
+ _get_macinfo(dbg, 0, 0);
+
+ /* Get first 100 entries. */
+ _get_macinfo(dbg, 0, 100);
+
+ /* Get all entries in all CUs. */
+ _get_all_macinfo(dbg);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_macinfo/ec64-g3.xml.gz b/test/libdwarf/ts/dwarf_macinfo/ec64-g3.xml.gz
new file mode 100644
index 0000000000000..a174e75b7ad03
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_macinfo/ec64-g3.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/Makefile b/test/libdwarf/ts/dwarf_next_cu_header/Makefile
new file mode 100644
index 0000000000000..ef798c118a566
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_next_cu_header.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_next_cu_header/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..e9f788ca68f3f
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_next_cu_header/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..60dfb4202084d
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/dwarf_next_cu_header.c b/test/libdwarf/ts/dwarf_next_cu_header/dwarf_next_cu_header.c
new file mode 100644
index 0000000000000..acfe506bb869f
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/dwarf_next_cu_header.c
@@ -0,0 +1,149 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_next_cu_header.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+static void tp_dwarf_next_cu_header(void);
+static void tp_dwarf_next_cu_header_b(void);
+static void tp_dwarf_next_cu_header_loop(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_next_cu_header", tp_dwarf_next_cu_header},
+ {"tp_dwarf_next_cu_header_b", tp_dwarf_next_cu_header_b},
+ {"tp_dwarf_next_cu_header_loop", tp_dwarf_next_cu_header_loop},
+ {NULL, NULL},
+};
+#include "driver.c"
+
+static void
+tp_dwarf_next_cu_header(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Unsigned cu_header_length;
+ Dwarf_Half cu_version;
+ Dwarf_Off cu_abbrev_offset;
+ Dwarf_Half cu_pointer_size;
+ Dwarf_Unsigned cu_next_offset;
+ int fd, result;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ while (dwarf_next_cu_header(dbg, &cu_header_length, &cu_version,
+ &cu_abbrev_offset, &cu_pointer_size, &cu_next_offset, &de) ==
+ DW_DLV_OK) {
+ TS_CHECK_UINT(cu_header_length);
+ TS_CHECK_UINT(cu_version);
+ TS_CHECK_INT(cu_abbrev_offset);
+ TS_CHECK_UINT(cu_pointer_size);
+ TS_CHECK_UINT(cu_next_offset);
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_next_cu_header_b(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Unsigned cu_header_length;
+ Dwarf_Half cu_version;
+ Dwarf_Off cu_abbrev_offset;
+ Dwarf_Half cu_pointer_size;
+ Dwarf_Half cu_offset_size;
+ Dwarf_Half cu_extension_size;
+ Dwarf_Unsigned cu_next_offset;
+ int fd, result;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ while (dwarf_next_cu_header_b(dbg, &cu_header_length, &cu_version,
+ &cu_abbrev_offset, &cu_pointer_size, &cu_offset_size,
+ &cu_extension_size, &cu_next_offset, &de) == DW_DLV_OK) {
+ TS_CHECK_UINT(cu_header_length);
+ TS_CHECK_UINT(cu_version);
+ TS_CHECK_INT(cu_abbrev_offset);
+ TS_CHECK_UINT(cu_pointer_size);
+ TS_CHECK_UINT(cu_offset_size);
+ TS_CHECK_UINT(cu_extension_size);
+ TS_CHECK_UINT(cu_next_offset);
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+#define _LOOP_COUNT 50
+
+static void
+tp_dwarf_next_cu_header_loop(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ int i, r, fd, result;
+ Dwarf_Unsigned cu_next_offset;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ for (i = 0; i < _LOOP_COUNT; i++) {
+ tet_printf("dwarf_next_cu_header loop(%d)\n", i);
+ r = dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL,
+ &cu_next_offset, &de);
+ TS_CHECK_INT(r);
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_next_cu_header/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..6efbf28a509d0
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_next_cu_header/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_next_cu_header/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..e03947ddbac55
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_next_cu_header/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_pubnames/Makefile b/test/libdwarf/ts/dwarf_pubnames/Makefile
new file mode 100644
index 0000000000000..b86f3b3affaf3
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_pubnames/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_pubnames.c
+TS_DATA= dt32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_pubnames/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_pubnames/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..fe85f1786c8c6
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_pubnames/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_pubnames/dwarf_pubnames.c b/test/libdwarf/ts/dwarf_pubnames/dwarf_pubnames.c
new file mode 100644
index 0000000000000..c6c677fbec2bd
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_pubnames/dwarf_pubnames.c
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_pubnames.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf address range API.
+ */
+static void tp_dwarf_pubnames(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_pubnames", tp_dwarf_pubnames},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+static void
+tp_dwarf_pubnames(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Global *globals;
+ Dwarf_Signed global_cnt;
+ Dwarf_Off die_off, cu_off;
+ char *glob_name;
+ int fd, r_globals, i;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ r_globals = dwarf_get_globals(dbg, &globals, &global_cnt, &de);
+ TS_CHECK_INT(r_globals);
+ if (r_globals == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_globals failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ TS_CHECK_INT(global_cnt);
+ if (r_globals == DW_DLV_OK) {
+ for (i = 0; i < global_cnt; i++) {
+ if (dwarf_globname(globals[i], &glob_name, &de) !=
+ DW_DLV_OK) {
+ tet_printf("dwarf_globname failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_STRING(glob_name);
+ if (dwarf_global_die_offset(globals[i], &die_off,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_global_die_offset failed: "
+ "%s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(die_off);
+ if (dwarf_global_cu_offset(globals[i], &cu_off,
+ &de) != DW_DLV_OK) {
+ tet_printf("dwarf_global_cu_offset failed: "
+ "%s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_INT(cu_off);
+ if (dwarf_global_name_offsets(globals[i], &glob_name,
+ &die_off, &cu_off, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_global_name_offsets failed: ",
+ "%s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+ TS_CHECK_STRING(glob_name);
+ TS_CHECK_INT(die_off);
+ TS_CHECK_INT(cu_off);
+ }
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_pubnames/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_pubnames/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..4549439f6e0a4
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_pubnames/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_ranges/Makefile b/test/libdwarf/ts/dwarf_ranges/Makefile
new file mode 100644
index 0000000000000..2221599117b5c
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_ranges/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_ranges.c
+TS_DATA= dt32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_ranges/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_ranges/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..12d4edf630763
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_ranges/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_ranges/dwarf_ranges.c b/test/libdwarf/ts/dwarf_ranges/dwarf_ranges.c
new file mode 100644
index 0000000000000..2cb758bb81933
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_ranges/dwarf_ranges.c
@@ -0,0 +1,102 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_ranges.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+/*
+ * Test case for dwarf address range API.
+ */
+static void tp_dwarf_ranges(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_ranges", tp_dwarf_ranges},
+ {NULL, NULL},
+};
+static int result = TET_UNRESOLVED;
+#include "driver.c"
+
+static void
+tp_dwarf_ranges(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Ranges *ranges;
+ Dwarf_Signed range_cnt;
+ Dwarf_Unsigned byte_cnt;
+ Dwarf_Off off;
+ Dwarf_Error de;
+ int fd, r_ranges, i;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ off = 0;
+ for (;;) {
+ tet_printf("check ranges at offset(%ju):\n", (uintmax_t) off);
+ r_ranges = dwarf_get_ranges_a(dbg, off, NULL, &ranges,
+ &range_cnt, &byte_cnt, &de);
+ if (r_ranges != DW_DLV_OK)
+ break;
+ TS_CHECK_INT(range_cnt);
+ TS_CHECK_UINT(byte_cnt);
+ off += byte_cnt;
+ for (i = 0; i < range_cnt; i++) {
+ tet_printf("check range %d:\n", i);
+ TS_CHECK_INT(ranges[i].dwr_type);
+ TS_CHECK_UINT(ranges[i].dwr_addr1);
+ TS_CHECK_UINT(ranges[i].dwr_addr2);
+ }
+ }
+
+ /*
+ * SGI libdwarf return DW_DLV_ERROR when provided offset is out of
+ * range, instead of DW_DLV_NO_ENTRY as stated in the SGI libdwarf
+ * documentation. elftoolchain libdwarf follows the SGI libdwarf
+ * documentation.
+ */
+#if 0
+ if (r_ranges == DW_DLV_ERROR) {
+ tet_printf("dwarf_get_ranges failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ }
+#endif
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_ranges/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_ranges/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..acb5532cdfd5d
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_ranges/ec64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_siblingof/Makefile b/test/libdwarf/ts/dwarf_siblingof/Makefile
new file mode 100644
index 0000000000000..48e8d43e7c0c7
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/Makefile
@@ -0,0 +1,8 @@
+# $Id: Makefile 2084 2011-10-27 04:48:12Z jkoshy $
+
+TOP= ../../../..
+
+TS_SRCS= dwarf_siblingof.c
+TS_DATA= dt32-g1 dt64-g1 ec32-g1 ec64-g1
+
+.include "${TOP}/mk/elftoolchain.tet.mk"
diff --git a/test/libdwarf/ts/dwarf_siblingof/dt32-g1.xml.gz b/test/libdwarf/ts/dwarf_siblingof/dt32-g1.xml.gz
new file mode 100644
index 0000000000000..adec08c4e32e2
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/dt32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_siblingof/dt64-g1.xml.gz b/test/libdwarf/ts/dwarf_siblingof/dt64-g1.xml.gz
new file mode 100644
index 0000000000000..f4e01e048a4bb
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/dt64-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_siblingof/dwarf_siblingof.c b/test/libdwarf/ts/dwarf_siblingof/dwarf_siblingof.c
new file mode 100644
index 0000000000000..534762068943c
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/dwarf_siblingof.c
@@ -0,0 +1,160 @@
+/*-
+ * Copyright (c) 2010 Kai Wang
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf_siblingof.c 2084 2011-10-27 04:48:12Z jkoshy $
+ */
+
+#include <assert.h>
+#include <dwarf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libdwarf.h>
+#include <string.h>
+
+#include "driver.h"
+#include "tet_api.h"
+
+static void tp_dwarf_siblingof_level1(void);
+static void tp_dwarf_siblingof_sanity(void);
+static struct dwarf_tp dwarf_tp_array[] = {
+ {"tp_dwarf_siblingof_level1", tp_dwarf_siblingof_level1},
+ {"tp_dwarf_siblingof_sanity", tp_dwarf_siblingof_sanity},
+ {NULL, NULL},
+};
+#include "driver.c"
+
+static void
+tp_dwarf_siblingof_level1(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Die die, die0;
+ Dwarf_Unsigned cu_next_offset;
+ int r, fd, result, die_cnt;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ tet_infoline("count the number of level 1 DIEs");
+
+ die_cnt = 0;
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ r = dwarf_siblingof(dbg, NULL, &die, &de);
+ while (r == DW_DLV_OK) {
+ if (die == NULL) {
+ tet_infoline("dwarf_siblingof return DW_DLV_OK"
+ " while argument die is not filled in");
+ result = TET_FAIL;
+ goto done;
+ }
+ die_cnt++;
+ die0 = die;
+ r = dwarf_siblingof(dbg, die0, &die, &de);
+ }
+ if (r == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ TS_CHECK_INT(die_cnt);
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
+
+static void
+tp_dwarf_siblingof_sanity(void)
+{
+ Dwarf_Debug dbg;
+ Dwarf_Error de;
+ Dwarf_Die die, die0;
+ Dwarf_Half tag, tag0;
+ Dwarf_Unsigned cu_next_offset;
+ int fd, result;
+
+ result = TET_UNRESOLVED;
+
+ TS_DWARF_INIT(dbg, fd, de);
+
+ if (dwarf_siblingof(dbg, NULL, &die, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_siblingof didn't return DW_DLV_ERROR when"
+ " called without CU context");
+ result = TET_FAIL;
+ goto done;
+ }
+
+ die = die0 = NULL;
+ TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
+ if (dwarf_siblingof(dbg, NULL, &die, &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_siblingof(dbg, NULL, &die0, &de) == DW_DLV_ERROR) {
+ tet_printf("dwarf_siblingof failed: %s\n",
+ dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_tag(die0, &tag0, &de) != DW_DLV_OK) {
+ tet_printf("dwarf_tag failed: %s\n", dwarf_errmsg(de));
+ result = TET_FAIL;
+ goto done;
+ }
+ if (tag != tag0) {
+ tet_infoline("DIEs returned by two identical "
+ "dwarf_siblingof calls have different tags");
+ result = TET_FAIL;
+ goto done;
+ }
+ if (dwarf_siblingof(NULL, die0, &die, &de) != DW_DLV_ERROR) {
+ tet_infoline("dwarf_siblingof didn't return "
+ "DW_DLV_ERROR when called with NULL dbg");
+ result = TET_FAIL;
+ goto done;
+ }
+ }
+
+ if (result == TET_UNRESOLVED)
+ result = TET_PASS;
+
+done:
+ TS_DWARF_FINISH(dbg, de);
+ TS_RESULT(result);
+}
diff --git a/test/libdwarf/ts/dwarf_siblingof/ec32-g1.xml.gz b/test/libdwarf/ts/dwarf_siblingof/ec32-g1.xml.gz
new file mode 100644
index 0000000000000..7dc98d9a7e3d8
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/ec32-g1.xml.gz
Binary files differ
diff --git a/test/libdwarf/ts/dwarf_siblingof/ec64-g1.xml.gz b/test/libdwarf/ts/dwarf_siblingof/ec64-g1.xml.gz
new file mode 100644
index 0000000000000..ec096c453da63
--- /dev/null
+++ b/test/libdwarf/ts/dwarf_siblingof/ec64-g1.xml.gz
Binary files differ