Initialize gflags in signalhandler_unittest.
[platform/upstream/glog.git] / src / demangle_unittest.sh
1 #! /bin/sh
2 # Copyright 2006 Google, Inc.  All Rights Reserved. 
3 # Author: Satoru Takabayashi
4 #
5 # Unit tests for demangle.c with a real binary.
6
7 set -e
8
9 die () {
10     echo $1
11     exit 1
12 }
13
14 BINDIR=".libs"
15 LIBGLOG="$BINDIR/libglog.so"
16
17 DEMANGLER="$BINDIR/demangle_unittest"
18
19 if test -e "$DEMANGLER"; then
20   # We need shared object.
21   export LD_LIBRARY_PATH=$BINDIR
22   export DYLD_LIBRARY_PATH=$BINDIR
23 else
24   # For windows
25   DEMANGLER="./demangle_unittest.exe"
26   if ! test -e "$DEMANGLER"; then
27     echo "We coundn't find demangle_unittest binary."
28     exit 1
29   fi
30 fi
31
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"
35
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
39     echo "PASS"
40     exit 0
41 fi
42
43 # Demangle the symbols using our demangler.
44 DM_OUTPUT="demangle.dm"
45 GLOG_demangle_filter=1 "$DEMANGLER" --demangle_filter < "$NM_OUTPUT" > "$DM_OUTPUT"
46
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 }'`
50
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"
54 fi
55
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"
59 fi
60
61 # All C++ symbols are demangled successfully.
62 echo "PASS"
63 exit 0