From 2f0c60a70b7c2115c7efb362b8a8e67bb1604eb6 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 17:09:28 +0100 Subject: [PATCH 01/10] Fix old bugs in `TRCompilationTestShell` and `TR...RemoteUsingSSH` This commit fixes old bugs in shells caused (probably) by renaming instance variables. --- src/Tinyrossa-Tests/TRCompilationTestShell.class.st | 2 +- .../TRCompilationTestShellRemoteUsingSSH.class.st | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st index 5314faa..b55e5a9 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st @@ -143,7 +143,7 @@ TRCompilationTestShell >> tearDownDebugger [ debugger send: 'kill'. shouldQuitDebugger := (Smalltalk includesKey: #VDBDebuggerApplication) not - or:[(Smalltalk at: #VDBDebuggerApplication) allInstances allSatisfy:[:vdbApp | vdbApp debugger ~~ target]]. + or:[(Smalltalk at: #VDBDebuggerApplication) allInstances allSatisfy:[:vdbApp | vdbApp debugger ~~ debugger]]. shouldQuitDebugger ifTrue: [ debugger send: 'quit' andWait: false. ]. diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st index e90ac5b..cccdcc8 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellRemoteUsingSSH.class.st @@ -33,7 +33,7 @@ TRCompilationTestShellRemoteUsingSSH >> setUp [ debugger := (Smalltalk at: #GDBDebugger) new. debugger executable: binary. - target send: 'target extended-remote | ssh -C ', self class host , ' gdbserver - /tmp/' , binary baseName. + debugger send: 'target extended-remote | ssh -C ', self class host , ' gdbserver - /tmp/' , binary baseName. ^self ] ifFalse:[ self error: 'This shell require libgdbs' From e8385f04b71460366f98cb31a56ed91b199b1ad6 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 23:01:59 +0100 Subject: [PATCH 02/10] Implement `TRRealRegister >> #printOn:` and `#printString` --- src/Tinyrossa/TRRealRegister.class.st | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Tinyrossa/TRRealRegister.class.st b/src/Tinyrossa/TRRealRegister.class.st index 71b1b56..138221b 100644 --- a/src/Tinyrossa/TRRealRegister.class.st +++ b/src/Tinyrossa/TRRealRegister.class.st @@ -43,6 +43,16 @@ TRRealRegister >> kind [ ^ kind ] +{ #category : #'printing & storing' } +TRRealRegister >> printOn: aStream [ + aStream nextPutAll: self name +] + +{ #category : #'printing & storing' } +TRRealRegister >> printString [ + ^ self name +] + { #category : #initialization } TRRealRegister >> setAssigned [ "No-op, we do not track assignments to real registers" From 895c862fe759786d41af9e82f2a7af13c2b1cd74 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 23:07:45 +0100 Subject: [PATCH 03/10] POWER: introduce custom real register class This commit introduces POWER-specific `TRPPCRegister` class. The main reason is that different tools use different register names: * Tinyrossa (as well as Testarossa) use `gr0`, `gr1` for GPRs, * GDB uses just `r0`, `r1` and so on and * in assembly (and ArchC) plain `0`, `1` is used. Having a custom subclass allows for having multiple methods returning register names suitable for given tool. --- src/Tinyrossa-POWER/TRPPC64Registers.class.st | 82 +++++++++---------- src/Tinyrossa-POWER/TRPPCRegister.class.st | 22 +++++ 2 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 src/Tinyrossa-POWER/TRPPCRegister.class.st diff --git a/src/Tinyrossa-POWER/TRPPC64Registers.class.st b/src/Tinyrossa-POWER/TRPPC64Registers.class.st index 0ea9bc3..66c636c 100644 --- a/src/Tinyrossa-POWER/TRPPC64Registers.class.st +++ b/src/Tinyrossa-POWER/TRPPC64Registers.class.st @@ -54,48 +54,48 @@ TRPPC64Registers class >> initialize [ | gprs ccrs | gprs := AcProcessorDescriptions powerpc64 maps at: 'reg'. - gr0 := TRRealRegister value: (gprs lookup: '0') kind: GPR. - gr1 := TRRealRegister value: (gprs lookup: '1') kind: GPR. - gr2 := TRRealRegister value: (gprs lookup: '2') kind: GPR. - gr3 := TRRealRegister value: (gprs lookup: '3') kind: GPR. - gr4 := TRRealRegister value: (gprs lookup: '4') kind: GPR. - gr5 := TRRealRegister value: (gprs lookup: '5') kind: GPR. - gr6 := TRRealRegister value: (gprs lookup: '6') kind: GPR. - gr7 := TRRealRegister value: (gprs lookup: '7') kind: GPR. - gr8 := TRRealRegister value: (gprs lookup: '8') kind: GPR. - gr9 := TRRealRegister value: (gprs lookup: '9') kind: GPR. - gr10 := TRRealRegister value: (gprs lookup: '10') kind: GPR. - gr11 := TRRealRegister value: (gprs lookup: '11') kind: GPR. - gr12 := TRRealRegister value: (gprs lookup: '12') kind: GPR. - gr13 := TRRealRegister value: (gprs lookup: '13') kind: GPR. - gr14 := TRRealRegister value: (gprs lookup: '14') kind: GPR. - gr15 := TRRealRegister value: (gprs lookup: '15') kind: GPR. - gr16 := TRRealRegister value: (gprs lookup: '16') kind: GPR. - gr17 := TRRealRegister value: (gprs lookup: '17') kind: GPR. - gr18 := TRRealRegister value: (gprs lookup: '18') kind: GPR. - gr19 := TRRealRegister value: (gprs lookup: '19') kind: GPR. - gr20 := TRRealRegister value: (gprs lookup: '20') kind: GPR. - gr21 := TRRealRegister value: (gprs lookup: '21') kind: GPR. - gr22 := TRRealRegister value: (gprs lookup: '22') kind: GPR. - gr23 := TRRealRegister value: (gprs lookup: '23') kind: GPR. - gr24 := TRRealRegister value: (gprs lookup: '24') kind: GPR. - gr25 := TRRealRegister value: (gprs lookup: '25') kind: GPR. - gr26 := TRRealRegister value: (gprs lookup: '26') kind: GPR. - gr27 := TRRealRegister value: (gprs lookup: '27') kind: GPR. - gr28 := TRRealRegister value: (gprs lookup: '28') kind: GPR. - gr29 := TRRealRegister value: (gprs lookup: '29') kind: GPR. - gr30 := TRRealRegister value: (gprs lookup: '30') kind: GPR. - gr31 := TRRealRegister value: (gprs lookup: '31') kind: GPR. + gr0 := TRPPCRegister value: (gprs lookup: '0') kind: GPR. + gr1 := TRPPCRegister value: (gprs lookup: '1') kind: GPR. + gr2 := TRPPCRegister value: (gprs lookup: '2') kind: GPR. + gr3 := TRPPCRegister value: (gprs lookup: '3') kind: GPR. + gr4 := TRPPCRegister value: (gprs lookup: '4') kind: GPR. + gr5 := TRPPCRegister value: (gprs lookup: '5') kind: GPR. + gr6 := TRPPCRegister value: (gprs lookup: '6') kind: GPR. + gr7 := TRPPCRegister value: (gprs lookup: '7') kind: GPR. + gr8 := TRPPCRegister value: (gprs lookup: '8') kind: GPR. + gr9 := TRPPCRegister value: (gprs lookup: '9') kind: GPR. + gr10 := TRPPCRegister value: (gprs lookup: '10') kind: GPR. + gr11 := TRPPCRegister value: (gprs lookup: '11') kind: GPR. + gr12 := TRPPCRegister value: (gprs lookup: '12') kind: GPR. + gr13 := TRPPCRegister value: (gprs lookup: '13') kind: GPR. + gr14 := TRPPCRegister value: (gprs lookup: '14') kind: GPR. + gr15 := TRPPCRegister value: (gprs lookup: '15') kind: GPR. + gr16 := TRPPCRegister value: (gprs lookup: '16') kind: GPR. + gr17 := TRPPCRegister value: (gprs lookup: '17') kind: GPR. + gr18 := TRPPCRegister value: (gprs lookup: '18') kind: GPR. + gr19 := TRPPCRegister value: (gprs lookup: '19') kind: GPR. + gr20 := TRPPCRegister value: (gprs lookup: '20') kind: GPR. + gr21 := TRPPCRegister value: (gprs lookup: '21') kind: GPR. + gr22 := TRPPCRegister value: (gprs lookup: '22') kind: GPR. + gr23 := TRPPCRegister value: (gprs lookup: '23') kind: GPR. + gr24 := TRPPCRegister value: (gprs lookup: '24') kind: GPR. + gr25 := TRPPCRegister value: (gprs lookup: '25') kind: GPR. + gr26 := TRPPCRegister value: (gprs lookup: '26') kind: GPR. + gr27 := TRPPCRegister value: (gprs lookup: '27') kind: GPR. + gr28 := TRPPCRegister value: (gprs lookup: '28') kind: GPR. + gr29 := TRPPCRegister value: (gprs lookup: '29') kind: GPR. + gr30 := TRPPCRegister value: (gprs lookup: '30') kind: GPR. + gr31 := TRPPCRegister value: (gprs lookup: '31') kind: GPR. ccrs := AcProcessorDescriptions powerpc64 maps at: 'ccr'. - cr0 := TRRealRegister value: (ccrs lookup: 'cr0') kind: CCR. - cr1 := TRRealRegister value: (ccrs lookup: 'cr1') kind: CCR. - cr2 := TRRealRegister value: (ccrs lookup: 'cr2') kind: CCR. - cr3 := TRRealRegister value: (ccrs lookup: 'cr3') kind: CCR. - cr4 := TRRealRegister value: (ccrs lookup: 'cr4') kind: CCR. - cr5 := TRRealRegister value: (ccrs lookup: 'cr5') kind: CCR. - cr6 := TRRealRegister value: (ccrs lookup: 'cr6') kind: CCR. - cr7 := TRRealRegister value: (ccrs lookup: 'cr7') kind: CCR. + cr0 := TRPPCRegister value: (ccrs lookup: 'cr0') kind: CCR. + cr1 := TRPPCRegister value: (ccrs lookup: 'cr1') kind: CCR. + cr2 := TRPPCRegister value: (ccrs lookup: 'cr2') kind: CCR. + cr3 := TRPPCRegister value: (ccrs lookup: 'cr3') kind: CCR. + cr4 := TRPPCRegister value: (ccrs lookup: 'cr4') kind: CCR. + cr5 := TRPPCRegister value: (ccrs lookup: 'cr5') kind: CCR. + cr6 := TRPPCRegister value: (ccrs lookup: 'cr6') kind: CCR. + cr7 := TRPPCRegister value: (ccrs lookup: 'cr7') kind: CCR. " @@ -103,7 +103,7 @@ TRPPC64Registers class >> initialize [ self bindingsDo: [ :binding | (binding key startsWith:'gr') ifTrue: [ s nextPutAll: ' '; nextPutAll: binding key; - nextPutAll: ' := TRRealRegister value: (gprs lookup: '; nextPutAll: (binding key asString copyFrom:3) storeString; + nextPutAll: ' := TRPPCRegister value: (gprs lookup: '; nextPutAll: (binding key asString copyFrom:3) storeString; nextPutAll: ') kind: GPR.'; cr. ] ]. diff --git a/src/Tinyrossa-POWER/TRPPCRegister.class.st b/src/Tinyrossa-POWER/TRPPCRegister.class.st new file mode 100644 index 0000000..17b0bb1 --- /dev/null +++ b/src/Tinyrossa-POWER/TRPPCRegister.class.st @@ -0,0 +1,22 @@ +Class { + #name : #TRPPCRegister, + #superclass : #TRRealRegister, + #pools : [ + 'TRPPC64RegisterKinds' + ], + #category : #'Tinyrossa-POWER-Codegen' +} + +{ #category : #accessing } +TRPPCRegister >> name [ + kind == GPR ifTrue: [ + ^ 'gr', value name + ]. + kind == FPR ifTrue: [ + ^ 'fp', value name + ]. + kind == CCR ifTrue: [ + ^ 'cr', value name + ]. + ^ super name +] From 84b25194f075dca7fb909ceee754c1b7016b6194 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 17:19:58 +0100 Subject: [PATCH 04/10] Implement `TRCompilationTestShell >> #call` and `#call:` This commit implements `#call` and `#call:` to reduce code duplication in tests. These methods care for injecting the code, setting up parameters (in registers) and extracting return value (from return register). All this is done in target and linkage neutral way, though some extra support in linkages is needed. In order to do that, shell objects now hold on whole compilation rather than just the target. --- .../TRPPC64PSABILinkage.extension.st | 21 +++++ .../TRPPCRegister.extension.st | 19 +++++ .../TRRV64GPSABILinkage.extension.st | 21 +++++ .../TRCompilationTestCase.class.st | 2 +- .../TRCompilationTestShell.class.st | 79 +++++++++++++++++-- .../TRCompilationTestShellGem5.class.st | 6 +- .../TRCompilationTestShellQEMU.class.st | 2 +- src/Tinyrossa-Tests/TRLinkage.extension.st | 21 +++++ .../TRRealRegister.extension.st | 11 +++ 9 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 src/Tinyrossa-Tests-POWER/TRPPC64PSABILinkage.extension.st create mode 100644 src/Tinyrossa-Tests-POWER/TRPPCRegister.extension.st create mode 100644 src/Tinyrossa-Tests-RISCV/TRRV64GPSABILinkage.extension.st create mode 100644 src/Tinyrossa-Tests/TRLinkage.extension.st create mode 100644 src/Tinyrossa-Tests/TRRealRegister.extension.st diff --git a/src/Tinyrossa-Tests-POWER/TRPPC64PSABILinkage.extension.st b/src/Tinyrossa-Tests-POWER/TRPPC64PSABILinkage.extension.st new file mode 100644 index 0000000..0a8e906 --- /dev/null +++ b/src/Tinyrossa-Tests-POWER/TRPPC64PSABILinkage.extension.st @@ -0,0 +1,21 @@ +Extension { #name : #TRPPC64PSABILinkage } + +{ #category : #'*Tinyrossa-Tests-POWER' } +TRPPC64PSABILinkage >> parameterRegisters: kind [ + "Return (ordered) list of parameter registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ self parameterRegisters select: [:r | r kind = kind ] +] + +{ #category : #'*Tinyrossa-Tests-POWER' } +TRPPC64PSABILinkage >> returnRegisters: kind [ + "Return (ordered) list of return registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ { gr4 } select: [:r | r kind = kind ] +] diff --git a/src/Tinyrossa-Tests-POWER/TRPPCRegister.extension.st b/src/Tinyrossa-Tests-POWER/TRPPCRegister.extension.st new file mode 100644 index 0000000..7ebe8d6 --- /dev/null +++ b/src/Tinyrossa-Tests-POWER/TRPPCRegister.extension.st @@ -0,0 +1,19 @@ +Extension { #name : #TRPPCRegister } + +{ #category : #'*Tinyrossa-Tests-POWER' } +TRPPCRegister >> nameInGDB [ + kind == GPR ifTrue: [ + "See https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=gdb/features/rs6000/power-core.xml;hb=HEAD" + ^ 'r' , value name + ]. + kind == FPR ifTrue: [ + "See https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=gdb/features/rs6000/power-fpu.xml;hb=HEAD" + ^ 'f' , value name + ]. + kind == CCR ifTrue: [ + "See https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=gdb/features/rs6000/power-core.xml;hb=HEAD + and https://github.com/janvrany/Pharo-ArchC-PDL/blob/master/powerpc/powerpc_isa.ac" + ^ value name + ]. + ^ super nameInGDB +] diff --git a/src/Tinyrossa-Tests-RISCV/TRRV64GPSABILinkage.extension.st b/src/Tinyrossa-Tests-RISCV/TRRV64GPSABILinkage.extension.st new file mode 100644 index 0000000..cc25668 --- /dev/null +++ b/src/Tinyrossa-Tests-RISCV/TRRV64GPSABILinkage.extension.st @@ -0,0 +1,21 @@ +Extension { #name : #TRRV64GPSABILinkage } + +{ #category : #'*Tinyrossa-Tests-RISCV' } +TRRV64GPSABILinkage >> parameterRegisters: kind [ + "Return (ordered) list of parameter registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ self parameterRegisters select: [:r | r kind = kind ] +] + +{ #category : #'*Tinyrossa-Tests-RISCV' } +TRRV64GPSABILinkage >> returnRegisters: kind [ + "Return (ordered) list of return registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ { a0 . a1 } select: [:r | r kind = kind ] +] diff --git a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st index 422ec90..56f1726 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st @@ -27,7 +27,7 @@ TRCompilationTestCase class >> isAbstract [ { #category : #running } TRCompilationTestCase >> setUpForTarget: aTRCompilationTarget [ compilation := TRCompilation forTarget: aTRCompilationTarget. - shell := TRCompilationTestShell forTarget: aTRCompilationTarget. + shell := TRCompilationTestShell forCompilation: compilation. ] { #category : #running } diff --git a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st index b55e5a9..0d00ecc 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShell.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShell.class.st @@ -2,13 +2,16 @@ Class { #name : #TRCompilationTestShell, #superclass : #TestAsserter, #instVars : [ - 'target', + 'compilation', 'binary', 'debugger' ], #classVars : [ 'DefaultImpl' ], + #pools : [ + 'TRRegisterKinds' + ], #category : #'Tinyrossa-Tests-Shells-SmalltalkX' } @@ -27,11 +30,11 @@ TRCompilationTestShell class >> defaultImpl: aClass [ ] { #category : #'instance creation' } -TRCompilationTestShell class >> forTarget: aTRCompilationTarget [ +TRCompilationTestShell class >> forCompilation: aTRCompilation [ self == TRCompilationTestShell ifTrue: [ - ^ self defaultImpl forTarget: aTRCompilationTarget + ^ self defaultImpl forCompilation: aTRCompilation ] ifFalse: [ - ^ self new initializeWithTarget: aTRCompilationTarget + ^ self new initializeWithCompilation: aTRCompilation ]. ] @@ -73,6 +76,66 @@ TRCompilationTestShell class >> shellDirectory [ " ] +{ #category : #utilities } +TRCompilationTestShell >> call [ + ^ self callWithArguments: #() +] + +{ #category : #utilities } +TRCompilationTestShell >> call: arg1 [ + ^ self callWithArguments: { arg1 } +] + +{ #category : #utilities } +TRCompilationTestShell >> call: arg1 _:arg2 [ + ^ self callWithArguments: { arg1 . arg2 } +] + +{ #category : #'utilities-private' } +TRCompilationTestShell >> callWithArguments: values [ + | params | + + "Inject compiled code into shell" + debugger memoryAt: self nzone put: compilation codeBuffer bytes. + + "Prepare parameters" + params := (compilation symbolManager lookupSymbolsByType: TRParameterSymbol) sorted: [ :a :b | a index < b index ]. + self assert: values size == params size description: 'Number of formal paramerers does not match actual'. + 1 to: values size do: [:i | + | param value | + + param := params at: i. + value := values at: i. + + param type validateConstant: value. + + param type isIntegerType ifTrue: [ + | argReg | + + argReg := (compilation codegen linkage parameterRegisters: GPR) at: i. + debugger setRegister: argReg nameInGDB to: value. + ] ifFalse: [ + self error: 'Parameter type not supported yet: ' , param type name + ]. + ]. + + "Call injected function" + " + VDBDebuggerApplication openFor: debugger + " + debugger c. + + "Retrieve return value" + compilation functionSymbol type isIntegerType ifTrue: [ + | retReg | + + retReg := (compilation codegen linkage returnRegisters: GPR) at: 1. + ^ debugger getRegister: retReg nameInGDB + ] ifFalse: [ + self error: 'Return type not supported yet: ' , compilation functionSymbol type name + ]. +] + { #category : #accessing } TRCompilationTestShell >> debugger [ self assert: debugger notNil. @@ -80,8 +143,8 @@ TRCompilationTestShell >> debugger [ ] { #category : #initialization } -TRCompilationTestShell >> initializeWithTarget: aTRCompilationTarget [ - target := aTRCompilationTarget. +TRCompilationTestShell >> initializeWithCompilation: aTRCompilation [ + compilation := aTRCompilation. self setUp; reset. ] @@ -101,10 +164,10 @@ TRCompilationTestShell >> reset [ TRCompilationTestShell >> setUp [ | shellDir | - shellDir := self class shellDirectory. + shellDir := self class shellDirectory. self assert: shellDir notNil description:'Could not determine directory with test shells!'. - binary := shellDir / ('shell-' , (target name readStream upTo: $-)). + binary := shellDir / ('shell-' , (compilation config target name readStream upTo: $-)). self assert: binary isExecutable. ] diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st index f8a0607..d71d41f 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellGem5.class.st @@ -37,13 +37,13 @@ TRCompilationTestShellGem5 >> setUp [ gem5exe := gem5dir asFileReference / 'build' / 'ALL' / 'gem5.debug'. ]. gem5exe exists ifFalse: [ - gem5exe := gem5dir asFileReference / 'build' / target gem5 / 'gem5.opt'. + gem5exe := gem5dir asFileReference / 'build' / compilation config target gem5 / 'gem5.opt'. ]. gem5exe exists ifFalse: [ - gem5exe := gem5dir asFileReference / 'build' / target gem5 / 'gem5.opt'. + gem5exe := gem5dir asFileReference / 'build' / compilation config target gem5 / 'gem5.opt'. ]. - self assert: gem5exe exists description: 'No gem5.debug nor gem5.opt found in GEM5_DIR/build/ALL nor GEM5_DIR/build/',target gem5. + self assert: gem5exe exists description: 'No gem5.debug nor gem5.opt found in GEM5_DIR/build/ALL nor GEM5_DIR/build/',compilation config target gem5. gem5cmd := '<1s> --listener-mode on "--debug-flags=Decode" <2s>/shell-gem5.py -c <3s> --wait-gdb --param ''system.shared_backstore = "/gem5"''' expandMacrosWith: gem5exe pathString with: shellDir pathString with: binary pathString. diff --git a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st index 9af8f91..18f8050 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestShellQEMU.class.st @@ -13,7 +13,7 @@ TRCompilationTestShellQEMU >> setUp [ super setUp. - qemuCmd := target qemu, ' -g 1234 ', binary pathString. + qemuCmd := compilation config target qemu, ' -g 1234 ', binary pathString. "First, start QEMU... " qemu := OSProcess new command: qemuCmd. diff --git a/src/Tinyrossa-Tests/TRLinkage.extension.st b/src/Tinyrossa-Tests/TRLinkage.extension.st new file mode 100644 index 0000000..1ae6248 --- /dev/null +++ b/src/Tinyrossa-Tests/TRLinkage.extension.st @@ -0,0 +1,21 @@ +Extension { #name : #TRLinkage } + +{ #category : #'*Tinyrossa-Tests' } +TRLinkage >> parameterRegisters: kind [ + "Return (ordered) list of parameter registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ self subclassResponsibility +] + +{ #category : #'*Tinyrossa-Tests' } +TRLinkage >> returnRegisters: kind [ + "Return (ordered) list of return registers of given kind. + + Note, that this method is used by tests only, compiler + does not use it." + + ^ self subclassResponsibility +] diff --git a/src/Tinyrossa-Tests/TRRealRegister.extension.st b/src/Tinyrossa-Tests/TRRealRegister.extension.st new file mode 100644 index 0000000..0fffc4f --- /dev/null +++ b/src/Tinyrossa-Tests/TRRealRegister.extension.st @@ -0,0 +1,11 @@ +Extension { #name : #TRRealRegister } + +{ #category : #'*Tinyrossa-Tests' } +TRRealRegister >> nameInGDB [ + "Return name of the register as used by GDB. + + To be overriden in custom subclasses for some architectures + where register names used by Tinyrossa and/or ArchC differ (POWER)." + + ^ value name +] From 038843036af961a4c9a42443d64afd57ed754d43 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Fri, 2 Feb 2024 14:38:55 +0000 Subject: [PATCH 05/10] Add support for parametrized tests to dependencies --- pharo/GNUmakefile | 2 ++ src/BaselineOfTinyrossa/BaselineOfTinyrossa.class.st | 7 ++++++- src/Tinyrossa-Tests/ManifestTinyrossaTests.class.st | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pharo/GNUmakefile b/pharo/GNUmakefile index c46634c..6e21259 100644 --- a/pharo/GNUmakefile +++ b/pharo/GNUmakefile @@ -76,6 +76,8 @@ $(PROJECT).image: ../src/*/*.st $(call pharo-load-local, $@, SmallRSP, $(SMALLRSP_DIR)/src) $(call pharo-load-local, $@, LibUnix, $(PHARO_HACKS_DIR)/src) $(call pharo-load-local, $@, LibCompat, $(PHARO_HACKS_DIR)/src) + $(call pharo-load-local, $@, LibCompat, $(PHARO_HACKS_DIR)/src) + $(call pharo-load-local, $@, SUnitParametrized,$(PHARO_HACKS_DIR)/src) $(call pharo-load-local, $@, PTerm, $(PTERM_DIR)) $(call pharo-load-local, $@, LibGDBs, $(LIBGDBS_DIR)/ports/pharo/src-generated) $(call pharo-load-local, $@, Tinyrossa, ../src) diff --git a/src/BaselineOfTinyrossa/BaselineOfTinyrossa.class.st b/src/BaselineOfTinyrossa/BaselineOfTinyrossa.class.st index abc1536..97e0045 100644 --- a/src/BaselineOfTinyrossa/BaselineOfTinyrossa.class.st +++ b/src/BaselineOfTinyrossa/BaselineOfTinyrossa.class.st @@ -25,7 +25,11 @@ BaselineOfTinyrossa >> baseline: spec [ spec baseline: 'LibUnix' with: [ spec repository: 'github://janvrany/pharo-hacks'. ]. - + + spec baseline: 'SUnitParametrized' with: [ + spec repository: 'github://janvrany/pharo-hacks'. + ]. + spec baseline: 'Roassal3' with: [ spec repository: 'github://ObjectProfile/Roassal3:v0.9.2' ]. @@ -38,6 +42,7 @@ BaselineOfTinyrossa >> baseline: spec [ spec requires: 'ArchC' ]; package: #'Tinyrossa-Tests' with: [ + spec requires: 'SUnitParametrized'. spec requires: 'SmallRSP'. ]; package: #'Tinyrossa-RISCV' with: [ diff --git a/src/Tinyrossa-Tests/ManifestTinyrossaTests.class.st b/src/Tinyrossa-Tests/ManifestTinyrossaTests.class.st index 97d3556..63d4f3c 100644 --- a/src/Tinyrossa-Tests/ManifestTinyrossaTests.class.st +++ b/src/Tinyrossa-Tests/ManifestTinyrossaTests.class.st @@ -17,6 +17,7 @@ ManifestTinyrossaTests class >> mandatoryPreRequisites [ ^ #( #Tinyrossa "TRCompilationExamples - superclass of TRCompilationExamplesTests" #'stx:goodies/sunit' "TestAsserter - superclass of TRCompilationExamplesTests" + #'stx:goodies/sunit/ext/parametrized' #'stx:libbasic' "Object - superclass of ManifestTinyrossaTests" #'stx:libcompat' "PackageManifest - superclass of ManifestTinyrossaTests" ) From a9d484e211934de746b7fc851084d8b276ac5ac4 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 14:55:53 +0100 Subject: [PATCH 06/10] Convert compilation tests to parameterized tests This commit turns `TRCompilationTestCase` to parametrized testcase without changing tests themselves. --- .../TRPPC64CompilationTests.class.st | 6 +++--- .../TRRV64GCompilationTests.class.st | 6 +++--- .../TRCompilationTestCase.class.st | 21 ++++++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st index a84ec63..7bc0c13 100644 --- a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st +++ b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st @@ -4,9 +4,9 @@ Class { #category : #'Tinyrossa-Tests-POWER' } -{ #category : #running } -TRPPC64CompilationTests >> setUp [ - self setUpForTarget: TRPPC64Linux default +{ #category : #accessing } +TRPPC64CompilationTests >> target [ + ^ TRPPC64Linux default ] { #category : #tests } diff --git a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st index fe9f53a..dda05ca 100644 --- a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st +++ b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st @@ -4,9 +4,9 @@ Class { #category : #'Tinyrossa-Tests-RISCV' } -{ #category : #running } -TRRV64GCompilationTests >> setUp [ - self setUpForTarget: TRRV64GLinux default +{ #category : #accessing } +TRRV64GCompilationTests >> target [ + ^ TRRV64GLinux default ] { #category : #tests } diff --git a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st index 56f1726..3e5ccc3 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st @@ -1,6 +1,6 @@ Class { #name : #TRCompilationTestCase, - #superclass : #TestCase, + #superclass : #TestCaseParametrized, #instVars : [ 'compilation', 'shell' @@ -24,12 +24,27 @@ TRCompilationTestCase class >> isAbstract [ ^ self == TRCompilationTestCase ] +{ #category : #accessing } +TRCompilationTestCase >> parametersIterator [ + ^ super parametersIterator , + (self parameter: #target values: { self target }) +] + { #category : #running } -TRCompilationTestCase >> setUpForTarget: aTRCompilationTarget [ - compilation := TRCompilation forTarget: aTRCompilationTarget. +TRCompilationTestCase >> setUp [ + | target | + + target := testParameters at:#target. + + compilation := TRCompilation forTarget: target. shell := TRCompilationTestShell forCompilation: compilation. ] +{ #category : #accessing } +TRCompilationTestCase >> target [ + ^ self subclassResponsibility +] + { #category : #running } TRCompilationTestCase >> tearDown [ super tearDown. From fd45f5d70f6ffd0fd59fd2e80cc06b9f25838de5 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 17:32:03 +0100 Subject: [PATCH 07/10] RISC-V: update RISC-V tests to use new `#call`,`#call:` and `#call:_:` This commit update RISC-V compilation tests to use new shell helper methods introduced in previous commit. --- .../TRRV64GCompilationTests.class.st | 130 ++---------------- 1 file changed, 13 insertions(+), 117 deletions(-) diff --git a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st index dda05ca..6e52c30 100644 --- a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st +++ b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st @@ -11,205 +11,101 @@ TRRV64GCompilationTests >> target [ { #category : #tests } TRRV64GCompilationTests >> test01_bytecode_abs [ - | debugger | - super test01_bytecode_abs. - " - VDBDebuggerAp - " - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 2. - - " - VDBDebuggerApplication openFor: debugger - " - - debugger c. - self assert: (debugger getRegister: 'a0') equals: 2 abs. + self assert: (shell call: 2) equals: 2 abs. ] { #category : #tests } TRRV64GCompilationTests >> test02_iconst_n [ - | debugger | - super test02_iconst_n. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'a0') equals: -16r7FEDCBA9. + self assert: (shell call) equals: -16r7FEDCBA9. ] { #category : #tests } TRRV64GCompilationTests >> test02_iconst_p [ - | debugger | - super test02_iconst_p. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'a0') equals: 16r7FEDCBA9. + self assert: (shell call) equals: 16r7FEDCBA9. ] { #category : #tests } TRRV64GCompilationTests >> test03_lconst_n [ - | debugger | - super test03_lconst_n. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'a0') equals: -16r7AFEAFFECAFEAFFE. + self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. ] { #category : #tests } TRRV64GCompilationTests >> test03_lconst_p [ - | debugger | - super test03_lconst_p. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'a0') equals: 16r7AFEAFFECAFEAFFE. + self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example01_meaningOfLife [ - | debugger | - TRCompilationExamples new compilation: compilation; example01_meaningOfLife. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger c. - self assert: (debugger getRegister: 'a0') equals: 42. + self assert: (shell call) equals: 42. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example03_signum [ - | debugger | - TRCompilationExamples new compilation: compilation; example03_signum. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: -5. - debugger c. - self assert: (debugger getRegister: 'a0') equals: -1. + self assert: (shell call:-5) equals: -5 sign. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example04_factorial_i [ - | debugger | - TRCompilationExamples new compilation: compilation; example04_factorial_i. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 5. - debugger c. - self assert: (debugger getRegister: 'a0') equals: 5 factorial. + self assert: (shell call:5) equals: 5 factorial. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example05_factorial_r [ - | debugger | - TRCompilationExamples new compilation: compilation; example05_factorial_r. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 5. - debugger c. - self assert: (debugger getRegister: 'a0') equals: 5 factorial. + self assert: (shell call:5) equals: 5 factorial. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example08_bytecode_compiler [ - | debugger | - TRCompilationExamples new compilation: compilation; example08_bytecode_compiler. - " - VDBDebuggerAp - " - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 2. - - " - VDBDebuggerApplication openFor: debugger - " - - debugger c. - self assert: (debugger getRegister: 'a0') equals: 2 factorial. + self assert: (shell call:2) equals: 2 factorial. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example09_signum_2 [ - | debugger | - TRCompilationExamples new compilation: compilation; example09_signum_2. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: -5. - debugger c. - self assert: (debugger getRegister: 'a0') equals: -1. + self assert: (shell call:-1) equals: -1 sign. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example15_add_with_overflow_check [ - | debugger | - TRCompilationExamples new compilation: compilation; example15_add_with_overflow_check. - - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 16r7FFFFFFE. - debugger setRegister: 'a1' to: 2. - debugger c. - self assert: (debugger getRegister: 'a0') equals: 0. + self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. ] { #category : #'tests - examples' } TRRV64GCompilationTests >> test_example16_factorial_i_with_overflow [ - | debugger | - TRCompilationExamples new compilation: compilation; example16_factorial_i_with_overflow. - - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'a0' to: 13. - debugger c. - self assert: (debugger getRegister: 'a0') equals: -1. + self assert: (shell call:13)equals: -1. " From 1ee5b1452f257232bd7f3dcfb3cef836d2fd34b7 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 20 May 2024 23:01:34 +0100 Subject: [PATCH 08/10] POWER: update POWER tests to use new `#call`,`#call:` and `#call:_:` This commit update POWER compilation tests to use new shell helper methods introduced in previous commit. --- .../TRPPC64CompilationTests.class.st | 133 +++--------------- 1 file changed, 17 insertions(+), 116 deletions(-) diff --git a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st index 7bc0c13..c89ae85 100644 --- a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st +++ b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st @@ -11,202 +11,103 @@ TRPPC64CompilationTests >> target [ { #category : #tests } TRPPC64CompilationTests >> test01_bytecode_abs [ - | debugger | - super test01_bytecode_abs. - " - VDBDebuggerAp - " - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: -12. - - " - VDBDebuggerApplication openFor: debugger - " - - debugger c. - self assert: (debugger getRegister: 'r4') equals: -12 abs. + self assert: (shell call: 2) equals: 2 abs. ] { #category : #tests } TRPPC64CompilationTests >> test02_iconst_n [ - | debugger | - super test02_iconst_n. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'r4') equals: -16r7FEDCBA9. + self assert: (shell call) equals: -16r7FEDCBA9. ] { #category : #tests } TRPPC64CompilationTests >> test02_iconst_p [ - | debugger | - super test02_iconst_p. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'r4') equals: 16r7FEDCBA9. + self assert: (shell call) equals: 16r7FEDCBA9. ] { #category : #tests } TRPPC64CompilationTests >> test03_lconst_n [ - | debugger | - - self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER'. + self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. super test03_lconst_n. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'r4') hex equals: '-7AFEAFFECAFEAFFE'. + self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. ] { #category : #tests } TRPPC64CompilationTests >> test03_lconst_p [ - | debugger | - - self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER'. + self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. super test03_lconst_p. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - " - VDBDebuggerApplication openFor: debugger - " - debugger c. - self assert: (debugger getRegister: 'r4') equals: 16r7AFEAFFECAFEAFFE. + self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example01_meaningOfLife [ - | debugger | - TRCompilationExamples new compilation: compilation; example01_meaningOfLife. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger c. - self assert: (debugger getRegister: 'r4') equals: 42. + self assert: (shell call) equals: 42. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example03_signum [ - | debugger | - TRCompilationExamples new compilation: compilation; - example03_signum. + example03_signum. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 0. - debugger c. - self assert: (debugger getRegister: 'r4') equals: 0. + self assert: (shell call:-5) equals: -5 sign. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example04_factorial_i [ - | debugger | - TRCompilationExamples new compilation: compilation; example04_factorial_i. - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 5. - debugger c. - self assert: (debugger getRegister: 'r4') equals: 5 factorial. + self assert: (shell call:5) equals: 5 factorial. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example08_bytecode_compiler [ - | debugger | - TRCompilationExamples new compilation: compilation; example08_bytecode_compiler. - " - VDBDebuggerAp - " - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 6. - - " - VDBDebuggerApplication openFor: debugger - " - - debugger c. - self assert: (debugger getRegister: 'r4') equals: 6 factorial. + self assert: (shell call:6) equals: 6 factorial. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example09_signum_2 [ - | debugger | - TRCompilationExamples new compilation: compilation; example09_signum_2. - - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 0. - debugger c. - self assert: (debugger getRegister: 'r4') equals: 0. + self assert: (shell call:0) equals: 0 sign ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example15_add_with_overflow_check [ - | debugger | - (TRPPC64CodeEvaluator methodDictionary at: #evaluate_overflowchk: ifAbsent:[nil]) isNil ifTrue: [ - self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER' + self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER (see issue #44)' ]. TRCompilationExamples new compilation: compilation; example15_add_with_overflow_check. - - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 0x7FFFFFFE. - debugger setRegister: 'r5' to: 2. - debugger c. - self assert: (debugger getRegister: 'gr4') equals: 0. + self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. ] { #category : #'tests - examples' } TRPPC64CompilationTests >> test_example16_factorial_i_with_overflow [ - | debugger | - (TRPPC64CodeEvaluator methodDictionary at: #evaluate_overflowchk: ifAbsent:[nil]) isNil ifTrue: [ - self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER' + self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER (see issue #44)' ]. TRCompilationExamples new compilation: compilation; example16_factorial_i_with_overflow. - - debugger := shell debugger. - debugger memoryAt: shell nzone put: compilation codeBuffer bytes. - debugger setRegister: 'r4' to: 13. - debugger c. - self assert: (debugger getRegister: 'r4') equals: -1. + self assert: (shell call: 13) equals: -1. " From 2546bd204ee8521c091aa4d9eb8efad26616cda2 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Tue, 21 May 2024 15:59:51 +0100 Subject: [PATCH 09/10] RISC-V, POWER: move all tests up to TRCompilationTestCase ...to reduce code duplication. Tests that do now work on all targets are selectively skipped. This has the nice side-effect of documenting what's missing in particular for particular architectures. --- .../TRPPC64CompilationTests.class.st | 107 ----------------- .../TRRV64GCompilationTests.class.st | 105 ---------------- .../TRCompilationTestCase.class.st | 112 ++++++++++++++++-- 3 files changed, 105 insertions(+), 219 deletions(-) diff --git a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st index c89ae85..6be5384 100644 --- a/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st +++ b/src/Tinyrossa-Tests-POWER/TRPPC64CompilationTests.class.st @@ -8,110 +8,3 @@ Class { TRPPC64CompilationTests >> target [ ^ TRPPC64Linux default ] - -{ #category : #tests } -TRPPC64CompilationTests >> test01_bytecode_abs [ - super test01_bytecode_abs. - self assert: (shell call: 2) equals: 2 abs. -] - -{ #category : #tests } -TRPPC64CompilationTests >> test02_iconst_n [ - super test02_iconst_n. - self assert: (shell call) equals: -16r7FEDCBA9. -] - -{ #category : #tests } -TRPPC64CompilationTests >> test02_iconst_p [ - super test02_iconst_p. - self assert: (shell call) equals: 16r7FEDCBA9. -] - -{ #category : #tests } -TRPPC64CompilationTests >> test03_lconst_n [ - self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. - - super test03_lconst_n. - self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. -] - -{ #category : #tests } -TRPPC64CompilationTests >> test03_lconst_p [ - self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. - - super test03_lconst_p. - self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example01_meaningOfLife [ - TRCompilationExamples new - compilation: compilation; - example01_meaningOfLife. - - self assert: (shell call) equals: 42. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example03_signum [ - TRCompilationExamples new - compilation: compilation; - example03_signum. - - self assert: (shell call:-5) equals: -5 sign. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example04_factorial_i [ - TRCompilationExamples new - compilation: compilation; - example04_factorial_i. - - self assert: (shell call:5) equals: 5 factorial. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example08_bytecode_compiler [ - TRCompilationExamples new - compilation: compilation; - example08_bytecode_compiler. - self assert: (shell call:6) equals: 6 factorial. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example09_signum_2 [ - TRCompilationExamples new - compilation: compilation; - example09_signum_2. - self assert: (shell call:0) equals: 0 sign -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example15_add_with_overflow_check [ - (TRPPC64CodeEvaluator methodDictionary at: #evaluate_overflowchk: ifAbsent:[nil]) isNil ifTrue: [ - self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER (see issue #44)' - ]. - - TRCompilationExamples new - compilation: compilation; - example15_add_with_overflow_check. - self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. -] - -{ #category : #'tests - examples' } -TRPPC64CompilationTests >> test_example16_factorial_i_with_overflow [ - (TRPPC64CodeEvaluator methodDictionary at: #evaluate_overflowchk: ifAbsent:[nil]) isNil ifTrue: [ - self skip: 'Skipped since #evaluate_overflowchk: is not implemented for POWER (see issue #44)' - ]. - - TRCompilationExamples new - compilation: compilation; - example16_factorial_i_with_overflow. - self assert: (shell call: 13) equals: -1. - - - " - 13 factorial > 0x7FFFFFFF - 22 factorial > 0x7FFFFFFFFFFFFFFF - " -] diff --git a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st index 6e52c30..020914c 100644 --- a/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st +++ b/src/Tinyrossa-Tests-RISCV/TRRV64GCompilationTests.class.st @@ -8,108 +8,3 @@ Class { TRRV64GCompilationTests >> target [ ^ TRRV64GLinux default ] - -{ #category : #tests } -TRRV64GCompilationTests >> test01_bytecode_abs [ - super test01_bytecode_abs. - self assert: (shell call: 2) equals: 2 abs. -] - -{ #category : #tests } -TRRV64GCompilationTests >> test02_iconst_n [ - super test02_iconst_n. - self assert: (shell call) equals: -16r7FEDCBA9. -] - -{ #category : #tests } -TRRV64GCompilationTests >> test02_iconst_p [ - super test02_iconst_p. - self assert: (shell call) equals: 16r7FEDCBA9. -] - -{ #category : #tests } -TRRV64GCompilationTests >> test03_lconst_n [ - super test03_lconst_n. - self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. -] - -{ #category : #tests } -TRRV64GCompilationTests >> test03_lconst_p [ - super test03_lconst_p. - self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example01_meaningOfLife [ - TRCompilationExamples new - compilation: compilation; - example01_meaningOfLife. - - self assert: (shell call) equals: 42. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example03_signum [ - TRCompilationExamples new - compilation: compilation; - example03_signum. - - self assert: (shell call:-5) equals: -5 sign. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example04_factorial_i [ - TRCompilationExamples new - compilation: compilation; - example04_factorial_i. - - self assert: (shell call:5) equals: 5 factorial. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example05_factorial_r [ - TRCompilationExamples new - compilation: compilation; - example05_factorial_r. - - self assert: (shell call:5) equals: 5 factorial. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example08_bytecode_compiler [ - TRCompilationExamples new - compilation: compilation; - example08_bytecode_compiler. - self assert: (shell call:2) equals: 2 factorial. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example09_signum_2 [ - TRCompilationExamples new - compilation: compilation; - example09_signum_2. - - self assert: (shell call:-1) equals: -1 sign. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example15_add_with_overflow_check [ - TRCompilationExamples new - compilation: compilation; - example15_add_with_overflow_check. - self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. -] - -{ #category : #'tests - examples' } -TRRV64GCompilationTests >> test_example16_factorial_i_with_overflow [ - TRCompilationExamples new - compilation: compilation; - example16_factorial_i_with_overflow. - self assert: (shell call:13)equals: -1. - - - " - 13 factorial > 0x7FFFFFFF - 22 factorial > 0x7FFFFFFFFFFFFFFF - " -] diff --git a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st index 3e5ccc3..00984b8 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st @@ -168,7 +168,7 @@ TRCompilationTestCase >> test01_bytecode_abs [ compilation compile. - compilation codeBuffer. "Only convenience inspection." + self assert: (shell call: 2) equals: 2 abs. ] { #category : #tests } @@ -182,7 +182,8 @@ TRCompilationTestCase >> test02_iconst_n [ }. compilation optimize. compilation compile. - compilation codeBuffer. + + self assert: (shell call) equals: -16r7FEDCBA9. " TRRV64GCompilationTests debug: #test02_iconst_p @@ -200,7 +201,8 @@ TRCompilationTestCase >> test02_iconst_p [ }. compilation optimize. compilation compile. - compilation codeBuffer. + + self assert: (shell call) equals: 16r7FEDCBA9. " TRRV64GCompilationTests debug: #test02_iconst_p @@ -211,16 +213,19 @@ TRCompilationTestCase >> test02_iconst_p [ TRCompilationTestCase >> test03_lconst_n [ | builder | + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. + ]. + builder := compilation builder. builder defineName: testSelector type: Int64. builder lreturn: { builder lconst: -16r7AFEAFFECAFEAFFE }. compilation optimize. - compilation compile. - compilation codeBuffer. + self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. " TRRV64GCompilationTests debug: #test03_lconst_n @@ -232,19 +237,112 @@ TRCompilationTestCase >> test03_lconst_n [ TRCompilationTestCase >> test03_lconst_p [ | builder | + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. + ]. + builder := compilation builder. builder defineName: testSelector type: Int64. builder lreturn: { builder lconst: 16r7AFEAFFECAFEAFFE }. compilation optimize. - compilation compile. - compilation codeBuffer. + self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. " TRRV64GCompilationTests debug: #test03_lconst_p TRPPC64CompilationTests debug: #test03_lconst_p " ] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example01_meaningOfLife [ + TRCompilationExamples new + compilation: compilation; + example01_meaningOfLife. + + self assert: (shell call) equals: 42. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example03_signum [ + TRCompilationExamples new + compilation: compilation; + example03_signum. + + self assert: (shell call:-5) equals: -5 sign. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example04_factorial_i [ + TRCompilationExamples new + compilation: compilation; + example04_factorial_i. + + self assert: (shell call:5) equals: 5 factorial. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example05_factorial_r [ + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Skipped since calls are not implemented for POWER (see issue #45)'. + ]. + TRCompilationExamples new + compilation: compilation; + example05_factorial_r. + + self assert: (shell call:5) equals: 5 factorial. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example08_bytecode_compiler [ + TRCompilationExamples new + compilation: compilation; + example08_bytecode_compiler. + self assert: (shell call:2) equals: 2 factorial. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example09_signum_2 [ + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Known failure (see issue #46)'. + ]. + + TRCompilationExamples new + compilation: compilation; + example09_signum_2. + + self assert: (shell call:-1) equals: -1 sign. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example15_add_with_overflow_check [ + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Skipped since overflowchk evaluator is not implemented for POWER (see issue #44)'. + ]. + + TRCompilationExamples new + compilation: compilation; + example15_add_with_overflow_check. + self assert: (shell call: 16r7FFFFFFE _: 2 ) equals: 0. +] + +{ #category : #'tests - examples' } +TRCompilationTestCase >> test_example16_factorial_i_with_overflow [ + self target name = 'powerpc64le-linux' ifTrue: [ + self skip: 'Skipped since overflowchk evaluator is not implemented for POWER (see issue #44)'. + ]. + + TRCompilationExamples new + compilation: compilation; + example16_factorial_i_with_overflow. + self assert: (shell call:13)equals: -1. + + + " + 13 factorial > 0x7FFFFFFF + 22 factorial > 0x7FFFFFFFFFFFFFFF + " +] From 8c2352743cb991634f789c7db419032661896266 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Tue, 21 May 2024 17:07:02 +0100 Subject: [PATCH 10/10] Parametrize `test_iconst` and `test_lconst` --- .../TRCompilationTestCase.class.st | 93 +++++++++---------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st index 00984b8..e6aaa3f 100644 --- a/src/Tinyrossa-Tests/TRCompilationTestCase.class.st +++ b/src/Tinyrossa-Tests/TRCompilationTestCase.class.st @@ -24,6 +24,36 @@ TRCompilationTestCase class >> isAbstract [ ^ self == TRCompilationTestCase ] +{ #category : #'accessing - parameters' } +TRCompilationTestCase >> int32Values [ + ^ { -16r80000000 . + -16r7FEDCBA9 . + -16rCBA9 . + -16rA9 . + -1 . + 0 . + 16rA9 . + 16rCBA9 . + 16r7FEDCBA9 . + 16r7FFFFFFF } +] + +{ #category : #'accessing - parameters' } +TRCompilationTestCase >> int64Values [ + ^ { -16r8000000000000000 . + -16r7AFEAFFECAFEAFFE . + -16r7FEDCBA9 . + -16rCBA9 . + -16rA9 . + -1 . + 0 . + 16rA9 . + 16rCBA9 . + 16r7FEDCBA9 . + 16r7AFEAFFECAFEAFFE . + 16r7FFFFFFFFFFFFFFF } +] + { #category : #accessing } TRCompilationTestCase >> parametersIterator [ ^ super parametersIterator , @@ -172,37 +202,21 @@ TRCompilationTestCase >> test01_bytecode_abs [ ] { #category : #tests } -TRCompilationTestCase >> test02_iconst_n [ - | builder | +TRCompilationTestCase >> test02_iconst [ + - builder := compilation builder. - builder defineName: testSelector type: Int32. - builder ireturn: { - builder iconst: -16r7FEDCBA9 - }. - compilation optimize. - compilation compile. - - self assert: (shell call) equals: -16r7FEDCBA9. - - " - TRRV64GCompilationTests debug: #test02_iconst_p - TRPPC64CompilationTests debug: #test02_iconst_p" -] - -{ #category : #tests } -TRCompilationTestCase >> test02_iconst_p [ - | builder | + | x builder | + x := testParameters at: #x. builder := compilation builder. builder defineName: testSelector type: Int32. builder ireturn: { - builder iconst: 16r7FEDCBA9 + builder iconst: x }. compilation optimize. compilation compile. - self assert: (shell call) equals: 16r7FEDCBA9. + self assert: (shell call) equals: x. " TRRV64GCompilationTests debug: #test02_iconst_p @@ -210,22 +224,25 @@ TRCompilationTestCase >> test02_iconst_p [ ] { #category : #tests } -TRCompilationTestCase >> test03_lconst_n [ - | builder | +TRCompilationTestCase >> test03_lconst [ + + + | x builder | self target name = 'powerpc64le-linux' ifTrue: [ self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. ]. + x := testParameters at: #x. builder := compilation builder. builder defineName: testSelector type: Int64. builder lreturn: - { builder lconst: -16r7AFEAFFECAFEAFFE }. + { builder lconst: x }. compilation optimize. compilation compile. - self assert: (shell call) equals: -16r7AFEAFFECAFEAFFE. + self assert: (shell call) equals: x. " TRRV64GCompilationTests debug: #test03_lconst_n @@ -233,30 +250,6 @@ TRCompilationTestCase >> test03_lconst_n [ " ] -{ #category : #tests } -TRCompilationTestCase >> test03_lconst_p [ - | builder | - - self target name = 'powerpc64le-linux' ifTrue: [ - self skip: 'Skipped since #loadConstant64:into: is not implemented for POWER (see issue #43)'. - ]. - - builder := compilation builder. - builder defineName: testSelector type: Int64. - builder lreturn: - { builder lconst: 16r7AFEAFFECAFEAFFE }. - - compilation optimize. - compilation compile. - - self assert: (shell call) equals: 16r7AFEAFFECAFEAFFE. - - " - TRRV64GCompilationTests debug: #test03_lconst_p - TRPPC64CompilationTests debug: #test03_lconst_p - " -] - { #category : #'tests - examples' } TRCompilationTestCase >> test_example01_meaningOfLife [ TRCompilationExamples new