Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4cf765c
Adds Analytics Auto Test
lee-aandrew Jun 28, 2023
bbe7752
Adds Analytics Testcases
lee-aandrew Jul 10, 2023
f5baed0
Fixes formatting issues
lee-aandrew Jul 10, 2023
756fbb4
Removes dependency on Newtonsoft Json + updates requirement for Unity…
lee-aandrew Jul 10, 2023
c327942
Attempt at adding AddPackage at the beginning of the test
lee-aandrew Jul 10, 2023
b92a095
Remove 2 testing lines
lee-aandrew Jul 10, 2023
678ac6f
Removes the AddPackage.cs and dependency on the analytics debugger fr…
lee-aandrew Jul 13, 2023
27e2dbc
Adds Analytics Auto Test
lee-aandrew Jun 28, 2023
021fec9
Adds Analytics Testcases
lee-aandrew Jul 10, 2023
079bc20
Fixes formatting issues
lee-aandrew Jul 10, 2023
d5018a8
Removes dependency on Newtonsoft Json + updates requirement for Unity…
lee-aandrew Jul 10, 2023
f8b2a18
Attempt at adding AddPackage at the beginning of the test
lee-aandrew Jul 10, 2023
00f3942
Remove 2 testing lines
lee-aandrew Jul 10, 2023
aa6bc05
Removes the AddPackage.cs and dependency on the analytics debugger fr…
lee-aandrew Jul 13, 2023
370d07c
Rebase with dev - Test Codes refactor
lee-aandrew Jul 18, 2023
38c98f6
Increase wait frame count for better stability
lee-aandrew Jul 26, 2023
e98e0f9
Merge branch 'AddAnalyticsTest' of https://github.com/Unity-Technolog…
lee-aandrew Jul 26, 2023
d7ad1f1
Apply test code refactoring changes
lee-aandrew Jul 26, 2023
4fa0878
Reverting unnecessary changes
lee-aandrew Jul 26, 2023
2e7398e
Adds analytics test enabling argument
lee-aandrew Jul 27, 2023
2fba851
Fix formatting for yamato script
lee-aandrew Jul 27, 2023
5908426
applying code review fixes
lee-aandrew Aug 2, 2023
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 .yamato/package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ test_{{ platform.name }}_{{ editor.version }}:
UPMCI_PKG: "upm-ci-utils@stable"
commands:
- npm install {% if platform.name == "win" %}"%UPMCI_PKG%"{% else %}"$UPMCI_PKG"{% endif %} -g --registry {{ registry.npm }}
{% if editor.version == "trunk" %}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6" --extra-editor-arg=-editorAnalyticsTestMode
{% else %}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6"
{% endif %}
artifacts:
logs:
paths:
Expand Down
16 changes: 11 additions & 5 deletions package/com.unity.formats.usd/Common/UsdEditorAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

# if ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_EDITOR
# define USE_EDITOR_ANALYTICS
# endif

using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
Expand All @@ -40,7 +42,8 @@ public static class UsdEditorAnalytics
// Universal USD Analytics
const string k_UsageEventName = "USDPackageUsage";

struct UsageAnalyticsData
[Serializable]
public struct UsageAnalyticsData
{
public bool InitSucceeded;
public double TimeTakenMs;
Expand All @@ -49,7 +52,8 @@ struct UsageAnalyticsData
// USD Import Analytics
const string k_ImportEventName = "USDFileImport";

struct ImportAnalyticsData
[Serializable]
public struct ImportAnalyticsData
{
public string FileExtension;
public double TimeTakenMs;
Expand Down Expand Up @@ -83,7 +87,8 @@ public struct ImportResult
// USD Reimport Analytics
const string k_ReimportEventName = "USDFileReimport";

struct ReimportAnalyticsData
[Serializable]
public struct ReimportAnalyticsData
{
public string FileExtension;
public double TimeTakenMs;
Expand All @@ -98,7 +103,8 @@ struct ReimportAnalyticsData
// USD Export Analytics
const string k_ExportEventName = "USDFileExport";

struct ExportAnalyticsData
[Serializable]
public struct ExportAnalyticsData
{
public string FileExtension;
public double TimeTakenMs;
Expand All @@ -109,7 +115,7 @@ struct ExportAnalyticsData
// USD Recorder Export Analytics
const string k_RecorderExportEventName = "USDFileRecorderExport";

struct RecorderExportAnalyticsData
public struct RecorderExportAnalyticsData
{
public string FileExtension;
public double TimeTakenMs;
Expand Down
13 changes: 12 additions & 1 deletion package/com.unity.formats.usd/Tests/Common/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using UnityEngine;
using UnityEditor;
using UnityScene = UnityEngine.SceneManagement.Scene;
using USD.NET;
using USD.NET.Unity;
using System;

namespace Unity.Formats.USD.Tests
{
Expand Down Expand Up @@ -47,7 +50,15 @@ public void CleanupTestArtifacts()
{
if (Directory.Exists(ArtifactsDirectoryFullPath))
{
Directory.Delete(ArtifactsDirectoryFullPath, true);
try
{
Directory.Delete(ArtifactsDirectoryFullPath, true);
}
catch (Exception e)
{
Debug.Log("Artifact Clean up has failed - This should not happen in most cases, but even if so, the test case should not be affected.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we feed back further detail on the failure by also logging the exception?

Debug.Log($"Exception Message: {e.Message}");
}
}

TestUtility.DeleteMetaFile(ArtifactsDirectoryFullPath);
Expand Down
8 changes: 8 additions & 0 deletions package/com.unity.formats.usd/Tests/Common/Data/Invalid.meta

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

Empty file.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalidFile

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

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def Xform "TestPrim"
{
double3 xformOp:translate = (1, 1, 1)
double3 xformOp:translate = (2, 2, 2)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

5 changes: 5 additions & 0 deletions package/com.unity.formats.usd/Tests/Common/TestDataGuids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ public struct Instancer
public const string UpAxisZLeftHandedUsda = "a01f0befc190ba34e9b0a5405f145a86"; // Tests/Common/Data/Instancer/UsdInstance_UpAxisZ_LeftHanded.usda
public const string UpAxisZRightHandedUsda = "051b4a1cb85f6024191275df09e12fc2"; // Tests/Common/Data/Instancer/UsdInstance_UpAxisZ_RightHanded.usda
}

public struct Invalid
{
public const string InvalidContent = "1a61f8a8f354bba4cb68212f4609270e"; // Tests/Common/Data/Invalid/InvalidContent.usda
}
}
}
9 changes: 9 additions & 0 deletions package/com.unity.formats.usd/Tests/Common/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public static string CreateTmpUsdFile(string testArtifactFullPath, string fileNa
return usdScenePath;
}

public static USDScene CreateEmptyTestUsdScene(string testArtifactFullPath, string fileName = "testUsd.usda")
{
var dummyUsdPath = CreateTmpUsdFile(testArtifactFullPath, fileName);
var scene = ImportHelpers.InitForOpen(dummyUsdPath);
scene.Write("/emptyRoot", new XformSample());
scene.Save();
return scene;
}

public static USDScene CreateTestUsdScene(string testArtifactFullPath, string fileName = "testUsd.usda")
{
var dummyUsdPath = CreateTmpUsdFile(testArtifactFullPath, fileName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# if UNITY_2023_3_OR_NEWER

using System.Collections;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;

namespace Unity.Formats.USD.Tests
{
public class EditorAnalyticsBaseFixture : BaseFixtureEditor
{
protected const string k_TestPrefabName = "TestPrefab";
protected static string[] usdExtensions = new string[] { TestUtility.FileExtension.Usd, TestUtility.FileExtension.Usda, TestUtility.FileExtension.Usdc };

protected struct UsdAnalyticsTypes
{
public const string Import = "editor.USDFileImport";
public const string ReImport = "editor.USDFileReimport";
public const string Export = "editor.USDFileExport";
}

public enum ImportMethods
{
AsGameObject,
AsPrefab,
AsTimelineRecording
}

bool m_initialAnalyticsSetting;
bool m_initialRecordEventsSetting;
bool m_initialSendEventsImmediatelySetting;

[OneTimeSetUp]
public void SetEditorAnalyticsSettings()
{
m_initialAnalyticsSetting = EditorAnalytics.enabled;
m_initialRecordEventsSetting = EditorAnalytics.recordEventsEnabled;
m_initialSendEventsImmediatelySetting = EditorAnalytics.SendAnalyticsEventsImmediately;

EditorAnalytics.enabled = true;
EditorAnalytics.recordEventsEnabled = true;
EditorAnalytics.SendAnalyticsEventsImmediately = true;
}

[OneTimeTearDown]
public void RevertEditorAnalyticsSettings()
{
// Maybe implmeent a package clean up here

EditorAnalytics.enabled = m_initialAnalyticsSetting;
EditorAnalytics.recordEventsEnabled = m_initialRecordEventsSetting;
EditorAnalytics.SendAnalyticsEventsImmediately = m_initialSendEventsImmediatelySetting;
}

[SetUp]
public void ResetEventList()
{
DebuggerEventListHandler.ClearEventList();
InitUsd.Initialize();
}

public IEnumerator WaitForUsdAnalytics<T>(string expectedType, System.Action<T> actualEvent, float attemptTimeLimitMs = 1500) where T: UsdAnalyticsEvent
{
bool found = false;
var stopWatch = System.Diagnostics.Stopwatch.StartNew();

while (!found && stopWatch.Elapsed.TotalMilliseconds < attemptTimeLimitMs)
{
T expectedAnalyticsEvent = null;
foreach (var concattedEvent in DebuggerEventListHandler.fetchEventList())
{
if (!concattedEvent.Contains(expectedType))
{
continue;
}

var splitEvents = concattedEvent.Split("\n");
var usdIndex = FindUsdAnalyticsIndex(expectedType, splitEvents);
var usdEvent = JsonUtility.FromJson<T>(splitEvents[usdIndex]);

if (usdEvent.type.Contains(expectedType))
{
expectedAnalyticsEvent = usdEvent;

actualEvent(expectedAnalyticsEvent);
found = true;
break;
}
}

DebuggerEventListHandler.ClearEventList();

yield return null;
}
}

private int FindUsdAnalyticsIndex(string expectedType, string[] splitEvents)
{
for (int index = 0; index < splitEvents.Length; index++)
{
if (splitEvents[index].Contains(expectedType))
{
return index;
}
}

return -1;
}
}

public class UsdAnalyticsEvent
{
public string type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understanding correctly that this actually stores the event name string eg editor.USDFileImport, or is it actually the C# type name of the event? If it is the former I'd suggest a more explicit variable name :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nono its the former, its the event name, i'll change it to something like "name" or "eventName"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i cant change this as the result json's variable is called "type" and as far as i know Unity's JsonUtility does not have something similar to JsonProperty

}

public class UsdAnalyticsEventImport: UsdAnalyticsEvent
{
public UsdEditorAnalytics.ImportAnalyticsData msg;
}

public class UsdAnalyticsEventReImport : UsdAnalyticsEvent
{
public UsdEditorAnalytics.ReimportAnalyticsData msg;
}

public class UsdAnalyticsEventExport : UsdAnalyticsEvent
{
public UsdEditorAnalytics.ExportAnalyticsData msg;
}
}
#endif

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

Loading