From f68dcbe0930b38db2a0909934f64175b1c51745a Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 2 Feb 2016 17:13:03 -0800 Subject: [PATCH] Fix our fortify tests for global -Werror. If anyone has a better way of doing this it would be welcome... Bug: http://b/26936282 Change-Id: I796896866327b4b5b5ee4ec36994fb320993f85d --- tests/Android.mk | 2 +- tests/file-check-cxx | 2 +- tests/fortify_test.cpp | 8 ++++++++ tests/fortify_test_main.cpp | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/fortify_test_main.cpp diff --git a/tests/Android.mk b/tests/Android.mk index 3712920e5..fb3c25445 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -162,7 +162,7 @@ $(foreach compiler,gcc clang, \ -D_FORTIFY_SOURCE=$(test) \ -DTEST_NAME=Fortify$(test)_$(compiler)); \ $(eval fortify$(test)-tests-$(compiler)_src_files := \ - fortify_test.cpp); \ + fortify_test_main.cpp); \ $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ ) \ ) diff --git a/tests/file-check-cxx b/tests/file-check-cxx index 40182656b..d3bc5f76f 100755 --- a/tests/file-check-cxx +++ b/tests/file-check-cxx @@ -5,7 +5,7 @@ PREFIX=$3 shift 3 SOURCE=$(echo "$@" | grep -oP '\S+\.cpp\b') OBJ=$(echo "$@" | grep -oP '\S+\.o\b') -$CXX "$@" 2>&1 | $FILECHECK -check-prefix=$PREFIX $SOURCE +$CXX "$@" -Wno-error 2>&1 | $FILECHECK -check-prefix=$PREFIX $SOURCE if [ "$?" -eq 0 ]; then touch $OBJ else diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp index a349da907..4ffd5f92c 100644 --- a/tests/fortify_test.cpp +++ b/tests/fortify_test.cpp @@ -14,6 +14,14 @@ * limitations under the License. */ +// -Werror is on whether we like it or not, and we're intentionally doing awful +// things in this file. GCC is dumb and doesn't have a specific error class for +// the fortify failures (it's just -Werror), so we can't use anything more +// constrained than disabling all the warnings in the file :( It also won't let +// us use system_header in a .cpp file, so we have to #include this from +// fortify_test_main.cpp. +#pragma GCC system_header + #include #include "BionicDeathTest.h" diff --git a/tests/fortify_test_main.cpp b/tests/fortify_test_main.cpp new file mode 100644 index 000000000..8e52d42e5 --- /dev/null +++ b/tests/fortify_test_main.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "fortify_test.cpp"