Просмотр исходного кода

Fix temp collector manual SRAM argument

Codex 4 месяцев назад
Родитель
Сommit
3e960f5f65

+ 31 - 1
tests/unit/test_remote_scripts.py

@@ -147,6 +147,34 @@ class RemoteScriptTests(unittest.TestCase):
         ]:
             self.assertIn(marker, output)
 
+    def test_collect_j6_host_sensor_real_fan_ptc_accepts_native_bool_argument_shape(self) -> None:
+        powershell = shutil.which("powershell")
+        if powershell is None:
+            self.skipTest("PowerShell is not available")
+
+        script_path = ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1"
+        result = subprocess.run(
+            [
+                powershell,
+                "-NoProfile",
+                "-ExecutionPolicy",
+                "Bypass",
+                "-File",
+                str(script_path),
+                "-SelfTest",
+                "-AssumeManualSramProgrammed",
+                "$true",
+            ],
+            cwd=ROOT,
+            text=True,
+            capture_output=True,
+            check=False,
+        )
+
+        output = result.stderr + result.stdout
+        self.assertEqual(result.returncode, 0, output)
+        self.assertIn("selftest=pass", output)
+
     def test_collect_j6_host_sensor_real_fan_ptc_handles_discarded_ack_arrays(self) -> None:
         powershell = shutil.which("powershell")
         if powershell is None:
@@ -440,11 +468,11 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
             "SET PTC 24 20",
             "SET FAN 01 40",
             "SET FAN 04 30",
-            "-AssumeManualSramProgrammed $true",
             "excluded_self_referential_file",
         ]:
             self.assertIn(marker, script)
         self.assertNotIn("Set-ExecutionPolicy", script)
+        self.assertNotIn("-AssumeManualSramProgrammed $true", script)
         for marker in [
             "formal-uart",
             "j6-host-sensor-real-fan-ptc-formal-uart-debug921-v1",
@@ -536,10 +564,12 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
                     self.assertIn("powershell.exe -NoProfile -ExecutionPolicy Bypass -File", start_here)
                     self.assertIn("-HostPort COM8 -DebugPort COM7", start_here)
                     self.assertNotIn("Set-ExecutionPolicy", start_here)
+                    self.assertNotIn("-AssumeManualSramProgrammed", start_here)
                     collect_template = (stage / "commands" / "collect-template.ps1").read_text(
                         encoding="utf-8-sig"
                     )
                     self.assertNotIn("Set-ExecutionPolicy", collect_template)
+                    self.assertNotIn("-AssumeManualSramProgrammed", collect_template)
                     self.assertIn("-NoProfile", collect_template)
                     self.assertIn("-ExecutionPolicy Bypass", collect_template)
                     self.assertIn("-File .\\collector\\collect-j6-host-sensor-real-fan-ptc.ps1", collect_template)

+ 3 - 3
tools/package_j6_host_sensor_real_fan_ptc_debug921.ps1

@@ -15,7 +15,7 @@ $ErrorActionPreference = "Stop"
 # Package profile:
 # temp-uart-ptc-remap -> j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2
 # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
-# The run template includes -AssumeManualSramProgrammed $true.
+# The collector defaults to assuming the operator already ran PROGRAM_SRAM.
 
 function Get-Sha256([string]$Path) {
     if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
@@ -107,7 +107,7 @@ bitstreams/$BitName
 确认 SRAM 下载完成后,在本包根目录打开 PowerShell,复制执行下面这一条命令:
 
 ~~~powershell
-powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\bitstreams\$BitName -TdReceipt .\td-receipts\$TdName -AssumeManualSramProgrammed `$true
+powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\bitstreams\$BitName -TdReceipt .\td-receipts\$TdName
 ~~~
 
 也可以执行包内快捷脚本:
@@ -166,7 +166,7 @@ Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
 $bitName = Split-Path -Leaf $bitstreamCopy
 $tdName = Split-Path -Leaf $tdReceiptCopy
 $template = @'
-& "$PSHOME\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile __PROFILE__ -Bitstream .\bitstreams\__BITSTREAM__ -TdReceipt .\td-receipts\__TD_RECEIPT__ -AssumeManualSramProgrammed $true
+& "$PSHOME\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile __PROFILE__ -Bitstream .\bitstreams\__BITSTREAM__ -TdReceipt .\td-receipts\__TD_RECEIPT__
 '@
 $template = $template.Replace("__PROFILE__", $Profile).Replace("__BITSTREAM__", $bitName).Replace("__TD_RECEIPT__", $tdName)
 Set-Content -LiteralPath (Join-Path $stage "commands\collect-template.ps1") -Encoding UTF8 -Value $template

+ 26 - 3
tools/remote/collect-j6-host-sensor-real-fan-ptc.ps1

@@ -18,7 +18,7 @@
     [ValidateSet("temp-uart-ptc-remap")]
     [string]$Profile = "temp-uart-ptc-remap",
     [string]$Operator = "",
-    [bool]$AssumeManualSramProgrammed = $true,
+    [object]$AssumeManualSramProgrammed = $true,
     [switch]$SelfTest,
     [string[]]$Commands = @(
         "SET PTC 01 10",
@@ -38,6 +38,29 @@
 
 $ErrorActionPreference = "Stop"
 
+function Convert-ToBooleanParameter([object]$Value, [string]$Name) {
+    if ($null -eq $Value) {
+        return $false
+    }
+    if ($Value -is [bool]) {
+        return [bool]$Value
+    }
+    if ($Value -is [int] -or $Value -is [long]) {
+        if ([int64]$Value -eq 1) { return $true }
+        if ([int64]$Value -eq 0) { return $false }
+    }
+    $text = ([string]$Value).Trim()
+    if ($text -in @('$true', 'true', 'True', 'TRUE', '1')) {
+        return $true
+    }
+    if ($text -in @('$false', 'false', 'False', 'FALSE', '0')) {
+        return $false
+    }
+    throw "$Name must be true/false/1/0"
+}
+
+$assumeManualSramProgrammedBool = Convert-ToBooleanParameter $AssumeManualSramProgrammed "AssumeManualSramProgrammed"
+
 # Static operator contract: HostPort BaudRate = 115200, DebugBaud = 921600.
 # HostPort carries allowlisted 1-based real FAN/PTC control commands and SENS/DIMM/STAT/PWM/PID reports.
 # DebugPort is read-only and carries J6CMD/J6RAW/J6EVT/J6PWM/J6MOD/J6STAT/J6MAP/J6TEMP evidence.
@@ -976,7 +999,7 @@ $tdReceiptRef = if ($tdReceiptPath) { New-ArtifactRef $tdReceiptPath $out } else
 $manualSramArtifactPath = Join-Path $artifactDir "manual-sram-attestation.json"
 [ordered]@{
     schema = "manual-sram-attestation-v1"
-    status = if ($AssumeManualSramProgrammed) { "pass" } else { "blocked_operator_assertion_missing" }
+    status = if ($assumeManualSramProgrammedBool) { "pass" } else { "blocked_operator_assertion_missing" }
     mode = "PROGRAM_SRAM"
     source = "operator_assertion_from_runbook"
     operator = $manualSramOperator
@@ -1047,7 +1070,7 @@ $manifest = [ordered]@{
 Write-JsonFile $manifest $manifestPath
 $manifestHash = Get-Sha256 $manifestPath
 
-$manualReady = ($AssumeManualSramProgrammed -and $manualSramOperator -and $manualSramProgrammedAt -and $manualSramBitstreamSha256 -and $manualSramTdReceiptSha256)
+$manualReady = ($assumeManualSramProgrammedBool -and $manualSramOperator -and $manualSramProgrammedAt -and $manualSramBitstreamSha256 -and $manualSramTdReceiptSha256)
 $receiptStatus = if ($captureStatus -ne "pass") {
     $captureStatus
 } elseif (-not $bitstreamPath) {