updated jni_tests to new external tools configuration

This commit is contained in:
fros4943 2007-09-05 18:39:42 +00:00
parent e097e17a15
commit e04e128a59
2 changed files with 130 additions and 106 deletions

View file

@ -1,58 +1,71 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project name="COOJA Simulator - JNI Tests" default="about" basedir="."> <project name="COOJA Simulator - JNI Tests" default="about" basedir=".">
<property environment="env"/>
<!-- Properties used inside the COOJA Simulator --> <!-- CONFIGURATION -->
<!-- Change these until all tests pass! -->
<!-- The working configuration must manually be entered in COOJA -->
<property name="PATH_C_COMPILER" value="gcc"/> <property name="PATH_C_COMPILER" value="gcc"/>
<property name="COMPILER_ARGS" value=""/> <property name="COMPILER_ARGS" value="-Wall -D_JNI_IMPLEMENTATION_ -I'$(JAVA_HOME)/include' -I'$(JAVA_HOME)/include/win32'"/>
<property name="PATH_LINKER" value="ld"/> <property name="LINK_COMMAND_1" value="gcc -shared -Wl,-Map=$(MAPFILE) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -o $(LIBFILE)"/>
<property name="LINKER_ARGS_1" value=""/> <property name="LINK_COMMAND_2" value=""/>
<property name="LINKER_ARGS_2" value=""/>
<target name="help"> <target name="help">
<echo> <echo>
Win32 cygwin users may try: Cygwin users may try:
COMPILER_ARGS = -mno-cygwin -I....../jdk1.5.0/include -I....../jdk1.5.0/include/win32 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_1 = --add-stdcall-alias /usr/lib/mingw/dllcrt2.o
LINKER_ARGS_2 = -L/usr/lib/mingw -lmingw32 -lmingwex -lmsvcrt LINKER_ARGS_2 = -L/usr/lib/mingw -lmingw32 -lmingwex -lmsvcrt
Only for level 1, try the following compiler arguments: Note for Windows users with recent Cygwin:
COMPILER_ARGS= -mno-cygwin -I....../jdk1.5.0/include -I....../jdk1.5.0/include/win32 -Wl,--add-stdcall 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 =
</echo> </echo>
</target> </target>
<target name="about"> <target name="about">
<echo> <echo>
The COOJA Simulator - JNI Tests The COOJA Simulator - JNI Tests
There examples may help understand errors during compilation from inside COOJA. -------------------------------
For some examples; "ant help".
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 level1 You may have to change the configuration (4 properties) in this file (build.xml).
Runs JNI test level 1: When all tests pass, the settings should be entered into the COOJA External tool settings dialog.
[compilation test]
Compiles level1.c to level1.library, using only c compiler.
Java class loads the library and calls a simple native function.
ant level2 To run the first test:
> ant level2
For more information including configuration examples:
> ant help
> ant level2
Runs JNI test level 2: Runs JNI test level 2:
[compilation test] [compilation test]
Compiles level2.c to level2.library, using both c compiler and linker. Compiles level2.c to level2.library, using both c compiler and linker.
Java class loads the library and calls a simple native function. Java class loads the library and calls a simple native function.
ant level3 > ant level3
Runs JNI test level 3: Runs JNI test level 3:
[map file parsing test] [map file parsing test]
Compiles java + c. Compiles java + c.
The map file is parsed, and information about data+bss sections is outputted. The map file is parsed, and information about data+bss sections is outputted.
ant level4 > ant level4
Runs JNI test level 4: Runs JNI test level 4:
[fetching reference var] [fetching reference var]
Calculates offset between relative (mapfile) and absolute memory. Calculates offset between relative (mapfile) and absolute memory.
A simple native function increases two counters (from both data and bss sections). A simple native function increases two counters (from both data and bss sections).
ant level5 > ant level5
Runs JNI test level 5: Runs JNI test level 5:
[fetches and restores memory segments - the final test] [fetches and restores memory segments - the final test]
A simple native function increases two counters (from both data and bss sections). A simple native function increases two counters (from both data and bss sections).
@ -67,6 +80,8 @@ ant level5
<fileset dir="." includes="**/*.library" /> <fileset dir="." includes="**/*.library" />
<fileset dir="." includes="**/*.o" /> <fileset dir="." includes="**/*.o" />
<fileset dir="." includes="**/*.map" /> <fileset dir="." includes="**/*.map" />
<fileset dir="." includes="**/*.log" />
<fileset dir="." includes="build.temp" />
</delete> </delete>
</target> </target>
@ -74,80 +89,81 @@ ant level5
<tstamp/> <tstamp/>
</target> </target>
<target name="level1_compile_c" depends="init"> <target name="compile_library" depends="init">
<echo message="EXECUTING: ${PATH_C_COMPILER} ${COMPILER_ARGS} -o level1.library -shared level1.c"/> <property name="SRCFILE" value="${LEVEL}.c"/>
<exec dir="level1" executable="${PATH_C_COMPILER}" failonerror="true"> <property name="OBJFILE" value="${LEVEL}.o"/>
<arg line="${COMPILER_ARGS} -o level1.library -shared level1.c"/> <property name="LIBFILE" value="${LEVEL}.library"/>
<property name="MAPFILE" value="${LEVEL}.map"/>
<property name="ARFILE" value="${LEVEL}.a"/>
<property name="COMPILE_COMMAND" value="${PATH_C_COMPILER} ${COMPILER_ARGS} -c ${SRCFILE} -o ${OBJFILE}"/>
<property name="LINKER_COMMAND" value="${LINK_COMMAND_1} ${OBJFILE} ${LINK_COMMAND_2}"/>
<propertyfile file="build.temp">
<entry key="COMPILE_EXEC" value="${COMPILE_COMMAND}"/>
<entry key="COMPILE_ARGS" value="${COMPILE_COMMAND}"/>
<entry key="LINKER_EXEC" value="${LINKER_COMMAND}"/>
<entry key="LINKER_ARGS" value="${LINKER_COMMAND}"/>
</propertyfile>
<replace file="build.temp" token="$(JAVA_HOME)" value="${env.JAVA_HOME}"/>
<replace file="build.temp" token="$(LIBFILE)" value="${LIBFILE}"/>
<replace file="build.temp" token="$(MAPFILE)" value="${MAPFILE}"/>
<replace file="build.temp" token="$(ARFILE)" value="${ARFILE}"/>
<replaceregexp
file="build.temp" match="COMPILE_EXEC=(\w*).*"
replace="COMPILE_EXEC=\1" byline="true"/>
<replaceregexp
file="build.temp" match="COMPILE_ARGS=\w*(.*)"
replace="COMPILE_ARGS=\1" byline="true"/>
<replaceregexp
file="build.temp" match="LINKER_EXEC=(\w*).*"
replace="LINKER_EXEC=\1" byline="true"/>
<replaceregexp
file="build.temp" match="LINKER_ARGS=\w*(.*)"
replace="LINKER_ARGS=\1" byline="true"/>
<property file="build.temp"/>
<echo message="EXECUTING: ${COMPILE_EXEC} ${COMPILE_ARGS}"/>
<exec dir="${LEVEL}" executable="${COMPILE_EXEC}" failonerror="true">
<arg line="${COMPILE_ARGS}"/>
</exec>
<echo message="EXECUTING: ${LINKER_EXEC} ${LINKER_ARGS}"/>
<exec dir="${LEVEL}" executable="${LINKER_EXEC}" failonerror="true">
<arg line="${LINKER_ARGS}"/>
</exec> </exec>
</target> </target>
<target name="level1" depends="init, level1_compile_c"> <target name="level2" depends="init">
<javac srcdir="level1" destdir="level1"/> <property name="LEVEL" value="level2"/>
<java fork="yes" dir="level1" classname="Level1"/> <antcall target="compile_library" inheritall="true"/>
<javac srcdir="${LEVEL}" destdir="${LEVEL}"/>
<java fork="yes" dir="${LEVEL}" classname="Level2"/>
</target> </target>
<target name="level2_compile_c" depends="init"> <target name="level3" depends="init">
<echo message="EXECUTING: ${PATH_C_COMPILER} ${COMPILER_ARGS} -c -o level2.o -shared level2.c"/> <property name="LEVEL" value="level3"/>
<exec dir="level2" executable="${PATH_C_COMPILER}" failonerror="true"> <antcall target="compile_library" inheritall="true"/>
<arg line="${COMPILER_ARGS} -c -o level2.o -shared level2.c"/>
</exec> <javac srcdir="${LEVEL}" destdir="${LEVEL}"/>
<echo message="EXECUTING: ${PATH_LINKER} -Map=level2.map -shared ${LINKER_ARGS_1} -o level2.library level2.o ${LINKER_ARGS_2}"/> <java fork="yes" dir="${LEVEL}" classname="Level3"/>
<exec dir="level2" executable="${PATH_LINKER}" failonerror="true">
<arg line="-Map=level2.map -shared ${LINKER_ARGS_1} -o level2.library level2.o ${LINKER_ARGS_2}"/>
</exec>
</target> </target>
<target name="level2" depends="init, level2_compile_c"> <target name="level4" depends="init">
<javac srcdir="level2" destdir="level2"/> <property name="LEVEL" value="level4"/>
<java fork="yes" dir="level2" classname="Level2"/> <antcall target="compile_library" inheritall="true"/>
<javac srcdir="${LEVEL}" destdir="${LEVEL}"/>
<java fork="yes" dir="${LEVEL}" classname="Level4"/>
</target> </target>
<target name="level3_compile_c" depends="init"> <target name="level5" depends="init">
<echo message="EXECUTING: ${PATH_C_COMPILER} ${COMPILER_ARGS} -c -o level3.o -shared level3.c"/> <property name="LEVEL" value="level5"/>
<exec dir="level3" executable="${PATH_C_COMPILER}" failonerror="true"> <antcall target="compile_library" inheritall="true"/>
<arg line="${COMPILER_ARGS} -c -o level3.o -shared level3.c"/>
</exec>
<echo message="EXECUTING: ${PATH_LINKER} -Map=level3.map -shared ${LINKER_ARGS_1} -o level3.library level3.o ${LINKER_ARGS_2}"/>
<exec dir="level3" executable="${PATH_LINKER}" failonerror="true">
<arg line="-Map=level3.map -shared ${LINKER_ARGS_1} -o level3.library level3.o ${LINKER_ARGS_2}"/>
</exec>
</target>
<target name="level3" depends="init, level3_compile_c"> <javac srcdir="${LEVEL}" destdir="${LEVEL}"/>
<javac srcdir="level3" destdir="level3"/> <java fork="yes" dir="${LEVEL}" classname="Level5"/>
<java fork="yes" dir="level3" classname="Level3"/>
</target>
<target name="level4_compile_c" depends="init">
<echo message="EXECUTING: ${PATH_C_COMPILER} ${COMPILER_ARGS} -c -o level4.o -shared level4.c"/>
<exec dir="level4" executable="${PATH_C_COMPILER}" failonerror="true">
<arg line="${COMPILER_ARGS} -c -o level4.o -shared level4.c"/>
</exec>
<echo message="EXECUTING: ${PATH_LINKER} -Map=level4.map -shared ${LINKER_ARGS_1} -o level4.library level4.o ${LINKER_ARGS_2}"/>
<exec dir="level4" executable="${PATH_LINKER}" failonerror="true">
<arg line="-Map=level4.map -shared ${LINKER_ARGS_1} -o level4.library level4.o ${LINKER_ARGS_2}"/>
</exec>
</target>
<target name="level4" depends="init, level4_compile_c">
<javac srcdir="level4" destdir="level4"/>
<java fork="yes" dir="level4" classname="Level4"/>
</target>
<target name="level5_compile_c" depends="init">
<echo message="EXECUTING: ${PATH_C_COMPILER} ${COMPILER_ARGS} -c -o level5.o -shared level5.c"/>
<exec dir="level5" executable="${PATH_C_COMPILER}" failonerror="true">
<arg line="${COMPILER_ARGS} -c -o level5.o -shared level5.c"/>
</exec>
<echo message="EXECUTING: ${PATH_LINKER} -Map=level5.map -shared ${LINKER_ARGS_1} -o level5.library level5.o ${LINKER_ARGS_2}"/>
<exec dir="level5" executable="${PATH_LINKER}" failonerror="true">
<arg line="-Map=level5.map -shared ${LINKER_ARGS_1} -o level5.library level5.o ${LINKER_ARGS_2}"/>
</exec>
</target>
<target name="level5" depends="init, level5_compile_c">
<javac srcdir="level5" destdir="level5"/>
<java fork="yes" dir="level5" classname="Level5"/>
</target> </target>
</project> </project>

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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.*; import java.io.*;
@ -65,20 +65,20 @@ public class Level3 {
System.err.println("Parsing map file"); System.err.println("Parsing map file");
int relDataSectionAddr = loadRelDataSectionAddr(mapContents); int relDataSectionAddr = loadRelDataSectionAddr(mapContents);
int dataSectionSize = (int) loadDataSectionSize(mapContents); int dataSectionSize = loadDataSectionSize(mapContents);
int relBssSectionAddr = loadRelBssSectionAddr(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 relative data section address: 0x" + Integer.toHexString(relDataSectionAddr));
System.err.println("Found data section size: 0x" + Integer.toHexString(dataSectionSize)); 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 relative bss section address: 0x" + Integer.toHexString(relBssSectionAddr));
System.err.println("Found bss section size: 0x" + Integer.toHexString(bssSectionSize)); 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.err.println("Data section size is " + Integer.toHexString(dataSectionSize) + " but should be 0x4!");
System.exit(1); System.exit(1);
} }
if (bssSectionSize != 4) { if (bssSectionSize < 4) {
System.err.println("BSS section size is " + Integer.toHexString(bssSectionSize) + " but should be 0x4!"); System.err.println("BSS section size is " + Integer.toHexString(bssSectionSize) + " but should be 0x4!");
System.exit(1); System.exit(1);
} }
@ -112,33 +112,41 @@ public class Level3 {
private static int loadRelDataSectionAddr(Vector<String> mapFile) { private static int loadRelDataSectionAddr(Vector<String> mapFile) {
String retString = getFirstMatchGroup(mapFile, dataSectionAddrRegExp, 1); String retString = getFirstMatchGroup(mapFile, dataSectionAddrRegExp, 1);
if (retString != null) if (retString != null) {
return Integer.parseInt(retString.trim(), 16); return Integer.parseInt(retString.trim(), 16);
else return 0; } else {
return 0;
}
} }
private static int loadDataSectionSize(Vector<String> mapFile) { private static int loadDataSectionSize(Vector<String> mapFile) {
String retString = getFirstMatchGroup(mapFile, dataSectionSizeRegExp, 1); String retString = getFirstMatchGroup(mapFile, dataSectionSizeRegExp, 1);
if (retString != null) if (retString != null) {
return Integer.parseInt(retString.trim(), 16); return Integer.parseInt(retString.trim(), 16);
else return 0; } else {
return 0;
}
} }
private static int loadRelBssSectionAddr(Vector<String> mapFile) { private static int loadRelBssSectionAddr(Vector<String> mapFile) {
String retString = getFirstMatchGroup(mapFile, bssSectionAddrRegExp, 1); String retString = getFirstMatchGroup(mapFile, bssSectionAddrRegExp, 1);
if (retString != null) if (retString != null) {
return Integer.parseInt(retString.trim(), 16); return Integer.parseInt(retString.trim(), 16);
else return 0; } else {
return 0;
}
} }
private static int loadBssSectionSize(Vector<String> mapFile) { private static int loadBssSectionSize(Vector<String> mapFile) {
String retString = getFirstMatchGroup(mapFile, bssSectionSizeRegExp, 1); String retString = getFirstMatchGroup(mapFile, bssSectionSizeRegExp, 1);
if (retString != null) if (retString != null) {
return Integer.parseInt(retString.trim(), 16); return Integer.parseInt(retString.trim(), 16);
else return 0; } else {
return 0;
}
} }
private static String getFirstMatchGroup(Vector<String> lines, String regexp, int groupNr) { private static String getFirstMatchGroup(Vector<String> lines, String regexp, int groupNr) {