Beispiel #1
0
        private static void CollectAndUploadCrashReports(bool remoteTelemetryEnabled)
        {
            if (s_crashCollector != null)
            {
                // Put the state file at the root of the sandbox exec directory
                var stateFileDirectory = Directory.GetCurrentDirectory();

                CrashCollectorMacOS.Upload upload = (IReadOnlyList <CrashReport> reports, string sessionId) =>
                {
                    if (!remoteTelemetryEnabled)
                    {
                        return(false);
                    }

                    foreach (var report in reports)
                    {
                        Tracing.Logger.Log.DominoMacOSCrashReport(s_loggingContext, sessionId, report.Content, report.Type.ToString(), report.FileName);
                    }

                    return(true);
                };

                try
                {
                    s_crashCollector.UploadCrashReportsFromLastSession(s_loggingContext.Session.Id, stateFileDirectory, out var stateFilePath, upload);
                }
                catch (Exception exception)
                {
                    PrintToStderr(exception.Message ?? exception.InnerException.Message);
                }
            }
        }
Beispiel #2
0
        public void TestUploadCrashReports()
        {
            var date      = DateTime.Now;
            var stateFile = Path.Combine(m_userCrashReportFolder, CrashReportStateFile);

            // Generate some random state matching build invocations with crashes
            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 5, date.AddDays(-7), "Some very old data");          // Crashes from before crash uploading ever happened
            m_crashCollector.CreateCrashReportStateFileEntry("test_session1", date.AddDays(-4), stateFile);
            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 4, date.AddDays(-4).AddMinutes(1), "Some old data"); // Crashes from session 1

            m_crashCollector.CreateCrashReportStateFileEntry("test_session2", date.AddDays(-3), stateFile);
            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 3, date.AddDays(-3).AddMinutes(1), "Some recent data"); // Crashes from session 2

            m_crashCollector.CreateCrashReportStateFileEntry("test_session3", date.AddDays(-2), stateFile);
            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 2, date.AddDays(-2).AddMinutes(1), "Some new data"); // Crashes from session 3

            m_crashCollector.CreateCrashReportStateFileEntry("test_session4", date.AddDays(-1), stateFile);
            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 1, date.AddDays(-1).AddMinutes(1), "Newest data"); // Crashes from session 4

            m_crashCollector.UploadCrashReportsFromLastSession("test_session5", m_userCrashReportFolder, out _, (IReadOnlyList <CrashReport> reports, string sessionId) =>
            {
                switch (sessionId)
                {
                case "test_session1":
                    // Old crash data and crash data after the 'test_session1' run
                    XAssert.IsTrue(reports.Count == 9);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("old data")));
                    return(true);

                case "test_session2":
                    XAssert.IsTrue(reports.Count == 3);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("recent data")));
                    return(false);    // Fail upload process

                case "test_session3":
                    XAssert.IsTrue(reports.Count == 2);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("new data")));
                    return(true);

                case "test_session4":
                    XAssert.IsTrue(reports.Count == 1);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("Newest data")));
                    return(false);    // Fail upload process

                default:
                    XAssert.Fail("Only test session 1-4 should be present");
                    return(true);
                }
            }, date.AddMinutes(1));

            var failedState = m_crashCollector.GetStateData(stateFile);

            XAssert.IsTrue(failedState.Count == 3);

            CreateCrashReports(m_userCrashReportFolder, CrashType.BuildXL, 1, date.AddMinutes(1).AddSeconds(30), "Future data"); // Crashes from session 5

            var remainingReports = m_crashCollector.GetCrashReports(CrashType.BuildXL);

            XAssert.IsTrue(remainingReports.Count == 5);

            m_crashCollector.UploadCrashReportsFromLastSession("test_session6", m_userCrashReportFolder, out _, (IReadOnlyList <CrashReport> reports, string sessionId) =>
            {
                switch (sessionId)
                {
                case "test_session2":
                    XAssert.IsTrue(reports.Count == 3);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("recent data")));
                    return(true);

                case "test_session4":
                    XAssert.IsTrue(reports.Count == 1);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("Newest data")));
                    return(false);    // Fail upload process

                case "test_session5":
                    XAssert.IsTrue(reports.Count == 1);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("Future data")));
                    return(true);

                default:
                    XAssert.Fail("Only test session 2, 4 and 5 should be present");
                    return(true);
                }
            }, date.AddMinutes(3));

            remainingReports = m_crashCollector.GetCrashReports(CrashType.BuildXL);
            XAssert.IsTrue(remainingReports.Count == 1);

            m_crashCollector.UploadCrashReportsFromLastSession("test_session7", m_userCrashReportFolder, out _, (IReadOnlyList <CrashReport> reports, string sessionId) =>
            {
                switch (sessionId)
                {
                case "test_session4":
                    XAssert.IsTrue(reports.Count == 1);
                    XAssert.IsTrue(reports.All(r => r.Content.Contains("Newest data")));
                    return(true);

                default:
                    XAssert.Fail("Only test session 4 should be present");
                    return(true);
                }
            }, date.AddMinutes(5));

            // Make sure we only have test session 7 peristed, 6 got removed as we had no crash reports happen
            var state = m_crashCollector.GetStateData(stateFile);

            XAssert.IsTrue(state.Count == 1);
            XAssert.IsTrue(state[0].Item1.Equals("test_session7"));

            remainingReports = m_crashCollector.GetCrashReports(CrashType.BuildXL);
            XAssert.IsTrue(remainingReports.Count == 0);
        }