- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / tcmalloc / vendor / src / tests / debugallocation_test.sh
1 #!/bin/sh
2
3 # Copyright (c) 2009, Google Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
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
15 # distribution.
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.
19 #
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.
31 #
32 # ---
33 # Author: Craig Silverstein
34
35 BINDIR="${BINDIR:-.}"
36
37 if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
38   echo "USAGE: $0 [unittest dir]"
39   echo "       By default, unittest_dir=$BINDIR"
40   exit 1
41 fi
42
43 DEBUGALLOCATION_TEST="${1:-$BINDIR/debugallocation_test}"
44
45 num_failures=0
46
47 # Run the i-th death test and make sure the test has the expected
48 # regexp.  We can depend on the first line of the output being
49 #    Expected regex:<regex>
50 # Evaluates to "done" if we are not actually a death-test (so $1 is
51 # too big a number, and we can stop).  Evaluates to "" otherwise.
52 # Increments num_failures if the death test does not succeed.
53 OneDeathTest() {
54   "$DEBUGALLOCATION_TEST" "$1" 2>&1 | {
55     regex_line='dummy'
56     # Normally the regex_line is the first line of output, but not
57     # always (if tcmalloc itself does any logging to stderr).
58     while test -n "$regex_line"; do
59       read regex_line
60       regex=`expr "$regex_line" : "Expected regex:\(.*\)"`
61       test -n "$regex" && break   # found the regex line
62     done
63     test -z "$regex" && echo "done" || grep "$regex" 2>&1
64   }
65 }
66
67 death_test_num=0   # which death test to run
68 while :; do        # same as 'while true', but more portable
69   echo -n "Running death test $death_test_num..."
70   output="`OneDeathTest $death_test_num`"
71   case $output in
72      # Empty string means grep didn't find anything.
73      "")      echo "FAILED"; num_failures=`expr $num_failures + 1`;;
74      "done"*) echo "done with death tests"; break;;
75      # Any other string means grep found something, like it ought to.
76      *)       echo "OK";;
77   esac
78   death_test_num=`expr $death_test_num + 1`
79 done
80
81 # Test the non-death parts of the test too
82 echo -n "Running non-death tests..."
83 if "$DEBUGALLOCATION_TEST"; then
84   echo "OK"
85 else
86   echo "FAILED"
87   num_failures=`expr $num_failures + 1`
88 fi
89
90 if [ "$num_failures" = 0 ]; then
91   echo "PASS"
92 else
93   echo "Failed with $num_failures failures"
94 fi
95 exit $num_failures