Skip to content

Commit

Permalink
Add NDK_ANALYZER_OUT, expand the test.
Browse files Browse the repository at this point in the history
Allow analyzer output to be sent somewhere other than /tmp with
NDK_ANALYZER_OUT. Now that we can predict the output, improve the
test (since it clearly wasn't catching anything).

Also, remove the test config saying the test was clang specific. It
actually works with both Clang and GCC.

Test: ./run_tests.py --filter NDK_ANALYZE
Bug: android/ndk#362
Change-Id: I7226e6fba1190573280e8b0c21b8550fb5636005
  • Loading branch information
DanAlbert committed Jul 26, 2017
1 parent 2408902 commit c205e1b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 11 additions & 0 deletions build/ndk-build
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fi

PROJECT_PATH=
PROJECT_PATH_NEXT=
NDK_ANALYZER_OUT=
for opt; do
if [ -z "$PROJECT_PATH" -a "$PROJECT_PATH_NEXT" = "yes" ] ; then
PROJECT_PATH=$opt
Expand All @@ -79,6 +80,9 @@ for opt; do
NDK_ANALYZE=*)
NDK_ANALYZE=0
;;
NDK_ANALYZER_OUT=*)
NDK_ANALYZER_OUT=${opt#NDK_ANALYZER_OUT=}
;;
NDK_TOOLCHAIN_VERSION=*)
NDK_TOOLCHAIN_VERSION=${opt#NDK_TOOLCHAIN_VERSION=}
;;
Expand Down Expand Up @@ -264,6 +268,7 @@ if [ "$NDK_ANALYZE" = 1 ]; then
for ABI in $APP_ABIS; do
TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $ABI`
LLVM_PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG
ANALYZER_OUT=`get_build_var NDK_APP_ANALYZER_OUT`

if [ "$TOOLCHAIN" = "clang" ]; then
ANALYZER_CC=$LLVM_PATH/bin/clang
Expand All @@ -273,11 +278,17 @@ if [ "$NDK_ANALYZE" = 1 ]; then
ANALYZER_CXX=${TOOLCHAIN_PREFIX}g++
fi

ANALYZER_OUT_FLAG=
if [ -n "$NDK_ANALYZER_OUT" ]; then
ANALYZER_OUT_FLAG="-o $NDK_ANALYZER_OUT/$ABI"
fi

perl $LLVM_PATH/tools/scan-build/bin/scan-build \
--use-analyzer $LLVM_PATH/bin/${ABI}/analyzer \
--use-cc $ANALYZER_CC \
--use-c++ $ANALYZER_CXX \
--status-bugs \
$ANALYZER_OUT_FLAG \
$GNUMAKE -f $PROGDIR/core/build-local.mk "$@" APP_ABI=$ABI
done
else
Expand Down
6 changes: 5 additions & 1 deletion tests/build/NDK_ANALYZE/project/jni/foo.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
void foo() {}
#include <malloc.h>

void foo() {
malloc(0);
}
15 changes: 14 additions & 1 deletion tests/build/NDK_ANALYZE/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ def run_test(abi, platform, _toolchain, build_flags):
ndk_dir = os.environ['NDK']
ndk_build = os.path.join(ndk_dir, 'ndk-build')
project_path = 'project'
analyzer_out = os.path.join(project_path, 'report')
ndk_args = build_flags + [
'APP_ABI=' + abi,
'APP_PLATFORM=android-{}'.format(platform),
'NDK_ANALYZE=1',
'NDK_ANALYZER_OUT=' + analyzer_out,
]
proc = subprocess.Popen([ndk_build, '-C', project_path] + ndk_args,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = proc.communicate()
return proc.returncode == 0, out
# We expect the analyzer to find an issue and exit with a failure.
if proc.returncode == 0:
return False, out

analyzer_abi_out = os.path.join(analyzer_out, abi)
# The out directory gets created even if the analyzer fails, so we
# intentionally include bad code and make sure we get a failure report.
reports = os.listdir(analyzer_abi_out)
if len(reports) == 0:
return False, 'No analyzer output found in ' + analyzer_abi_out

return True, out
2 changes: 0 additions & 2 deletions tests/build/NDK_ANALYZE/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
def build_unsupported(_abi, _api, toolchain):
if sys.platform == 'win32':
return sys.platform
if toolchain != 'clang':
return toolchain
return None

0 comments on commit c205e1b

Please sign in to comment.