3 # Copyright (c) 2006, Google Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # Author: Satoru Takabayashi
34 # Unit tests for demangle.c with a real binary.
44 LIBGLOG="$BINDIR/libglog.so"
46 DEMANGLER="$BINDIR/demangle_unittest"
48 if test -e "$DEMANGLER"; then
49 # We need shared object.
50 export LD_LIBRARY_PATH=$BINDIR
51 export DYLD_LIBRARY_PATH=$BINDIR
54 DEMANGLER="./demangle_unittest.exe"
55 if ! test -e "$DEMANGLER"; then
56 echo "We coundn't find demangle_unittest binary."
61 # Extract C++ mangled symbols from libbase.so.
62 NM_OUTPUT="demangle.nm"
63 nm "$LIBGLOG" | perl -nle 'print $1 if /\s(_Z\S+$)/' > "$NM_OUTPUT"
65 # Check if mangled symbols exist. If there are none, we quit.
66 # The binary is more likely compiled with GCC 2.95 or something old.
67 if ! grep --quiet '^_Z' "$NM_OUTPUT"; then
72 # Demangle the symbols using our demangler.
73 DM_OUTPUT="demangle.dm"
74 GLOG_demangle_filter=1 "$DEMANGLER" --demangle_filter < "$NM_OUTPUT" > "$DM_OUTPUT"
76 # Calculate the numbers of lines.
77 NM_LINES=`wc -l "$NM_OUTPUT" | awk '{ print $1 }'`
78 DM_LINES=`wc -l "$DM_OUTPUT" | awk '{ print $1 }'`
80 # Compare the numbers of lines. They must be the same.
81 if test "$NM_LINES" != "$DM_LINES"; then
82 die "$NM_OUTPUT and $DM_OUTPUT don't have the same numbers of lines"
85 # Check if mangled symbols exist. They must not exist.
86 if grep --quiet '^_Z' "$DM_OUTPUT"; then
87 die "Mangled symbols found in $DM_OUTPUT"
90 # All C++ symbols are demangled successfully.