Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing project #4

Merged
merged 6 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,34 @@ on:
branches: [ "main" ]

jobs:
build:

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Initialize submodules
run: |
git submodule init
git submodule update
- name: install standalone wasmtime
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
export PATH=$HOME/.wasmtime/bin:$PATH
wasmtime --version
- name: build MSBuild for unit test .dll
run: ./msbuild/build.sh
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Publish
run: dotnet publish src
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test
- name: Examples
run: dotnet build examples
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
obj/
.vs
Playground/
Playground/
/MSBuildWasmLocal.sln
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "msbuild"]
path = msbuild
url = https://github.com/dotnet/msbuild
6 changes: 0 additions & 6 deletions MSBuildWasm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleProject", "examples\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WasmTasksTests", "test\WasmTasksTests\WasmTasksTests.csproj", "{94FE5153-34D6-4F93-9792-7408AD89945D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground", "Playground\Playground.csproj", "{047F357B-00C5-49E1-B577-A17D5CFBD02E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,10 +27,6 @@ Global
{94FE5153-34D6-4F93-9792-7408AD89945D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94FE5153-34D6-4F93-9792-7408AD89945D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94FE5153-34D6-4F93-9792-7408AD89945D}.Release|Any CPU.Build.0 = Release|Any CPU
{047F357B-00C5-49E1-B577-A17D5CFBD02E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{047F357B-00C5-49E1-B577-A17D5CFBD02E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{047F357B-00C5-49E1-B577-A17D5CFBD02E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{047F357B-00C5-49E1-B577-A17D5CFBD02E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions examples/ExampleProject/ExampleProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<ProjectReference Include="../../src/MSBuildWasm.csproj" />
</ItemGroup>

<UsingTask TaskName="WasmWasiTasks.WasmTask" AssemblyFile="..\..\src\bin\Release\net8.0\publish\MSBuildWasm.dll" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="WasmWasiTasks.WasmExec" AssemblyFile="..\..\src\bin\Release\net8.0\publish\MSBuildWasm.dll" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="MSBuildWasm.WasmTask" AssemblyFile="..\..\src\bin\Release\net8.0\publish\MSBuildWasm.dll" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="MSBuildWasm.WasmExec" AssemblyFile="..\..\src\bin\Release\net8.0\publish\MSBuildWasm.dll" TaskFactory="TaskHostFactory" />

<Target Name="RunWasm1" BeforeTargets="AfterBuild">
<WasmTask WasmFilePath="..\rust_template\target\wasm32-wasi\release\rust_template.wasm" EnableTmp="false" EnableIO="true" />
Expand Down
1 change: 1 addition & 0 deletions msbuild
Submodule msbuild added at a9c95c
2 changes: 1 addition & 1 deletion src/WasmExec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Threading.Tasks;
using Microsoft.Build.Framework;

namespace WasmWasiTasks
namespace MSBuildWasm
{
public class WasmExec : Microsoft.Build.Utilities.Task, IWasmTask
{
Expand Down
46 changes: 33 additions & 13 deletions src/WasmTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public class WasmTask : Microsoft.Build.Utilities.Task, IWasmTask
public bool EnableIO { get; set; } = true;


readonly string outputPath = Path.GetFullPath("output.txt");
readonly string errorPath = Path.GetFullPath("output.txt");
readonly string tmpPath = Path.GetFullPath("tmp");

const string executeFunctionName = "execute";
const string outDirName = "wasmtaskoutput";

public WasmTask()
{

}

public override bool Execute()
{
try
Expand All @@ -51,14 +63,13 @@ public override bool Execute()
}
if (HomeDir != null)
{
var dir = Directory.CreateDirectory("wasmtaskoutput");
var dir = Directory.CreateDirectory(outDirName);
wasiConfigBuilder = wasiConfigBuilder.WithPreopenedDirectory(dir.FullName, "/out");
}

if (EnableIO)
{
wasiConfigBuilder = wasiConfigBuilder.WithStandardOutput("output.txt")
.WithStandardError("error.txt");
wasiConfigBuilder = wasiConfigBuilder.WithStandardOutput(outputPath)
.WithStandardError(errorPath);
}

using var store = new Store(engine);
Expand All @@ -67,7 +78,11 @@ public override bool Execute()


Instance instance = linker.Instantiate(store, module);
Action fn = instance.GetAction("execute"); // TBD parameters
Action fn = instance.GetAction(executeFunctionName);
//dynamic instance =

//var instancedifferent = instance.GetFunction();


if (fn == null)
{
Expand All @@ -86,19 +101,24 @@ public override bool Execute()
{
if (EnableTmp)
{
Directory.Delete("tmp", true);
Directory.Delete(tmpPath, true);
}
if (EnableIO)
{
// TODO unique filenames
string output = File.ReadAllText("output.txt");
string error = File.ReadAllText("error.txt");

Log.LogMessage(MessageImportance.High, $"Output: {output}");
Log.LogMessage(MessageImportance.Normal, $"Error: {error}");
if (File.Exists(outputPath))
{
string output = File.ReadAllText(outputPath);
Log.LogMessage(MessageImportance.High, $"Output: {output}");
File.Delete(outputPath);
}

File.Delete("output.txt");
File.Delete("error.txt");
if (File.Exists(errorPath))
{
string error = File.ReadAllText(errorPath);
Log.LogMessage(MessageImportance.Normal, $"Error: {error}");
File.Delete(errorPath);
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion test/WasmTasksTests/WasmTask_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Build.UnitTests.Shared;
using MSBuildWasm;
using Xunit;
using Shouldly;
using Microsoft.Build.UnitTests;

namespace WasmTasksTests
{
public class WasmTask_Tests
{
[Fact]
public void Execute_WithDefaultSettings_ShouldSucceed()
public void ExecuteTemplate_WithDefaultSettings_ShouldSucceed()
{
IWasmTask task = new WasmTask {
BuildEngine = new MockEngine(),
WasmFilePath = "../../../../../examples/rust_template/target/wasm32-wasi/release/rust_template.wasm"
};

task.Execute().ShouldBeTrue();
}

}
Expand Down
13 changes: 10 additions & 3 deletions test/WasmTasksTests/WasmTasksTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MSBuildWasm.csproj" />
<Reference Include="Microsoft.Build.UnitTests.Shared">
<HintPath>$(MSBuildThisFileDirectory)\..\..\msbuild\artifacts\bin\Microsoft.Build.UnitTests.Shared\Debug\net8.0\Microsoft.Build.UnitTests.Shared.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
Loading