hfim-cli 1.15.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. fim/__init__.py +42 -0
  2. fim/analysis/__init__.py +53 -0
  3. fim/analysis/burst_sdc.py +160 -0
  4. fim/analysis/classifier.py +924 -0
  5. fim/analysis/comparator.py +738 -0
  6. fim/analysis/consolidate.py +625 -0
  7. fim/analysis/csv_io.py +28 -0
  8. fim/analysis/ecc_quartet.py +167 -0
  9. fim/analysis/nvm_endurance_matrix.py +170 -0
  10. fim/analysis/observable_state.py +945 -0
  11. fim/analysis/reporter.py +712 -0
  12. fim/analysis/results_txt.py +229 -0
  13. fim/campaigns/__init__.py +28 -0
  14. fim/campaigns/base_campaign.py +5151 -0
  15. fim/campaigns/cache_campaign.py +233 -0
  16. fim/campaigns/campaign_view.py +135 -0
  17. fim/campaigns/csr_campaign.py +31 -0
  18. fim/campaigns/fault_plan.py +105 -0
  19. fim/campaigns/faultlist_builder.py +503 -0
  20. fim/campaigns/gem5_parallel_runner.py +210 -0
  21. fim/campaigns/golden_gate.py +158 -0
  22. fim/campaigns/injection_point_selector.py +473 -0
  23. fim/campaigns/memory_campaign.py +686 -0
  24. fim/campaigns/parallel_runner.py +510 -0
  25. fim/campaigns/register_campaign.py +617 -0
  26. fim/campaigns/serial_feeder.py +169 -0
  27. fim/cli.py +2652 -0
  28. fim/configs/benchmarks/bitcount.yaml +11 -0
  29. fim/configs/benchmarks/checksum.yaml +11 -0
  30. fim/configs/benchmarks/dotprod_f64.yaml +12 -0
  31. fim/configs/benchmarks/fibonacci.yaml +10 -0
  32. fim/configs/boards/board_spec_schema.yaml +216 -0
  33. fim/configs/boards/raspberry_pi_5.yaml +122 -0
  34. fim/configs/boards/xuantie_c906.yaml +127 -0
  35. fim/configs/boards/xuantie_c906_ruby_nvmain.yaml +85 -0
  36. fim/configs/dramsim3/DDR3_1Gb_x8_1333.ini +69 -0
  37. fim/configs/dramsim3/DDR3_4Gb_x16_1600.ini +67 -0
  38. fim/configs/dramsim3/DDR3_4Gb_x16_1866.ini +67 -0
  39. fim/configs/dramsim3/DDR3_4Gb_x4_1600.ini +67 -0
  40. fim/configs/dramsim3/DDR3_4Gb_x4_1866.ini +67 -0
  41. fim/configs/dramsim3/DDR3_4Gb_x8_1600.ini +67 -0
  42. fim/configs/dramsim3/DDR3_4Gb_x8_1866.ini +67 -0
  43. fim/configs/dramsim3/DDR3_8Gb_x16_1600.ini +67 -0
  44. fim/configs/dramsim3/DDR3_8Gb_x16_1866.ini +67 -0
  45. fim/configs/dramsim3/DDR3_8Gb_x4_1600.ini +67 -0
  46. fim/configs/dramsim3/DDR3_8Gb_x4_1866.ini +67 -0
  47. fim/configs/dramsim3/DDR3_8Gb_x8_1600.ini +67 -0
  48. fim/configs/dramsim3/DDR3_8Gb_x8_1866.ini +67 -0
  49. fim/configs/dramsim3/DDR4_4Gb_x16_1866.ini +67 -0
  50. fim/configs/dramsim3/DDR4_4Gb_x16_2133.ini +67 -0
  51. fim/configs/dramsim3/DDR4_4Gb_x16_2133_2.ini +67 -0
  52. fim/configs/dramsim3/DDR4_4Gb_x16_2400.ini +67 -0
  53. fim/configs/dramsim3/DDR4_4Gb_x16_2400_2.ini +67 -0
  54. fim/configs/dramsim3/DDR4_4Gb_x16_2666.ini +67 -0
  55. fim/configs/dramsim3/DDR4_4Gb_x16_2666_2.ini +67 -0
  56. fim/configs/dramsim3/DDR4_4Gb_x4_1866.ini +67 -0
  57. fim/configs/dramsim3/DDR4_4Gb_x4_2133.ini +67 -0
  58. fim/configs/dramsim3/DDR4_4Gb_x4_2133_2.ini +67 -0
  59. fim/configs/dramsim3/DDR4_4Gb_x4_2400.ini +67 -0
  60. fim/configs/dramsim3/DDR4_4Gb_x4_2400_2.ini +67 -0
  61. fim/configs/dramsim3/DDR4_4Gb_x4_2666.ini +67 -0
  62. fim/configs/dramsim3/DDR4_4Gb_x4_2666_2.ini +67 -0
  63. fim/configs/dramsim3/DDR4_4Gb_x8_1866.ini +67 -0
  64. fim/configs/dramsim3/DDR4_4Gb_x8_2133.ini +67 -0
  65. fim/configs/dramsim3/DDR4_4Gb_x8_2133_2.ini +67 -0
  66. fim/configs/dramsim3/DDR4_4Gb_x8_2400.ini +67 -0
  67. fim/configs/dramsim3/DDR4_4Gb_x8_2400_2.ini +67 -0
  68. fim/configs/dramsim3/DDR4_4Gb_x8_2666.ini +67 -0
  69. fim/configs/dramsim3/DDR4_4Gb_x8_2666_2.ini +67 -0
  70. fim/configs/dramsim3/DDR4_8Gb_x16_1866.ini +67 -0
  71. fim/configs/dramsim3/DDR4_8Gb_x16_2133.ini +67 -0
  72. fim/configs/dramsim3/DDR4_8Gb_x16_2133_2.ini +67 -0
  73. fim/configs/dramsim3/DDR4_8Gb_x16_2400.ini +67 -0
  74. fim/configs/dramsim3/DDR4_8Gb_x16_2400_2.ini +67 -0
  75. fim/configs/dramsim3/DDR4_8Gb_x16_2666.ini +67 -0
  76. fim/configs/dramsim3/DDR4_8Gb_x16_2666_2.ini +67 -0
  77. fim/configs/dramsim3/DDR4_8Gb_x16_2933.ini +67 -0
  78. fim/configs/dramsim3/DDR4_8Gb_x16_2933_2.ini +67 -0
  79. fim/configs/dramsim3/DDR4_8Gb_x16_3200.ini +67 -0
  80. fim/configs/dramsim3/DDR4_8Gb_x4_1866.ini +67 -0
  81. fim/configs/dramsim3/DDR4_8Gb_x4_2133.ini +67 -0
  82. fim/configs/dramsim3/DDR4_8Gb_x4_2133_2.ini +67 -0
  83. fim/configs/dramsim3/DDR4_8Gb_x4_2400.ini +67 -0
  84. fim/configs/dramsim3/DDR4_8Gb_x4_2400_2.ini +67 -0
  85. fim/configs/dramsim3/DDR4_8Gb_x4_2666.ini +67 -0
  86. fim/configs/dramsim3/DDR4_8Gb_x4_2666_2.ini +67 -0
  87. fim/configs/dramsim3/DDR4_8Gb_x4_2933.ini +67 -0
  88. fim/configs/dramsim3/DDR4_8Gb_x4_2933_2.ini +67 -0
  89. fim/configs/dramsim3/DDR4_8Gb_x4_3200.ini +67 -0
  90. fim/configs/dramsim3/DDR4_8Gb_x8_1866.ini +67 -0
  91. fim/configs/dramsim3/DDR4_8Gb_x8_2133.ini +67 -0
  92. fim/configs/dramsim3/DDR4_8Gb_x8_2133_2.ini +67 -0
  93. fim/configs/dramsim3/DDR4_8Gb_x8_2400.ini +77 -0
  94. fim/configs/dramsim3/DDR4_8Gb_x8_2400_2.ini +67 -0
  95. fim/configs/dramsim3/DDR4_8Gb_x8_2666.ini +67 -0
  96. fim/configs/dramsim3/DDR4_8Gb_x8_2666_2.ini +67 -0
  97. fim/configs/dramsim3/DDR4_8Gb_x8_2933.ini +67 -0
  98. fim/configs/dramsim3/DDR4_8Gb_x8_2933_2.ini +67 -0
  99. fim/configs/dramsim3/DDR4_8Gb_x8_3200.ini +67 -0
  100. fim/configs/ecc_policies/c906.yaml +26 -0
  101. fim/configs/matmul_aarch64.yaml +62 -0
  102. fim/configs/mcpat/c906.xml +481 -0
  103. fim/configs/mcpat/raspberry_pi_5.xml +405 -0
  104. fim/configs/mcpat/sTemplate.xml +444 -0
  105. fim/configs/mcpat/template.xml +405 -0
  106. fim/configs/mmult.yaml +140 -0
  107. fim/configs/mmult_memory_gem5.yaml +23 -0
  108. fim/configs/nvmain/2D_DRAM_example.config +249 -0
  109. fim/configs/nvmain/3D_DRAMCache_OffChipMemory_example.config +154 -0
  110. fim/configs/nvmain/3D_DRAMCache_example.config +275 -0
  111. fim/configs/nvmain/3D_DRAM_example.config +237 -0
  112. fim/configs/nvmain/3D_PredictorDRC_example.config +277 -0
  113. fim/configs/nvmain/3D_VariableDRC_example.config +278 -0
  114. fim/configs/nvmain/Hybrid_DRAM_channel.config +249 -0
  115. fim/configs/nvmain/Hybrid_NVM_channel.config +208 -0
  116. fim/configs/nvmain/Hybrid_NVM_channel_BitModel.config +208 -0
  117. fim/configs/nvmain/Hybrid_example.config +72 -0
  118. fim/configs/nvmain/Hybrid_example_BitModel.config +72 -0
  119. fim/configs/nvmain/PCM_ISSCC_2012_4GB.config +217 -0
  120. fim/configs/nvmain/PCM_ISSCC_2012_4GB_BitModel.config +217 -0
  121. fim/configs/nvmain/PCM_ISSCC_2012_4GB_BitModel_ECP.config +222 -0
  122. fim/configs/nvmain/PCM_ISSCC_2012_4GB_ByteModel.config +217 -0
  123. fim/configs/nvmain/PCM_ISSCC_2012_4GB_RowModel.config +217 -0
  124. fim/configs/nvmain/PCM_ISSCC_2012_4GB_WordModel.config +217 -0
  125. fim/configs/nvmain/PCM_MLC_estimated.config +233 -0
  126. fim/configs/nvmain/PCM_MLC_example.config +232 -0
  127. fim/configs/nvmain/PCM_MLC_example_BitModel.config +232 -0
  128. fim/configs/nvmain/PerfectMemory.config +229 -0
  129. fim/configs/nvmain/RRAM_ISSCC_2012_4GB.config +218 -0
  130. fim/configs/nvmain/STTRAM_Everspin_4GB.config +217 -0
  131. fim/configs/nvmain/STTRAM_Everspin_4GB_BitModel.config +217 -0
  132. fim/configs/nvmain/printtrace.config +145 -0
  133. fim/configs/nvmain/printtrace_bitflip.config +146 -0
  134. fim/configs/quicksort_dmr.yaml +225 -0
  135. fim/configs/rust_sort_array.yaml +28 -0
  136. fim/configs/rust_sort_bss.yaml +38 -0
  137. fim/configs/sum.yaml +149 -0
  138. fim/configs/template.yaml +418 -0
  139. fim/configs/toolchains.remote.json +14 -0
  140. fim/core/__init__.py +161 -0
  141. fim/core/artifacts/__init__.py +25 -0
  142. fim/core/artifacts/adapters/__init__.py +146 -0
  143. fim/core/artifacts/adapters/board.py +38 -0
  144. fim/core/artifacts/adapters/config.py +115 -0
  145. fim/core/artifacts/adapters/sdk.py +435 -0
  146. fim/core/artifacts/adapters/simulator.py +139 -0
  147. fim/core/artifacts/adapters/template.py +107 -0
  148. fim/core/artifacts/classification.py +95 -0
  149. fim/core/artifacts/hashing.py +265 -0
  150. fim/core/artifacts/inputs.py +179 -0
  151. fim/core/artifacts/records.py +238 -0
  152. fim/core/artifacts/retention.py +504 -0
  153. fim/core/artifacts/staleness.py +486 -0
  154. fim/core/artifacts/store.py +202 -0
  155. fim/core/artifacts/workspace.py +108 -0
  156. fim/core/checkpoint.py +338 -0
  157. fim/core/checkpoint_policy.py +171 -0
  158. fim/core/classifier_view.py +96 -0
  159. fim/core/clock_view.py +99 -0
  160. fim/core/configuration/__init__.py +13 -0
  161. fim/core/configuration/frozen.py +85 -0
  162. fim/core/configuration/groups.py +41 -0
  163. fim/core/configuration/includes.py +249 -0
  164. fim/core/configuration/lifecycle_rules.py +83 -0
  165. fim/core/configuration/reference.py +200 -0
  166. fim/core/configuration/reference_docs.py +344 -0
  167. fim/core/configuration/resolver.py +495 -0
  168. fim/core/configuration/run_context.py +51 -0
  169. fim/core/configuration/schema.py +784 -0
  170. fim/core/configuration/sources.py +121 -0
  171. fim/core/configuration/template_pins.py +79 -0
  172. fim/core/fault_models.py +261 -0
  173. fim/core/fim.py +452 -0
  174. fim/core/gdb_controller.py +2053 -0
  175. fim/core/gem5_controller.py +1226 -0
  176. fim/core/gem5_launch.py +489 -0
  177. fim/core/gem5_observable.py +202 -0
  178. fim/core/gem5_producers.py +684 -0
  179. fim/core/gem5_simulator.py +724 -0
  180. fim/core/golden_view.py +94 -0
  181. fim/core/hardware_cluster.py +236 -0
  182. fim/core/hardware_simulator.py +992 -0
  183. fim/core/hardware_spec.py +352 -0
  184. fim/core/hardware_station.py +374 -0
  185. fim/core/hardware_view.py +64 -0
  186. fim/core/hardware_window.py +102 -0
  187. fim/core/hook_view.py +52 -0
  188. fim/core/lifecycle.py +433 -0
  189. fim/core/machine_binding.py +317 -0
  190. fim/core/ovp_plan.py +419 -0
  191. fim/core/ovp_protocol.py +647 -0
  192. fim/core/ovp_simulator.py +1201 -0
  193. fim/core/ovp_view.py +99 -0
  194. fim/core/qemu_controller.py +1396 -0
  195. fim/core/qemu_launch.py +179 -0
  196. fim/core/qemu_simulator.py +329 -0
  197. fim/core/results_store.py +218 -0
  198. fim/core/results_view.py +94 -0
  199. fim/core/simulator_controller.py +298 -0
  200. fim/core/simulator_manifest.py +739 -0
  201. fim/core/station_host.py +277 -0
  202. fim/install/__init__.py +16 -0
  203. fim/install/ensure.py +182 -0
  204. fim/install/home.py +126 -0
  205. fim/install/index.py +122 -0
  206. fim/install/index.yaml +59 -0
  207. fim/install/prebuilt.py +120 -0
  208. fim/install/probes.py +182 -0
  209. fim/install/remote.py +165 -0
  210. fim/install/sdk.py +178 -0
  211. fim/install/setup.py +184 -0
  212. fim/install/simulators.py +323 -0
  213. fim/install/template.py +147 -0
  214. fim/install/uninstall.py +149 -0
  215. fim/provision/__init__.py +48 -0
  216. fim/provision/catalog.py +278 -0
  217. fim/provision/commands.py +1051 -0
  218. fim/provision/doctor.py +291 -0
  219. fim/provision/drain.py +117 -0
  220. fim/provision/forms/__init__.py +4 -0
  221. fim/provision/forms/docker.py +469 -0
  222. fim/provision/forms/fake.py +281 -0
  223. fim/provision/forms/native.py +438 -0
  224. fim/provision/fresh_layout.py +66 -0
  225. fim/provision/hostdeps.py +229 -0
  226. fim/provision/layout_units.py +148 -0
  227. fim/provision/lock.py +100 -0
  228. fim/provision/package.py +110 -0
  229. fim/provision/plan.py +356 -0
  230. fim/provision/privilege.py +259 -0
  231. fim/provision/probe.py +117 -0
  232. fim/provision/release.py +188 -0
  233. fim/provision/sdk.py +102 -0
  234. fim/provision/steps.py +324 -0
  235. fim/provision/switch.py +80 -0
  236. fim/provision/switch_recovery.py +165 -0
  237. fim/remote/__init__.py +15 -0
  238. fim/remote/access/__init__.py +203 -0
  239. fim/remote/access/credential.py +46 -0
  240. fim/remote/access/credentials/__init__.py +4 -0
  241. fim/remote/access/credentials/command.py +50 -0
  242. fim/remote/access/credentials/keychain.py +50 -0
  243. fim/remote/access/credentials/none.py +16 -0
  244. fim/remote/access/credentials/peer.py +25 -0
  245. fim/remote/access/credentials/token.py +50 -0
  246. fim/remote/access/spec.py +34 -0
  247. fim/remote/access/transport.py +66 -0
  248. fim/remote/access/transports/__init__.py +4 -0
  249. fim/remote/access/transports/command.py +222 -0
  250. fim/remote/access/transports/direct.py +39 -0
  251. fim/remote/access/transports/ssh_tunnel.py +74 -0
  252. fim/remote/api.py +245 -0
  253. fim/remote/commands.py +625 -0
  254. fim/remote/fetch.py +155 -0
  255. fim/remote/follow.py +157 -0
  256. fim/remote/journal.py +150 -0
  257. fim/remote/location.py +108 -0
  258. fim/remote/preflight.py +350 -0
  259. fim/remote/servers.py +159 -0
  260. fim/remote/snapshot.py +249 -0
  261. fim/remote/submit.py +302 -0
  262. fim/scripts/__init__.py +2 -0
  263. fim/scripts/generate_report.py +108 -0
  264. fim/scripts/run_campaign.py +1447 -0
  265. fim/scripts/run_ecc_quartet.py +94 -0
  266. fim/scripts/run_golden.py +2256 -0
  267. fim/scripts/verify_provenance.py +61 -0
  268. fim/utils/__init__.py +74 -0
  269. fim/utils/board.py +378 -0
  270. fim/utils/board_view.py +39 -0
  271. fim/utils/config.py +1714 -0
  272. fim/utils/coredump.py +28 -0
  273. fim/utils/elf_parser.py +1118 -0
  274. fim/utils/elf_provenance.py +140 -0
  275. fim/utils/injection_file_writer.py +309 -0
  276. fim/utils/logger.py +362 -0
  277. fim/utils/picker.py +195 -0
  278. fim/utils/prng.py +207 -0
  279. fim/utils/provenance.py +873 -0
  280. fim/utils/register_width.py +52 -0
  281. hfim_cli-1.15.6.data/data/share/hfim/gem5_to_mcpat.py +508 -0
  282. hfim_cli-1.15.6.dist-info/METADATA +131 -0
  283. hfim_cli-1.15.6.dist-info/RECORD +288 -0
  284. hfim_cli-1.15.6.dist-info/WHEEL +5 -0
  285. hfim_cli-1.15.6.dist-info/entry_points.txt +2 -0
  286. hfim_cli-1.15.6.dist-info/licenses/LICENSE +21 -0
  287. hfim_cli-1.15.6.dist-info/licenses/THIRD_PARTY_NOTICES +166 -0
  288. hfim_cli-1.15.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,712 @@
1
+ # SPDX-FileCopyrightText: 2026 HI-REST and the HFIM contributors
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """
5
+ Results Reporter for FIM campaigns.
6
+
7
+ This module generates human-readable HTML reports from fault injection campaign
8
+ results. It uses Jinja2 templates for flexible report generation with
9
+ visualization of outcome distributions and detailed statistics.
10
+ """
11
+
12
+ import csv
13
+ import json
14
+ import os
15
+
16
+ from fim.analysis.classifier import REPORT_OUTCOME_ORDER
17
+ from datetime import datetime
18
+ from pathlib import Path
19
+ from typing import Dict, List, Any, Optional
20
+
21
+ try:
22
+ from jinja2 import Template, Environment, BaseLoader
23
+ except ImportError:
24
+ raise ImportError(
25
+ "jinja2 is required for report generation. "
26
+ "Install with: pip install jinja2"
27
+ )
28
+
29
+ from fim.utils.logger import get_logger
30
+
31
+
32
+ # Constants
33
+ DEFAULT_RESULTS_DIR = "results"
34
+
35
+
36
+ class ReporterError(Exception):
37
+ """Exception raised during report generation."""
38
+ pass
39
+
40
+
41
+ class CampaignReporter:
42
+ """
43
+ Generates HTML reports from fault injection campaign results.
44
+
45
+ The reporter loads campaign results from CSV and metadata JSON files,
46
+ calculates statistics, and generates an HTML report with outcome
47
+ visualization and detailed analysis.
48
+
49
+ Attributes:
50
+ campaign_id: Unique identifier for the campaign.
51
+ results_dir: Directory containing campaign results.
52
+ logger: Logger instance for reporting progress.
53
+ """
54
+
55
+ def __init__(self, campaign_id: str, results_dir: str = DEFAULT_RESULTS_DIR):
56
+ """
57
+ Initialize campaign reporter.
58
+
59
+ Args:
60
+ campaign_id: Campaign identifier (directory name in results/).
61
+ results_dir: Base directory containing results (default: "results").
62
+
63
+ Raises:
64
+ ReporterError: If campaign results directory doesn't exist.
65
+ """
66
+ self.campaign_id = campaign_id
67
+ self.results_dir = results_dir
68
+ self.campaign_dir = os.path.join(results_dir, campaign_id)
69
+ self.logger = get_logger(f"fim.reporter.{campaign_id}")
70
+
71
+ # Validate campaign directory exists
72
+ if not os.path.exists(self.campaign_dir):
73
+ raise ReporterError(
74
+ f"Campaign results not found: {self.campaign_dir}"
75
+ )
76
+
77
+ # Paths to campaign files
78
+ self.injections_csv = os.path.join(self.campaign_dir, "injections.csv")
79
+ self.metadata_json = os.path.join(self.campaign_dir, "metadata.json")
80
+ self.report_html = os.path.join(self.campaign_dir, "report.html")
81
+
82
+ # Data loaded from files
83
+ self.metadata: Optional[Dict[str, Any]] = None
84
+ self.injections: List[Dict[str, Any]] = []
85
+ self.statistics: Optional[Dict[str, Any]] = None
86
+
87
+ def generate_report(self) -> str:
88
+ """
89
+ Generate HTML report from campaign results.
90
+
91
+ Returns:
92
+ Path to generated HTML report file.
93
+
94
+ Raises:
95
+ ReporterError: If report generation fails.
96
+ """
97
+ self.logger.info("=" * 80)
98
+ self.logger.info(f"GENERATING REPORT FOR CAMPAIGN: {self.campaign_id}")
99
+ self.logger.info("=" * 80)
100
+
101
+ try:
102
+ # Load campaign data
103
+ self._load_metadata()
104
+ self._load_injections()
105
+
106
+ # Extract statistics from metadata
107
+ self.statistics = self.metadata.get('statistics', {})
108
+
109
+ # Generate HTML report
110
+ html_content = self._render_html()
111
+
112
+ # Save report to file
113
+ with open(self.report_html, 'w', encoding='utf-8') as f:
114
+ f.write(html_content)
115
+
116
+ self.logger.info(f"Report generated: {self.report_html}")
117
+ self.logger.info("=" * 80)
118
+
119
+ return self.report_html
120
+
121
+ except Exception as e:
122
+ raise ReporterError(f"Failed to generate report: {e}")
123
+
124
+ def _load_metadata(self) -> None:
125
+ """
126
+ Load campaign metadata from JSON file.
127
+
128
+ Raises:
129
+ ReporterError: If metadata file doesn't exist or is invalid.
130
+ """
131
+ if not os.path.exists(self.metadata_json):
132
+ raise ReporterError(f"Metadata file not found: {self.metadata_json}")
133
+
134
+ try:
135
+ with open(self.metadata_json, 'r') as f:
136
+ self.metadata = json.load(f)
137
+ self.logger.debug(f"Loaded metadata from: {self.metadata_json}")
138
+ except json.JSONDecodeError as e:
139
+ raise ReporterError(f"Invalid JSON in metadata file: {e}")
140
+ except Exception as e:
141
+ raise ReporterError(f"Failed to load metadata: {e}")
142
+
143
+ def _load_injections(self) -> None:
144
+ """
145
+ Load injection results from CSV file.
146
+
147
+ Raises:
148
+ ReporterError: If CSV file doesn't exist or is invalid.
149
+ """
150
+ if not os.path.exists(self.injections_csv):
151
+ raise ReporterError(f"Injections CSV not found: {self.injections_csv}")
152
+
153
+ try:
154
+ with open(self.injections_csv, 'r', newline='') as f:
155
+ reader = csv.DictReader(f)
156
+ self.injections = list(reader)
157
+ self.logger.debug(f"Loaded {len(self.injections)} injections from CSV")
158
+ except Exception as e:
159
+ raise ReporterError(f"Failed to load injections CSV: {e}")
160
+
161
+ def _get_top_sdc_injections(self, limit: int = 10) -> List[Dict[str, Any]]:
162
+ """
163
+ Get top injection points that caused SDC (Silent Data Corruption).
164
+
165
+ Args:
166
+ limit: Maximum number of injections to return.
167
+
168
+ Returns:
169
+ List of injection dictionaries with SDC outcomes.
170
+ """
171
+ sdc_injections = [
172
+ inj for inj in self.injections
173
+ if inj.get('outcome', '').lower() == 'sdc'
174
+ ]
175
+
176
+ # Sort by instruction count (earliest injections first)
177
+ sdc_injections.sort(key=lambda x: int(x.get('instruction_count', 0)))
178
+
179
+ return sdc_injections[:limit]
180
+
181
+ def _get_outcome_data_for_chart(self) -> Dict[str, List]:
182
+ """
183
+ Prepare outcome data for pie chart visualization.
184
+
185
+ Returns:
186
+ Dictionary with labels, values, and colors for chart (all as lists).
187
+ """
188
+ # Outcome colors (matching standard severity levels)
189
+ outcome_colors = {
190
+ 'masked': '#28a745', # Green - good (fault had no effect)
191
+ 'detected': '#ffc107', # Yellow - acceptable (detected by DMR)
192
+ 'sdc': '#dc3545', # Red - critical (silent corruption)
193
+ 'crash': '#fd7e14', # Orange - serious (system failure)
194
+ 'timeout': '#6c757d', # Gray - inconclusive
195
+ 'unknown': '#e9ecef', # Light gray - unclassified
196
+ }
197
+
198
+ labels: List[str] = []
199
+ values: List[int] = []
200
+ colors: List[str] = []
201
+
202
+ # Order outcomes by criticality
203
+ outcome_order = list(REPORT_OUTCOME_ORDER)
204
+
205
+ for outcome in outcome_order:
206
+ outcome_stats = self.statistics.get(outcome, {})
207
+ count = outcome_stats.get('count', 0)
208
+ if count > 0: # Only include outcomes that occurred
209
+ labels.append(outcome.upper())
210
+ values.append(count)
211
+ colors.append(outcome_colors.get(outcome, '#6c757d'))
212
+
213
+ return {
214
+ 'labels': labels,
215
+ 'values': values,
216
+ 'colors': colors,
217
+ }
218
+
219
+ def _render_html(self) -> str:
220
+ """
221
+ Render HTML report using Jinja2 template.
222
+
223
+ Returns:
224
+ HTML content as string.
225
+ """
226
+ template_str = self._get_html_template()
227
+ template = Template(template_str)
228
+
229
+ # Prepare data for template
230
+ chart_data = self._get_outcome_data_for_chart()
231
+ top_sdc = self._get_top_sdc_injections(limit=10)
232
+
233
+ # Calculate derived metrics
234
+ total = self.statistics.get('total', 0)
235
+ dmr_effectiveness = self.statistics.get('dmr_effectiveness', 0.0)
236
+
237
+ # Format timestamps
238
+ report_timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
239
+ campaign_completed = self.metadata.get('completed_at', 'Unknown')
240
+
241
+ # Convert statistics to JSON-serializable dict
242
+ # (Sometimes stats contain dict_values objects that aren't JSON serializable)
243
+ stats_dict = {}
244
+ for key, value in self.statistics.items():
245
+ if isinstance(value, dict):
246
+ stats_dict[key] = dict(value)
247
+ else:
248
+ stats_dict[key] = value
249
+
250
+ # Pre-serialize chart data as JSON strings for JavaScript
251
+ import json
252
+ chart_labels_json = json.dumps(chart_data['labels'])
253
+ chart_values_json = json.dumps(chart_data['values'])
254
+ chart_colors_json = json.dumps(chart_data['colors'])
255
+
256
+ # Render template
257
+ html = template.render(
258
+ campaign_id=self.campaign_id,
259
+ benchmark=self.metadata.get('benchmark', 'Unknown'),
260
+ seed=self.metadata.get('seed', 0),
261
+ fault_model=self.metadata.get('fault_model', 'Unknown'),
262
+ total_injections=total,
263
+ detection_string=self.metadata.get('detection_string', 'None'),
264
+ config_path=self.metadata.get('config_path', 'Unknown'),
265
+ target_types=', '.join(self.metadata.get('target_types', [])),
266
+ completed_at=campaign_completed,
267
+ report_timestamp=report_timestamp,
268
+ statistics=stats_dict,
269
+ chart_labels_json=chart_labels_json,
270
+ chart_values_json=chart_values_json,
271
+ chart_colors_json=chart_colors_json,
272
+ top_sdc=top_sdc,
273
+ dmr_effectiveness=dmr_effectiveness,
274
+ )
275
+
276
+ return html
277
+
278
+ def _get_html_template(self) -> str:
279
+ """
280
+ Get HTML template string for report generation.
281
+
282
+ Returns:
283
+ HTML template with Jinja2 placeholders.
284
+ """
285
+ return """<!DOCTYPE html>
286
+ <html lang="en">
287
+ <head>
288
+ <meta charset="UTF-8">
289
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
290
+ <title>FIM Campaign Report - {{ campaign_id }}</title>
291
+ <style>
292
+ * {
293
+ margin: 0;
294
+ padding: 0;
295
+ box-sizing: border-box;
296
+ }
297
+ body {
298
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
299
+ line-height: 1.6;
300
+ color: #333;
301
+ background: #f5f5f5;
302
+ padding: 20px;
303
+ }
304
+ .container {
305
+ max-width: 1200px;
306
+ margin: 0 auto;
307
+ background: white;
308
+ padding: 30px;
309
+ border-radius: 8px;
310
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
311
+ }
312
+ header {
313
+ border-bottom: 3px solid #007bff;
314
+ padding-bottom: 20px;
315
+ margin-bottom: 30px;
316
+ }
317
+ h1 {
318
+ color: #007bff;
319
+ font-size: 2.5em;
320
+ margin-bottom: 10px;
321
+ }
322
+ h2 {
323
+ color: #495057;
324
+ font-size: 1.8em;
325
+ margin-top: 30px;
326
+ margin-bottom: 15px;
327
+ border-bottom: 2px solid #e9ecef;
328
+ padding-bottom: 10px;
329
+ }
330
+ h3 {
331
+ color: #6c757d;
332
+ font-size: 1.3em;
333
+ margin-top: 20px;
334
+ margin-bottom: 10px;
335
+ }
336
+ .meta-grid {
337
+ display: grid;
338
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
339
+ gap: 15px;
340
+ margin-bottom: 30px;
341
+ }
342
+ .meta-item {
343
+ background: #f8f9fa;
344
+ padding: 15px;
345
+ border-radius: 5px;
346
+ border-left: 4px solid #007bff;
347
+ }
348
+ .meta-label {
349
+ font-weight: bold;
350
+ color: #6c757d;
351
+ font-size: 0.9em;
352
+ text-transform: uppercase;
353
+ margin-bottom: 5px;
354
+ }
355
+ .meta-value {
356
+ color: #212529;
357
+ font-size: 1.1em;
358
+ }
359
+ .stats-grid {
360
+ display: grid;
361
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
362
+ gap: 15px;
363
+ margin-bottom: 30px;
364
+ }
365
+ .stat-card {
366
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
367
+ color: white;
368
+ padding: 20px;
369
+ border-radius: 8px;
370
+ text-align: center;
371
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
372
+ }
373
+ .stat-card.masked { background: linear-gradient(135deg, #28a745 0%, #20c997 100%); }
374
+ .stat-card.detected { background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%); }
375
+ .stat-card.sdc { background: linear-gradient(135deg, #dc3545 0%, #c82333 100%); }
376
+ .stat-card.crash { background: linear-gradient(135deg, #fd7e14 0%, #e83e8c 100%); }
377
+ .stat-card.timeout { background: linear-gradient(135deg, #6c757d 0%, #495057 100%); }
378
+ .stat-value {
379
+ font-size: 2.5em;
380
+ font-weight: bold;
381
+ margin-bottom: 5px;
382
+ }
383
+ .stat-label {
384
+ font-size: 0.9em;
385
+ opacity: 0.9;
386
+ text-transform: uppercase;
387
+ }
388
+ .stat-percentage {
389
+ font-size: 1.1em;
390
+ margin-top: 5px;
391
+ }
392
+ .chart-container {
393
+ margin: 30px 0;
394
+ text-align: center;
395
+ }
396
+ .chart-wrapper {
397
+ display: inline-block;
398
+ max-width: 600px;
399
+ width: 100%;
400
+ }
401
+ canvas {
402
+ max-width: 100%;
403
+ height: auto;
404
+ }
405
+ table {
406
+ width: 100%;
407
+ border-collapse: collapse;
408
+ margin-top: 15px;
409
+ font-size: 0.9em;
410
+ }
411
+ th, td {
412
+ text-align: left;
413
+ padding: 12px;
414
+ border-bottom: 1px solid #dee2e6;
415
+ }
416
+ th {
417
+ background: #f8f9fa;
418
+ font-weight: bold;
419
+ color: #495057;
420
+ text-transform: uppercase;
421
+ font-size: 0.85em;
422
+ }
423
+ tr:hover {
424
+ background: #f8f9fa;
425
+ }
426
+ .outcome-badge {
427
+ display: inline-block;
428
+ padding: 4px 8px;
429
+ border-radius: 3px;
430
+ font-size: 0.85em;
431
+ font-weight: bold;
432
+ text-transform: uppercase;
433
+ }
434
+ .outcome-sdc { background: #dc3545; color: white; }
435
+ .outcome-crash { background: #fd7e14; color: white; }
436
+ .outcome-detected { background: #ffc107; color: #212529; }
437
+ .outcome-masked { background: #28a745; color: white; }
438
+ .outcome-timeout { background: #6c757d; color: white; }
439
+ .dmr-effectiveness {
440
+ background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
441
+ color: white;
442
+ padding: 25px;
443
+ border-radius: 8px;
444
+ text-align: center;
445
+ margin: 20px 0;
446
+ }
447
+ .dmr-value {
448
+ font-size: 3em;
449
+ font-weight: bold;
450
+ }
451
+ .dmr-label {
452
+ font-size: 1.2em;
453
+ margin-top: 10px;
454
+ }
455
+ .no-data {
456
+ text-align: center;
457
+ color: #6c757d;
458
+ padding: 40px;
459
+ background: #f8f9fa;
460
+ border-radius: 5px;
461
+ }
462
+ footer {
463
+ margin-top: 50px;
464
+ padding-top: 20px;
465
+ border-top: 2px solid #e9ecef;
466
+ text-align: center;
467
+ color: #6c757d;
468
+ font-size: 0.9em;
469
+ }
470
+ .code {
471
+ font-family: 'Courier New', monospace;
472
+ background: #f8f9fa;
473
+ padding: 2px 6px;
474
+ border-radius: 3px;
475
+ font-size: 0.9em;
476
+ }
477
+ </style>
478
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
479
+ </head>
480
+ <body>
481
+ <div class="container">
482
+ <header>
483
+ <h1>Fault Injection Campaign Report</h1>
484
+ <p style="color: #6c757d; font-size: 1.1em; margin-top: 10px;">
485
+ Campaign ID: <span class="code">{{ campaign_id }}</span>
486
+ </p>
487
+ </header>
488
+
489
+ <section>
490
+ <h2>Campaign Configuration</h2>
491
+ <div class="meta-grid">
492
+ <div class="meta-item">
493
+ <div class="meta-label">Benchmark</div>
494
+ <div class="meta-value">{{ benchmark }}</div>
495
+ </div>
496
+ <div class="meta-item">
497
+ <div class="meta-label">Fault Model</div>
498
+ <div class="meta-value">{{ fault_model }}</div>
499
+ </div>
500
+ <div class="meta-item">
501
+ <div class="meta-label">PRNG Seed</div>
502
+ <div class="meta-value">{{ seed }}</div>
503
+ </div>
504
+ <div class="meta-item">
505
+ <div class="meta-label">Total Injections</div>
506
+ <div class="meta-value">{{ total_injections }}</div>
507
+ </div>
508
+ <div class="meta-item">
509
+ <div class="meta-label">Target Types</div>
510
+ <div class="meta-value">{{ target_types }}</div>
511
+ </div>
512
+ <div class="meta-item">
513
+ <div class="meta-label">Detection String</div>
514
+ <div class="meta-value">{{ detection_string if detection_string else 'None' }}</div>
515
+ </div>
516
+ <div class="meta-item">
517
+ <div class="meta-label">Completed At</div>
518
+ <div class="meta-value">{{ completed_at }}</div>
519
+ </div>
520
+ <div class="meta-item">
521
+ <div class="meta-label">Config File</div>
522
+ <div class="meta-value code" style="font-size: 0.85em; word-break: break-all;">{{ config_path }}</div>
523
+ </div>
524
+ </div>
525
+ </section>
526
+
527
+ <section>
528
+ <h2>Results Summary</h2>
529
+
530
+ {% if statistics and statistics.total > 0 %}
531
+
532
+ <div class="stats-grid">
533
+ {% if statistics.masked.count > 0 %}
534
+ <div class="stat-card masked">
535
+ <div class="stat-value">{{ statistics.masked.count }}</div>
536
+ <div class="stat-label">Masked</div>
537
+ <div class="stat-percentage">{{ "%.1f"|format(statistics.masked.percentage) }}%</div>
538
+ </div>
539
+ {% endif %}
540
+
541
+ {% if statistics.detected.count > 0 %}
542
+ <div class="stat-card detected">
543
+ <div class="stat-value">{{ statistics.detected.count }}</div>
544
+ <div class="stat-label">Detected</div>
545
+ <div class="stat-percentage">{{ "%.1f"|format(statistics.detected.percentage) }}%</div>
546
+ </div>
547
+ {% endif %}
548
+
549
+ {% if statistics.sdc.count > 0 %}
550
+ <div class="stat-card sdc">
551
+ <div class="stat-value">{{ statistics.sdc.count }}</div>
552
+ <div class="stat-label">SDC</div>
553
+ <div class="stat-percentage">{{ "%.1f"|format(statistics.sdc.percentage) }}%</div>
554
+ </div>
555
+ {% endif %}
556
+
557
+ {% if statistics.crash.count > 0 %}
558
+ <div class="stat-card crash">
559
+ <div class="stat-value">{{ statistics.crash.count }}</div>
560
+ <div class="stat-label">Crash</div>
561
+ <div class="stat-percentage">{{ "%.1f"|format(statistics.crash.percentage) }}%</div>
562
+ </div>
563
+ {% endif %}
564
+
565
+ {% if statistics.timeout.count > 0 %}
566
+ <div class="stat-card timeout">
567
+ <div class="stat-value">{{ statistics.timeout.count }}</div>
568
+ <div class="stat-label">Timeout</div>
569
+ <div class="stat-percentage">{{ "%.1f"|format(statistics.timeout.percentage) }}%</div>
570
+ </div>
571
+ {% endif %}
572
+ </div>
573
+
574
+ {% if dmr_effectiveness > 0 %}
575
+ <div class="dmr-effectiveness">
576
+ <div class="dmr-value">{{ "%.1f"|format(dmr_effectiveness) }}%</div>
577
+ <div class="dmr-label">DMR Effectiveness</div>
578
+ <div style="margin-top: 10px; opacity: 0.9; font-size: 0.9em;">
579
+ Fault detection rate: DETECTED / (DETECTED + SDC + CRASH)
580
+ </div>
581
+ </div>
582
+ {% endif %}
583
+
584
+ <div class="chart-container">
585
+ <h3>Outcome Distribution</h3>
586
+ <div class="chart-wrapper">
587
+ <canvas id="outcomeChart"></canvas>
588
+ </div>
589
+ </div>
590
+
591
+ {% else %}
592
+ <div class="no-data">No injection results available</div>
593
+ {% endif %}
594
+ </section>
595
+
596
+ {% if top_sdc %}
597
+ <section>
598
+ <h2>Top SDC-Causing Injections</h2>
599
+ <p style="color: #6c757d; margin-bottom: 15px;">
600
+ Silent Data Corruption (SDC) injections that produced incorrect output without detection:
601
+ </p>
602
+ <table>
603
+ <thead>
604
+ <tr>
605
+ <th>ID</th>
606
+ <th>Instruction</th>
607
+ <th>Target</th>
608
+ <th>Target Name</th>
609
+ <th>Original Value</th>
610
+ <th>Faulty Value</th>
611
+ <th>Bit Position</th>
612
+ <th>State Match</th>
613
+ </tr>
614
+ </thead>
615
+ <tbody>
616
+ {% for inj in top_sdc %}
617
+ <tr>
618
+ <td>{{ inj.injection_id }}</td>
619
+ <td>{{ inj.instruction_count }}</td>
620
+ <td>{{ inj.target_type }}</td>
621
+ <td class="code">{{ inj.target_name }}</td>
622
+ <td class="code">{{ inj.original_value }}</td>
623
+ <td class="code">{{ inj.faulty_value }}</td>
624
+ <td>{{ inj.bit_position }}</td>
625
+ <td>{% if inj.state_match is not none %}{{ 'Yes' if inj.state_match else 'No' }}{% else %}-{% endif %}</td>
626
+ </tr>
627
+ {% endfor %}
628
+ </tbody>
629
+ </table>
630
+ </section>
631
+ {% endif %}
632
+
633
+ <footer>
634
+ <p>Generated by FIM (Fault Injection Manager) on {{ report_timestamp }}</p>
635
+ <p style="margin-top: 5px;">RISC-V C906 QEMU Simulation Framework</p>
636
+ </footer>
637
+ </div>
638
+
639
+ <script>
640
+ // Render pie chart for outcome distribution
641
+ {% if statistics and statistics.total > 0 %}
642
+ const ctx = document.getElementById('outcomeChart').getContext('2d');
643
+ const chartLabels = {{ chart_labels_json | safe }};
644
+ const chartValues = {{ chart_values_json | safe }};
645
+ const chartColors = {{ chart_colors_json | safe }};
646
+
647
+ new Chart(ctx, {
648
+ type: 'pie',
649
+ data: {
650
+ labels: chartLabels,
651
+ datasets: [{
652
+ data: chartValues,
653
+ backgroundColor: chartColors,
654
+ borderWidth: 2,
655
+ borderColor: '#fff'
656
+ }]
657
+ },
658
+ options: {
659
+ responsive: true,
660
+ maintainAspectRatio: true,
661
+ plugins: {
662
+ legend: {
663
+ position: 'bottom',
664
+ labels: {
665
+ padding: 15,
666
+ font: {
667
+ size: 14
668
+ }
669
+ }
670
+ },
671
+ tooltip: {
672
+ callbacks: {
673
+ label: function(context) {
674
+ const label = context.label || '';
675
+ const value = context.parsed || 0;
676
+ const total = context.dataset.data.reduce((a, b) => a + b, 0);
677
+ const percentage = ((value / total) * 100).toFixed(1);
678
+ return label + ': ' + value + ' (' + percentage + '%)';
679
+ }
680
+ }
681
+ }
682
+ }
683
+ }
684
+ });
685
+ {% endif %}
686
+ </script>
687
+ </body>
688
+ </html>
689
+ """
690
+
691
+
692
+ def generate_report(campaign_id: str, results_dir: str = DEFAULT_RESULTS_DIR) -> str:
693
+ """
694
+ Convenience function to generate report for a campaign.
695
+
696
+ Args:
697
+ campaign_id: Campaign identifier (directory name in results/).
698
+ results_dir: Base directory containing results (default: "results").
699
+
700
+ Returns:
701
+ Path to generated HTML report file.
702
+
703
+ Raises:
704
+ ReporterError: If report generation fails.
705
+
706
+ Example:
707
+ >>> report_path = generate_report("quicksort_dmr_20260203_143022_123456")
708
+ >>> print(f"Report: {report_path}")
709
+ Report: results/quicksort_dmr_20260203_143022_123456/report.html
710
+ """
711
+ reporter = CampaignReporter(campaign_id, results_dir)
712
+ return reporter.generate_report()