diff options
author | Sven Gothel <[email protected]> | 2015-02-01 05:21:39 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-02-01 05:21:39 +0100 |
commit | a3f2d08801c5a54048faca52f422bcededf81b2a (patch) | |
tree | 96e83956b62ae3e25043ccc67f4cb1c2c1f232a1 /src/junit/com/jogamp/common/os | |
parent | 0deceee37d943faa7c34971388863a27f395d6a5 (diff) |
Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless
ELF Reader 'jogamp.common.os.elf' currently uses
Platform's pre-determined OS_TYPE and CPUType.
It also uses the host platforms MachineDescription,
hence can not read ELF files from other machines.
This also forbids Platform to determine CPUType etc
w/o having a valid 'os.arch' property.
+++
ElfHeader should be split in
- ElfHeaderPart1 (CPUType independent)
- ElfHeaderPart2 (CPUType dependent)
Fix shall make the ELF Reader self containing
by only using ELF CPUType data, etc.
This requires customization of struct parsing,
where MachineDescription.Static index shall be
- defined in ElfHeaderPart1 using e_Ident's CPUType.
- used in ElfHeaderPart2 and all its struct types.
Diffstat (limited to 'src/junit/com/jogamp/common/os')
-rw-r--r-- | src/junit/com/jogamp/common/os/TestElfReader01.java | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/src/junit/com/jogamp/common/os/TestElfReader01.java b/src/junit/com/jogamp/common/os/TestElfReader01.java index a750dd0..980a17a 100644 --- a/src/junit/com/jogamp/common/os/TestElfReader01.java +++ b/src/junit/com/jogamp/common/os/TestElfReader01.java @@ -8,7 +8,9 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.util.List; -import jogamp.common.os.elf.ElfHeader; +import jogamp.common.os.PlatformPropsImpl; +import jogamp.common.os.elf.ElfHeaderPart1; +import jogamp.common.os.elf.ElfHeaderPart2; import jogamp.common.os.elf.Section; import jogamp.common.os.elf.SectionArmAttributes; import jogamp.common.os.elf.SectionHeader; @@ -26,6 +28,7 @@ public class TestElfReader01 extends SingletonJunitCase { public static String GNU_LINUX_SELF_EXE = "/proc/self/exe"; public static String ARM_HF_EXE = "tst-exe-armhf"; public static String ARM_SF_EXE = "tst-exe-arm"; + static File userFile = null; private static boolean checkFileReadAccess(final File file) { try { @@ -49,49 +52,64 @@ public class TestElfReader01 extends SingletonJunitCase { } @Test - public void testGNULinuxSelfExe () throws IOException { - if( OSType.LINUX == Platform.getOSType() ) { - final File f = new File(GNU_LINUX_SELF_EXE); - if( checkFileReadAccess(f) ) { - testElfHeaderImpl(f, false); + public void test01GNULinuxSelfExe () throws IOException { + if( null == userFile ) { + if( OSType.LINUX == Platform.getOSType() ) { + final File f = new File(GNU_LINUX_SELF_EXE); + if( checkFileReadAccess(f) ) { + testElfHeaderImpl(f, false); + } } } } @Test - public void testJavaLib () throws IOException { - File jvmLib = findJVMLib("java"); - if( null == jvmLib ) { - jvmLib = findJVMLib("jvm"); + public void test02JavaLib () throws IOException { + if( null == userFile ) { + File jvmLib = findJVMLib("java"); + if( null == jvmLib ) { + jvmLib = findJVMLib("jvm"); + } + if( null != jvmLib ) { + testElfHeaderImpl(jvmLib, false); + } } - if( null != jvmLib ) { - testElfHeaderImpl(jvmLib, false); + } + + @Test + public void test99UserFile() throws IOException { + if( null != userFile ) { + testElfHeaderImpl(userFile, false); } } void testElfHeaderImpl(final File file, final boolean fileOutSections) throws IOException { + Platform.initSingleton(); System.err.println("Test file "+file.getAbsolutePath()); final RandomAccessFile in = new RandomAccessFile(file, "r"); try { - final ElfHeader eh; + final ElfHeaderPart1 eh1; + final ElfHeaderPart2 eh2; try { - eh = ElfHeader.read(in); + eh1 = ElfHeaderPart1.read(PlatformPropsImpl.OS_TYPE, in); + eh2 = ElfHeaderPart2.read(eh1, in); } catch (final Exception e) { System.err.println("Probably not an ELF file - or not in current format: (caught) "+e.getMessage()); e.printStackTrace(); return; } int i=0; - System.err.println(eh); - System.err.println("SH entsz "+eh.d.getE_shentsize()); - System.err.println("SH off "+toHexString(eh.d.getE_shoff())); - System.err.println("SH strndx "+eh.d.getE_shstrndx()); - System.err.println("SH num "+eh.sht.length); - if( 0 < eh.sht.length ) { - System.err.println("SH size "+eh.sht[0].d.getBuffer().limit()); + System.err.println(eh1); + System.err.println(eh2); + System.err.println("SH entsz "+eh2.raw.getE_shentsize()); + System.err.println("SH off "+toHexString(eh2.raw.getE_shoff())); + System.err.println("SH strndx "+eh2.raw.getE_shstrndx()); + System.err.println("SH num "+eh2.sht.length); + if( 0 < eh2.sht.length ) { + System.err.println("SH size "+eh2.sht[0].raw.getBuffer().limit()); } { - final SectionHeader sh = eh.getSectionHeader(SectionHeader.SHT_ARM_ATTRIBUTES); + final SectionHeader sh = eh2.getSectionHeader(SectionHeader.SHT_ARM_ATTRIBUTES); boolean abiVFPArgsAcceptsVFPVariant = false; if( null != sh ) { final SectionArmAttributes sArmAttrs = (SectionArmAttributes) sh.readSection(in); @@ -102,8 +120,8 @@ public class TestElfReader01 extends SingletonJunitCase { } System.err.println("abiVFPArgsAcceptsVFPVariant "+abiVFPArgsAcceptsVFPVariant); } - for(i=0; i<eh.sht.length; i++) { - final SectionHeader sh = eh.sht[i]; + for(i=0; i<eh2.sht.length; i++) { + final SectionHeader sh = eh2.sht[i]; System.err.println(sh); final int type = sh.getType(); if( SectionHeader.SHT_STRTAB == type ) { @@ -132,6 +150,12 @@ public class TestElfReader01 extends SingletonJunitCase { } public static void main(final String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-file")) { + i++; + userFile = new File(args[i]); + } + } final String tstname = TestElfReader01.class.getName(); org.junit.runner.JUnitCore.main(tstname); } |