2 # Copyright 2006 Google, Inc. All Rights Reserved.
3 # Author: Satoru Takabayashi
5 # Unit tests for demangle.c with a real binary.
15 LIBGLOG="$BINDIR/libglog.so"
17 DEMANGLER="$BINDIR/demangle_unittest"
19 if test -e "$DEMANGLER"; then
20 # We need shared object.
21 export LD_LIBRARY_PATH=$BINDIR
22 export DYLD_LIBRARY_PATH=$BINDIR
25 DEMANGLER="./demangle_unittest.exe"
26 if ! test -e "$DEMANGLER"; then
27 echo "We coundn't find demangle_unittest binary."
32 # Extract C++ mangled symbols from libbase.so.
33 NM_OUTPUT="demangle.nm"
34 nm "$LIBGLOG" | perl -nle 'print $1 if /\s(_Z\S+$)/' > "$NM_OUTPUT"
36 # Check if mangled symbols exist. If there are none, we quit.
37 # The binary is more likely compiled with GCC 2.95 or something old.
38 if ! grep --quiet '^_Z' "$NM_OUTPUT"; then
43 # Demangle the symbols using our demangler.
44 DM_OUTPUT="demangle.dm"
45 GLOG_demangle_filter=1 "$DEMANGLER" --demangle_filter < "$NM_OUTPUT" > "$DM_OUTPUT"
47 # Calculate the numbers of lines.
48 NM_LINES=`wc -l "$NM_OUTPUT" | awk '{ print $1 }'`
49 DM_LINES=`wc -l "$DM_OUTPUT" | awk '{ print $1 }'`
51 # Compare the numbers of lines. They must be the same.
52 if test "$NM_LINES" != "$DM_LINES"; then
53 die "$NM_OUTPUT and $DM_OUTPUT don't have the same numbers of lines"
56 # Check if mangled symbols exist. They must not exist.
57 if grep --quiet '^_Z' "$DM_OUTPUT"; then
58 die "Mangled symbols found in $DM_OUTPUT"
61 # All C++ symbols are demangled successfully.