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.
# -----------------------------------------------------------------------------
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 \
-g \
-Wall -Wextra \
-Werror \
-fno-builtin \
ifeq ($(TARGET_ARCH),arm64)
$(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 = \
libBionicStandardTests_src_files := \
buffer_tests.cpp \
dirent_test.cpp \
eventfd_test.cpp \
@ -54,6 +58,7 @@ test_src_files = \
signal_test.cpp \
stack_protector_test.cpp \
stack_unwinding_test.cpp \
stack_unwinding_test_impl.c \
statvfs_test.cpp \
stdio_test.cpp \
stdlib_test.cpp \
@ -73,106 +78,168 @@ test_src_files = \
time_test.cpp \
unistd_test.cpp \
test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
test_dynamic_src_files = \
dlfcn_test.cpp \
libBionicStandardTests_cflags := \
$(test_cflags) \
test_fortify_static_libraries = \
fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
libBionicStandardTests_ldlibs_host := \
-lrt \
include $(CLEAR_VARS)
LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
LOCAL_SRC_FILES := stack_unwinding_test_impl.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
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)
module := libBionicStandardTests
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
# -----------------------------------------------------------------------------
# We build the static unit tests as a library so they can be used both for
# bionic-unit-tests-static and also as part of CTS.
# Fortify tests.
# -----------------------------------------------------------------------------
$(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)
LOCAL_MODULE := libBionicTests
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_CFLAGS += $(test_c_flags)
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_CFLAGS += \
-DGTEST_OS_LINUX_ANDROID \
-DGTEST_HAS_STD_STRING \
module := fortify1-tests-gcc
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
LOCAL_C_INCLUDES += \
bionic bionic/libstdc++/include \
external/gtest/include \
external/stlport/stlport \
module := fortify2-tests-gcc
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
LOCAL_WHOLE_STATIC_LIBRARIES := \
$(test_fortify_static_libraries) \
bionic-unit-tests-unwind-test-impl \
fortify1-tests-clang_clang_target := true
fortify1-tests-clang_cflags_host := -D__clang__
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
# only has a GNU-style hash table. MIPS doesn't support GNU hash style.
ifneq ($(TARGET_ARCH),mips)
include $(CLEAR_VARS)
LOCAL_MODULE := no-elf-hash-table-library
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_SRC_FILES := empty.cpp
LOCAL_LDFLAGS := -Wl,--hash-style=gnu
include $(BUILD_SHARED_LIBRARY)
module := libBionicTests
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
# -----------------------------------------------------------------------------
# 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
# -----------------------------------------------------------------------------
# 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).
# Note that this will build against glibc, so it's not useful for testing
# bionic's implementation, but it does let you use glibc as a reference
# implementation for testing the tests themselves.
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
include $(CLEAR_VARS)
LOCAL_MODULE := bionic-unit-tests-glibc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_CFLAGS += $(test_c_flags)
LOCAL_LDFLAGS += -lpthread -ldl -lrt
LOCAL_LDFLAGS += $(test_dynamic_ldflags)
LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
include $(BUILD_HOST_NATIVE_TEST)
bionic-unit-tests_src_files := \
dlfcn_test.cpp \
bionic-unit-tests_ldflags := \
-Wl,--export-dynamic \
-Wl,-u,DlSymTestFunction \
bionic-unit-tests_shared_libraries_target := \
libdl \
module := bionic-unit-tests
module_tag := optional
build_type := target
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.
# 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_ROOT=$(TARGET_OUT) \
$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
endif
# -----------------------------------------------------------------------------
# Run the unit tests built against x86 bionic on an x86 host.
# -----------------------------------------------------------------------------
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
ifeq ($(TARGET_ARCH),x86)
@ -213,55 +278,4 @@ bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LIN
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

View File

@ -14,11 +14,25 @@
* limitations under the License.
*/
#include <errno.h>
#include <fcntl.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>
#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) {
unsigned int initial_value = 2;
@ -43,5 +57,3 @@ TEST(eventfd, smoke) {
close(fd);
}
#endif

View File

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

View File

@ -31,10 +31,11 @@
#endif
#if defined(GETAUXVAL_CAN_COMPILE)
#include <sys/auxv.h>
#endif
TEST(getauxval, expected_values) {
#if defined(GETAUXVAL_CAN_COMPILE)
ASSERT_EQ((unsigned long int) 0, getauxval(AT_SECURE));
ASSERT_EQ(getuid(), getauxval(AT_UID));
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_ENTRY));
ASSERT_NE((unsigned long int) 0, getauxval(AT_PAGESZ));
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
TEST(getauxval, unexpected_values) {
#if defined(GETAUXVAL_CAN_COMPILE)
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 <inttypes.h>
#if defined(__BIONIC__) // Doesn't work on glibc because we use -m32.
TEST(inttypes, misc) {
char buf[512];
@ -39,4 +38,3 @@ TEST(inttypes, misc) {
sscanf(buf, "%08" SCNuPTR, &u);
sscanf(buf, "%08" SCNxPTR, &u);
}
#endif

View File

@ -17,12 +17,12 @@
#include <gtest/gtest.h>
#if defined(__BIONIC__)
#include "../libc/bionic/libc_logging.cpp"
extern int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...);
#endif // __BIONIC__
TEST(libc_logging, smoke) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__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);
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) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%d", INT_MAX);
EXPECT_STREQ("2147483647", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libc_logging, d_INT_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%d", INT_MIN);
EXPECT_STREQ("-2147483648", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libc_logging, ld_LONG_MAX) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MAX);
#if __LP64__
@ -126,9 +138,13 @@ TEST(libc_logging, ld_LONG_MAX) {
#else
EXPECT_STREQ("2147483647", buf);
#endif
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libc_logging, ld_LONG_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MIN);
#if __LP64__
@ -136,18 +152,27 @@ TEST(libc_logging, ld_LONG_MIN) {
#else
EXPECT_STREQ("-2147483648", buf);
#endif
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libc_logging, lld_LLONG_MAX) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MAX);
EXPECT_STREQ("9223372036854775807", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libc_logging, lld_LLONG_MIN) {
#if defined(__BIONIC__)
char buf[BUFSIZ];
__libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MIN);
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);
}
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("", ".");
TestBasename("/usr/lib", "lib");
@ -62,8 +64,7 @@ TEST(libgen, dirname) {
TestDirname("/", "/");
}
#if __BIONIC__
#if defined(__BIONIC__)
static void TestBasename(const char* in, const char* expected_out, int expected_rc,
char* buf, size_t buf_size, int expected_errno) {
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;
}
#endif // __BIONIC__
TEST(libgen, basename_r) {
#if defined(__BIONIC__)
char buf[256];
TestBasename("", ".", 1, NULL, 0, 0);
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("..", "..", 2, buf, sizeof(buf), 0);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(libgen, dirname_r) {
#if defined(__BIONIC__)
char buf[256];
TestDirname("", ".", 1, NULL, 0, 0);
TestDirname("", ".", -1, buf, 0, ERANGE);
@ -112,6 +119,7 @@ TEST(libgen, dirname_r) {
TestDirname("usr", ".", 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) {
#if defined(__BIONIC__)
ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
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) {
#if defined(__BIONIC__)
ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
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) {
#if defined(__BIONIC__)
EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0));
EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(double_subnormal()));
EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
TEST(math, finitef) {
ASSERT_TRUE(finitef(123.0f));
ASSERT_FALSE(finitef(HUGE_VALF));
}
#if defined(__BIONIC__)
TEST(math, __isfinite) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinite(123.0));
ASSERT_FALSE(__isfinite(HUGE_VAL));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
#if defined(__BIONIC__)
TEST(math, __isfinitef) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinitef(123.0f));
ASSERT_FALSE(__isfinitef(HUGE_VALF));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
#if defined(__BIONIC__)
TEST(math, __isfinitel) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isfinitel(123.0f));
ASSERT_FALSE(__isfinitel(HUGE_VALL));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
TEST(math, finite) {
ASSERT_TRUE(finite(123.0));
@ -190,26 +202,32 @@ TEST(math, isnanf) {
ASSERT_TRUE(isnanf(nanf("")));
}
#if defined(__BIONIC__)
TEST(math, __isnormal) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormal(123.0));
ASSERT_FALSE(__isnormal(double_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
#if defined(__BIONIC__)
TEST(math, __isnormalf) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormalf(123.0f));
ASSERT_FALSE(__isnormalf(float_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
#if defined(__BIONIC__)
TEST(math, __isnormall) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormall(123.0));
ASSERT_FALSE(__isnormall(double_subnormal()));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
TEST(math, __signbit) {
ASSERT_EQ(0, __signbit(0.0));
@ -1005,21 +1023,25 @@ TEST(math, gammaf) {
ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
}
#if defined(__BIONIC__)
TEST(math, gamma_r) {
#if defined(__BIONIC__)
int sign;
ASSERT_FLOAT_EQ(log(24.0), gamma_r(5.0, &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) {
#if defined(__BIONIC__)
int sign;
ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
ASSERT_EQ(1, sign);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
TEST(math, lgamma) {
ASSERT_FLOAT_EQ(log(24.0), lgamma(5.0));

View File

@ -20,6 +20,7 @@
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <sys/mman.h>
#include <unistd.h>
@ -31,8 +32,8 @@ TEST(pthread, pthread_key_create) {
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) {
#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.
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) {
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) {
return arg;
@ -249,31 +252,40 @@ TEST(pthread, pthread_sigmask) {
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);
#endif // __BIONIC__
TEST(pthread, __bionic_clone) {
#if defined(__BIONIC__)
// Check that our hand-written clone assembler sets errno correctly on failure.
uintptr_t fake_child_stack[16];
errno = 0;
ASSERT_EQ(-1, __bionic_clone(CLONE_THREAD, &fake_child_stack[16], NULL, NULL, NULL, NULL, NULL));
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) {
#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"));
#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) {
#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"));
#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) {
#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.
char* filename = NULL;
asprintf(&filename, "/proc/self/task/%d/comm", gettid());
@ -288,18 +300,22 @@ TEST(pthread, pthread_setname_np__other) {
} else {
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) {
#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
pthread_t dead_thread;
MakeDeadThread(dead_thread);
// Call pthread_setname_np after thread has already exited.
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) {
// 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_getstacksize(&attributes, &stack_size));
ASSERT_EQ(32*1024U + 1, stack_size);
#if __BIONIC__
#if defined(__BIONIC__)
// Bionic rounds up, which is what POSIX allows.
ASSERT_EQ(GetActualStackSize(attributes), (32 + 4)*1024U);
#else
#else // __BIONIC__
// glibc rounds down, in violation of POSIX. They document this in their BUGS section.
ASSERT_EQ(GetActualStackSize(attributes), 32*1024U);
#endif
#endif // __BIONIC__
}
TEST(pthread, pthread_rwlock_smoke) {

View File

@ -27,17 +27,13 @@
#include <unistd.h>
#include <set>
#ifdef __GLIBC__
#if defined(__GLIBC__)
// glibc doesn't expose gettid(2).
pid_t gettid() { return syscall(__NR_gettid); }
#endif
#ifdef __i386__
#endif // __GLIBC__
// For x86, bionic and glibc have per-thread stack guard values (all identical).
#if defined(__i386__)
static uint32_t GetGuardFromTls() {
uint32_t guard;
asm ("mov %%gs:0x14, %0": "=d" (guard));
@ -71,8 +67,10 @@ static void* ThreadGuardHelper(void* arg) {
checker->Check();
return NULL;
}
#endif // __i386__
TEST(stack_protector, same_guard_per_thread) {
#if defined(__i386__)
stack_protector_checker checker;
size_t thread_count = 10;
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.
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.
#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
// Android releases that didn't implement the TLS guard value.
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
* 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() {
__stack_chk_guard = 0x12345678;
}
#endif
TEST(stack_protector_DeathTest, modify_stack_protector) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
TEST(stack_protector, global_guard) {
#if defined(TEST_STACK_CHK_GUARD)
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>
#if defined(i386) // Only our x86 unwinding is good enough. Switch to libunwind?
extern "C" {
void do_test();
}
@ -29,8 +27,11 @@ extern "C" {
// We have to say "DeathTest" here so gtest knows to run this test (which exits)
// in its own process.
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";
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.
#if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno);
#endif
#endif // __BIONIC__
}
TEST(stdio, getline) {
@ -176,7 +176,7 @@ TEST(stdio, getline_invalid) {
// glibc sometimes doesn't set errno in this particular case.
#if defined(__BIONIC__)
ASSERT_EQ(EBADF, errno);
#endif
#endif // __BIONIC__
}
TEST(stdio, printf_ssize_t) {
@ -191,8 +191,8 @@ TEST(stdio, printf_ssize_t) {
snprintf(buf, sizeof(buf), "%zd", v);
}
#if !defined(__GLIBC__)
TEST(stdio, snprintf_n_format_specifier_not_implemented) {
#if defined(__BIONIC__)
char buf[32];
int i = 0;
// 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(0, i);
EXPECT_STREQ("a n b", buf);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif
TEST(stdio, snprintf_smoke) {
char buf[BUFSIZ];
@ -283,9 +285,9 @@ TEST(stdio, snprintf_smoke) {
snprintf(buf, sizeof(buf), "a%d,%pz", 5, p);
#if defined(__BIONIC__)
EXPECT_STREQ("a5,0x0z", buf);
#else
#else // __BIONIC__
EXPECT_STREQ("a5,(nil)z", buf);
#endif
#endif // __BIONIC__
snprintf(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8);
EXPECT_STREQ("a68719476736,6,7,8z", buf);

View File

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

View File

@ -23,8 +23,7 @@
#include <limits.h>
#include <unistd.h>
#if __BIONIC__
#if defined(__BIONIC__)
#define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
SCOPED_TRACE(username); \
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);
}
#else
#define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
TEST(getpwnam, system_id_root) {
CHECK_GETPWNAM_FOR("root", 0, TYPE_SYSTEM);
@ -104,5 +107,3 @@ TEST(getpwnam, app_id_u1_a0) {
TEST(getpwnam, app_id_u1_i0) {
CHECK_GETPWNAM_FOR("u1_i0", 199000, TYPE_APP);
}
#endif /* __BIONIC__ */

View File

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

View File

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

View File

@ -42,7 +42,6 @@ TEST(sys_sendfile, sendfile) {
ASSERT_STREQ("ll", buf);
}
#if __BIONIC__
TEST(sys_sendfile, sendfile64) {
TemporaryFile src_file;
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_STREQ("ll", buf);
}
#endif

View File

@ -20,7 +20,7 @@
#include <unistd.h>
#include <string>
#if __BIONIC__
#if defined(__BIONIC__)
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
@ -69,7 +69,54 @@ private:
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) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
@ -87,9 +134,13 @@ TEST(properties, add) {
ASSERT_EQ(6, __system_property_get("property_other", propvalue));
ASSERT_STREQ(propvalue, "value3");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, update) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
@ -120,9 +171,13 @@ TEST(properties, update) {
ASSERT_EQ(6, __system_property_get("property_other", propvalue));
ASSERT_STREQ(propvalue, "value6");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, fill) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
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(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
}
}
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)++;
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, foreach) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
size_t count = 0;
@ -181,9 +233,13 @@ TEST(properties, foreach) {
ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
ASSERT_EQ(3U, count);
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, find_nth) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
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(200));
ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247));
}
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;
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, fill_hierarchical) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
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) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
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", 4, "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) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
const prop_info *pi;
@ -309,22 +352,13 @@ TEST(properties, serial) {
serial = __system_property_serial(pi);
ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6));
ASSERT_NE(serial, __system_property_serial(pi));
}
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;
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
TEST(properties, wait) {
#if defined(__BIONIC__)
LocalPropertyTestState pa;
ASSERT_TRUE(pa.valid);
unsigned int serial;
@ -346,6 +380,9 @@ TEST(properties, wait) {
void* result;
ASSERT_EQ(0, pthread_join(t, &result));
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
class KilledByFault {
@ -362,6 +399,7 @@ bool KilledByFault::operator()(int exit_status) const {
}
TEST(properties_DeathTest, read_only) {
#if defined(__BIONIC__)
::testing::FLAGS_gtest_death_test_style = "threadsafe";
// 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(), "");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
#endif

View File

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