changeset 214:0592eb360af2

tests: - added dynload_plain test - added some more output to resolv_self - cleanups
author Tassilo Philipp
date Thu, 06 Apr 2017 02:13:57 +0200
parents 98057b3b28c2
children 2beca1d11c96
files ChangeLog test/CMakeLists.txt test/Makefile.embedded test/Makefile.generic test/Nmakefile test/dynload_plain/CMakeLists.txt test/dynload_plain/Makefile.embedded test/dynload_plain/Makefile.generic test/dynload_plain/Nmakefile test/dynload_plain/dynload_plain.c test/nm/nm.c test/resolve_self/main.c test/runalltests.bat
diffstat 13 files changed, 256 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 28 15:45:20 2017 +0200
+++ b/ChangeLog	Thu Apr 06 02:13:57 2017 +0200
@@ -28,6 +28,8 @@
   o better documentation, removed relative path dependencies, general cleanup
   o python: updated to latest signature format (was still on 0.1)
   o java: rewritten (old version was never complete, anyways)
+tests:
+  o added new dynload_plain test covering basic use of all dynload functions
 buildsys:
   o cmake: made to work on systems without C++ compiler (thanks Franklin Mathieu)
 
--- a/test/CMakeLists.txt	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/CMakeLists.txt	Thu Apr 06 02:13:57 2017 +0200
@@ -18,6 +18,7 @@
 add_subdirectory(suite)
 add_subdirectory(callf)
 add_subdirectory(nm)
+add_subdirectory(dynload_plain)
 add_subdirectory(resolve_self)
 add_subdirectory(thunk)
 add_subdirectory(malloc_wx)
--- a/test/Makefile.embedded	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/Makefile.embedded	Thu Apr 06 02:13:57 2017 +0200
@@ -3,6 +3,7 @@
 all: all-dyncall all-dyncallback all-dynload
 all-dynload:
 	cd nm && ${MAKE_CMD}
+	cd dynload_plain && ${MAKE_CMD}
 	cd resolve_self && ${MAKE_CMD}
 all-dyncall:
 	cd suite && ${MAKE_CMD}
@@ -26,6 +27,7 @@
 	cd call_suite && ${MAKE_CMD}
 	cd callf && ${MAKE_CMD}
 	cd nm && ${MAKE_CMD}
+	cd dynload_plain && ${MAKE_CMD}
 	cd resolve_self && ${MAKE_CMD}
 	cd thunk && ${MAKE_CMD}
 	cd malloc_wx && ${MAKE_CMD}
@@ -57,6 +59,7 @@
 	cd ellipsis && ${MAKE_CMD} clean
 	cd callf && ${MAKE_CMD} clean
 	cd nm && ${MAKE_CMD} clean
+	cd dynload_plain && ${MAKE_CMD} clean
 	cd resolve_self && ${MAKE_CMD} clean
 	cd thunk && ${MAKE_CMD} clean
 	cd malloc_wx && ${MAKE_CMD} clean
--- a/test/Makefile.generic	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/Makefile.generic	Thu Apr 06 02:13:57 2017 +0200
@@ -1,6 +1,6 @@
-ALL=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf syscall nm resolve_self thunk malloc_wx callback_plain
-PACK=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf resolve_self callback_plain
-ALL_C=plain call_suite suite callf syscall nm resolve_self thunk malloc_wx callback_plain callback_suite
+ALL=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf syscall nm dynload_plain resolve_self thunk malloc_wx callback_plain
+PACK=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf dynload_plain resolve_self callback_plain
+ALL_C=plain call_suite suite callf syscall nm dynload_plain resolve_self thunk malloc_wx callback_plain callback_suite
 .PHONY: all clean run-tests install distclean ${ALL} 
 all clean install: 
 	${MAKE} TARGET=$@ ${ALL}
@@ -15,6 +15,7 @@
 	cd callf && ${MAKE}
 	cd syscall && ${MAKE}
 	cd nm && ${MAKE}
+	cd dynload_plain && ${MAKE}
 	cd resolve_self && ${MAKE}
 	cd thunk && ${MAKE}
 	cd malloc_wx && ${MAKE}
@@ -56,9 +57,11 @@
 #	cd plain && ${MAKE}
 all-dynload:
 	cd nm && ${MAKE}
+	cd dynload_plain && ${MAKE}
 	cd resolve_self && ${MAKE}
 run-dynload:
 	#nm/nm
+	dynload_plain/dynload_plain
 	resolve_self/resolve_self
 all-dyncallback:
 	cd thunk && ${MAKE}
--- a/test/Nmakefile	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/Nmakefile	Thu Apr 06 02:13:57 2017 +0200
@@ -30,7 +30,7 @@
 !INCLUDE $(TOP)\buildsys\nmake\prolog.nmake
 
 
-DIRS = call_suite suite suite2 suite3 suite_floats callf ellipsis plain plain_c++ nm resolve_self thunk malloc_wx callback_plain callback_suite
+DIRS = call_suite suite suite2 suite3 suite_floats callf ellipsis plain plain_c++ nm dynload_plain resolve_self thunk malloc_wx callback_plain callback_suite
 !IF "$(BUILD_ARCH)" == "x86"
 DIRS = $(DIRS) suite_x86win32fast suite_x86win32std suite2_x86win32fast suite2_x86win32std
 !ENDIF
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/dynload_plain/CMakeLists.txt	Thu Apr 06 02:13:57 2017 +0200
@@ -0,0 +1,3 @@
+add_executable(dynload_plain dynload_plain.c)
+target_link_libraries(dynload_plain dynload_s ${CMAKE_DL_LIBS})
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/dynload_plain/Makefile.embedded	Thu Apr 06 02:13:57 2017 +0200
@@ -0,0 +1,20 @@
+APP = dynload_plain
+OBJS = dynload_plain.o
+
+TOP = ../..
+CFLAGS  += -I${TOP}/dynload
+LDFLAGS += -L${TOP}/dynload
+LDLIBS  += -ldynload_s
+# Works on: Darwin, NetBSD.
+# Linux: add '-ldl'
+
+all: ${APP}
+
+.PHONY: all clean
+
+${APP}: ${OBJS}
+	${CC} ${OBJS} ${LDFLAGS} ${LDLIBS} -o $@
+
+clean:
+	rm -f ${APP} ${OBJS}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/dynload_plain/Makefile.generic	Thu Apr 06 02:13:57 2017 +0200
@@ -0,0 +1,18 @@
+APP       = dynload_plain
+OBJS      = dynload_plain.o
+SRCTOP    = ${VPATH}/../..
+BLDTOP    = ../..
+CFLAGS   += -I${SRCTOP}/dynload
+LDLIBS_D += -L${BLDTOP}/dynload -ldynload_s
+# Works on: Darwin, NetBSD.
+# Linux: add '-ldl'
+.PHONY: all clean install
+all: ${APP}
+${APP}: ${OBJS}
+	${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS_D} ${LDLIBS} -o ${APP}
+clean:
+	rm -f ${APP} ${OBJS}
+install:
+	mkdir -p ${PREFIX}/test
+	cp ${APP} ${PREFIX}/test
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/dynload_plain/Nmakefile	Thu Apr 06 02:13:57 2017 +0200
@@ -0,0 +1,59 @@
+#//////////////////////////////////////////////////////////////////////////////
+#
+# Copyright (c) 2017 Tassilo Philipp <tphilipp@potion-studios.com>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+#//////////////////////////////////////////////////////////////////////////////
+
+#///////////////////////////////////////////////////
+#
+#	nmake makefile
+#	Nmakefile
+#
+#///////////////////////////////////////////////////
+
+
+TOP = ..\..
+
+!INCLUDE $(TOP)\buildsys\nmake\prolog.nmake
+
+
+!IF "$(BUILD_OS)" == "windows"
+
+TARGETS = dynload_plain.exe
+OBJS = dynload_plain.obj
+
+$(TARGETS): $(OBJS)
+	echo Linking $@ ...
+	$(LD) /OUT:"$@" $(LDFLAGS) $(OBJS) $(TOP)\dynload\libdynload_s.lib $(TOP)\dyncall\libdyncall_s.lib
+
+
+!ELSE IF "$(BUILD_OS)" == "nds"
+
+TARGETS = dynload_plain.nds
+OBJS = dynload_plain.o
+
+$(TARGETS):# $(OBJS)
+	echo Not building: There is no dynload support on this platform.
+#	echo Linking $@ ...
+#	$(LD) $(LDFLAGS) $(OBJS) $(DEVKITPRO_PATH)\libnds\lib\libnds9.a $(TOP)\dynload\libdynload_s.a $(TOP)/dyncall/libdyncall_s.a -o "$(@B).elf"
+#	$(OCP) -O binary "$(@B).elf" "$(@B).arm9"
+#	ndstool -c "$@" -9 "$(@B).arm9"
+#	del "$(@B).elf" "$(@B).arm9"
+
+!ENDIF
+
+
+!INCLUDE $(TOP)\buildsys\nmake\epilog.nmake
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/dynload_plain/dynload_plain.c	Thu Apr 06 02:13:57 2017 +0200
@@ -0,0 +1,127 @@
+/*
+
+ Package: dyncall
+ Library: test
+ File: test/dynload_plain/dynload_plain.c
+ Description:
+ License:
+
+   Copyright (c) 2017 Tassilo Philipp <tphilipp@potion-studios.com>
+
+   Permission to use, copy, modify, and distribute this software for any
+   purpose with or without fee is hereby granted, provided that the above
+   copyright notice and this permission notice appear in all copies.
+
+   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+*/
+
+
+#include "../../dynload/dynload.h"
+#include "../common/platformInit.h"
+
+#include <string.h>
+#include <unistd.h>
+
+
+int main(int argc, char* argv[])
+{
+  int r = 0, i;
+  void* p;
+  DLLib* pLib;
+  const char* path = NULL;
+  const char* clibs[] = { // hacky/lazy list of some clib paths per platform
+    "/lib/libc.so",
+    "/lib/libc.so.6",
+    "/lib/libc.so.7",
+    "/lib64/libc.so",
+    "/lib64/libc.so.6",
+    "/lib64/libc.so.7",
+    "/lib32/libc.so",
+    "/lib32/libc.so.6",
+    "/lib32/libc.so.7",
+    "/usr/lib/libc.dylib",
+    "C:\\Windows\\system32\\msvcrt.dll"
+  };
+
+
+  for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) {
+    if(access(clibs[i], F_OK) != -1)
+      path = clibs[i];
+  }
+
+  if(path) {
+    printf("using clib to test at: %s\n", path);
+    ++r;
+
+    // dl*Library tests
+    // --------
+    pLib = dlLoadLibrary(path); // check if we can load a lib
+    if(pLib) {
+      printf("pLib handle: %p\n", pLib);
+      ++r;
+
+      p = dlFindSymbol(pLib, "printf"); // check if we can lookup a symbol
+      printf("printf at: %p\n", p);
+      r += (p != NULL);
+
+      dlFreeLibrary(pLib);
+    }
+    else
+      printf("unable to open library %s\n", path);
+
+
+    // dlSyms* tests (intentionally after freeing lib above, as they work standalone)
+    // --------
+    DLSyms* pSyms = dlSymsInit(path); // check if we can iterate over symbols - init
+    if(pSyms) {
+      int n;
+      const char* name;
+
+      printf("pSyms handle: %p\n", pSyms);
+      ++r;
+
+      n = dlSymsCount(pSyms); // check if there are some syms to iterate over
+      printf("num of libc symbols: %d\n", n);
+      r += (n > 0);
+
+      for(i=0; i<n; ++i) {
+        name = dlSymsName(pSyms, i);
+        if(strcmp(name, "printf") == 0) { // check if we find "printf" also in iterated symbols
+          ++r;
+          break;
+        }
+      }
+      printf("printf symbol found by iteration: %d\n", i<n);
+
+      name = dlSymsName(pSyms, i);
+      r += (strcmp(name, "printf") == 0); // check if we can lookup "printf" by index
+      printf("printf symbol name by index: %s\n", name);
+
+      pLib = dlLoadLibrary(path); // check if we can resolve ptr -> name,
+      if(pLib) {                  // need to lookup by name again, first
+        p = dlFindSymbol(pLib, "printf");
+        name = dlSymsNameFromValue(pSyms, p);
+        printf("printf symbol name by its own address (%p): %s\n", p, name);
+        r += (strcmp(name, "printf") == 0);
+        dlFreeLibrary(pLib);
+      }
+
+      dlSymsCleanup(pSyms);
+    }
+    else
+      printf("dlSymsInit failed\n");
+  }
+
+  // All worked if we got a score of 6 right ones
+  r = (r == 8);
+  printf("result: dynload_plain: %d\n", r);
+  return !r;
+}
+
--- a/test/nm/nm.c	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/nm/nm.c	Thu Apr 06 02:13:57 2017 +0200
@@ -53,18 +53,18 @@
   int i, n;
   DLLib* pLib;
   const char* libPath;
-  
+
   if (argc == 1) {
     fprintf(stderr, "usage : %s <dllpath>\n", argv[0]);
     return 1;
   }
-  
+
   libPath = argv[1];
-  
+
   /* load lib */
 
   pLib = dlLoadLibrary(libPath);
-  
+
   if (!pLib) {
     fprintf(stderr, "unable to open library %s\n", libPath);
     return 2;
--- a/test/resolve_self/main.c	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/resolve_self/main.c	Thu Apr 06 02:13:57 2017 +0200
@@ -6,7 +6,7 @@
  Description: 
  License:
 
-   Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>,
+   Copyright (c) 2011-2017 Daniel Adler <dadler@uni-goettingen.de>,
                            Tassilo Philipp <tphilipp@potion-studios.com>
 
    Permission to use, copy, modify, and distribute this software for any
@@ -48,11 +48,17 @@
   int status;
   DLLib* pLib = dlLoadLibrary(NULL);
   assert(pLib);
+  printf("self loaded at %p\n", pLib);
 
   address = dlFindSymbol(pLib, "add_dd_d");
-  assert(address);
-  result = ( (double (*) (double,double) ) address ) (20.0, 3.0);
-  status = (result == 23); 
+  if(address) {
+    printf("address of function add_dd_d at %p\n", address);
+    result = ( (double (*) (double,double) ) address ) (20.0, 3.0);
+    status = (result == 23);
+  } else {
+    printf("can't resolve address of add_dd_d, it doesn't seem to be a *dynamic* symbol\n");
+    status = 0;
+  }
   printf("result: resolve_self: %d\n", status);
   return 0;
 }
--- a/test/runalltests.bat	Tue Mar 28 15:45:20 2017 +0200
+++ b/test/runalltests.bat	Thu Apr 06 02:13:57 2017 +0200
@@ -31,3 +31,5 @@
 pause
 callback_suite\callback_suite.exe
 pause
+dynload_plain\dynload_plain.exe
+pause