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

DM Code coverage #1534

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ jobs:
run: |
$env:COMPlus_gcServer=1
dotnet test --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -v n
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
15 changes: 13 additions & 2 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NUnit.Framework;
using OpenDreamRuntime;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Rendering;
using OpenDreamShared.Rendering;
using Robust.Shared.Asynchronous;
Expand All @@ -29,6 +30,7 @@ public sealed class DMTests : ContentUnitTest {
[Dependency] private readonly DreamManager _dreamMan = default!;
[Dependency] private readonly DreamObjectTree _objectTree = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly IDreamDebugManager _debugManager = default!;

[Flags]
public enum DMTestFlags {
Expand Down Expand Up @@ -71,7 +73,7 @@ private static void Cleanup(string? compiledFile) {
}

[Test, TestCaseSource(nameof(GetTests))]
public void TestFiles(string sourceFile, DMTestFlags testFlags) {
public void TestFiles(string sourceFile, string coverageFile, DMTestFlags testFlags) {
string initialDirectory = Directory.GetCurrentDirectory();
TestContext.WriteLine($"--- TEST {sourceFile} | Flags: {testFlags}");
try {
Expand All @@ -85,10 +87,15 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) {

Assert.IsTrue(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file");
Assert.IsTrue(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}");

_debugManager.InitializeCoverage(coverageFile);

_dreamMan.StartWorld();

(bool successfulRun, DreamValue? returned, Exception? exception) = RunTest();

_debugManager.Shutdown();

if (testFlags.HasFlag(DMTestFlags.NoReturn)) {
Assert.IsFalse(returned.HasValue, "proc returned unexpectedly");
} else {
Expand Down Expand Up @@ -137,8 +144,11 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) {
var watch = new Stopwatch();
watch.Start();

// hack to hopefully force spawned calls to finish
var iterationsRemaining = 100;

// Tick until our inner call has finished
while (!callTask.IsCompleted) {
while (!callTask.IsCompleted || iterationsRemaining-- > 0) {
_dreamMan.Update();
_taskManager.ProcessPendingTasks();

Expand All @@ -163,6 +173,7 @@ private static IEnumerable<object[]> GetTests()

yield return new object[] {
sourceFile2,
Path.GetFullPath($"{sourceFile[..^2]}coverage.xml"),
testFlags
};
}
Expand Down
7 changes: 6 additions & 1 deletion OpenDreamRuntime/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public override void Init() {
public override void PostInit() {
_commandSystem = _entitySystemManager.GetEntitySystem<DreamCommandSystem>();

var codeCoverageOutputFile = _configManager.GetCVar(OpenDreamCVars.CodeCoverage);
if (!String.IsNullOrWhiteSpace(codeCoverageOutputFile)) {
_debugManager.InitializeCoverage(codeCoverageOutputFile);
}

int debugAdapterPort = _configManager.GetCVar(OpenDreamCVars.DebugAdapterLaunched);
if (debugAdapterPort == 0) {
_dreamManager.PreInitialize(_configManager.GetCVar<string>(OpenDreamCVars.JsonPath));
_dreamManager.StartWorld();
} else {
// The debug manager is responsible for running _dreamManager.PreInitialize() and .StartWorld()
_debugManager.Initialize(debugAdapterPort);
_debugManager.InitializeDebugging(debugAdapterPort);
}
}

Expand Down
16 changes: 10 additions & 6 deletions OpenDreamRuntime/Objects/DreamObjectTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@

Strings = json.Strings ?? new();

var types = json.Types ?? Array.Empty<DreamTypeJson>();

Check failure on line 83 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

A local variable or function named 'types' is already defined in this scope

Check failure on line 83 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

A local variable or function named 'types' is already defined in this scope

Check failure on line 83 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

A local variable or function named 'types' is already defined in this scope

Check failure on line 83 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

A local variable or function named 'types' is already defined in this scope
var procs = json.Procs;
var globalProcs = json.GlobalProcs;

// Load procs first so types can set their init proc's super proc
LoadProcsFromJson(types, procs, globalProcs);

Check failure on line 88 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

No overload for method 'LoadProcsFromJson' takes 3 arguments

Check failure on line 88 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

No overload for method 'LoadProcsFromJson' takes 3 arguments

Check failure on line 88 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'LoadProcsFromJson' takes 3 arguments

Check failure on line 88 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'LoadProcsFromJson' takes 3 arguments
LoadTypesFromJson(types);

Check failure on line 89 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

There is no argument given that corresponds to the required parameter 'procs' of 'DreamObjectTree.LoadTypesFromJson(DreamTypeJson[], ProcDefinitionJson[]?, int[]?)'

Check failure on line 89 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

There is no argument given that corresponds to the required parameter 'procs' of 'DreamObjectTree.LoadTypesFromJson(DreamTypeJson[], ProcDefinitionJson[]?, int[]?)'

Check failure on line 89 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

There is no argument given that corresponds to the required parameter 'procs' of 'DreamObjectTree.LoadTypesFromJson(DreamTypeJson[], ProcDefinitionJson[]?, int[]?)'

Check failure on line 89 in OpenDreamRuntime/Objects/DreamObjectTree.cs

View workflow job for this annotation

GitHub Actions / build

There is no argument given that corresponds to the required parameter 'procs' of 'DreamObjectTree.LoadTypesFromJson(DreamTypeJson[], ProcDefinitionJson[]?, int[]?)'

if (json.GlobalInitProc is { } initProcDef) {
GlobalInitProc = new DMProc(0, Root, initProcDef, "<global init>", _dreamManager, _atomManager, _dreamMapManager, _dreamDebugManager, _dreamResourceManager, this, _procScheduler);
GlobalInitProc = new DMProc(Procs.Count, Root, initProcDef, "<global init>", _dreamManager, _atomManager, _dreamMapManager, _dreamDebugManager, _dreamResourceManager, this, _procScheduler);
Procs.Add(GlobalInitProc);
} else {
GlobalInitProc = null;
}

var procs = json.Procs;
var globalProcs = json.GlobalProcs;

LoadTypesFromJson(types, procs, globalProcs);
}

public TreeEntry GetTreeEntry(string path) {
Expand Down
Loading
Loading