| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 # Copyright (c) 2009, Google Inc. | 3 # Copyright (c) 2009, Google Inc. |
| 4 # All rights reserved. | 4 # All rights reserved. |
| 5 # | 5 # |
| 6 # Redistribution and use in source and binary forms, with or without | 6 # Redistribution and use in source and binary forms, with or without |
| 7 # modification, are permitted provided that the following conditions are | 7 # modification, are permitted provided that the following conditions are |
| 8 # met: | 8 # met: |
| 9 # | 9 # |
| 10 # * Redistributions of source code must retain the above copyright | 10 # * Redistributions of source code must retain the above copyright |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 num_failures=0 | 45 num_failures=0 |
| 46 | 46 |
| 47 # Run the i-th death test and make sure the test has the expected | 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 | 48 # regexp. We can depend on the first line of the output being |
| 49 # Expected regex:<regex> | 49 # Expected regex:<regex> |
| 50 # Evaluates to "done" if we are not actually a death-test (so $1 is | 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. | 51 # too big a number, and we can stop). Evaluates to "" otherwise. |
| 52 # Increments num_failures if the death test does not succeed. | 52 # Increments num_failures if the death test does not succeed. |
| 53 OneDeathTest() { | 53 OneDeathTest() { |
| 54 "$DEBUGALLOCATION_TEST" "$1" 2>&1 | { | 54 "$DEBUGALLOCATION_TEST" "$1" 2>&1 | { |
| 55 read regex_line | 55 regex_line='dummy' |
| 56 regex=`expr "$regex_line" : "Expected regex:\(.*\)"` | 56 # Normally the regex_line is the first line of output, but not |
| 57 test -z "$regex" && echo "done" # no regex line, not a death-case | 57 # always (if tcmalloc itself does any logging to stderr). |
| 58 grep "$regex" >/dev/null 2>&1 # pass the rest of the lines through grep | 58 while test -n "$regex_line"; do |
| 59 } || num_failures=`expr $num_failures + 1` | 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 } |
| 60 } | 65 } |
| 61 | 66 |
| 62 death_test_num=0 # which death test to run | 67 death_test_num=0 # which death test to run |
| 63 while test -z `OneDeathTest "$death_test_num"`; do | 68 while :; do # same as 'while true', but more portable |
| 64 echo "Done with death test $death_test_num" | 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 |
| 65 death_test_num=`expr $death_test_num + 1` | 78 death_test_num=`expr $death_test_num + 1` |
| 66 done | 79 done |
| 67 | 80 |
| 68 # Test the non-death parts of the test too | 81 # Test the non-death parts of the test too |
| 69 if ! "$DEBUGALLOCATION_TEST"; then | 82 echo -n "Running non-death tests..." |
| 83 if "$DEBUGALLOCATION_TEST"; then |
| 84 echo "OK" |
| 85 else |
| 86 echo "FAILED" |
| 70 num_failures=`expr $num_failures + 1` | 87 num_failures=`expr $num_failures + 1` |
| 71 fi | 88 fi |
| 72 | 89 |
| 73 if [ "$num_failures" = 0 ]; then | 90 if [ "$num_failures" = 0 ]; then |
| 74 echo "PASS" | 91 echo "PASS" |
| 75 else | 92 else |
| 76 echo "Failed with $num_failures failures" | 93 echo "Failed with $num_failures failures" |
| 77 fi | 94 fi |
| 78 exit $num_failures | 95 exit $num_failures |
| OLD | NEW |