From: Waldemar Kozaczuk <jwkozac...@gmail.com> Committer: Nadav Har'El <n...@scylladb.com> Branch: master
tests: add bionic tests to the source tree Instead of cloning full bionic source repo (~70MB) everytime we need to build tests image, this patch simply adds seven small source files to the OSv repo. The files are copies from the directory tests/libs of https://android.googlesource.com/platform/bionic at the commit 47ddeb1ae45dcd62c30c232c9b5490877da6185b. Please note the bionic test source code is licenced under permissive BSD-like license Apache 2.0. Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com> Message-Id: <20200218041658.29888-1-jwkozac...@gmail.com> --- diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,6 @@ modules/httpserver-jvm-plugin/obj/ modules/libtools/*.so modules/libtools/*.o modules/libyaml/usr.manifest -modules/dl_tests/bionic/ modules/dl_tests/usr.manifest .idea compile_commands.json diff --git a/licenses/bionic.txt b/licenses/bionic.txt --- a/licenses/bionic.txt +++ b/licenses/bionic.txt @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2016 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. + */ diff --git a/modules/dl_tests/Makefile b/modules/dl_tests/Makefile --- a/modules/dl_tests/Makefile +++ b/modules/dl_tests/Makefile @@ -31,18 +31,9 @@ tests := libtest_simple.so libtest_empty.so libtest_dlsym_from_this_grandchild.s libtest_dlsym_from_this_child.so libtest_dlsym_from_this.so libdlext_test.so \ libtest_with_dependency.so libtest_check_rtld_next_from_library.so -.PHONY: get_file -get_file: - if cd $(src)/modules/dl_tests/bionic; then \ - git pull; \ - else \ - git clone --depth=1 https://android.googlesource.com/platform/bionic $(src)/modules/dl_tests/bionic; \ - fi - all_tests := $(tests:%=dl_tests/%) build_all: - $(MAKE) get_file $(MAKE) $(all_tests:%=$(out)/%) .PHONY: build_all diff --git a/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp b/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp --- a/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp +++ b/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 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 <dlfcn.h> +#include <stdio.h> +#include <stdlib.h> + +static void* g_libc_fclose_ptr; + +static void __attribute__((constructor)) __libc_fclose_lookup() { + g_libc_fclose_ptr = dlsym(RTLD_NEXT, "fclose"); +} + +// A libc function used for RTLD_NEXT. +// This function in not supposed to be called. +extern "C" int __attribute__((weak)) fclose(FILE*) { + abort(); +} + +extern "C" void* get_libc_fclose_ptr() { + return g_libc_fclose_ptr; +} + + diff --git a/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp b/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp --- a/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp +++ b/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp @@ -0,0 +1,43 @@ +/* + * 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. + */ + +class A { +public: + virtual int getRandomNumber() { + return 4; // chosen by fair dice roll. + // guaranteed to be random. + } + + virtual ~A() {} +}; + +A a; + +// nested macros to make it easy to define a large amount of read-only data +// which will require relocation. +#define A_16 &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, +#define A_128 A_16 A_16 A_16 A_16 A_16 A_16 A_16 A_16 +#define A_1024 A_128 A_128 A_128 A_128 A_128 A_128 A_128 A_128 + +extern "C" A* const lots_of_relro[] = { + A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 +}; + +extern "C" int getRandomNumber() { + // access the relro section (twice, in fact, once for the pointer, and once + // for the vtable of A) to check it's actually there. + return lots_of_relro[0]->getRandomNumber(); +} diff --git a/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp b/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp --- a/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp +++ b/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp @@ -0,0 +1,24 @@ +/* + * 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 <stdint.h> +#include <stdlib.h> + +uint32_t dlopen_testlib_taxicab_number = 1729; + +extern "C" bool dlopen_testlib_simple_func() { + return true; +} diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp --- a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp +++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <dlfcn.h> +#include <stdio.h> + +extern int test_dlsym_symbol; + +int test_dlsym_symbol = -1; + +extern "C" int* lookup_dlsym_symbol_using_RTLD_DEFAULT() { + dlerror(); + int* result = static_cast<int*>(dlsym(RTLD_DEFAULT, "test_dlsym_symbol")); + // TODO: remove this once b/20049306 is fixed + if (result == nullptr) { + printf("Cannot find the answer\n"); + } + return result; +} + +extern "C" int* lookup_dlsym_symbol2_using_RTLD_DEFAULT() { + dlerror(); + int* result = static_cast<int*>(dlsym(RTLD_DEFAULT, "test_dlsym_symbol2")); + // TODO: remove this once b/20049306 is fixed + if (result == nullptr) { + printf("Cannot find the answer\n"); + } + return result; +} + +extern "C" int* lookup_dlsym_symbol_using_RTLD_NEXT() { + dlerror(); + int* result = static_cast<int*>(dlsym(RTLD_NEXT, "test_dlsym_symbol")); + // TODO: remove this once b/20049306 is fixed + if (result == nullptr) { + printf("Cannot find the answer\n"); + } + return result; +} + diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp --- a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp +++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +int test_dlsym_symbol = 42; diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp --- a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp +++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +int test_dlsym_symbol = 43; +int test_dlsym_symbol2 = 44; diff --git a/modules/dl_tests/bionic/tests/libs/empty.cpp b/modules/dl_tests/bionic/tests/libs/empty.cpp --- a/modules/dl_tests/bionic/tests/libs/empty.cpp +++ b/modules/dl_tests/bionic/tests/libs/empty.cpp null -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/00000000000023fb37059edb50b7%40google.com.