From e04e128a59f8aad9334aa0aad9571b04396b421a Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 5 Sep 2007 18:39:42 +0000 Subject: [PATCH] updated jni_tests to new external tools configuration --- tools/cooja/examples/jni_test/build.xml | 192 ++++++++++-------- .../examples/jni_test/level3/Level3.java | 44 ++-- 2 files changed, 130 insertions(+), 106 deletions(-) diff --git a/tools/cooja/examples/jni_test/build.xml b/tools/cooja/examples/jni_test/build.xml index fc6c688bd..a90289303 100644 --- a/tools/cooja/examples/jni_test/build.xml +++ b/tools/cooja/examples/jni_test/build.xml @@ -1,58 +1,71 @@ + - + + + - - - - - + + + + -Win32 cygwin users may try: - COMPILER_ARGS= -mno-cygwin -I....../jdk1.5.0/include -I....../jdk1.5.0/include/win32 +Cygwin users may try: + COMPILER_ARGS = -mno-cygwin -I....../jdk1.5.0/include -I....../jdk1.5.0/include/win32 LINKER_ARGS_1 = --add-stdcall-alias /usr/lib/mingw/dllcrt2.o LINKER_ARGS_2 = -L/usr/lib/mingw -lmingw32 -lmingwex -lmsvcrt - Only for level 1, try the following compiler arguments: - COMPILER_ARGS= -mno-cygwin -I....../jdk1.5.0/include -I....../jdk1.5.0/include/win32 -Wl,--add-stdcall +Note for Windows users with recent Cygwin: +In recent (early 2007) MinGW-Cygwin versions, the JNI support has been removed/limited. +This may cause COOJA not to be able to load libraries generated using gcc's -mno-cygwin flag. +One possible solution is to download "real" MinGW (http://www.mingw.org), and install it separately +from Cygwin (for example in c:\mingw). Try using the following settings: + + COMPILER_ARGS = -Wall -D_JNI_IMPLEMENTATION_ -I'$(JAVA_HOME)/include' -I'$(JAVA_HOME)/include/win32' + LINK_COMMAND_1 = gcc -shared -Wl,-Map=$(MAPFILE) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -o $(LIBFILE) + LINK_COMMAND_2 = The COOJA Simulator - JNI Tests -There examples may help understand errors during compilation from inside COOJA. -For some examples; "ant help". +------------------------------- - -ant level1 - Runs JNI test level 1: - [compilation test] - Compiles level1.c to level1.library, using only c compiler. - Java class loads the library and calls a simple native function. +These tests can be used to help understand COOJA errors, and to configure COOJA for new users. +For COOJA to compile JNI libraries successfully, tests 2-5 must be completed. -ant level2 +You may have to change the configuration (4 properties) in this file (build.xml). +When all tests pass, the settings should be entered into the COOJA External tool settings dialog. + +To run the first test: + > ant level2 + +For more information including configuration examples: + > ant help + +> ant level2 Runs JNI test level 2: [compilation test] Compiles level2.c to level2.library, using both c compiler and linker. Java class loads the library and calls a simple native function. -ant level3 +> ant level3 Runs JNI test level 3: [map file parsing test] Compiles java + c. The map file is parsed, and information about data+bss sections is outputted. -ant level4 +> ant level4 Runs JNI test level 4: [fetching reference var] Calculates offset between relative (mapfile) and absolute memory. A simple native function increases two counters (from both data and bss sections). -ant level5 +> ant level5 Runs JNI test level 5: [fetches and restores memory segments - the final test] A simple native function increases two counters (from both data and bss sections). @@ -67,6 +80,8 @@ ant level5 + + @@ -74,80 +89,81 @@ ant level5 - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + diff --git a/tools/cooja/examples/jni_test/level3/Level3.java b/tools/cooja/examples/jni_test/level3/Level3.java index 023471ba5..8fe806b8f 100644 --- a/tools/cooja/examples/jni_test/level3/Level3.java +++ b/tools/cooja/examples/jni_test/level3/Level3.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Level3.java,v 1.2 2007/01/11 14:26:47 fros4943 Exp $ + * $Id: Level3.java,v 1.3 2007/09/05 18:39:42 fros4943 Exp $ */ import java.io.*; @@ -44,7 +44,7 @@ public class Level3 { "^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$"; final static private String dataSectionSizeRegExp = "^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$"; - + static { System.load(new File("level3.library").getAbsolutePath()); } @@ -65,20 +65,20 @@ public class Level3 { System.err.println("Parsing map file"); int relDataSectionAddr = loadRelDataSectionAddr(mapContents); - int dataSectionSize = (int) loadDataSectionSize(mapContents); + int dataSectionSize = loadDataSectionSize(mapContents); int relBssSectionAddr = loadRelBssSectionAddr(mapContents); - int bssSectionSize = (int) loadBssSectionSize(mapContents); + int bssSectionSize = loadBssSectionSize(mapContents); System.err.println("Found relative data section address: 0x" + Integer.toHexString(relDataSectionAddr)); System.err.println("Found data section size: 0x" + Integer.toHexString(dataSectionSize)); System.err.println("Found relative bss section address: 0x" + Integer.toHexString(relBssSectionAddr)); System.err.println("Found bss section size: 0x" + Integer.toHexString(bssSectionSize)); - - if (dataSectionSize != 4) { + + if (dataSectionSize < 4) { System.err.println("Data section size is " + Integer.toHexString(dataSectionSize) + " but should be 0x4!"); System.exit(1); } - if (bssSectionSize != 4) { + if (bssSectionSize < 4) { System.err.println("BSS section size is " + Integer.toHexString(bssSectionSize) + " but should be 0x4!"); System.exit(1); } @@ -87,13 +87,13 @@ public class Level3 { private static Vector loadMapFile(File mapFile) { Vector mapContents = new Vector(); - + try { BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream(mapFile))); - + while (in.ready()) { mapContents.add(in.readLine()); @@ -105,40 +105,48 @@ public class Level3 { System.err.println("IO error: " + e); return null; } - + return mapContents; } private static int loadRelDataSectionAddr(Vector mapFile) { String retString = getFirstMatchGroup(mapFile, dataSectionAddrRegExp, 1); - if (retString != null) + if (retString != null) { return Integer.parseInt(retString.trim(), 16); - else return 0; + } else { + return 0; + } } private static int loadDataSectionSize(Vector mapFile) { String retString = getFirstMatchGroup(mapFile, dataSectionSizeRegExp, 1); - if (retString != null) + if (retString != null) { return Integer.parseInt(retString.trim(), 16); - else return 0; + } else { + return 0; + } } private static int loadRelBssSectionAddr(Vector mapFile) { String retString = getFirstMatchGroup(mapFile, bssSectionAddrRegExp, 1); - if (retString != null) + if (retString != null) { return Integer.parseInt(retString.trim(), 16); - else return 0; + } else { + return 0; + } } private static int loadBssSectionSize(Vector mapFile) { String retString = getFirstMatchGroup(mapFile, bssSectionSizeRegExp, 1); - if (retString != null) + if (retString != null) { return Integer.parseInt(retString.trim(), 16); - else return 0; + } else { + return 0; + } } private static String getFirstMatchGroup(Vector lines, String regexp, int groupNr) {