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

Fix collector command token parsing

Codex 5 месяцев назад
Родитель
Сommit
94e1596bc4
2 измененных файлов с 46 добавлено и 2 удалено
  1. 41 0
      tests/unit/test_remote_scripts.py
  2. 5 2
      tools/remote/collect-j6-host-sensor-real-fan-ptc.ps1

+ 41 - 0
tests/unit/test_remote_scripts.py

@@ -206,6 +206,47 @@ if ([int64]$events[2].fields.sum -ne 255) { throw "sum was $($events[2].fields.s
 
 
             self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
             self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
 
 
+    def test_collect_j6_host_sensor_real_fan_ptc_keeps_command_tokens_as_strings(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"
+        script = script_path.read_text(encoding="utf-8")
+        helper_start = script.index("function Convert-TokenValue")
+        helper_end = script.index("function Convert-BytesToEscapedText")
+        helpers = script[helper_start:helper_end]
+
+        with tempfile.TemporaryDirectory() as tmp:
+            probe_path = Path(tmp) / "probe.ps1"
+            probe_path.write_text(
+                helpers
+                + """
+$events = New-Object System.Collections.Generic.List[object]
+$events.Add((Convert-FrameLine "J6CMD seq=00000001 cmd=raw text=ipmitool" @("J6CMD"))) | Out-Null
+$events.Add((Convert-FrameLine "J6EVT seq=00000002 ok=1 err=0 type=PTCCH ch=01 pct=0A" @("J6EVT"))) | Out-Null
+$events.Add((Convert-FrameLine "OK seq=00000003 cmd=FANCH" @("OK"))) | Out-Null
+
+if ($events[0].fields.cmd -ne "raw") { throw "cmd was $($events[0].fields.cmd)" }
+if ($events[1].fields.type -ne "PTCCH") { throw "type was $($events[1].fields.type)" }
+if ($events[1].fields.ch.GetType().FullName -ne "System.Int64") { throw "ch type was $($events[1].fields.ch.GetType().FullName)" }
+if ([int64]$events[1].fields.ch -ne 1) { throw "ch was $($events[1].fields.ch)" }
+if ([int64]$events[1].fields.pct -ne 10) { throw "pct was $($events[1].fields.pct)" }
+if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.cmd)" }
+""",
+                encoding="utf-8",
+            )
+
+            result = subprocess.run(
+                [powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(probe_path)],
+                cwd=ROOT,
+                text=True,
+                capture_output=True,
+                check=False,
+            )
+
+            self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
+
     def test_j6_host_sensor_real_fan_ptc_package_script_creates_two_executable_profile_packages(self) -> None:
     def test_j6_host_sensor_real_fan_ptc_package_script_creates_two_executable_profile_packages(self) -> None:
         script = (ROOT / "tools" / "package_j6_host_sensor_real_fan_ptc_debug921.ps1").read_text(
         script = (ROOT / "tools" / "package_j6_host_sensor_real_fan_ptc_debug921.ps1").read_text(
             encoding="utf-8"
             encoding="utf-8"

+ 5 - 2
tools/remote/collect-j6-host-sensor-real-fan-ptc.ps1

@@ -148,12 +148,15 @@ function New-ArtifactRef([string]$Path, [string]$BaseDir) {
 }
 }
 
 
 function Convert-TokenValue([string]$Key, [string]$Raw) {
 function Convert-TokenValue([string]$Key, [string]$Raw) {
-    $stringKeys = @("data", "text", "source", "status", "st", "src", "pwm", "pwm_source", "pid")
+    $stringKeys = @("cmd", "data", "text", "source", "status", "st", "src", "pwm", "pwm_source", "pid", "type", "ty")
     if ($stringKeys -contains $Key) {
     if ($stringKeys -contains $Key) {
         return $Raw
         return $Raw
     }
     }
-    $hexKeys = @("seq", "s", "cmd", "id", "v", "m", "tp", "tx", "rx", "drop", "off", "len", "sum", "raw_in", "ri", "raw_out", "ro", "raw_drop", "rd", "host_report_drop", "hd", "fifo", "fifo_max", "bmc_berr", "be", "host_err", "he", "err", "e", "type", "ty", "ch", "c", "pct", "p", "p0", "p23", "f0", "f5", "ptc01", "ptc24", "fan01", "fan04")
+    $hexKeys = @("seq", "s", "id", "v", "m", "tp", "tx", "rx", "drop", "off", "len", "sum", "raw_in", "ri", "raw_out", "ro", "raw_drop", "rd", "host_report_drop", "hd", "fifo", "fifo_max", "bmc_berr", "be", "host_err", "he", "err", "e", "ch", "c", "pct", "p", "p0", "p23", "f0", "f5", "ptc01", "ptc24", "fan01", "fan04")
     if ($hexKeys -contains $Key) {
     if ($hexKeys -contains $Key) {
+        if ($Raw -notmatch '^[0-9A-Fa-f]+$') {
+            return $Raw
+        }
         return [Convert]::ToInt64($Raw, 16)
         return [Convert]::ToInt64($Raw, 16)
     }
     }
     if ($Raw.StartsWith("0x", [System.StringComparison]::OrdinalIgnoreCase)) {
     if ($Raw.StartsWith("0x", [System.StringComparison]::OrdinalIgnoreCase)) {