コード例 #1
0
    private IEnumerator TrackFrameRate()
    {
        AQALogger logger = new AQALogger();

        if (trackingFps)
        {
            yield return(null);
        }
        else
        {
            trackingFps = true;
            while (Application.isPlaying)
            {
                for (float x = 0; x <= 0.5f; x += Time.deltaTime)
                {
                    fpsSamples++;
                    fpsPool += (float)Math.Round(1.0f / Time.deltaTime, 0);
                    yield return(null);
                }
                float framerate = fpsPool / fpsSamples;
                ReportingManager.SampleFramerate(framerate);
//                logger.Log($"FPS {framerate} [Time: {Time.time}]");
                fpsPool = fpsSamples = 0;
            }
        }
    }
コード例 #2
0
        public static void DownloadRecording(string recordingFileName, string resultFileOutputPath)
        {
            var logger = new AQALogger();

            var projectId   = Application.cloudProjectId;
            var downloadUri =
                $"{AutomatedQARuntimeSettings.GAMESIM_API_ENDPOINT}/v1/recordings/{recordingFileName}/download?projectId={projectId}";

            var dh = new DownloadHandlerFile(resultFileOutputPath);

            dh.removeFileOnAbort = true;
            logger.Log("Starting download" + downloadUri);
            using (var webrx = UnityWebRequest.Get(downloadUri))
            {
                webrx.downloadHandler = dh;
                AsyncOperation request = webrx.SendWebRequest();

                while (!request.isDone)
                {
                }

                if (webrx.IsError())
                {
                    logger.LogError($"Couldn't download file. Error - {webrx.error}");
                }
                else
                {
                    logger.Log($"Downloaded file saved to {resultFileOutputPath}.");
                }
            }
        }
コード例 #3
0
        void Start()
        {
            logger = new AQALogger();
            if (AutomatedQARuntimeSettings.hostPlatform == HostPlatform.Cloud &&
                AutomatedQARuntimeSettings.buildType == BuildType.FullBuild)
            {
                DontDestroyOnLoad(this.gameObject);
                RecordedPlaybackPersistentData.SetRecordingMode(RecordingMode.Playback);
                DeviceFarmConfig dfConf = CloudTestManager.Instance.GetDeviceFarmConfig();
                Application.quitting += () =>
                {
# if UNITY_EDITOR
                    logger.Log($"Counters generated - {CloudTestManager.Instance.GetTestResults().ToString()}");
#else
                    CloudTestManager.UploadCounters();
#endif
                    RuntimeClient.LogTestCompletion(dfConf.testName);
                };

                // Optionally us a settings json file other than the default.
                TextAsset settings = Resources.Load <TextAsset>(Path.GetFileNameWithoutExtension(dfConf.settingsFileToLoad));
                if (!string.IsNullOrEmpty(dfConf.settingsFileToLoad) && settings != null && !string.IsNullOrEmpty(settings.text))
                {
                    logger.Log($"Updating default Automated QA settings file to {dfConf.settingsFileToLoad}");
                    AutomatedQARuntimeSettings.AutomatedQaSettingsFileName = dfConf.settingsFileToLoad;
                    AutomatedQARuntimeSettings.RefreshConfig();
                }
                RunTest(dfConf.testName);
            }
コード例 #4
0
        public static void UploadCounters(DeviceFarmOverrides dfConfOverrides = null)
        {
            AQALogger logger = new AQALogger();

            var testResults = CloudTestManager.Instance.GetTestResults(dfConfOverrides);

            logger.Log($"Uploading counters {testResults.ToString()}");
            var postUrl = $"{AutomatedQARuntimeSettings.DEVICE_TESTING_API_ENDPOINT}/v1/counters";

            logger.Log($"Counters = {testResults}");
            byte[]           counterPayload = GetBytes(testResults);
            UploadHandlerRaw uH             = new UploadHandlerRaw(counterPayload);

            uH.contentType = "application/json";


            using (var uwr = new UnityWebRequest(postUrl, UnityWebRequest.kHttpVerbPOST))
            {
                uwr.uploadHandler = uH;
                AsyncOperation request = uwr.SendWebRequest();

                while (!request.isDone)
                {
                }

                if (uwr.IsError())
                {
                    logger.LogError($"Couldn't upload counters. Error - {uwr.error}");
                }
                else
                {
                    logger.Log($"Uploaded counters.");
                }
            }
        }
コード例 #5
0
        public static List <string> CopyRecordingFile(string sourcePath, string destPath)
        {
            AQALogger logger = new AQALogger();

            var createdFiles = new List <string>();
            var destDir      = Path.GetDirectoryName(destPath) ?? "";

            if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }
            if (!File.Exists(sourcePath))
            {
                logger.LogException(new UnityException($"Required recording file does not exist [{sourcePath}]."));
            }
            File.Copy(sourcePath, destPath, true);
            createdFiles.Add(destPath);

            var recordingFiles = GetSegmentFiles(sourcePath);

            foreach (var recordingFile in recordingFiles)
            {
                var segmentPath = Path.Combine(Path.GetDirectoryName(sourcePath), recordingFile);
                var segmentDest = Path.Combine(destDir, recordingFile);
                File.Copy(segmentPath, segmentDest, true);
                createdFiles.Add(segmentDest);
            }
            logger.Log($"Copied recording file from {sourcePath} to {destPath}");

            return(createdFiles);
        }
コード例 #6
0
        public static string GetLocalRecordingFile(string testName)
        {
            var logger = new AQALogger();

            //TODO: Cache this ?
            foreach (var testdata in GetAllRecordedTests())
            {
                if (testdata.testMethod == testName)
                {
                    return(testdata.recording);
                }
            }

            logger.LogError($"Recording file not found for test {testName}");
            return(null);
        }
コード例 #7
0
        public static void SetRecordingDataFromFile(string sourcePath)
        {
            AQALogger logger = new AQALogger();

            RecordedPlaybackPersistentData.CleanRecordingData();
            string destPath = Path.Combine(AutomatedQARuntimeSettings.PersistentDataPath, kRecordedPlaybackFilename);

            if (!string.IsNullOrEmpty(sourcePath))
            {
                CopyRecordingFile(sourcePath, destPath);
            }
            else
            {
                logger.LogError($"Failed to copy recording file from {sourcePath} to {destPath}");
            }
        }
コード例 #8
0
        public static List <string> GetSegmentFiles(string fileName)
        {
            AQALogger logger = new AQALogger();

            try
            {
                var text          = File.ReadAllText(fileName);
                var recordingFile = JsonUtility.FromJson <RecordingInputModule.InputModuleRecordingData>(text);

                return(recordingFile.recordings.Select(x => x.filename));
            }
            catch (ArgumentException)
            {
                logger.LogWarning($"{fileName} is not a valid recording json file");
            }

            return(new List <string>());
        }
コード例 #9
0
        public static string CreateFileFromResource(string resourcePath, string fileName)
        {
            AQALogger logger = new AQALogger();

            var resource  = Path.Combine(Path.GetDirectoryName(resourcePath), Path.GetFileNameWithoutExtension(resourcePath));
            var recording = Resources.Load <TextAsset>(resource);

            if (recording != null)
            {
                string destPath = Path.Combine(AutomatedQARuntimeSettings.PersistentDataPath, fileName);
                File.WriteAllText(destPath, recording.text);
                logger.Log($"Copied recording file {resourcePath} to {destPath}");
                return(destPath);
            }
            else
            {
                logger.LogError($"Could not load recording {resourcePath}");
            }

            return(null);
        }
コード例 #10
0
            public TestName(string testName)
            {
                logger        = new AQALogger();
                this.fullName = testName;

                var matches = Regex.Matches(testName, @"[^.][a-zA-Z0-9-_]+");

                try
                {
                    this.funcName      = matches[matches.Count - 1].Value;
                    this.typeName      = matches[matches.Count - 2].Value;
                    this.namespaceName = matches.Count == 3 ? matches[matches.Count - 3].Value : null;
                }
                catch (IndexOutOfRangeException)
                {
                    logger.LogError($"Invalid testName: {testName}");
                    this.funcName      = null;
                    this.typeName      = null;
                    this.namespaceName = null;
                }
            }
コード例 #11
0
        private IEnumerator Start()
        {
            logger = new AQALogger();
            // Wait for 1 frame to avoid initializing too early
            yield return(null);

            if (Application.isPlaying)
            {
                if (runConfig == null)
                {
                    logger.LogError($"runConfig is null");
                }

                ReportingManager.CurrentTestName = AutomatorName;
                CentralAutomationController.Instance.Run(runConfig);
            }

            if (!runWhileEditorIsAlreadyStarted && !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                // Destroys the StartRecordedPlaybackFromEditor unless it is currently transitioning to playmode
                DestroyImmediate(this.gameObject);
            }
        }
コード例 #12
0
 private void Awake()
 {
     logger = new AQALogger();
 }
コード例 #13
0
        public static void LogTestCompletion(string testName)
        {
            var logger = new AQALogger();

            logger.Log("Unity Test Completed: " + testName);
        }