PrecommitWizardSettings.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Automation/ScriptReporter.h>
  9. #include <AzCore/std/containers/vector.h>
  10. #include <AzCore/std/containers/map.h>
  11. #include <AzCore/Preprocessor/Enum.h>
  12. namespace AtomSampleViewer
  13. {
  14. struct PrecommitWizardSettings
  15. {
  16. static const int DefaultInspectionSelection = -1;
  17. enum class Stage
  18. {
  19. Intro,
  20. RunFullsuiteTest,
  21. ReportFullsuiteSummary,
  22. ManualInspection,
  23. ReportFinalSummary
  24. };
  25. struct ImageDifferenceLevel
  26. {
  27. enum Levels
  28. {
  29. NoDifference = 0,
  30. LowDifference = 1,
  31. ModerateDifference = 2,
  32. HighDifference = 3,
  33. NumDifferenceLevels = 4
  34. };
  35. };
  36. static constexpr const char* ManualInspectionDifferenceLevels[] = {
  37. "No Difference",
  38. "Low Difference",
  39. "Moderate Difference",
  40. "High Difference"
  41. };
  42. static constexpr const char* ManualInspectionOptions[] = {
  43. "I don't see any difference",
  44. "I see a benign difference",
  45. "I see a difference that's *probably* benign",
  46. "This looks like a problem"
  47. };
  48. // This function does the following:
  49. // 1. Collect passing screenshot tests and sorts them by decreasing diff score.
  50. // 2. Collect failed screenshot tests and sorts them by decreasing diff score.
  51. void ProcessScriptReports(const AZStd::vector<ScriptReporter::ScriptReport>& scriptReports)
  52. {
  53. m_reportsOrderedByThresholdToInspect.clear();
  54. m_failedReports.clear();
  55. for (size_t i = 0; i < scriptReports.size(); ++i)
  56. {
  57. const AZStd::vector<ScriptReporter::ScreenshotTestInfo>& screenshotTestInfos = scriptReports[i].m_screenshotTests;
  58. for (size_t j = 0; j < screenshotTestInfos.size(); ++j)
  59. {
  60. // Collect and sort reports that passed by threshold. This will be used to detect false negatives
  61. // e.g. a test is reported to pass by being below the threshold when in fact it's simply because the threshold is too
  62. // high
  63. if (screenshotTestInfos[j].m_officialComparisonResult.m_resultCode == ScriptReporter::ImageComparisonResult::ResultCode::Pass)
  64. {
  65. m_reportsOrderedByThresholdToInspect.insert(AZStd::pair<float, ScriptReporter::ReportIndex>(
  66. screenshotTestInfos[j].m_officialComparisonResult.m_diffScore,
  67. ScriptReporter::ReportIndex{ i, j }));
  68. }
  69. else
  70. {
  71. m_failedReports.insert(AZStd::pair<float, ScriptReporter::ReportIndex>(
  72. screenshotTestInfos[j].m_officialComparisonResult.m_diffScore,
  73. ScriptReporter::ReportIndex{ i, j }));
  74. }
  75. }
  76. }
  77. m_reportIterator = m_reportsOrderedByThresholdToInspect.begin();
  78. }
  79. int m_inspectionSelection = DefaultInspectionSelection;
  80. Stage m_stage = Stage::Intro;
  81. AZStd::string m_exportedPngPath;
  82. AZStd::multimap<float, ScriptReporter::ReportIndex, AZStd::greater<float>> m_reportsOrderedByThresholdToInspect;
  83. AZStd::multimap<float, ScriptReporter::ReportIndex, AZStd::greater<float>> m_failedReports;
  84. AZStd::multimap<float, ScriptReporter::ReportIndex, AZStd::greater<float>>::iterator m_reportIterator;
  85. AZStd::unordered_map<ScriptReporter::ReportIndex, ImageDifferenceLevel::Levels> m_reportIndexDifferenceLevelMap;
  86. };
  87. } // namespace AtomSampleViewer