From: Joel Rosdahl Date: Tue, 1 Sep 2020 17:48:24 +0000 (+0200) Subject: Improve test cases that use objdump X-Git-Tag: v4.0~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98b8ad231bb738d79d7de9b6d35b6bef27bb15a2;p=thirdparty%2Fccache.git Improve test cases that use objdump - Added expect_objdump_contains and expect_objdump_not_contains utility functions to the main test framework, making objdump_cmd and grep_cmd (renamed to objdump_grep_cmd) internal utility functions. - Removed strange support for the $HOST_OS_WINDOWS || $HOST_OS_CYGWIN case in objdump_grep_cmd. Let’s re-add it later if and when it becomes a problem. - objdump_grep_cmd now greps for literal strings, thus no longer interpreting $PWD as a regex. - Made test cases use expect_objdump_(not_)contains instead of “objdump_grep_cmd | grep_cmd”. --- diff --git a/test/run b/test/run index 2bc580dbe..e0e9e3af3 100755 --- a/test/run +++ b/test/run @@ -124,12 +124,24 @@ file_size() { } objdump_cmd() { + local file="$1" + if $HOST_OS_APPLE; then - xcrun dwarfdump -r 0 $1 + xcrun dwarfdump -r 0 "$file" elif $HOST_OS_WINDOWS || $HOST_OS_CYGWIN; then - strings $1 # for some reason objdump only shows the basename of the file, so fall back to brute force and ignorance + # For some reason objdump only shows the basename of the file, so fall + # back to brute force and ignorance. + strings "$1" + else + objdump -W "$file" + fi +} + +objdump_grep_cmd() { + if $HOST_OS_APPLE; then + fgrep -q "\"$1\"" else - objdump -W $1 + fgrep -q ": $1" fi } @@ -250,6 +262,24 @@ expect_not_contains() { fi } +expect_objdump_contains() { + local file="$1" + local string="$2" + + if ! objdump_cmd "$file" | objdump_grep_cmd "$string"; then + test_failed "File $file does not contain \"$string\"" + fi +} + +expect_objdump_not_contains() { + local file="$1" + local string="$2" + + if objdump_cmd "$file" | objdump_grep_cmd "$string"; then + test_failed "File $file contains \"$string\"" + fi +} + expect_file_count() { local expected=$1 local pattern=$2 diff --git a/test/suites/debug_prefix_map.bash b/test/suites/debug_prefix_map.bash index 688daded4..ce36bfb5a 100644 --- a/test/suites/debug_prefix_map.bash +++ b/test/suites/debug_prefix_map.bash @@ -20,66 +20,44 @@ EOF backdate dir1/include/test.h dir2/include/test.h } -grep_cmd() { - if $HOST_OS_APPLE; then - grep \"$1\" - elif $HOST_OS_WINDOWS || $HOST_OS_CYGWIN; then - test -n "$2" && grep -E "$1|$2" || grep "$1" # accept a relative path for source code, in addition to relocation dir - else - grep ": $1[[:space:]]*$" - fi -} - SUITE_debug_prefix_map() { # ------------------------------------------------------------------------- TEST "Mapping of debug info CWD" cd dir1 - CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o + CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -g -fdebug-prefix-map=$(pwd)=some_name_not_likely_to_exist_in_path -c $(pwd)/src/test.c -o $(pwd)/test.o expect_stat 'cache hit (direct)' 0 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then - test_failed "Source dir (`pwd`) found in test.o" - fi - if ! objdump_cmd test.o | grep_cmd "dir" src/test.c >/dev/null 2>&1; then - test_failed "Relocation (dir) not found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" + expect_objdump_contains test.o some_name_not_likely_to_exist_in_path cd ../dir2 - CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o + CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -g -fdebug-prefix-map=$(pwd)=some_name_not_likely_to_exist_in_path -c $(pwd)/src/test.c -o $(pwd)/test.o expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then - test_failed "Source dir (`pwd`) found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" # ------------------------------------------------------------------------- TEST "Multiple -fdebug-prefix-map" cd dir1 - CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=name -fdebug-prefix-map=foo=bar -c `pwd`/src/test.c -o `pwd`/test.o + CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -g -fdebug-prefix-map=$(pwd)=some_name_not_likely_to_exist_in_path -fdebug-prefix-map=foo=bar -c $(pwd)/src/test.c -o $(pwd)/test.o expect_stat 'cache hit (direct)' 0 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then - test_failed "Source dir (`pwd`) found in test.o" - fi - if ! objdump_cmd test.o | grep_cmd "name" src/test.c >/dev/null 2>&1; then - test_failed "Relocation (name) not found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" + expect_objdump_contains test.o some_name_not_likely_to_exist_in_path cd ../dir2 - CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=name -fdebug-prefix-map=foo=bar -c `pwd`/src/test.c -o `pwd`/test.o + CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -g -fdebug-prefix-map=$(pwd)=some_name_not_likely_to_exist_in_path -fdebug-prefix-map=foo=bar -c $(pwd)/src/test.c -o $(pwd)/test.o expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then - test_failed "Source dir (`pwd`) found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" } diff --git a/test/suites/split_dwarf.bash b/test/suites/split_dwarf.bash index f912aa616..fb13f5914 100644 --- a/test/suites/split_dwarf.bash +++ b/test/suites/split_dwarf.bash @@ -106,9 +106,7 @@ SUITE_split_dwarf() { expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o 2>/dev/null | grep_cmd "$(pwd)" >/dev/null 2>&1; then - test_failed "Source dir ($(pwd)) found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" cd ../dir2 CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -gsplit-dwarf -fdebug-prefix-map=$(pwd)=. -c $(pwd)/src/test.c -o $(pwd)/test.o @@ -116,9 +114,7 @@ SUITE_split_dwarf() { expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 - if objdump_cmd test.o 2>/dev/null | grep_cmd "$(pwd)" >/dev/null 2>&1; then - test_failed "Source dir ($(pwd)) found in test.o" - fi + expect_objdump_not_contains test.o "$(pwd)" # ------------------------------------------------------------------------- TEST "-gsplit-dwarf -g1"