diff options
author | Niko Catania <> | 2009-03-30 12:50:58 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-30 12:50:58 -0700 |
commit | 3cb2639f22f8aaf46852c9f03e825e05fc7e7362 (patch) | |
tree | d73f44f9d24af9c11447fcb11a0d1aafe2bc656a | |
parent | 26c4c5f3205f521de9c6b420341fe67ec16810dc (diff) | |
download | extras-3cb2639f22f8aaf46852c9f03e825e05fc7e7362.tar.gz |
AI 143504: Completed cstddef to be non empty and similar to the gnu stl implementation.
Even if we don't want to have a bloated stl implementation, having empty
files around is probably not very good either.
Added a test to make sure the header file compiles on host and kila-eng.
QA Impact: In system/extras/test/bionic/libstdc++ build the tests using:
mm BIONIC_TESTS=1
to build the host and target tests.
BUG=1601432
Automated import of CL 143504
-rw-r--r-- | tests/bionic/libc/README.TXT | 2 | ||||
-rw-r--r-- | tests/bionic/libstdc++/Android.mk | 66 | ||||
-rw-r--r-- | tests/bionic/libstdc++/README.TXT | 14 | ||||
-rw-r--r-- | tests/bionic/libstdc++/test_cstddef.cpp | 102 |
4 files changed, 183 insertions, 1 deletions
diff --git a/tests/bionic/libc/README.TXT b/tests/bionic/libc/README.TXT index 5576b77b..7618f2b7 100644 --- a/tests/bionic/libc/README.TXT +++ b/tests/bionic/libc/README.TXT @@ -7,7 +7,7 @@ GNU Lesser General Public License (LGPL) You must define the BIONIC_TESTS environment variable to build these test programs. For example, do: - cd system/bionic-tests/ + cd system/extras/tests/bionic/libc mm BIONIC_TESTS=1 All test programs, except those in the 'other' directory, should exit diff --git a/tests/bionic/libstdc++/Android.mk b/tests/bionic/libstdc++/Android.mk new file mode 100644 index 00000000..fca89f6b --- /dev/null +++ b/tests/bionic/libstdc++/Android.mk @@ -0,0 +1,66 @@ +# Copyright (C) 2009 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. +# +# Build control file for Bionic's test programs +# define the BIONIC_TESTS environment variable to build the test programs +# + +ifdef BIONIC_TESTS + +LOCAL_PATH:= $(call my-dir) + +# used to define a simple test program and build it as a standalone +# device executable. +# +# you can use EXTRA_CFLAGS to indicate additional CFLAGS to use +# in the build. the variable will be cleaned on exit +# +define device-test + $(foreach file,$(1), \ + $(eval include $(CLEAR_VARS)) \ + $(eval LOCAL_SRC_FILES := $(file)) \ + $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ + $(eval $(info LOCAL_MODULE=$(LOCAL_MODULE))) \ + $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ + $(eval LOCAL_MODULE_TAGS := tests) \ + $(eval include $(BUILD_EXECUTABLE)) \ + ) \ + $(eval EXTRA_CFLAGS :=) +endef + +# same as 'device-test' but builds a host executable instead +# you can use EXTRA_LDLIBS to indicate additional linker flags +# +define host-test + $(foreach file,$(1), \ + $(eval include $(CLEAR_VARS)) \ + $(eval LOCAL_SRC_FILES := $(file)) \ + $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ + $(eval $(info LOCAL_MODULE=$(LOCAL_MODULE) file=$(file))) \ + $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ + $(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \ + $(eval LOCAL_MODULE_TAGS := tests) \ + $(eval include $(BUILD_HOST_EXECUTABLE)) \ + ) \ + $(eval EXTRA_CFLAGS :=) \ + $(eval EXTRA_LDLIBS :=) +endef + +sources := \ + test_cstddef.cpp + +$(call host-test, $(sources)) +$(call device-test, $(sources)) + +endif # BIONIC_TESTS diff --git a/tests/bionic/libstdc++/README.TXT b/tests/bionic/libstdc++/README.TXT new file mode 100644 index 00000000..90d40ea9 --- /dev/null +++ b/tests/bionic/libstdc++/README.TXT @@ -0,0 +1,14 @@ +This directory contains a set of tests for Android's Bionic Standard C++ library. + +You must define the BIONIC_TESTS environment variable to build these +test programs. For example, do: + + cd system/extras/tests/bionic/libstdc++ + mm BIONIC_TESTS=1 + +All test programs should exit with a status code of 0 in case of success, and 1 +in case of failure. + +The directory layout is currently flat because there is one Bionic test. If you +want to add GNU STDC++ or benchmark tests, look in tests/bionic/libc as an +example how to structure your files. diff --git a/tests/bionic/libstdc++/test_cstddef.cpp b/tests/bionic/libstdc++/test_cstddef.cpp new file mode 100644 index 00000000..7526d3c5 --- /dev/null +++ b/tests/bionic/libstdc++/test_cstddef.cpp @@ -0,0 +1,102 @@ +/* -*- c++ -*- */ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +// Test that including cstddef works. This should be the only include in this +// file to make sure that we don't pick definitions without us knowing. +#include <cstddef> + +namespace { +const int kPassed = 0; +const int kFailed = 1; +#define FAIL_UNLESS(f) if (!android::f()) return kFailed; +} // anonymous namespace + +namespace android { +// Dummy struct used to calculate offset of some of its fields. +struct Foo +{ + char field1; + char field2; +}; + +// Check various types are declared in the std namespace. +bool testTypesStd() +{ + // size_t should be defined in both namespaces + volatile ::size_t size_t_in_top_ns = 0; + volatile ::std::size_t size_t_in_std_ns = 0; + + if (sizeof(::size_t) != sizeof(::std::size_t)) + { + return false; + } + + // ptrdiff_t should be defined in both namespaces + volatile ::ptrdiff_t ptrdiff_t_in_top_ns = 0; + volatile ::std::ptrdiff_t ptrdiff_t_in_std_ns = 0; + + if (sizeof(::ptrdiff_t) != sizeof(::std::ptrdiff_t)) + { + return false; + } + // NULL is only in the top namespace + volatile int *null_is_defined = NULL; + return true; +} + +bool testOffsetOf() +{ +#ifndef offsetof +#error "offsetof is not a macro" +#endif + + // offsetof is only in the top namespace + volatile size_t offset = offsetof(struct Foo, field2); + return offset == 1; +} + +bool testNull() +{ +#ifndef NULL +#error "NULL is not a macro" +#endif + // If NULL is void* this will issue a warning. + volatile int null_is_not_void_star = NULL; + return true; +} + +} // android namespace + +int main(int argc, char **argv) +{ + FAIL_UNLESS(testTypesStd); + FAIL_UNLESS(testOffsetOf); + FAIL_UNLESS(testNull); + return kPassed; +} |