From b5084cd1808736362d7ffa534188ba1bd84578b3 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Wed, 15 Dec 2021 15:53:49 +0100 Subject: [PATCH] More tests --- .../SecondAssemblyOptimizationSuite.scala | 62 +++++++++++++------ .../scala/millfork/test/SegmentSuite.scala | 4 +- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/test/scala/millfork/test/SecondAssemblyOptimizationSuite.scala b/src/test/scala/millfork/test/SecondAssemblyOptimizationSuite.scala index fc77ce36..92a8bb94 100644 --- a/src/test/scala/millfork/test/SecondAssemblyOptimizationSuite.scala +++ b/src/test/scala/millfork/test/SecondAssemblyOptimizationSuite.scala @@ -146,26 +146,50 @@ class SecondAssemblyOptimizationSuite extends FunSuite with Matchers { } test("Bubblesort") { - EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80)( - """ - |array sorttable [2540] @$C000 - | - |void main() { - | byte t,i,n1,n2 - | for t,25,downto,0{ - | for i,0,to,25{ - | n1 = sorttable[i] - | n2 = sorttable[i+1] - | if n1>n2 { - | sorttable[i] = n2 - | sorttable[i+1] = n1 - | } - | } - | } - |} - | - |""".stripMargin) { m => + val size = 27 + val random = new scala.util.Random + val inputData = IndexedSeq.fill(size)(random.nextInt(256)) + val expected = inputData.sorted + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)( + s""" + |array sorttable [$size] @$$C000 = [${inputData.mkString(",")}] + | + |void main() { + | byte t,i,n1,n2 + | for t,${size - 2},downto,0{ + | for i,0,to,${size - 2}{ + | n1 = sorttable[i] + | n2 = sorttable[i+1] + | if n1>n2 { + | sorttable[i] = n2 + | sorttable[i+1] = n1 + | } + | } + | } + |} + | + |""".stripMargin) { m => + (0 until size).map(i => m.readByte(0xc000 + i)) should equal(expected) + } + } + test("Store-load-operate") { + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)( + """ + | byte output @$c000 + | byte output2 @$c001 + | noinline void f(byte a) { + | output = a + | output2 |= output + | } + | void main () { + | output2 = 5 + | f($a) + | } + | byte ee() { return $ee } + """.stripMargin) { m => + m.readByte(0xc000) should equal(0xa) + m.readByte(0xc001) should equal(0xf) } } } diff --git a/src/test/scala/millfork/test/SegmentSuite.scala b/src/test/scala/millfork/test/SegmentSuite.scala index 4d8aa1bf..1b76f173 100644 --- a/src/test/scala/millfork/test/SegmentSuite.scala +++ b/src/test/scala/millfork/test/SegmentSuite.scala @@ -1,7 +1,7 @@ package millfork.test import millfork.Cpu -import millfork.test.emu.EmuUnoptimizedCrossPlatformRun +import millfork.test.emu.EmuCrossPlatformBenchmarkRun import org.scalatest.{FunSuite, Matchers} /** @@ -39,7 +39,7 @@ class SegmentSuite extends FunSuite with Matchers { | output6 = segment.default.heapstart | } """.stripMargin - EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(source) { m => + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(source) { m => m.readByte(0xc000) should equal(source.count(_ == '+')) m.readByte(0xc001) should equal(0) m.readWord(0xc006) should equal(0x200)