Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/ReportFlightProfileTests.py

Source at documentation-generation time. See Test catalog for fixture associations.

1"""Phase classification, streaming and hot-path accounting regressions."""
2import csv
3import json
4import tempfile
5import unittest
6from pathlib import Path
7from ReportFrameProfile import analyze, read_frames
8from WatchRenderProfile import LiveProfile
9from ReportFrameProfileTests import fixture
10from ReportFlightProfile import analyze_flight, phase, write_report
11
12
13def flight_frame(number=1, altitude=1, density=0):
14 rows = fixture(number)
15 for row in rows:
16 row.update(width="3440", height="1351", msaa="4", vsync="1", vehicle="6", outside="0", rain="0",
17 above_clouds=str(int(altitude > 8)), volume_clouds="1", cloud_base_km="2", cloud_top_km="8",
18 cloud_density=str(density), altitude_km=str(altitude))
19 return rows
20
21
22class FlightTests(unittest.TestCase):
23 def test_chat_markers_do_not_change_timing_or_frame_completeness(self):
24 first, second = flight_frame(), flight_frame(2)
25 for item in first + second:
26 item.update(marker_channel="", marker_text="", billboard_decode_ms="0", billboard_decode_jobs="0",
27 geometry_draws="0", shader_bind_cpu_ms="0")
28 # A marker may arrive before its delayed GPU frame or after a later frame.
29 marker = dict(second[0], event_kind="marker", event_index="-1", seconds="2.4",
30 marker_channel="7", marker_text='hiccup, "clouds" \u00e9 </script>')
31 report, path = self.report([[marker], first, second])
32 self.assertEqual(report["excluded"], {})
33 self.assertEqual(report["phases"]["Below cloud layer"]["frames"], 2)
34 self.assertEqual(report["markers"][0]["marker_text"], marker["marker_text"])
35 detailed = analyze(read_frames(path))
36 self.assertEqual(detailed["cpu_frames"], 2)
37 self.assertEqual(detailed["frame_cpu_ms"]["mean"], 18)
38 self.assertEqual(detailed["markers"], report["markers"])
39 self.assertEqual(analyze(read_frames(path), duration=1)["markers"], [])
40 reader = LiveProfile(path)
41 self.assertTrue(reader.poll())
42 self.assertEqual(reader.snapshot()["complete_frames"], 2)
43 write_report(report, path.with_suffix(".html"))
44 self.assertNotIn('clouds" \u00e9 </script>', path.with_suffix(".html").read_text(encoding="utf-8"))
45
46 def report(self, sequences, partial=""):
47 directory = tempfile.TemporaryDirectory()
48 self.addCleanup(directory.cleanup)
49 path = Path(directory.name) / "flight.csv"
50 with path.open("w", newline="", encoding="utf-8") as out:
51 writer = csv.DictWriter(out, fieldnames=list(sequences[0][0]))
52 writer.writeheader()
53 for rows in sequences:
54 writer.writerows(rows)
55 out.write(partial)
56 return analyze_flight(path), path
57
58 def test_all_phases_and_density_gaps(self):
59 inputs = [(1, 0), (4, .5), (5, 0), (9, 0), (15, 0)]
60 report, _ = self.report([flight_frame(i + 1, altitude, density) for i, (altitude, density) in enumerate(inputs)])
61 self.assertEqual(list(report["phases"]), ["Below cloud layer", "Inside cloud", "Within layer, clear gap",
62 "Above cloud layer", "High view (14+ km)"])
63 head = flight_frame()[0]
64 del head["volume_clouds"]
65 self.assertIn("legacy", phase(head))
66
67 def test_tree_matches_existing_report_and_keeps_invalid_gpu_cpu(self):
68 first, second = flight_frame(), flight_frame(2)
69 second[1]["pass"] = "Sometimes"
70 for row in second:
71 row["gpu_valid"], row["gpu_ms"] = "0", ""
72 report, _ = self.report([second, first], "3,unfinished")
73 old = analyze({1: first, 2: second})
74 phase_report = report["phases"]["Below cloud layer"]
75 self.assertEqual((phase_report["frames"], phase_report["gpu_frames"]), (2, 1))
76 self.assertEqual(report["excluded"], {"invalid_gpu": 1})
77 tree = {tuple(n["path"]): n for n in phase_report["tree"]}
78 for node in old["tree"]:
79 for key in ("cpu_ms", "cpu_self_ms", "gpu_ms", "gpu_self_ms"):
80 self.assertEqual(tree[tuple(node["path"])].get(key), node[key])
81 self.assertEqual(phase_report["metrics"]["upload_bytes"]["mean"], 140)
82 self.assertEqual(phase_report["metrics"]["CPU excluding Present"]["mean"], 15)
83 self.assertEqual(phase_report["metrics"]["GPU frame GPU"]["mean"], 10)
84 self.assertLess(report["timeline"][0]["metrics"]["seconds"]["min"], report["timeline"][-1]["metrics"]["seconds"]["max"])
85
86 def test_overflow_and_truncated_frames_are_excluded(self):
87 bad = flight_frame(2)
88 bad[0]["overflow"] = "4"
89 report, path = self.report([flight_frame(), bad, flight_frame(3)[:-1]])
90 self.assertEqual(report["excluded"], {"overflow": 1, "incomplete": 1})
91 write_report(report, path.with_suffix(".html"))
92 self.assertTrue(path.with_suffix(".json").exists())
93 self.assertEqual(json.loads(path.with_suffix(".json").read_text()), report)
94
95
96if __name__ == "__main__":
97 unittest.main()
SCRIPT_CONTROL SCRIPT_STATE const void int