am 4affcbf8: Merge "Make sure that the same tests are on all platforms."

* commit '4affcbf87769c43c4d03ecd60f902b0b6a6cb84a':
  Make sure that the same tests are on all platforms.
This commit is contained in:
Christopher Ferris 2014-03-07 02:25:05 +00:00 committed by Android Git Automerger
commit e314bf20b6
20 changed files with 617 additions and 305 deletions

85
tests/Android.build.mk Normal file
View File

@ -0,0 +1,85 @@
#
# Copyright (C) 2014 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 $(CLEAR_VARS)
LOCAL_MODULE := $(module)
LOCAL_MODULE_TAGS := $(module_tag)
LOCAL_CLANG := $($(module)_clang_$(build_type))
LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
LOCAL_ADDITIONAL_DEPENDENCIES := \
$(LOCAL_PATH)/Android.mk \
$(LOCAL_PATH)/Android.build.mk \
LOCAL_CFLAGS := \
$(common_cflags) \
$($(module)_cflags) \
$($(module)_cflags_$(build_type)) \
LOCAL_CONLYFLAGS += \
$(common_conlyflags) \
$($(module)_conlyflags) \
$($(module)_conlyflags_$(build_type)) \
LOCAL_CPPFLAGS += \
$(common_cppflags) \
$($(module)_cppflags) \
$($(module)_cppflags_$(build_type)) \
LOCAL_C_INCLUDES := \
$(common_c_includes) \
$($(module)_c_includes) \
$($(module)_c_includes_$(build_type)) \
LOCAL_SRC_FILES := \
$($(module)_src_files) \
$($(module)_src_files_$(build_type)) \
LOCAL_STATIC_LIBRARIES := \
$($(module)_static_libraries) \
$($(module)_static_libraries_$(build_type)) \
LOCAL_SHARED_LIBRARIES := \
$($(module)_shared_libraries) \
$($(module)_shared_libraries_$(build_type)) \
LOCAL_WHOLE_STATIC_LIBRARIES := \
$($(module)_whole_static_libraries) \
$($(module)_whole_static_libraries_$(build_type)) \
LOCAL_LDFLAGS := \
$($(module)_ldflags) \
$($(module)_ldflags_$(build_type)) \
LOCAL_LDLIBS := \
$($(module)_ldlibs) \
$($(module)_ldlibs_$(build_type)) \
ifeq ($(build_type),target)
include external/stlport/libstlport.mk
include $(BUILD_$(build_target))
endif
ifeq ($(build_type),host)
# Only build if host builds are supported.
ifeq ($(build_host),true)
include $(BUILD_HOST_$(build_target))
endif
endif

View File

@ -22,19 +22,23 @@ LOCAL_PATH := $(call my-dir)
# Unit tests. # Unit tests.
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
test_c_flags = \ ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
build_host := true
else
build_host := false
endif
# -----------------------------------------------------------------------------
# All standard tests.
# -----------------------------------------------------------------------------
test_cflags = \
-fstack-protector-all \ -fstack-protector-all \
-g \ -g \
-Wall -Wextra \ -Wall -Wextra \
-Werror \ -Werror \
-fno-builtin \ -fno-builtin \
ifeq ($(TARGET_ARCH),arm64) libBionicStandardTests_src_files := \
$(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
test_c_flags += -fno-stack-protector
endif # arm64
test_src_files = \
buffer_tests.cpp \ buffer_tests.cpp \
dirent_test.cpp \ dirent_test.cpp \
eventfd_test.cpp \ eventfd_test.cpp \
@ -54,6 +58,7 @@ test_src_files = \
signal_test.cpp \ signal_test.cpp \
stack_protector_test.cpp \ stack_protector_test.cpp \
stack_unwinding_test.cpp \ stack_unwinding_test.cpp \
stack_unwinding_test_impl.c \
statvfs_test.cpp \ statvfs_test.cpp \
stdio_test.cpp \ stdio_test.cpp \
stdlib_test.cpp \ stdlib_test.cpp \
@ -73,106 +78,168 @@ test_src_files = \
time_test.cpp \ time_test.cpp \
unistd_test.cpp \ unistd_test.cpp \
test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction libBionicStandardTests_cflags := \
test_dynamic_src_files = \ $(test_cflags) \
dlfcn_test.cpp \
test_fortify_static_libraries = \ libBionicStandardTests_ldlibs_host := \
fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang -lrt \
include $(CLEAR_VARS) module := libBionicStandardTests
LOCAL_MODULE := bionic-unit-tests-unwind-test-impl module_tag := optional
LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions build_type := target
LOCAL_SRC_FILES := stack_unwinding_test_impl.c build_target := STATIC_TEST_LIBRARY
include $(BUILD_STATIC_LIBRARY) include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(CLEAR_VARS) include $(LOCAL_PATH)/Android.build.mk
LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
LOCAL_SRC_FILES := stack_unwinding_test_impl.c
include $(BUILD_HOST_STATIC_LIBRARY)
# Build tests for the device (with bionic's .so). Run with:
# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
include $(CLEAR_VARS)
LOCAL_MODULE := bionic-unit-tests
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_CFLAGS += $(test_c_flags)
LOCAL_LDFLAGS += $(test_dynamic_ldflags)
LOCAL_SHARED_LIBRARIES += libdl
LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
include $(BUILD_NATIVE_TEST)
# Build tests for the device (with bionic's .a). Run with:
# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
include $(CLEAR_VARS)
LOCAL_MODULE := bionic-unit-tests-static
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
include $(BUILD_NATIVE_TEST)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# We build the static unit tests as a library so they can be used both for # Fortify tests.
# bionic-unit-tests-static and also as part of CTS.
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
$(foreach compiler,gcc clang, \
$(foreach test,1 2, \
$(eval fortify$(test)-tests-$(compiler)_cflags := \
$(test_cflags) \
-U_FORTIFY_SOURCE \
-D_FORTIFY_SOURCE=$(test) \
-DTEST_NAME=Fortify$(test)_$(compiler)); \
$(eval fortify$(test)-tests-$(compiler)_cflags_host := \
-Wno-error); \
$(eval fortify$(test)-tests-$(compiler)_src_files := \
fortify_test.cpp); \
$(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
) \
)
include $(CLEAR_VARS) module := fortify1-tests-gcc
LOCAL_MODULE := libBionicTests module_tag := optional
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk build_type := target
LOCAL_CFLAGS += $(test_c_flags) build_target := STATIC_TEST_LIBRARY
LOCAL_SRC_FILES := $(test_src_files) include $(LOCAL_PATH)/Android.build.mk
LOCAL_CFLAGS += \ build_type := host
-DGTEST_OS_LINUX_ANDROID \ include $(LOCAL_PATH)/Android.build.mk
-DGTEST_HAS_STD_STRING \
LOCAL_C_INCLUDES += \ module := fortify2-tests-gcc
bionic bionic/libstdc++/include \ module_tag := optional
external/gtest/include \ build_type := target
external/stlport/stlport \ build_target := STATIC_TEST_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk
LOCAL_WHOLE_STATIC_LIBRARIES := \ fortify1-tests-clang_clang_target := true
$(test_fortify_static_libraries) \ fortify1-tests-clang_cflags_host := -D__clang__
bionic-unit-tests-unwind-test-impl \
include $(BUILD_STATIC_LIBRARY) module := fortify1-tests-clang
module_tag := optional
build_type := target
build_target := STATIC_TEST_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk
fortify2-tests-clang_clang_target := true
fortify2-tests-clang_cflags_host := -D__clang__
module := fortify2-tests-clang
module_tag := optional
build_type := target
build_target := STATIC_TEST_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Test library for the unit tests. # Library of all tests (excluding the dynamic linker tests).
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
libBionicTests_whole_static_libraries := \
libBionicStandardTests \
$(fortify_libs) \
# Build no-elf-hash-table-library.so to test dlopen(3) on a library that module := libBionicTests
# only has a GNU-style hash table. MIPS doesn't support GNU hash style. module_tag := optional
ifneq ($(TARGET_ARCH),mips) build_type := target
include $(CLEAR_VARS) build_target := STATIC_TEST_LIBRARY
LOCAL_MODULE := no-elf-hash-table-library include $(LOCAL_PATH)/Android.build.mk
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk build_type := host
LOCAL_SRC_FILES := empty.cpp include $(LOCAL_PATH)/Android.build.mk
LOCAL_LDFLAGS := -Wl,--hash-style=gnu
include $(BUILD_SHARED_LIBRARY) # -----------------------------------------------------------------------------
# Library used by dlfcn tests.
# -----------------------------------------------------------------------------
ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
no-elf-hash-table-library_src_files := \
empty.cpp \
no-elf-hash-table-library_ldflags := \
-Wl,--hash-style=gnu \
module := no-elf-hash-table-library
module_tag := optional
build_type := target
build_target := SHARED_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
endif endif
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Unit tests built against glibc. # Tests for the device using bionic's .so. Run with:
# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
bionic-unit-tests_whole_static_libraries := \
libBionicTests \
# Build tests for the host (with glibc). bionic-unit-tests_src_files := \
# Note that this will build against glibc, so it's not useful for testing dlfcn_test.cpp \
# bionic's implementation, but it does let you use glibc as a reference
# implementation for testing the tests themselves. bionic-unit-tests_ldflags := \
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) -Wl,--export-dynamic \
include $(CLEAR_VARS) -Wl,-u,DlSymTestFunction \
LOCAL_MODULE := bionic-unit-tests-glibc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk bionic-unit-tests_shared_libraries_target := \
LOCAL_CFLAGS += $(test_c_flags) libdl \
LOCAL_LDFLAGS += -lpthread -ldl -lrt
LOCAL_LDFLAGS += $(test_dynamic_ldflags) module := bionic-unit-tests
LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) module_tag := optional
LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host build_type := target
include $(BUILD_HOST_NATIVE_TEST) build_target := NATIVE_TEST
include $(LOCAL_PATH)/Android.build.mk
# -----------------------------------------------------------------------------
# Tests for the device linked against bionic's static library. Run with:
# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
# -----------------------------------------------------------------------------
bionic-unit-tests-static_whole_static_libraries := \
libBionicTests \
bionic-unit-tests-static_static_libraries := \
libstlport_static \
libm \
libc \
libstdc++ \
bionic-unit-tests-static_force_static_executable := true
module := bionic-unit-tests-static
module_tag := optional
build_type := target
build_target := NATIVE_TEST
include $(LOCAL_PATH)/Android.build.mk
# -----------------------------------------------------------------------------
# Tests to run on the host and linked against glibc. Run with:
# cd bionic/tests; mm bionic-unit-tests-glibc-run
# -----------------------------------------------------------------------------
bionic-unit-tests-glibc_whole_static_libraries := \
libBionicStandardTests \
bionic-unit-tests-glibc_ldlibs := \
-lrt \
module := bionic-unit-tests-glibc
module_tag := optional
build_type := host
build_target := NATIVE_TEST
include $(LOCAL_PATH)/Android.build.mk
# gtest needs ANDROID_DATA/local/tmp for death test output. # gtest needs ANDROID_DATA/local/tmp for death test output.
# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
@ -182,12 +249,10 @@ bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
ANDROID_DATA=$(TARGET_OUT_DATA) \ ANDROID_DATA=$(TARGET_OUT_DATA) \
ANDROID_ROOT=$(TARGET_OUT) \ ANDROID_ROOT=$(TARGET_OUT) \
$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
endif
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Run the unit tests built against x86 bionic on an x86 host. # Run the unit tests built against x86 bionic on an x86 host.
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
ifeq ($(TARGET_ARCH),x86) ifeq ($(TARGET_ARCH),x86)
@ -213,55 +278,4 @@ bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LIN
endif endif
endif endif
# -----------------------------------------------------------------------------
# FORTIFY_SOURCE tests
# -----------------------------------------------------------------------------
fortify_c_includes = \
bionic \
bionic/libstdc++/include \
external/stlport/stlport \
external/gtest/include
fortify_test_files = fortify_test.cpp
# -Wno-error=unused-parameter needed as
# external/stlport/stlport/stl/_threads.c (included from
# external/gtest/include/gtest/gtest.h) does not compile cleanly under
# clang. TODO: fix this.
fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(fortify_test_files)
LOCAL_MODULE := fortify1-tests-gcc
LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_C_INCLUDES += $(fortify_c_includes)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(fortify_test_files)
LOCAL_MODULE := fortify2-tests-gcc
LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_C_INCLUDES += $(fortify_c_includes)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(fortify_test_files)
LOCAL_MODULE := fortify1-tests-clang
LOCAL_CLANG := true
LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_C_INCLUDES += $(fortify_c_includes)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(fortify_test_files)
LOCAL_MODULE := fortify2-tests-clang
LOCAL_CLANG := true
LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_C_INCLUDES += $(fortify_c_includes)
include $(BUILD_STATIC_LIBRARY)
endif # !BUILD_TINY_ANDROID endif # !BUILD_TINY_ANDROID

View File

@ -14,11 +14,25 @@
* limitations under the License. * limitations under the License.
*/ */
#include <errno.h>
#include <fcntl.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#if !defined(__GLIBC__) // Android's prebuilt gcc's header files don't include <sys/eventfd.h>. #if defined(__BIONIC__) // Android's prebuilt gcc's header files don't include <sys/eventfd.h>.
#include <sys/eventfd.h> #include <sys/eventfd.h>
#else
// Include the necessary components of sys/eventfd.h right here.
#include <stdint.h>
typedef uint64_t eventfd_t;
__BEGIN_DECLS
extern int eventfd(int, int);
extern int eventfd_read(int, eventfd_t*);
extern int eventfd_write(int, eventfd_t);
__END_DECLS
#endif
TEST(eventfd, smoke) { TEST(eventfd, smoke) {
unsigned int initial_value = 2; unsigned int initial_value = 2;
@ -43,5 +57,3 @@ TEST(eventfd, smoke) {
close(fd); close(fd);
} }
#endif

View File

@ -15,6 +15,7 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <signal.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h> #include <sys/types.h>
@ -139,19 +140,21 @@ TEST(DEATHTEST, vsnprintf2_fortified2) {
} }
#endif #endif
#if __BIONIC__
#ifndef __clang__ #ifndef __clang__
// zero sized target with "\0" source (should fail) // zero sized target with "\0" source (should fail)
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strcpy_fortified2) { TEST(DEATHTEST, strcpy_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
char* src = strdup(""); char* src = strdup("");
ASSERT_EXIT(strcpy(myfoo.empty, src), ASSERT_EXIT(strcpy(myfoo.empty, src),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
free(src); free(src);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -160,12 +163,16 @@ TEST(DEATHTEST, strcpy_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strcpy2_fortified2) { TEST(DEATHTEST, strcpy2_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
char* src = strdup("1"); char* src = strdup("1");
ASSERT_EXIT(strcpy(myfoo.empty, src), ASSERT_EXIT(strcpy(myfoo.empty, src),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
free(src); free(src);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -174,12 +181,16 @@ TEST(DEATHTEST, strcpy2_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strcpy3_fortified2) { TEST(DEATHTEST, strcpy3_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
char* src = strdup("12"); char* src = strdup("12");
ASSERT_EXIT(strcpy(myfoo.one, src), ASSERT_EXIT(strcpy(myfoo.one, src),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
free(src); free(src);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -187,12 +198,16 @@ TEST(DEATHTEST, strcpy3_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strchr_fortified2) { TEST(DEATHTEST, strchr_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); memcpy(myfoo.a, "0123456789", sizeof(myfoo.a));
myfoo.b[0] = '\0'; myfoo.b[0] = '\0';
ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')), ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -200,12 +215,16 @@ TEST(DEATHTEST, strchr_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strrchr_fortified2) { TEST(DEATHTEST, strrchr_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
memcpy(myfoo.a, "0123456789", 10); memcpy(myfoo.a, "0123456789", 10);
memcpy(myfoo.b, "01234", 6); memcpy(myfoo.b, "01234", 6);
ASSERT_EXIT(printf("%s", strrchr(myfoo.a, 'a')), ASSERT_EXIT(printf("%s", strrchr(myfoo.a, 'a')),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -213,12 +232,16 @@ TEST(DEATHTEST, strrchr_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strlcpy_fortified2) { TEST(DEATHTEST, strlcpy_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
strcpy(myfoo.a, "01"); strcpy(myfoo.a, "01");
size_t n = strlen(myfoo.a); size_t n = strlen(myfoo.a);
ASSERT_EXIT(strlcpy(myfoo.one, myfoo.a, n), ASSERT_EXIT(strlcpy(myfoo.one, myfoo.a, n),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
@ -226,6 +249,7 @@ TEST(DEATHTEST, strlcpy_fortified2) {
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
TEST(DEATHTEST, strlcat_fortified2) { TEST(DEATHTEST, strlcat_fortified2) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo; foo myfoo;
strcpy(myfoo.a, "01"); strcpy(myfoo.a, "01");
@ -233,11 +257,12 @@ TEST(DEATHTEST, strlcat_fortified2) {
size_t n = strlen(myfoo.a); size_t n = strlen(myfoo.a);
ASSERT_EXIT(strlcat(myfoo.one, myfoo.a, n), ASSERT_EXIT(strlcat(myfoo.one, myfoo.a, n),
testing::KilledBySignal(SIGABRT), ""); testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif #endif
#endif /* __BIONIC__ */
#ifndef __clang__ #ifndef __clang__
// This test is disabled in clang because clang doesn't properly detect // This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang. // this buffer overflow. TODO: Fix clang.
@ -310,74 +335,106 @@ TEST(DEATHTEST, bzero_fortified2) {
#endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */ #endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */
#if __BIONIC__
// multibyte target where we over fill (should fail) // multibyte target where we over fill (should fail)
TEST(DEATHTEST, strcpy_fortified) { TEST(DEATHTEST, strcpy_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10]; char buf[10];
char *orig = strdup("0123456789"); char *orig = strdup("0123456789");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
free(orig); free(orig);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
// zero sized target with "\0" source (should fail) // zero sized target with "\0" source (should fail)
TEST(DEATHTEST, strcpy2_fortified) { TEST(DEATHTEST, strcpy2_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0]; char buf[0];
char *orig = strdup(""); char *orig = strdup("");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
free(orig); free(orig);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
// zero sized target with longer source (should fail) // zero sized target with longer source (should fail)
TEST(DEATHTEST, strcpy3_fortified) { TEST(DEATHTEST, strcpy3_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0]; char buf[0];
char *orig = strdup("1"); char *orig = strdup("1");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
free(orig); free(orig);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
// one byte target with longer source (should fail) // one byte target with longer source (should fail)
TEST(DEATHTEST, strcpy4_fortified) { TEST(DEATHTEST, strcpy4_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1]; char buf[1];
char *orig = strdup("12"); char *orig = strdup("12");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
free(orig); free(orig);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(DEATHTEST, strlen_fortified) { TEST(DEATHTEST, strlen_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10]; char buf[10];
memcpy(buf, "0123456789", sizeof(buf)); memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(DEATHTEST, strchr_fortified) { TEST(DEATHTEST, strchr_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10]; char buf[10];
memcpy(buf, "0123456789", sizeof(buf)); memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(DEATHTEST, strrchr_fortified) { TEST(DEATHTEST, strrchr_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10]; char buf[10];
memcpy(buf, "0123456789", sizeof(buf)); memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(DEATHTEST, strlcpy_fortified) { TEST(DEATHTEST, strlcpy_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15]; char bufa[15];
char bufb[10]; char bufb[10];
strcpy(bufa, "01234567890123"); strcpy(bufa, "01234567890123");
size_t n = strlen(bufa); size_t n = strlen(bufa);
ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(DEATHTEST, strlcat_fortified) { TEST(DEATHTEST, strlcat_fortified) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15]; char bufa[15];
char bufb[10]; char bufb[10];
@ -385,10 +442,11 @@ TEST(DEATHTEST, strlcat_fortified) {
strcpy(bufa, "01234567890123"); strcpy(bufa, "01234567890123");
size_t n = strlen(bufa); size_t n = strlen(bufa);
ASSERT_EXIT(strlcat(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); ASSERT_EXIT(strlcat(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(DEATHTEST, sprintf_fortified) { TEST(DEATHTEST, sprintf_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10]; char buf[10];

View File

@ -31,10 +31,11 @@
#endif #endif
#if defined(GETAUXVAL_CAN_COMPILE) #if defined(GETAUXVAL_CAN_COMPILE)
#include <sys/auxv.h> #include <sys/auxv.h>
#endif
TEST(getauxval, expected_values) { TEST(getauxval, expected_values) {
#if defined(GETAUXVAL_CAN_COMPILE)
ASSERT_EQ((unsigned long int) 0, getauxval(AT_SECURE)); ASSERT_EQ((unsigned long int) 0, getauxval(AT_SECURE));
ASSERT_EQ(getuid(), getauxval(AT_UID)); ASSERT_EQ(getuid(), getauxval(AT_UID));
ASSERT_EQ(geteuid(), getauxval(AT_EUID)); ASSERT_EQ(geteuid(), getauxval(AT_EUID));
@ -46,10 +47,15 @@ TEST(getauxval, expected_values) {
ASSERT_NE((unsigned long int) 0, getauxval(AT_PHNUM)); ASSERT_NE((unsigned long int) 0, getauxval(AT_PHNUM));
ASSERT_NE((unsigned long int) 0, getauxval(AT_ENTRY)); ASSERT_NE((unsigned long int) 0, getauxval(AT_ENTRY));
ASSERT_NE((unsigned long int) 0, getauxval(AT_PAGESZ)); ASSERT_NE((unsigned long int) 0, getauxval(AT_PAGESZ));
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
} }
TEST(getauxval, unexpected_values) { TEST(getauxval, unexpected_values) {
#if defined(GETAUXVAL_CAN_COMPILE)
ASSERT_EQ((unsigned long int) 0, getauxval(0xdeadbeef)); ASSERT_EQ((unsigned long int) 0, getauxval(0xdeadbeef));
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
} }
#endif /* GETAUXVAL_CAN_COMPILE */

View File

@ -19,7 +19,6 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#if defined(__BIONIC__) // Doesn't work on glibc because we use -m32.
TEST(inttypes, misc) { TEST(inttypes, misc) {
char buf[512]; char buf[512];
@ -39,4 +38,3 @@ TEST(inttypes, misc) {
sscanf(buf, "%08" SCNuPTR, &u); sscanf(buf, "%08" SCNuPTR, &u);
sscanf(buf, "%08" SCNxPTR, &u); sscanf(buf, "%08" SCNxPTR, &u);
} }
#endif

View File

@ -17,12 +17,12 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#if defined(__BIONIC__) #if defined(__BIONIC__)
#include "../libc/bionic/libc_logging.cpp" #include "../libc/bionic/libc_logging.cpp"
extern int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...); extern int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...);
#endif // __BIONIC__
TEST(libc_logging, smoke) { TEST(libc_logging, smoke) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "a"); __libc_format_buffer(buf, sizeof(buf), "a");
@ -104,21 +104,33 @@ TEST(libc_logging, smoke) {
__libc_format_buffer(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8); __libc_format_buffer(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8);
EXPECT_STREQ("a68719476736,6,7,8z", buf); EXPECT_STREQ("a68719476736,6,7,8z", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, d_INT_MAX) { TEST(libc_logging, d_INT_MAX) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%d", INT_MAX); __libc_format_buffer(buf, sizeof(buf), "%d", INT_MAX);
EXPECT_STREQ("2147483647", buf); EXPECT_STREQ("2147483647", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, d_INT_MIN) { TEST(libc_logging, d_INT_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%d", INT_MIN); __libc_format_buffer(buf, sizeof(buf), "%d", INT_MIN);
EXPECT_STREQ("-2147483648", buf); EXPECT_STREQ("-2147483648", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, ld_LONG_MAX) { TEST(libc_logging, ld_LONG_MAX) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MAX); __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MAX);
#if __LP64__ #if __LP64__
@ -126,9 +138,13 @@ TEST(libc_logging, ld_LONG_MAX) {
#else #else
EXPECT_STREQ("2147483647", buf); EXPECT_STREQ("2147483647", buf);
#endif #endif
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, ld_LONG_MIN) { TEST(libc_logging, ld_LONG_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MIN); __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MIN);
#if __LP64__ #if __LP64__
@ -136,18 +152,27 @@ TEST(libc_logging, ld_LONG_MIN) {
#else #else
EXPECT_STREQ("-2147483648", buf); EXPECT_STREQ("-2147483648", buf);
#endif #endif
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, lld_LLONG_MAX) { TEST(libc_logging, lld_LLONG_MAX) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MAX); __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MAX);
EXPECT_STREQ("9223372036854775807", buf); EXPECT_STREQ("9223372036854775807", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libc_logging, lld_LLONG_MIN) { TEST(libc_logging, lld_LLONG_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ]; char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MIN); __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MIN);
EXPECT_STREQ("-9223372036854775808", buf); EXPECT_STREQ("-9223372036854775808", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif

View File

@ -38,7 +38,9 @@ static void TestDirname(const char* in, const char* expected_out) {
free(writable_in); free(writable_in);
} }
TEST(libgen, basename) { // Do not use basename as the test name, it's defined to another value in glibc
// so leads to a differently named test on host versus target architectures.
TEST(libgen, basename_smoke) {
TestBasename(NULL, "."); TestBasename(NULL, ".");
TestBasename("", "."); TestBasename("", ".");
TestBasename("/usr/lib", "lib"); TestBasename("/usr/lib", "lib");
@ -62,8 +64,7 @@ TEST(libgen, dirname) {
TestDirname("/", "/"); TestDirname("/", "/");
} }
#if __BIONIC__ #if defined(__BIONIC__)
static void TestBasename(const char* in, const char* expected_out, int expected_rc, static void TestBasename(const char* in, const char* expected_out, int expected_rc,
char* buf, size_t buf_size, int expected_errno) { char* buf, size_t buf_size, int expected_errno) {
errno = 0; errno = 0;
@ -85,8 +86,10 @@ static void TestDirname(const char* in, const char* expected_out, int expected_r
} }
ASSERT_EQ(expected_errno, errno) << in; ASSERT_EQ(expected_errno, errno) << in;
} }
#endif // __BIONIC__
TEST(libgen, basename_r) { TEST(libgen, basename_r) {
#if defined(__BIONIC__)
char buf[256]; char buf[256];
TestBasename("", ".", 1, NULL, 0, 0); TestBasename("", ".", 1, NULL, 0, 0);
TestBasename("", ".", -1, buf, 0, ERANGE); TestBasename("", ".", -1, buf, 0, ERANGE);
@ -99,9 +102,13 @@ TEST(libgen, basename_r) {
TestBasename("/", "/", 1, buf, sizeof(buf), 0); TestBasename("/", "/", 1, buf, sizeof(buf), 0);
TestBasename(".", ".", 1, buf, sizeof(buf), 0); TestBasename(".", ".", 1, buf, sizeof(buf), 0);
TestBasename("..", "..", 2, buf, sizeof(buf), 0); TestBasename("..", "..", 2, buf, sizeof(buf), 0);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(libgen, dirname_r) { TEST(libgen, dirname_r) {
#if defined(__BIONIC__)
char buf[256]; char buf[256];
TestDirname("", ".", 1, NULL, 0, 0); TestDirname("", ".", 1, NULL, 0, 0);
TestDirname("", ".", -1, buf, 0, ERANGE); TestDirname("", ".", -1, buf, 0, ERANGE);
@ -112,6 +119,7 @@ TEST(libgen, dirname_r) {
TestDirname("usr", ".", 1, buf, sizeof(buf), 0); TestDirname("usr", ".", 1, buf, sizeof(buf), 0);
TestDirname(".", ".", 1, buf, sizeof(buf), 0); TestDirname(".", ".", 1, buf, sizeof(buf), 0);
TestDirname("..", ".", 1, buf, sizeof(buf), 0); TestDirname("..", ".", 1, buf, sizeof(buf), 0);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif

View File

@ -104,61 +104,73 @@ TEST(math, signbit) {
} }
*/ */
#if defined(__BIONIC__)
TEST(math, __fpclassifyd) { TEST(math, __fpclassifyd) {
#if defined(__BIONIC__)
ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL)); ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
ASSERT_EQ(FP_NAN, __fpclassifyd(nan(""))); ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0)); ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal())); ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0)); ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __fpclassifyf) { TEST(math, __fpclassifyf) {
#if defined(__BIONIC__)
ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF)); ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
ASSERT_EQ(FP_NAN, __fpclassifyf(nanf(""))); ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f)); ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal())); ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f)); ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __fpclassifyl) { TEST(math, __fpclassifyl) {
#if defined(__BIONIC__)
EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL)); EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
EXPECT_EQ(FP_NAN, __fpclassifyl(nanl(""))); EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0)); EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0));
EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(double_subnormal())); EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(double_subnormal()));
EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0)); EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(math, finitef) { TEST(math, finitef) {
ASSERT_TRUE(finitef(123.0f)); ASSERT_TRUE(finitef(123.0f));
ASSERT_FALSE(finitef(HUGE_VALF)); ASSERT_FALSE(finitef(HUGE_VALF));
} }
#if defined(__BIONIC__)
TEST(math, __isfinite) { TEST(math, __isfinite) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinite(123.0)); ASSERT_TRUE(__isfinite(123.0));
ASSERT_FALSE(__isfinite(HUGE_VAL)); ASSERT_FALSE(__isfinite(HUGE_VAL));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __isfinitef) { TEST(math, __isfinitef) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinitef(123.0f)); ASSERT_TRUE(__isfinitef(123.0f));
ASSERT_FALSE(__isfinitef(HUGE_VALF)); ASSERT_FALSE(__isfinitef(HUGE_VALF));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __isfinitel) { TEST(math, __isfinitel) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinitel(123.0f)); ASSERT_TRUE(__isfinitel(123.0f));
ASSERT_FALSE(__isfinitel(HUGE_VALL)); ASSERT_FALSE(__isfinitel(HUGE_VALL));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(math, finite) { TEST(math, finite) {
ASSERT_TRUE(finite(123.0)); ASSERT_TRUE(finite(123.0));
@ -190,26 +202,32 @@ TEST(math, isnanf) {
ASSERT_TRUE(isnanf(nanf(""))); ASSERT_TRUE(isnanf(nanf("")));
} }
#if defined(__BIONIC__)
TEST(math, __isnormal) { TEST(math, __isnormal) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormal(123.0)); ASSERT_TRUE(__isnormal(123.0));
ASSERT_FALSE(__isnormal(double_subnormal())); ASSERT_FALSE(__isnormal(double_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __isnormalf) { TEST(math, __isnormalf) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormalf(123.0f)); ASSERT_TRUE(__isnormalf(123.0f));
ASSERT_FALSE(__isnormalf(float_subnormal())); ASSERT_FALSE(__isnormalf(float_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, __isnormall) { TEST(math, __isnormall) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormall(123.0)); ASSERT_TRUE(__isnormall(123.0));
ASSERT_FALSE(__isnormall(double_subnormal())); ASSERT_FALSE(__isnormall(double_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(math, __signbit) { TEST(math, __signbit) {
ASSERT_EQ(0, __signbit(0.0)); ASSERT_EQ(0, __signbit(0.0));
@ -1005,21 +1023,25 @@ TEST(math, gammaf) {
ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f)); ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
} }
#if defined(__BIONIC__)
TEST(math, gamma_r) { TEST(math, gamma_r) {
#if defined(__BIONIC__)
int sign; int sign;
ASSERT_FLOAT_EQ(log(24.0), gamma_r(5.0, &sign)); ASSERT_FLOAT_EQ(log(24.0), gamma_r(5.0, &sign));
ASSERT_EQ(1, sign); ASSERT_EQ(1, sign);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if defined(__BIONIC__)
TEST(math, gammaf_r) { TEST(math, gammaf_r) {
#if defined(__BIONIC__)
int sign; int sign;
ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign)); ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
ASSERT_EQ(1, sign); ASSERT_EQ(1, sign);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(math, lgamma) { TEST(math, lgamma) {
ASSERT_FLOAT_EQ(log(24.0), lgamma(5.0)); ASSERT_FLOAT_EQ(log(24.0), lgamma(5.0));

View File

@ -20,6 +20,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <pthread.h> #include <pthread.h>
#include <signal.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
@ -31,8 +32,8 @@ TEST(pthread, pthread_key_create) {
ASSERT_EQ(EINVAL, pthread_key_delete(key)); ASSERT_EQ(EINVAL, pthread_key_delete(key));
} }
#if !defined(__GLIBC__) // glibc uses keys internally that its sysconf value doesn't account for.
TEST(pthread, pthread_key_create_lots) { TEST(pthread, pthread_key_create_lots) {
#if defined(__BIONIC__) // glibc uses keys internally that its sysconf value doesn't account for.
// POSIX says PTHREAD_KEYS_MAX should be at least 128. // POSIX says PTHREAD_KEYS_MAX should be at least 128.
ASSERT_GE(PTHREAD_KEYS_MAX, 128); ASSERT_GE(PTHREAD_KEYS_MAX, 128);
@ -59,8 +60,10 @@ TEST(pthread, pthread_key_create_lots) {
for (size_t i = 0; i < keys.size(); ++i) { for (size_t i = 0; i < keys.size(); ++i) {
ASSERT_EQ(0, pthread_key_delete(keys[i])); ASSERT_EQ(0, pthread_key_delete(keys[i]));
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
static void* IdFn(void* arg) { static void* IdFn(void* arg) {
return arg; return arg;
@ -249,31 +252,40 @@ TEST(pthread, pthread_sigmask) {
ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL)); ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
} }
#if __BIONIC__ #if defined(__BIONIC__)
extern "C" pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg); extern "C" pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
#endif // __BIONIC__
TEST(pthread, __bionic_clone) { TEST(pthread, __bionic_clone) {
#if defined(__BIONIC__)
// Check that our hand-written clone assembler sets errno correctly on failure. // Check that our hand-written clone assembler sets errno correctly on failure.
uintptr_t fake_child_stack[16]; uintptr_t fake_child_stack[16];
errno = 0; errno = 0;
ASSERT_EQ(-1, __bionic_clone(CLONE_THREAD, &fake_child_stack[16], NULL, NULL, NULL, NULL, NULL)); ASSERT_EQ(-1, __bionic_clone(CLONE_THREAD, &fake_child_stack[16], NULL, NULL, NULL, NULL, NULL));
ASSERT_EQ(EINVAL, errno); ASSERT_EQ(EINVAL, errno);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
TEST(pthread, pthread_setname_np__too_long) { TEST(pthread, pthread_setname_np__too_long) {
#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "this name is far too long for linux")); ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "this name is far too long for linux"));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
TEST(pthread, pthread_setname_np__self) { TEST(pthread, pthread_setname_np__self) {
#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
ASSERT_EQ(0, pthread_setname_np(pthread_self(), "short 1")); ASSERT_EQ(0, pthread_setname_np(pthread_self(), "short 1"));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
TEST(pthread, pthread_setname_np__other) { TEST(pthread, pthread_setname_np__other) {
#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
// Emulator kernels don't currently support setting the name of other threads. // Emulator kernels don't currently support setting the name of other threads.
char* filename = NULL; char* filename = NULL;
asprintf(&filename, "/proc/self/task/%d/comm", gettid()); asprintf(&filename, "/proc/self/task/%d/comm", gettid());
@ -288,18 +300,22 @@ TEST(pthread, pthread_setname_np__other) {
} else { } else {
fprintf(stderr, "skipping test: this kernel doesn't have /proc/self/task/tid/comm files!\n"); fprintf(stderr, "skipping test: this kernel doesn't have /proc/self/task/tid/comm files!\n");
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
TEST(pthread, pthread_setname_np__no_such_thread) { TEST(pthread, pthread_setname_np__no_such_thread) {
#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
pthread_t dead_thread; pthread_t dead_thread;
MakeDeadThread(dead_thread); MakeDeadThread(dead_thread);
// Call pthread_setname_np after thread has already exited. // Call pthread_setname_np after thread has already exited.
ASSERT_EQ(ESRCH, pthread_setname_np(dead_thread, "short 3")); ASSERT_EQ(ESRCH, pthread_setname_np(dead_thread, "short 3"));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(pthread, pthread_kill__0) { TEST(pthread, pthread_kill__0) {
// Signal 0 just tests that the thread exists, so it's safe to call on ourselves. // Signal 0 just tests that the thread exists, so it's safe to call on ourselves.
@ -511,13 +527,13 @@ TEST(pthread, pthread_attr_setstacksize) {
ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 32*1024 + 1)); ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 32*1024 + 1));
ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size)); ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size));
ASSERT_EQ(32*1024U + 1, stack_size); ASSERT_EQ(32*1024U + 1, stack_size);
#if __BIONIC__ #if defined(__BIONIC__)
// Bionic rounds up, which is what POSIX allows. // Bionic rounds up, which is what POSIX allows.
ASSERT_EQ(GetActualStackSize(attributes), (32 + 4)*1024U); ASSERT_EQ(GetActualStackSize(attributes), (32 + 4)*1024U);
#else #else // __BIONIC__
// glibc rounds down, in violation of POSIX. They document this in their BUGS section. // glibc rounds down, in violation of POSIX. They document this in their BUGS section.
ASSERT_EQ(GetActualStackSize(attributes), 32*1024U); ASSERT_EQ(GetActualStackSize(attributes), 32*1024U);
#endif #endif // __BIONIC__
} }
TEST(pthread, pthread_rwlock_smoke) { TEST(pthread, pthread_rwlock_smoke) {

View File

@ -27,17 +27,13 @@
#include <unistd.h> #include <unistd.h>
#include <set> #include <set>
#ifdef __GLIBC__ #if defined(__GLIBC__)
// glibc doesn't expose gettid(2). // glibc doesn't expose gettid(2).
pid_t gettid() { return syscall(__NR_gettid); } pid_t gettid() { return syscall(__NR_gettid); }
#endif // __GLIBC__
#endif
#ifdef __i386__
// For x86, bionic and glibc have per-thread stack guard values (all identical). // For x86, bionic and glibc have per-thread stack guard values (all identical).
#if defined(__i386__)
static uint32_t GetGuardFromTls() { static uint32_t GetGuardFromTls() {
uint32_t guard; uint32_t guard;
asm ("mov %%gs:0x14, %0": "=d" (guard)); asm ("mov %%gs:0x14, %0": "=d" (guard));
@ -71,8 +67,10 @@ static void* ThreadGuardHelper(void* arg) {
checker->Check(); checker->Check();
return NULL; return NULL;
} }
#endif // __i386__
TEST(stack_protector, same_guard_per_thread) { TEST(stack_protector, same_guard_per_thread) {
#if defined(__i386__)
stack_protector_checker checker; stack_protector_checker checker;
size_t thread_count = 10; size_t thread_count = 10;
for (size_t i = 0; i < thread_count; ++i) { for (size_t i = 0; i < thread_count; ++i) {
@ -86,24 +84,19 @@ TEST(stack_protector, same_guard_per_thread) {
// bionic and glibc use the same guard for every thread. // bionic and glibc use the same guard for every thread.
ASSERT_EQ(1U, checker.guards.size()); ASSERT_EQ(1U, checker.guards.size());
#else // __i386__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __i386__
} }
#endif
#if defined(__BIONIC__) || defined(__arm__) || defined(__mips__)
// For ARM and MIPS, glibc has a global stack check guard value. // For ARM and MIPS, glibc has a global stack check guard value.
#if defined(__BIONIC__) || defined(__arm__) || defined(__mips__)
#define TEST_STACK_CHK_GUARD
// Bionic has the global for x86 too, to support binaries that can run on // Bionic has the global for x86 too, to support binaries that can run on
// Android releases that didn't implement the TLS guard value. // Android releases that didn't implement the TLS guard value.
extern "C" uintptr_t __stack_chk_guard; extern "C" uintptr_t __stack_chk_guard;
TEST(stack_protector, global_guard) {
ASSERT_NE(0, gettid());
ASSERT_NE(0U, __stack_chk_guard);
}
/* /*
* When this function returns, the stack canary will be inconsistent * When this function returns, the stack canary will be inconsistent
* with the previous value, which will generate a call to __stack_chk_fail(), * with the previous value, which will generate a call to __stack_chk_fail(),
@ -116,10 +109,22 @@ __attribute__ ((noinline))
static void do_modify_stack_chk_guard() { static void do_modify_stack_chk_guard() {
__stack_chk_guard = 0x12345678; __stack_chk_guard = 0x12345678;
} }
#endif
TEST(stack_protector_DeathTest, modify_stack_protector) { TEST(stack_protector, global_guard) {
::testing::FLAGS_gtest_death_test_style = "threadsafe"; #if defined(TEST_STACK_CHK_GUARD)
ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), ""); ASSERT_NE(0, gettid());
ASSERT_NE(0U, __stack_chk_guard);
#else // TEST_STACK_CHK_GUARD
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // TEST_STACK_CHK_GUARD
} }
#endif TEST(stack_protector_DeathTest, modify_stack_protector) {
#if defined(TEST_STACK_CHK_GUARD)
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
#else // TEST_STACK_CHK_GUARD
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // TEST_STACK_CHK_GUARD
}

View File

@ -20,8 +20,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#if defined(i386) // Only our x86 unwinding is good enough. Switch to libunwind?
extern "C" { extern "C" {
void do_test(); void do_test();
} }
@ -29,8 +27,11 @@ extern "C" {
// We have to say "DeathTest" here so gtest knows to run this test (which exits) // We have to say "DeathTest" here so gtest knows to run this test (which exits)
// in its own process. // in its own process.
TEST(stack_unwinding_DeathTest, unwinding_through_signal_frame) { TEST(stack_unwinding_DeathTest, unwinding_through_signal_frame) {
// Only our x86 unwinding is good enough. Switch to libunwind?
#if defined(__BIONIC__) && defined(__i386__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(do_test(), ::testing::ExitedWithCode(42), ""); ASSERT_EXIT(do_test(), ::testing::ExitedWithCode(42), "");
#else // __i386__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __i386__
} }
#endif

View File

@ -107,7 +107,7 @@ TEST(stdio, getdelim_invalid) {
// glibc sometimes doesn't set errno in this particular case. // glibc sometimes doesn't set errno in this particular case.
#if defined(__BIONIC__) #if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno); ASSERT_EQ(EBADF, errno);
#endif #endif // __BIONIC__
} }
TEST(stdio, getline) { TEST(stdio, getline) {
@ -176,7 +176,7 @@ TEST(stdio, getline_invalid) {
// glibc sometimes doesn't set errno in this particular case. // glibc sometimes doesn't set errno in this particular case.
#if defined(__BIONIC__) #if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno); ASSERT_EQ(EBADF, errno);
#endif #endif // __BIONIC__
} }
TEST(stdio, printf_ssize_t) { TEST(stdio, printf_ssize_t) {
@ -191,8 +191,8 @@ TEST(stdio, printf_ssize_t) {
snprintf(buf, sizeof(buf), "%zd", v); snprintf(buf, sizeof(buf), "%zd", v);
} }
#if !defined(__GLIBC__)
TEST(stdio, snprintf_n_format_specifier_not_implemented) { TEST(stdio, snprintf_n_format_specifier_not_implemented) {
#if defined(__BIONIC__)
char buf[32]; char buf[32];
int i = 0; int i = 0;
// We deliberately don't implement %n, so it's treated like // We deliberately don't implement %n, so it's treated like
@ -200,8 +200,10 @@ TEST(stdio, snprintf_n_format_specifier_not_implemented) {
EXPECT_EQ(5, snprintf(buf, sizeof(buf), "a %n b", &i)); EXPECT_EQ(5, snprintf(buf, sizeof(buf), "a %n b", &i));
EXPECT_EQ(0, i); EXPECT_EQ(0, i);
EXPECT_STREQ("a n b", buf); EXPECT_STREQ("a n b", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(stdio, snprintf_smoke) { TEST(stdio, snprintf_smoke) {
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -283,9 +285,9 @@ TEST(stdio, snprintf_smoke) {
snprintf(buf, sizeof(buf), "a%d,%pz", 5, p); snprintf(buf, sizeof(buf), "a%d,%pz", 5, p);
#if defined(__BIONIC__) #if defined(__BIONIC__)
EXPECT_STREQ("a5,0x0z", buf); EXPECT_STREQ("a5,0x0z", buf);
#else #else // __BIONIC__
EXPECT_STREQ("a5,(nil)z", buf); EXPECT_STREQ("a5,(nil)z", buf);
#endif #endif // __BIONIC__
snprintf(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8); snprintf(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8);
EXPECT_STREQ("a68719476736,6,7,8z", buf); EXPECT_STREQ("a68719476736,6,7,8z", buf);

View File

@ -46,14 +46,16 @@ TEST(string, strerror) {
ASSERT_STREQ("Unknown error 1234", strerror(1234)); ASSERT_STREQ("Unknown error 1234", strerror(1234));
} }
#if __BIONIC__ // glibc's strerror isn't thread safe, only its strsignal. #if defined(__BIONIC__)
static void* ConcurrentStrErrorFn(void*) { static void* ConcurrentStrErrorFn(void*) {
bool equal = (strcmp("Unknown error 2002", strerror(2002)) == 0); bool equal = (strcmp("Unknown error 2002", strerror(2002)) == 0);
return reinterpret_cast<void*>(equal); return reinterpret_cast<void*>(equal);
} }
#endif // __BIONIC__
// glibc's strerror isn't thread safe, only its strsignal.
TEST(string, strerror_concurrent) { TEST(string, strerror_concurrent) {
#if defined(__BIONIC__)
const char* strerror1001 = strerror(1001); const char* strerror1001 = strerror(1001);
ASSERT_STREQ("Unknown error 1001", strerror1001); ASSERT_STREQ("Unknown error 1001", strerror1001);
@ -64,12 +66,13 @@ TEST(string, strerror_concurrent) {
ASSERT_TRUE(static_cast<bool>(result)); ASSERT_TRUE(static_cast<bool>(result));
ASSERT_STREQ("Unknown error 1001", strerror1001); ASSERT_STREQ("Unknown error 1001", strerror1001);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__ // glibc's strerror_r doesn't even have the same signature as the POSIX one.
TEST(string, strerror_r) { TEST(string, strerror_r) {
#if defined(__BIONIC__) // glibc's strerror_r doesn't even have the same signature as the POSIX one.
char buf[256]; char buf[256];
// Valid. // Valid.
@ -87,8 +90,10 @@ TEST(string, strerror_r) {
// Buffer too small. // Buffer too small.
ASSERT_EQ(-1, strerror_r(0, buf, 2)); ASSERT_EQ(-1, strerror_r(0, buf, 2));
ASSERT_EQ(ERANGE, errno); ASSERT_EQ(ERANGE, errno);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(string, strsignal) { TEST(string, strsignal) {
// A regular signal. // A regular signal.
@ -478,8 +483,8 @@ TEST(string, strcpy) {
} }
#if __BIONIC__
TEST(string, strlcat) { TEST(string, strlcat) {
#if defined(__BIONIC__)
StringTestState<char> state(SMALL); StringTestState<char> state(SMALL);
for (size_t i = 0; i < state.n; i++) { for (size_t i = 0; i < state.n; i++) {
for (size_t j = 0; j < POS_ITER; j++) { for (size_t j = 0; j < POS_ITER; j++) {
@ -504,11 +509,13 @@ TEST(string, strlcat) {
ASSERT_TRUE(memcmp(state.ptr, state.ptr2, state.MAX_LEN + state.len[i]) == 0); ASSERT_TRUE(memcmp(state.ptr, state.ptr2, state.MAX_LEN + state.len[i]) == 0);
} }
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
#if __BIONIC__
TEST(string, strlcpy) { TEST(string, strlcpy) {
#if defined(__BIONIC__)
StringTestState<char> state(SMALL); StringTestState<char> state(SMALL);
for (size_t j = 0; j < POS_ITER; j++) { for (size_t j = 0; j < POS_ITER; j++) {
state.NewIteration(); state.NewIteration();
@ -539,8 +546,10 @@ TEST(string, strlcpy) {
ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0) || ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0) ||
(memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0)); (memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0));
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(string, strncat) { TEST(string, strncat) {
StringTestState<char> state(SMALL); StringTestState<char> state(SMALL);
@ -732,10 +741,10 @@ TEST(string, memcmp) {
} }
} }
#if defined(__BIONIC__)
extern "C" int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n); extern "C" int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n);
TEST(string, __memcmp16) { TEST(string, __memcmp16) {
#if defined(__BIONIC__)
StringTestState<unsigned short> state(SMALL); StringTestState<unsigned short> state(SMALL);
for (size_t i = 0; i < state.n; i++) { for (size_t i = 0; i < state.n; i++) {
@ -758,8 +767,10 @@ TEST(string, __memcmp16) {
ASSERT_EQ(expected, actual); ASSERT_EQ(expected, actual);
} }
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(string, wmemcmp) { TEST(string, wmemcmp) {
StringTestState<wchar_t> state(SMALL); StringTestState<wchar_t> state(SMALL);

View File

@ -23,8 +23,7 @@
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#if __BIONIC__ #if defined(__BIONIC__)
#define CHECK_GETPWNAM_FOR(username, uid, uid_type) \ #define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
SCOPED_TRACE(username); \ SCOPED_TRACE(username); \
ASSERT_NO_FATAL_FAILURE(check_getpwnam(username, uid, uid_type)); ASSERT_NO_FATAL_FAILURE(check_getpwnam(username, uid, uid_type));
@ -51,6 +50,10 @@ static void check_getpwnam(const char* username, uid_t uid, uid_type_t uid_type)
EXPECT_STREQ("/system/bin/sh", pwd->pw_shell); EXPECT_STREQ("/system/bin/sh", pwd->pw_shell);
} }
#else
#define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
TEST(getpwnam, system_id_root) { TEST(getpwnam, system_id_root) {
CHECK_GETPWNAM_FOR("root", 0, TYPE_SYSTEM); CHECK_GETPWNAM_FOR("root", 0, TYPE_SYSTEM);
@ -104,5 +107,3 @@ TEST(getpwnam, app_id_u1_a0) {
TEST(getpwnam, app_id_u1_i0) { TEST(getpwnam, app_id_u1_i0) {
CHECK_GETPWNAM_FOR("u1_i0", 199000, TYPE_APP); CHECK_GETPWNAM_FOR("u1_i0", 199000, TYPE_APP);
} }
#endif /* __BIONIC__ */

View File

@ -17,6 +17,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <errno.h> #include <errno.h>
#include <signal.h>
#include <sys/epoll.h> #include <sys/epoll.h>
TEST(sys_epoll, smoke) { TEST(sys_epoll, smoke) {

View File

@ -17,6 +17,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <errno.h> #include <errno.h>
#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/select.h> #include <sys/select.h>

View File

@ -42,7 +42,6 @@ TEST(sys_sendfile, sendfile) {
ASSERT_STREQ("ll", buf); ASSERT_STREQ("ll", buf);
} }
#if __BIONIC__
TEST(sys_sendfile, sendfile64) { TEST(sys_sendfile, sendfile64) {
TemporaryFile src_file; TemporaryFile src_file;
ASSERT_EQ(5, TEMP_FAILURE_RETRY(write(src_file.fd, "hello", 5))); ASSERT_EQ(5, TEMP_FAILURE_RETRY(write(src_file.fd, "hello", 5)));
@ -61,4 +60,3 @@ TEST(sys_sendfile, sendfile64) {
ASSERT_EQ(2, TEMP_FAILURE_RETRY(read(dst_file.fd, &buf, 2))); ASSERT_EQ(2, TEMP_FAILURE_RETRY(read(dst_file.fd, &buf, 2)));
ASSERT_STREQ("ll", buf); ASSERT_STREQ("ll", buf);
} }
#endif

View File

@ -20,7 +20,7 @@
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
#if __BIONIC__ #if defined(__BIONIC__)
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h> #include <sys/_system_properties.h>
@ -69,7 +69,54 @@ private:
void *old_pa; void *old_pa;
}; };
static void foreach_test_callback(const prop_info *pi, void* cookie) {
size_t *count = static_cast<size_t *>(cookie);
ASSERT_NE((prop_info *)NULL, pi);
(*count)++;
}
static void hierarchical_test_callback(const prop_info *pi, void *cookie) {
bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie);
char name[PROP_NAME_MAX];
char value[PROP_VALUE_MAX];
__system_property_read(pi, name, value);
int name_i, name_j, name_k;
int value_i, value_j, value_k;
ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k));
ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k));
ASSERT_EQ(name_i, value_i);
ASSERT_GE(name_i, 0);
ASSERT_LT(name_i, 8);
ASSERT_EQ(name_j, value_j);
ASSERT_GE(name_j, 0);
ASSERT_LT(name_j, 8);
ASSERT_EQ(name_k, value_k);
ASSERT_GE(name_k, 0);
ASSERT_LT(name_k, 8);
ok[name_i][name_j][name_k] = true;
}
static void *PropertyWaitHelperFn(void *arg) {
int *flag = (int *)arg;
prop_info *pi;
pi = (prop_info *)__system_property_find("property");
usleep(100000);
*flag = 1;
__system_property_update(pi, "value3", 6);
return NULL;
}
#endif // __BIONIC__
TEST(properties, add) { TEST(properties, add) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
@ -87,9 +134,13 @@ TEST(properties, add) {
ASSERT_EQ(6, __system_property_get("property_other", propvalue)); ASSERT_EQ(6, __system_property_get("property_other", propvalue));
ASSERT_STREQ(propvalue, "value3"); ASSERT_STREQ(propvalue, "value3");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(properties, update) { TEST(properties, update) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
@ -120,9 +171,13 @@ TEST(properties, update) {
ASSERT_EQ(6, __system_property_get("property_other", propvalue)); ASSERT_EQ(6, __system_property_get("property_other", propvalue));
ASSERT_STREQ(propvalue, "value6"); ASSERT_STREQ(propvalue, "value6");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(properties, fill) { TEST(properties, fill) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
char prop_name[PROP_NAME_MAX]; char prop_name[PROP_NAME_MAX];
@ -161,16 +216,13 @@ TEST(properties, fill) {
ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret)); ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret));
ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX)); ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
} }
} #else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
static void foreach_test_callback(const prop_info *pi, void* cookie) { #endif // __BIONIC__
size_t *count = static_cast<size_t *>(cookie);
ASSERT_NE((prop_info *)NULL, pi);
(*count)++;
} }
TEST(properties, foreach) { TEST(properties, foreach) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
size_t count = 0; size_t count = 0;
@ -181,9 +233,13 @@ TEST(properties, foreach) {
ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count)); ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
ASSERT_EQ(3U, count); ASSERT_EQ(3U, count);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(properties, find_nth) { TEST(properties, find_nth) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
@ -201,34 +257,13 @@ TEST(properties, find_nth) {
ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(100)); ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(100));
ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(200)); ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(200));
ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247)); ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247));
} #else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
static void hierarchical_test_callback(const prop_info *pi, void *cookie) { #endif // __BIONIC__
bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie);
char name[PROP_NAME_MAX];
char value[PROP_VALUE_MAX];
__system_property_read(pi, name, value);
int name_i, name_j, name_k;
int value_i, value_j, value_k;
ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k));
ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k));
ASSERT_EQ(name_i, value_i);
ASSERT_GE(name_i, 0);
ASSERT_LT(name_i, 8);
ASSERT_EQ(name_j, value_j);
ASSERT_GE(name_j, 0);
ASSERT_LT(name_j, 8);
ASSERT_EQ(name_k, value_k);
ASSERT_GE(name_k, 0);
ASSERT_LT(name_k, 8);
ok[name_i][name_j][name_k] = true;
} }
TEST(properties, fill_hierarchical) { TEST(properties, fill_hierarchical) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
char prop_name[PROP_NAME_MAX]; char prop_name[PROP_NAME_MAX];
@ -279,9 +314,13 @@ TEST(properties, fill_hierarchical) {
} }
} }
} }
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(properties, errors) { TEST(properties, errors) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
char prop_value[PROP_NAME_MAX]; char prop_value[PROP_NAME_MAX];
@ -296,9 +335,13 @@ TEST(properties, errors) {
ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5)); ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5));
ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX)); ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX));
ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX)); ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
TEST(properties, serial) { TEST(properties, serial) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
const prop_info *pi; const prop_info *pi;
@ -309,22 +352,13 @@ TEST(properties, serial) {
serial = __system_property_serial(pi); serial = __system_property_serial(pi);
ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6)); ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6));
ASSERT_NE(serial, __system_property_serial(pi)); ASSERT_NE(serial, __system_property_serial(pi));
} #else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
static void *PropertyWaitHelperFn(void *arg) #endif // __BIONIC__
{
int *flag = (int *)arg;
prop_info *pi;
pi = (prop_info *)__system_property_find("property");
usleep(100000);
*flag = 1;
__system_property_update(pi, "value3", 6);
return NULL;
} }
TEST(properties, wait) { TEST(properties, wait) {
#if defined(__BIONIC__)
LocalPropertyTestState pa; LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid); ASSERT_TRUE(pa.valid);
unsigned int serial; unsigned int serial;
@ -346,6 +380,9 @@ TEST(properties, wait) {
void* result; void* result;
ASSERT_EQ(0, pthread_join(t, &result)); ASSERT_EQ(0, pthread_join(t, &result));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
class KilledByFault { class KilledByFault {
@ -362,6 +399,7 @@ bool KilledByFault::operator()(int exit_status) const {
} }
TEST(properties_DeathTest, read_only) { TEST(properties_DeathTest, read_only) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe"; ::testing::FLAGS_gtest_death_test_style = "threadsafe";
// This test only makes sense if we're talking to the real system property service. // This test only makes sense if we're talking to the real system property service.
@ -371,6 +409,7 @@ TEST(properties_DeathTest, read_only) {
} }
ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), ""); ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif

View File

@ -20,9 +20,12 @@
#include <time.h> #include <time.h>
#ifdef __BIONIC__ // mktime_tz is a bionic extension. #if defined(__BIONIC__) // mktime_tz is a bionic extension.
#include <libc/private/bionic_time.h> #include <libc/private/bionic_time.h>
#endif // __BIONIC__
TEST(time, mktime_tz) { TEST(time, mktime_tz) {
#if defined(__BIONIC__)
struct tm epoch; struct tm epoch;
memset(&epoch, 0, sizeof(tm)); memset(&epoch, 0, sizeof(tm));
epoch.tm_year = 1970 - 1900; epoch.tm_year = 1970 - 1900;
@ -40,8 +43,10 @@ TEST(time, mktime_tz) {
// Missing. Falls back to UTC. // Missing. Falls back to UTC.
ASSERT_EQ(2678400, mktime_tz(&epoch, "PST")); ASSERT_EQ(2678400, mktime_tz(&epoch, "PST"));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
} }
#endif
TEST(time, gmtime) { TEST(time, gmtime) {
time_t t = 0; time_t t = 0;
@ -55,7 +60,6 @@ TEST(time, gmtime) {
ASSERT_EQ(1970, broken_down->tm_year + 1900); ASSERT_EQ(1970, broken_down->tm_year + 1900);
} }
#if __BIONIC__
TEST(time, mktime_10310929) { TEST(time, mktime_10310929) {
struct tm t; struct tm t;
memset(&t, 0, sizeof(tm)); memset(&t, 0, sizeof(tm));
@ -66,7 +70,9 @@ TEST(time, mktime_10310929) {
#if !defined(__LP64__) #if !defined(__LP64__)
// 32-bit bionic stupidly had a signed 32-bit time_t. // 32-bit bionic stupidly had a signed 32-bit time_t.
ASSERT_EQ(-1, mktime(&t)); ASSERT_EQ(-1, mktime(&t));
#if defined(__BIONIC__)
ASSERT_EQ(-1, mktime_tz(&t, "UTC")); ASSERT_EQ(-1, mktime_tz(&t, "UTC"));
#endif
#else #else
// Everyone else should be using a signed 64-bit time_t. // Everyone else should be using a signed 64-bit time_t.
ASSERT_GE(sizeof(time_t) * 8, 64U); ASSERT_GE(sizeof(time_t) * 8, 64U);
@ -74,12 +80,15 @@ TEST(time, mktime_10310929) {
setenv("TZ", "America/Los_Angeles", 1); setenv("TZ", "America/Los_Angeles", 1);
tzset(); tzset();
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t)); ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t));
#if defined(__BIONIC__)
ASSERT_EQ(static_cast<time_t>(4108320000U), mktime_tz(&t, "UTC")); ASSERT_EQ(static_cast<time_t>(4108320000U), mktime_tz(&t, "UTC"));
#endif
setenv("TZ", "UTC", 1); setenv("TZ", "UTC", 1);
tzset(); tzset();
ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t)); ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t));
#if defined(__BIONIC__)
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime_tz(&t, "America/Los_Angeles")); ASSERT_EQ(static_cast<time_t>(4108348800U), mktime_tz(&t, "America/Los_Angeles"));
#endif #endif
}
#endif #endif
}