More tests for CompiledCodeObject and ObjectFileLoader.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 24 Jan 2016 22:26:45 +0000
changeset 12 6e775bad5027
parent 11 cfe5c9d79fbc
child 13 b3d0f59702b7
More tests for CompiledCodeObject and ObjectFileLoader.
CompiledCodeObject.st
CompiledCodeObjectSectionFormat.st
CompiledCodeObjectTests.st
Make.proto
ObjectFileLoaderTests.st
abbrev.stc
bc.mak
jv_dragonfly.st
--- a/CompiledCodeObject.st	Wed Jan 20 22:46:04 2016 +0000
+++ b/CompiledCodeObject.st	Sun Jan 24 22:26:45 2016 +0000
@@ -194,10 +194,16 @@
 !
 
 sectionNamed: aString
-    ^ self sections detect:[:section | section name = aString ] 
-                    ifNone:[ self error: 'No section named "', aString , '"' ]
+    ^ self sectionNamed: aString ifAbsent:[ self error: 'No section named "', aString , '"' ]
 
     "Created: / 19-01-2016 / 21:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-01-2016 / 20:51:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sectionNamed: aString ifAbsent: aBlock
+    ^ self sections detect:[:section | section name = aString ] ifNone: aBlock
+
+    "Created: / 24-01-2016 / 20:51:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 sections
@@ -367,6 +373,15 @@
     "Created: / 07-12-2015 / 16:36:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompiledCodeObject methodsFor:'queries'!
+
+hasSectionNamed: aString
+    self sectionNamed: aString ifAbsent: [ ^ false ].
+    ^ true
+
+    "Created: / 24-01-2016 / 20:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !CompiledCodeObject class methodsFor:'documentation'!
 
 version_HG
--- a/CompiledCodeObjectSectionFormat.st	Wed Jan 20 22:46:04 2016 +0000
+++ b/CompiledCodeObjectSectionFormat.st	Sun Jan 24 22:26:45 2016 +0000
@@ -15,7 +15,8 @@
 
 SharedPool subclass:#CompiledCodeObjectSectionFormat
 	instanceVariableNames:''
-	classVariableNames:'SectionFormatBytes SectionFormatText SectionFormatOBJVector SectionFormatILCVector SectionFormatINTVector'
+	classVariableNames:'SectionFormatBytes SectionFormatText SectionFormatOBJVector
+		SectionFormatILCVector SectionFormatINTVector'
 	poolDictionaries:''
 	category:'System-Compiler-Interface'
 !
@@ -52,5 +53,12 @@
     "Modified: / 07-12-2015 / 21:43:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompiledCodeObjectSectionFormat class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
 
 CompiledCodeObjectSectionFormat initialize!
--- a/CompiledCodeObjectTests.st	Wed Jan 20 22:46:04 2016 +0000
+++ b/CompiledCodeObjectTests.st	Sun Jan 24 22:26:45 2016 +0000
@@ -6,7 +6,7 @@
 	instanceVariableNames:'jitEnabled'
 	classVariableNames:''
 	poolDictionaries:'CompiledCodeObjectSectionFormat'
-	category:'System-Compiler-Interface'
+	category:'System-Compiler-Interface-Tests'
 !
 
 !CompiledCodeObjectTests class methodsFor:'documentation'!
@@ -121,6 +121,59 @@
     "Created: / 06-12-2015 / 00:15:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 23-01-2016 / 22:15:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 
+!
+
+test_02a
+    "Tests creation of new code object for method which has
+     not yet been compiled"
+
+    | method object section |
+
+    method := Method new.
+    method numberOfArgs: 0.
+    method numberOfVars: 0.
+    method stackSize: 0.          
+
+    object := CompiledCodeObject forCompiledCode: method text: 6 literals: 1 ilcs: 0.
+    self assert: object compiledCode == method.
+
+    section := object sectionNamed: '.text'.
+    self assert: section format = SectionFormatText.
+    self assert: section size == 6.
+    self assert: ((1 to: section size) allSatisfy:[:i | (section at: i) == 0 ]).
+
+    section := object sectionNamed: '.stx.codeobj.literals'.
+    self assert: section format = SectionFormatOBJVector.
+    self assert: section size == 1.
+    self assert: ((1 to: section size) allSatisfy:[:i | (section at: i) isNil ]).
+
+    "Created: / 24-01-2016 / 20:49:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02b
+    "Tests creation of new code object for method which has
+     not yet been compiled"
+
+    | method object section |
+
+    method := Method new.
+    method numberOfArgs: 0.
+    method numberOfVars: 0.
+    method stackSize: 0.          
+
+    object := CompiledCodeObject forCompiledCode: method text: 0 literals: 1 ilcs: 0.
+    self assert: object compiledCode == method.
+
+    self assert: (object hasSectionNamed: '.text') not.
+
+    object allocateTextSection: 10.
+    section := object sectionNamed: '.text'.
+
+    self assert: section format = SectionFormatText.
+    self assert: section size == 10.
+    self assert: ((1 to: section size) allSatisfy:[:i | (section at: i) == 0 ]).
+
+    "Created: / 24-01-2016 / 20:50:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompiledCodeObjectTests methodsFor:'utilities'!
--- a/Make.proto	Wed Jan 20 22:46:04 2016 +0000
+++ b/Make.proto	Sun Jan 24 22:26:45 2016 +0000
@@ -34,7 +34,7 @@
 # add the path(es) here:,
 # ********** OPTIONAL: MODIFY the next lines ***
 # LOCALINCLUDES=-Ifoo -Ibar
-LOCALINCLUDES= -I$(INCLUDE_TOP)/jv/dragonfly/udis86sx -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libbasic
+LOCALINCLUDES= -I$(INCLUDE_TOP)/jv/dragonfly/udis86sx -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libcomp
 
 
 # if you need any additional defines for embedded C code,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ObjectFileLoaderTests.st	Sun Jan 24 22:26:45 2016 +0000
@@ -0,0 +1,39 @@
+"{ Package: 'jv:dragonfly' }"
+
+"{ NameSpace: Smalltalk }"
+
+TestCase subclass:#ObjectFileLoaderTests
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'System-Compiler-Tests'
+!
+
+
+!ObjectFileLoaderTests methodsFor:'test - dlsym / GetProcAddress'!
+
+test_01
+
+    | handle address |
+
+    handle := ObjectFileLoader loadDynamicObject: nil.
+    handle sysHandle1: 0.
+    handle sysHandle2: 0.
+
+    address := ObjectFileLoader getSymbol: '_SEND0' function: true from: handle.
+    self assert: address notNil.
+
+    address := ObjectFileLoader getSymbol: '__vmDataPtr__' function: true from: handle.
+    self assert: address notNil.
+
+    "Created: / 24-01-2016 / 21:26:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-01-2016 / 23:04:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ObjectFileLoaderTests class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
--- a/abbrev.stc	Wed Jan 20 22:46:04 2016 +0000
+++ b/abbrev.stc	Sun Jan 24 22:26:45 2016 +0000
@@ -3,6 +3,7 @@
 # it provides information about a classes filename, category and especially namespace.
 CompiledCodeObject CompiledCodeObject jv:dragonfly 'System-Compiler-Interface' 0
 CompiledCodeObjectSectionFormat CompiledCodeObjectSectionFormat jv:dragonfly 'System-Compiler-Interface' 0
+ObjectFileLoaderTests ObjectFileLoaderTests jv:dragonfly 'System-Compiler-Tests' 1
 jv_dragonfly jv_dragonfly jv:dragonfly '* Projects & Packages *' 3
 CompiledCodeObjectSection CompiledCodeObjectSection jv:dragonfly 'System-Compiler-Interface' 0
-CompiledCodeObjectTests CompiledCodeObjectTests jv:dragonfly 'System-Compiler-Interface' 1
+CompiledCodeObjectTests CompiledCodeObjectTests jv:dragonfly 'System-Compiler-Interface-Tests' 1
--- a/bc.mak	Wed Jan 20 22:46:04 2016 +0000
+++ b/bc.mak	Sun Jan 24 22:26:45 2016 +0000
@@ -35,7 +35,7 @@
 
 
 
-LOCALINCLUDES= -I$(INCLUDE_TOP)\jv\dragonfly\udis86sx -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libbasic
+LOCALINCLUDES= -I$(INCLUDE_TOP)\jv\dragonfly\udis86sx -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libcomp
 LOCALDEFINES=
 
 STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES)  -varPrefix=$(LIBNAME)
--- a/jv_dragonfly.st	Wed Jan 20 22:46:04 2016 +0000
+++ b/jv_dragonfly.st	Sun Jan 24 22:26:45 2016 +0000
@@ -47,6 +47,7 @@
     ^ #(
         #'jv:dragonfly/udis86sx'    "UDIS86 - referenced by CompiledCodeObjectSection>>inspector2TabAssembly"
         #'stx:goodies/sunit'    "TestAsserter - superclass of CompiledCodeObjectTests"
+        #'stx:libcomp'    "ObjectFileLoader - referenced by ObjectFileLoaderTests>>test_01"
     )
 !
 
@@ -73,6 +74,7 @@
         "<className> or (<className> attributes...) in load order"
         CompiledCodeObject
         CompiledCodeObjectSectionFormat
+        (ObjectFileLoaderTests autoload)
         #'jv_dragonfly'
         CompiledCodeObjectSection
         (CompiledCodeObjectTests autoload)