Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
add new test, bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed May 4, 2020
1 parent b5e49b1 commit ab9a755
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Yuuki Wesp</Authors>
<Company>Ancient Project</Company>
<Version>0.70.379.120</Version>
<Version>0.70.404.120</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ancient.Runtime" Version="0.60.345.605" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>0.70.374.37</Version>
<Version>0.70.399.37</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://raw.githubusercontent.com/ancientproject/cli/master/resource/icon.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/0xF6/ancient_cpu</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageIconUrl>https://raw.githubusercontent.com/ancientproject/cli/master/resource/icon.png</PackageIconUrl>
<RepositoryUrl>https://github.com/0xF6/ancient_cpu</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>0.70.374.91</Version>
<Version>0.70.399.116</Version>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration) == 'Debug'">
<BumpRevision>true</BumpRevision>
Expand Down
99 changes: 92 additions & 7 deletions test/vm_test/ExecuteTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace vm_test
{
using System;
using System.Linq;
using ancient.runtime;
using ancient.runtime.emit.sys;
using ancient.runtime.hardware;
using NUnit.Framework;
using System;
using System.Linq;
using vm.component;

[TestFixture]
Expand All @@ -15,28 +15,113 @@ public class ExecuteTest : VMBehaviour
[OneTimeSetUp]
public void Setup() => IntConverter.Register<char>();

[Test]
[Author("Yuuki Wesp", "[email protected]")]
[Description("ckft operation")]
public void TestComplexCalculation()
{
var mem = new ulong[]
{
// 0x0 - var 200
// 0x1 - int i
// 0x2 - double target
// 0x3 - int -1
// 0x4 - int temp
// 0x5 - Math.pow(-1,i+1)
// 0x6 - (2*i - 1)
// 0x9 - pi
// 0xA - ref
new ldx(0x11, 0x1), // set trace=ON
new ldx(0x18, 0x1), // enable float-mode
new ldi(0x0, 200), // max steps
new nop(),
new orb(1),
new val(0.0f), // double target = 0;
new pull(0x2),
new orb(1),
new val(-1f),// const float minusOne = -1;
new pull(0x3),
// i++
new ldx(0x18, 0x1),
new inc(0x1),


// Math.pow(-1, i + 1)
new dup(0x1, 0x5),
new inc(0x5),
new ldx(0x18, 0x1),
new pow(0x5, 0x3, 0x5),

// (2 * i - 1)
new dup(0x1, 0x6),
new orb(1),
new val(2.0f), // double target = 0;
new pull(0x4),
new mul(0x6, 0x4, 0x6),
new dec(0x6),

new div(0x4, 0x5, 0x6),
new swap(0x4, 0x9),
// if result 0x9 cell is not infinity
new ckft(0x9)
};
load(mem);
shot();
AssertRegister<ulong>(x => x.mem[0x11], 0x1);
shot();
AssertRegister<ulong>(x => x.mem[0x18], 0x1);
shot();
AssertRegister<ulong>(x => x.mem[0x0], 200);
shot(3);
AssertRegister<ulong>(x => x.mem[0x2], State.f32u64 & 0.0f);
shot(2);
AssertRegister<ulong>(x => x.mem[0x3], State.f32u64 & -1.0f);
shot(2);
AssertRegister<ulong>(x => x.mem[0x1], State.f32u64 & 1f);
shot();
AssertRegister<ulong>(x => x.mem[0x1], state.mem[0x5]);
shot();
AssertRegister<ulong>(x => x.mem[0x5], State.f32u64 & (State.u64f32 & state.mem[0x1]) + 1f);
shot(2);
var t = State.u64f32 & state.mem[0x5];
AssertRegister<ulong>(x => x.mem[0x5], State.f32u64 & MathF.Pow(-1, 1 + 1));
shot(); // new dup(0x1, 0x6),
AssertRegister<ulong>(x => x.mem[0x1], state.mem[0x5]);
shot(2); // new val(2.0f), new pull(0x4),
AssertRegister<ulong>(x => x.mem[0x4], State.f32u64 & 2f);
shot(2); // new mul(0x6, 0x4, 0x6), new dec(0x6),
AssertRegister<ulong>(x => x.mem[0x6], State.f32u64 & (2 * 1 - 1));
shot(); // new div(0x4, 0x5, 0x6),
AssertRegister<ulong>(x => x.mem[0x4], State.f32u64 & MathF.Pow(-1, 1 + 1) / (2 * 1 - 1));
}

[Test]
[Author("Yuuki Wesp", "[email protected]")]
[Description("ckft operation")]
public void ckftTest()
{
static ulong float2raw(float value) =>
(ulong)BitConverter.ToInt32(BitConverter.GetBytes(value), 0);

state.ff = true;
var mem = new ulong[]
{
new orb(1),
new val(1.0f),
new orb(1),
new val(float.PositiveInfinity),
new pull(0x0),
new pull(0x1),
new pull(0x0), // pull PositiveInfinity from stack into 0x0 cell
new pull(0x1), // pull 1.0f from stack into 0x1 cell

// validate finity value
new ckft(0x0),
new ckft(0x1),
};
load(mem);
shot(mem.Length);
AssertRegister(x => x.mem[0x0], (ulong)BitConverter.ToInt32(BitConverter.GetBytes(float.PositiveInfinity), 0));
AssertRegister(x => x.mem[0x1], (ulong)BitConverter.ToInt32(BitConverter.GetBytes(1.0f), 0));
Assert.True(IsHalt());
AssertRegister(x => x.mem[0x0], float2raw(float.PositiveInfinity));
AssertRegister(x => x.mem[0x1], float2raw(1.0f));
Assert.True(IsHalt()); // validate halting with x87 float exception
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion vm/csharp/component/State.eval.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace vm.component
namespace vm.component
{
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion vm/csharp/vm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win10-x64;osx.10.14-x64;linux-x64</RuntimeIdentifiers>
<Version>0.70.442-beta</Version>
<Version>0.70.467-beta</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Copyright>Yuuki Wesp (C) 2020</Copyright>
</PropertyGroup>
Expand Down

0 comments on commit ab9a755

Please sign in to comment.