[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/build/uClibc/test/dlopen/Makefile b/ap/build/uClibc/test/dlopen/Makefile
new file mode 100644
index 0000000..92d14b9
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/Makefile
@@ -0,0 +1,12 @@
+# uClibc dlopen tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+include ../Rules.mak
+-include Makefile.in
+ifneq ($(HAVE_SHARED),y)
+TESTS_DISABLED := test3
+LDFLAGS_libtest.so := -lpthread
+endif
+
+include ../Test.mak
diff --git a/ap/build/uClibc/test/dlopen/Makefile.in b/ap/build/uClibc/test/dlopen/Makefile.in
new file mode 100644
index 0000000..22190d9
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/Makefile.in
@@ -0,0 +1,39 @@
+# uClibc dlopen tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+# rules need a little love to work with glibc ...
+export UCLIBC_ONLY := 1
+
+TESTS := dltest dltest2 dlstatic test1 test2 test3 dlundef dlafk dladdr
+
+CFLAGS_dltest := -DLIBNAME="\"./libtest.so\""
+CFLAGS_dltest2 := -DLIBNAME="\"./libtest3.so\""
+
+LDFLAGS_dlstatic := -ldl
+LDFLAGS_dltest := -ldl
+LDFLAGS_dltest2 := -ldl
+LDFLAGS_dlundef := -ldl
+LDFLAGS_dlafk := -ldl ./libafk.so -Wl,-rpath,.
+LDFLAGS_test1 := -ldl
+LDFLAGS_test2 := -ldl
+LDFLAGS_test3 := -ldl ./libtest1.so ./libtest2.so -Wl,-rpath,.
+LDFLAGS_dladdr := -ldl
+
+DEBUG_LIBS := X
+WRAPPER := env $(DEBUG_LIBS)=all LD_LIBRARY_PATH="$$PWD:.:$(LD_LIBRARY_PATH)"
+
+dltest: libtest.so
+dltest2: libtest3.so
+dlstatic: libstatic.so
+dlundef: libundef.so
+dlafk: libafk.so
+libafk.so: libafk-temp.so
+LDFLAGS_libafk.so := ./libafk-temp.so -Wl,-rpath,.
+test1: libtest1.so
+test2: libtest1.so libtest2.so
+test3: libtest1.so libtest2.so
+libtest1.so: libtest2.so
+LDFLAGS_libtest.so := -lpthread
+LDFLAGS_libtest1.so := ./libtest2.so -Wl,-rpath,.
+LDFLAGS_libtest2.so := -Wl,-rpath,.
+LDFLAGS_libtest3.so := -lpthread -Wl,-rpath,.
diff --git a/ap/build/uClibc/test/dlopen/dladdr.c b/ap/build/uClibc/test/dlopen/dladdr.c
new file mode 100644
index 0000000..b64c000
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dladdr.c
@@ -0,0 +1,25 @@
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ Dl_info info;
+ int res = 0;
+
+ memset(&info, '\0', sizeof(Dl_info));
+ res = dladdr((void *)1, &info);
+ if (res != 0) {
+ fprintf(stderr, "dladdr() should fail\n");
+ fprintf(stderr, "dli_fname = %s\n", info.dli_fname);
+ fprintf(stderr, "dli_fbase = 0x%08x\n", (unsigned int)info.dli_fbase);
+ fprintf(stderr, "dli_sname = %s\n", info.dli_sname);
+ fprintf(stderr, "dli_saddr = 0x%08x\n", (unsigned int)info.dli_saddr);
+ exit(1);
+ }
+
+ fprintf(stderr, "dladdr() failed as expected\n");
+ return EXIT_SUCCESS;
+}
+
diff --git a/ap/build/uClibc/test/dlopen/dlafk.c b/ap/build/uClibc/test/dlopen/dlafk.c
new file mode 100644
index 0000000..2eac4af
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dlafk.c
@@ -0,0 +1,36 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#define LIBNAME "libafk.so"
+
+#define LIBAFK "libafk-temp.so"
+#define LIBAFK_BAK ".libafk-temp.so.temp"
+
+int main(int argc, char **argv)
+{
+ void *handle;
+
+ if (rename(LIBAFK, LIBAFK_BAK)) {
+ fprintf(stderr, "Unable to rename %s: %s\n", LIBAFK, strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ handle = dlopen(LIBNAME, RTLD_NOW);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
+ return EXIT_FAILURE;
+ }
+
+ if (rename(LIBAFK_BAK, LIBAFK)) {
+ fprintf(stderr, "Unable to rename %s: %s\n", LIBAFK_BAK, strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/ap/build/uClibc/test/dlopen/dlstatic.c b/ap/build/uClibc/test/dlopen/dlstatic.c
new file mode 100644
index 0000000..57c8c5d
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dlstatic.c
@@ -0,0 +1,43 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+#define LIBNAME "libstatic.so"
+
+int load_and_test(void)
+{
+ void *handle;
+ int (*mystatic)(void);
+
+ handle = dlopen(LIBNAME, RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
+ return 1;
+ }
+
+ mystatic = dlsym(handle, "static_test");
+ if (mystatic == NULL) {
+ fprintf(stderr, "Could not locate symbol 'static_test': %s\n", dlerror());
+ return 1;
+ }
+
+ if (!mystatic()) {
+ fprintf(stderr, "mystatic() failed: static vars were not setup properly\n");
+ return 1;
+ }
+
+ dlclose(handle);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int count = 5;
+ while (count-- > 0)
+ if (load_and_test())
+ return EXIT_FAILURE;
+ return EXIT_SUCCESS;
+}
diff --git a/ap/build/uClibc/test/dlopen/dltest.c b/ap/build/uClibc/test/dlopen/dltest.c
new file mode 100644
index 0000000..b5fa1cd
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dltest.c
@@ -0,0 +1,41 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+int main(int argc, char **argv)
+{
+ int ret = EXIT_SUCCESS;
+ void *handle;
+ void (*mydltest)(void *value1, void *value2);
+ char *error;
+ uint32_t *value1, *value2;
+
+ handle = dlopen (LIBNAME, RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
+ exit(1);
+ }
+
+ mydltest = dlsym(handle, "dltest");
+ if ((error = dlerror()) != NULL) {
+ fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
+ exit(1);
+ }
+
+ mydltest(&value1, &value2);
+ printf("dltest: pthread_once=%p\n", value1);
+ printf("dltest: pthread_self=%p\n", value2);
+ if (value1 == value2) {
+ ret = EXIT_FAILURE;
+ printf("dltest: values should NOT be equal Weak values resolved incorrectly!\n");
+ } else {
+ printf("dltest: weak symbols resoved correctly.\n");
+ }
+
+ dlclose(handle);
+
+ return ret;
+}
+
diff --git a/ap/build/uClibc/test/dlopen/dltest2.c b/ap/build/uClibc/test/dlopen/dltest2.c
new file mode 100644
index 0000000..127b3b5
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dltest2.c
@@ -0,0 +1 @@
+#include "dltest.c"
diff --git a/ap/build/uClibc/test/dlopen/dlundef.c b/ap/build/uClibc/test/dlopen/dlundef.c
new file mode 100644
index 0000000..cefd933
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/dlundef.c
@@ -0,0 +1,29 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+#define LIBNAME "libundef.so"
+
+int main(int argc, char **argv)
+{
+ void *handle;
+ int (*myundefined)(void);
+
+ handle = dlopen(LIBNAME, RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
+ return EXIT_FAILURE;
+ }
+
+ myundefined = dlsym(handle, "__booga_booga_you_cant_touch_this__");
+ if (myundefined != NULL) {
+ fprintf(stderr, "dlsym() found a symbol that does not exist!\n");
+ return EXIT_FAILURE;
+ }
+
+ dlclose(handle);
+
+ return EXIT_SUCCESS;
+}
diff --git a/ap/build/uClibc/test/dlopen/libafk-temp.c b/ap/build/uClibc/test/dlopen/libafk-temp.c
new file mode 100644
index 0000000..39b58df
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libafk-temp.c
@@ -0,0 +1 @@
+/* the actual contents doesnt matter */
diff --git a/ap/build/uClibc/test/dlopen/libafk.c b/ap/build/uClibc/test/dlopen/libafk.c
new file mode 100644
index 0000000..39b58df
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libafk.c
@@ -0,0 +1 @@
+/* the actual contents doesnt matter */
diff --git a/ap/build/uClibc/test/dlopen/libstatic.c b/ap/build/uClibc/test/dlopen/libstatic.c
new file mode 100644
index 0000000..bf44c3c
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libstatic.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+static int global_static = -1;
+
+int static_test(void)
+{
+ static int local_static = -2;
+
+ if (global_static != -1)
+ printf("FAIL: global_static is not -1\n");
+ if (local_static != -2)
+ printf("FAIL: local_static is not -2\n");
+
+ return (global_static == -1 && local_static == -2);
+}
diff --git a/ap/build/uClibc/test/dlopen/libtest.c b/ap/build/uClibc/test/dlopen/libtest.c
new file mode 100644
index 0000000..3fd137f
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libtest.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <stdint.h>
+
+void dltest(uint32_t **value1, uint32_t **value2);
+void dltest(uint32_t **value1, uint32_t **value2)
+{
+ *value1 = (uint32_t *) pthread_once;
+ *value2 = (uint32_t *) pthread_self;
+}
+
diff --git a/ap/build/uClibc/test/dlopen/libtest1.c b/ap/build/uClibc/test/dlopen/libtest1.c
new file mode 100644
index 0000000..a2f7dcd
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libtest1.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+
+extern int libtest2_func(const char *s);
+
+void __attribute__((constructor)) libtest1_ctor(void);
+void libtest1_ctor(void)
+{
+ printf("libtest1: constructor!\n");
+}
+
+void __attribute__((destructor)) libtest1_dtor(void);
+void libtest1_dtor(void)
+{
+ printf("libtest1: destructor!\n");
+}
+
+void __attribute__((weak)) function1(void);
+void function1(void)
+{
+ printf("libtest1: I am weak function1!\n");
+}
+
+void function2(void);
+void function2(void)
+{
+ printf("libtest1: I am function2!\n");
+}
+
+int dltest(const char *s);
+int dltest(const char *s)
+{
+ printf( "libtest1: function1 = %p\n"
+ "libtest1: function2 = %p\n",
+ function1, function2);
+ function1();
+ function2();
+ return(libtest2_func(s));
+}
+
+
diff --git a/ap/build/uClibc/test/dlopen/libtest2.c b/ap/build/uClibc/test/dlopen/libtest2.c
new file mode 100644
index 0000000..5261506
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libtest2.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <pthread.h>
+
+void __attribute__((constructor)) libtest2_ctor(void);
+void libtest2_ctor(void)
+{
+ printf("libtest2: constructor!\n");
+}
+
+void __attribute__((destructor)) libtest2_dtor(void);
+void libtest2_dtor(void)
+{
+ printf("libtest2: destructor!\n");
+}
+
+void function1(void);
+void function1(void)
+{
+ printf("libtest2: I am function1!\n");
+}
+
+void __attribute__((weak)) function2(void);
+void function2(void)
+{
+ printf("libtest2: I am weak function2!\n");
+}
+
+
+int libtest2_func(const char *s);
+int libtest2_func(const char *s)
+{
+ printf( "libtest2: function1 = %p\n"
+ "libtest2: function2 = %p\n",
+ function1, function2);
+ function1();
+ function2();
+ return 0;
+}
diff --git a/ap/build/uClibc/test/dlopen/libtest3.c b/ap/build/uClibc/test/dlopen/libtest3.c
new file mode 100644
index 0000000..1d4bd7e
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libtest3.c
@@ -0,0 +1 @@
+#include "libtest.c"
diff --git a/ap/build/uClibc/test/dlopen/libundef.c b/ap/build/uClibc/test/dlopen/libundef.c
new file mode 100644
index 0000000..39b58df
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/libundef.c
@@ -0,0 +1 @@
+/* the actual contents doesnt matter */
diff --git a/ap/build/uClibc/test/dlopen/test1.c b/ap/build/uClibc/test/dlopen/test1.c
new file mode 100644
index 0000000..c13eb30
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/test1.c
@@ -0,0 +1,33 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+#ifdef __UCLIBC__
+extern void _dlinfo(void);
+#endif
+
+int main(int argc, char **argv) {
+ void *handle;
+ int (*mydltest)(const char *s);
+ char *error;
+
+ handle = dlopen ("./libtest1.so", RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./libtest1.so: %s\n", dlerror());
+ exit(1);
+ }
+
+ mydltest = dlsym(handle, "dltest");
+ if ((error = dlerror()) != NULL) {
+ fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
+ exit(1);
+ }
+
+ mydltest("hello world!");
+
+ dlclose(handle);
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/ap/build/uClibc/test/dlopen/test2.c b/ap/build/uClibc/test/dlopen/test2.c
new file mode 100644
index 0000000..d8428f7
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/test2.c
@@ -0,0 +1,39 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+#ifdef __UCLIBC__
+extern void _dlinfo(void);
+#endif
+
+int main(int argc, char **argv) {
+ void *handle;
+ int (*mydltest)(const char *s);
+ char *error;
+
+ handle = dlopen ("./libtest2.so", RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./libtest2.so: %s\n", dlerror());
+ exit(1);
+ }
+
+ handle = dlopen ("./libtest1.so", RTLD_LAZY);
+ if (!handle) {
+ fprintf(stderr, "Could not open ./libtest1.so: %s\n", dlerror());
+ exit(1);
+ }
+
+ mydltest = dlsym(handle, "dltest");
+ if ((error = dlerror()) != NULL) {
+ fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
+ exit(1);
+ }
+
+ mydltest("hello world!");
+
+ dlclose(handle);
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/ap/build/uClibc/test/dlopen/test3.c b/ap/build/uClibc/test/dlopen/test3.c
new file mode 100644
index 0000000..2f2dfc6
--- /dev/null
+++ b/ap/build/uClibc/test/dlopen/test3.c
@@ -0,0 +1,13 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+extern int dltest(const char *s);
+
+int main(int argc, char **argv)
+{
+ dltest("hello world!");
+ return EXIT_SUCCESS;
+}
+