Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RegressionGames.StateRecorder.BotSegments.Models;
using StateRecorder.BotSegments.Models;
using StateRecorder.BotSegments.Models.SegmentValidations;

namespace RegressionGames.StateRecorder.BotSegments
{
Expand Down Expand Up @@ -65,5 +67,25 @@ public BotSegment PeekBotSegment()

return null;
}


/**
* <summary>Collects all of the results from the top-level validations and individual bot segments</summary>
*/
public List<SegmentValidationResultSetContainer> GetAllValidationResults()
{

// First add all the top level results
var results = Validations.Select(validation => validation.data.GetResults()).ToList();

// Then add the individual bot segment results
foreach (var botSegment in _botSegments)
{
results.AddRange(botSegment.validations.Select(v => v.data.GetResults()));
}

return results;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using RegressionGames.StateRecorder.BotSegments.Models;
using RegressionGames.StateRecorder.BotSegments.Models.BotActions.KeyMoments;
using RegressionGames.StateRecorder.Models;
using StateRecorder.BotSegments;
using StateRecorder.BotSegments.Models;
using StateRecorder.BotSegments.Models.SegmentValidations;
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand Down Expand Up @@ -664,6 +666,7 @@ public void UnloadSegmentsAndReset()
_replaySuccessful = null;
WaitingForKeyFrameConditions = null;

_screenRecorder.validationResults = _dataPlaybackContainer?.GetAllValidationResults() ?? new List<SegmentValidationResultSetContainer>();
_screenRecorder.StopRecording();
#if ENABLE_LEGACY_INPUT_MANAGER
RGLegacyInputWrapper.StopSimulation();
Expand Down Expand Up @@ -704,6 +707,7 @@ public void Stop()
WaitingForKeyFrameConditions = null;
_lastSegmentPlaybackWarning = null;

_screenRecorder.validationResults = _dataPlaybackContainer?.GetAllValidationResults() ?? new List<SegmentValidationResultSetContainer>();
_screenRecorder.StopRecording();
#if ENABLE_LEGACY_INPUT_MANAGER
RGLegacyInputWrapper.StopSimulation();
Expand Down Expand Up @@ -825,6 +829,7 @@ private void LogPlaybackWarning(string loggedMessage, Exception ex = null)
RGDebug.LogWarning(loggedMessage);
}
}

FindObjectOfType<ReplayToolbarManager>()?.SetKeyFrameWarningText(loggedMessage);
if (pauseEditorOnPlaybackWarning)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace StateRecorder.BotSegments.Models.SegmentValidations
{
Expand Down Expand Up @@ -28,6 +30,7 @@ public class SegmentValidationResultContainer
* The actual state of this validation result
* </summary>
*/
[JsonConverter(typeof(StringEnumConverter))]
public SegmentValidationStatus result;

public SegmentValidationResultContainer(string name, [CanBeNull] string description, SegmentValidationStatus result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using RegressionGames.ActionManager;
using RegressionGames.CodeCoverage;
using RegressionGames.RemoteOrchestration;
using RegressionGames.StateRecorder.BotSegments.Models;
using RegressionGames.StateRecorder.BotSegments.Models.BotActions;
using RegressionGames.StateRecorder.BotSegments.Models.BotCriteria;
using RegressionGames.StateRecorder.Models;
using RegressionGames.Validation;
using StateRecorder.BotSegments;
using StateRecorder.BotSegments.Models.SegmentValidations;
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand Down Expand Up @@ -85,6 +88,7 @@ public class ScreenRecorder : MonoBehaviour
private string _currentGameplaySessionGameMetadataPath;
private string _currentGameplaySessionThumbnailPath;
private string _currentGameplaySessionLogsDirectoryPrefix;
private string _currentGameplaySessionValidationsPrefix;

private CancellationTokenSource _tokenSource;

Expand Down Expand Up @@ -112,6 +116,8 @@ public class ScreenRecorder : MonoBehaviour

private KeyMomentEvaluator _keyMomentEvaluator = new();

public List<SegmentValidationResultSetContainer> validationResults = new();

#if UNITY_EDITOR
private bool _needToRefreshAssets;
#endif
Expand Down Expand Up @@ -182,6 +188,7 @@ private async Task HandleEndRecording(long tickCount,
string thumbnailPath,
string logsDirectoryPrefix,
string gameMetadataPath,
string validationsPath,
bool onDestroy = false)
{
if (!onDestroy)
Expand Down Expand Up @@ -265,6 +272,9 @@ private async Task HandleEndRecording(long tickCount,
ZipFile.CreateFromDirectory(keyMomentsDirectoryPrefix, keyMomentsDirectoryPrefix + ".zip");
RGDebug.LogInfo($"Finished zipping replay to file: {keyMomentsDirectoryPrefix}.zip");
});

// Save the validation results to the validations JSON file, if there are any
await File.WriteAllBytesAsync(_currentGameplaySessionValidationsPrefix, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(validationResults ?? new List<SegmentValidationResultSetContainer>())));

// Finally, we also save a thumbnail, by choosing the middle file in the screenshots
var screenshotFiles = Directory.GetFiles(screenshotsDirectoryPrefix);
Expand All @@ -279,6 +289,9 @@ private async Task HandleEndRecording(long tickCount,

// wait for the zip tasks to finish
Task.WaitAll(zipTask1, zipTask2, zipTask3, zipTask4, zipTask5);

// print validation results
RGValidateLoggerUtility.LogValidationResults(validationResults);

if (!wasReplay)
{
Expand Down Expand Up @@ -575,6 +588,7 @@ private IEnumerator StartRecordingCoroutine(string referenceSessionId)
_startTime = DateTime.Now;
_tickQueue = new BlockingCollection<(TickDataToWriteToDisk, Action)>(new ConcurrentQueue<(TickDataToWriteToDisk, Action)>());
_tokenSource = new CancellationTokenSource();
validationResults = new();

Directory.CreateDirectory(stateRecordingsDirectory);

Expand Down Expand Up @@ -616,6 +630,7 @@ private IEnumerator StartRecordingCoroutine(string referenceSessionId)
Directory.CreateDirectory(_currentGameplaySessionMetadataDirectoryPrefix);

_currentGameplaySessionThumbnailPath = _currentGameplaySessionDirectoryPrefix + "/thumbnail.jpg";
_currentGameplaySessionValidationsPrefix = _currentGameplaySessionDirectoryPrefix + "/validations.json";

// run the tick processor in the background, but don't hook it to the token source.. we'll manage cancelling this on our own so we don't miss processing ticks
Task.Run(ProcessTicks);
Expand Down Expand Up @@ -739,6 +754,7 @@ private void StopRecordingCleanupHelper(bool wasRecording, bool wasReplay)
_currentGameplaySessionThumbnailPath,
_currentGameplaySessionLogsDirectoryPrefix,
_currentGameplaySessionGameMetadataPath,
_currentGameplaySessionValidationsPrefix,
true);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Collections.Generic;
using System.Text;
using JetBrains.Annotations;
using StateRecorder.BotSegments.Models.SegmentValidations;

namespace RegressionGames.Validation
{

/**
* A set of utilities for logging results related to validations
*/
public class RGValidateLoggerUtility
{

/**
* <summary>Prints out validation results in a clean way in the logs</summary>
*/
public static void LogValidationResults([CanBeNull] List<SegmentValidationResultSetContainer> results)
{

if (results == null)
{
// For now, if there are no validations, we just print a small message
RGDebug.LogInfo("No validations were provided as part of this run");
return;
}

// Print out results while also collecting total results
var passed = 0;
var failed = 0;
var unknown = 0;

var logBuilder = new StringBuilder(100_000);

logBuilder.Append("<b>--------------- VALIDATION RESULTS ---------------</b> (If in the editor, click this to view more)\n\n");
foreach (var resultSet in results)
{
logBuilder.Append("<b>" + resultSet.name + "</b>\n");
foreach (var validation in resultSet.validationResults)
{
switch (validation.result)
{
case SegmentValidationStatus.PASSED:
logBuilder.Append(" <b><color=green>[PASS]</color></b> ");
passed++;
break;
case SegmentValidationStatus.FAILED:
logBuilder.Append(" <b><color=red>[FAIL]</color></b> ");
failed++;
break;
case SegmentValidationStatus.UNKNOWN:
logBuilder.Append(" <b>[UNKNOWN]</b> ");
unknown++;
break;
}
logBuilder.Append(validation.name + "\n");
}

logBuilder.Append("\n");
}

if (failed > 0)
{
logBuilder.Append("<b><color=red>VALIDATIONS FAILED</color> - ");
}
else
{
logBuilder.Append("<b><color=green>VALIDATIONS PASSED</color> - ");
}

logBuilder.Append($"<color=red>{failed} FAILED</color>, <color=green>{passed} PASSED</color> <i>({unknown} UNKNOWN)</i></b>\n\n");

// Finally log the results
if (failed > 0)
{
RGDebug.LogError(logBuilder.ToString());
}
else
{
RGDebug.LogInfo(logBuilder.ToString());
}

}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading