Fix bionic-unit-tests-static crash
The crash happens because for static executables call to dlopen results in crash. This change moves dlopen() == nullptr check from static variable to a functions so that the dlopen crash only affects tests calling dlopen but not the whole executable. Also make static tests report crashes to debugerd Test: run bionic-unit-tests-static (for arm 32 and 64) Bug: http://b/34129417 Change-Id: I7c4d8caf2a43250234fe24496b1c95eab572769f
This commit is contained in:
parent
fb07c36bc0
commit
462ea664cf
3 changed files with 37 additions and 7 deletions
|
@ -422,6 +422,9 @@ cc_test {
|
|||
defaults: ["bionic_tests_defaults"],
|
||||
host_supported: false,
|
||||
|
||||
srcs: [
|
||||
"gtest_preinit_debuggerd.cpp",
|
||||
],
|
||||
whole_static_libs: [
|
||||
"libBionicTests",
|
||||
"libBionicGtestMain",
|
||||
|
@ -435,6 +438,7 @@ cc_test {
|
|||
"libtinyxml2",
|
||||
"liblog",
|
||||
"libbase",
|
||||
"libdebuggerd_client",
|
||||
],
|
||||
|
||||
static_executable: true,
|
||||
|
|
24
tests/gtest_preinit_debuggerd.cpp
Normal file
24
tests/gtest_preinit_debuggerd.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2017 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 "debuggerd/client.h"
|
||||
|
||||
void __gtest_preinit() {
|
||||
debuggerd_init(nullptr);
|
||||
}
|
||||
|
||||
__attribute__((section(".preinit_array"), __used__))
|
||||
void (*__local_gtest_preinit)(void) = __gtest_preinit;
|
|
@ -29,7 +29,9 @@ class UtfLocale {
|
|||
|
||||
// bionic's dlsym doesn't work in static binaries, so we can't access icu,
|
||||
// so any unicode test case will fail.
|
||||
static bool have_dl = (dlopen("libc.so", 0) != nullptr);
|
||||
static bool have_dl() {
|
||||
return (dlopen("libc.so", 0) != nullptr);
|
||||
}
|
||||
|
||||
static void TestIsWideFn(int fn(wint_t),
|
||||
int fn_l(wint_t, locale_t),
|
||||
|
@ -37,7 +39,7 @@ static void TestIsWideFn(int fn(wint_t),
|
|||
const wchar_t* falses) {
|
||||
UtfLocale l;
|
||||
for (const wchar_t* p = trues; *p; ++p) {
|
||||
if (!have_dl && *p > 0x7f) {
|
||||
if (!have_dl() && *p > 0x7f) {
|
||||
GTEST_LOG_(INFO) << "skipping unicode test " << *p;
|
||||
continue;
|
||||
}
|
||||
|
@ -45,7 +47,7 @@ static void TestIsWideFn(int fn(wint_t),
|
|||
EXPECT_TRUE(fn_l(*p, l.l)) << *p;
|
||||
}
|
||||
for (const wchar_t* p = falses; *p; ++p) {
|
||||
if (!have_dl && *p > 0x7f) {
|
||||
if (!have_dl() && *p > 0x7f) {
|
||||
GTEST_LOG_(INFO) << "skipping unicode test " << *p;
|
||||
continue;
|
||||
}
|
||||
|
@ -107,7 +109,7 @@ TEST(wctype, towlower) {
|
|||
EXPECT_EQ(wint_t('!'), towlower(L'!'));
|
||||
EXPECT_EQ(wint_t('a'), towlower(L'a'));
|
||||
EXPECT_EQ(wint_t('a'), towlower(L'A'));
|
||||
if (have_dl) {
|
||||
if (have_dl()) {
|
||||
EXPECT_EQ(wint_t(L'ç'), towlower(L'ç'));
|
||||
EXPECT_EQ(wint_t(L'ç'), towlower(L'Ç'));
|
||||
EXPECT_EQ(wint_t(L'δ'), towlower(L'δ'));
|
||||
|
@ -123,7 +125,7 @@ TEST(wctype, towlower_l) {
|
|||
EXPECT_EQ(wint_t('!'), towlower_l(L'!', l.l));
|
||||
EXPECT_EQ(wint_t('a'), towlower_l(L'a', l.l));
|
||||
EXPECT_EQ(wint_t('a'), towlower_l(L'A', l.l));
|
||||
if (have_dl) {
|
||||
if (have_dl()) {
|
||||
EXPECT_EQ(wint_t(L'ç'), towlower_l(L'ç', l.l));
|
||||
EXPECT_EQ(wint_t(L'ç'), towlower_l(L'Ç', l.l));
|
||||
EXPECT_EQ(wint_t(L'δ'), towlower_l(L'δ', l.l));
|
||||
|
@ -138,7 +140,7 @@ TEST(wctype, towupper) {
|
|||
EXPECT_EQ(wint_t('!'), towupper(L'!'));
|
||||
EXPECT_EQ(wint_t('A'), towupper(L'a'));
|
||||
EXPECT_EQ(wint_t('A'), towupper(L'A'));
|
||||
if (have_dl) {
|
||||
if (have_dl()) {
|
||||
EXPECT_EQ(wint_t(L'Ç'), towupper(L'ç'));
|
||||
EXPECT_EQ(wint_t(L'Ç'), towupper(L'Ç'));
|
||||
EXPECT_EQ(wint_t(L'Δ'), towupper(L'δ'));
|
||||
|
@ -154,7 +156,7 @@ TEST(wctype, towupper_l) {
|
|||
EXPECT_EQ(wint_t('!'), towupper_l(L'!', l.l));
|
||||
EXPECT_EQ(wint_t('A'), towupper_l(L'a', l.l));
|
||||
EXPECT_EQ(wint_t('A'), towupper_l(L'A', l.l));
|
||||
if (have_dl) {
|
||||
if (have_dl()) {
|
||||
EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'ç', l.l));
|
||||
EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'Ç', l.l));
|
||||
EXPECT_EQ(wint_t(L'Δ'), towupper_l(L'δ', l.l));
|
||||
|
|
Loading…
Reference in a new issue