[libc-commits] [libc] [libc] init uefi os target (PR #120687)

via libc-commits libc-commits at lists.llvm.org
Tue Dec 24 20:44:09 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r f06756f50e1f70664adc25a41ccabf5b018a504a...524b7cb9f48b62b2188f014653d34278ed169ca3 libc/test/scripts/uefi_runner.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- uefi_runner.py	2024-12-25 04:38:26.000000 +0000
+++ uefi_runner.py	2024-12-25 04:43:35.725027 +0000
@@ -14,13 +14,14 @@
 import re
 import shutil
 import subprocess
 import tempfile
 
+
 class Target:
     def __init__(self, triple: str):
-        self.triple = triple.split('-')
+        self.triple = triple.split("-")
         assert len(self.triple) == 2 or len(self.triple) == 3
 
     def arch(self):
         return self.triple[0]
 
@@ -60,12 +61,14 @@
 
             return args
 
         if self.arch() == "x86_64" and self.isNativeArch():
             return [
-                "-machine", "accel=kvm:tcg",
-                "-cpu", "max",
+                "-machine",
+                "accel=kvm:tcg",
+                "-cpu",
+                "max",
             ]
         return []
 
     def ovmfPath(self):
         if self.arch() == "aarch64":
@@ -98,15 +101,14 @@
         return platform.machine()
 
     def defaultOs():
         return platform.system().lower()
 
+
 def main():
     parser = argparse.ArgumentParser(description="UEFI runner for binaries")
-    parser.add_argument(
-        "binary_file", help="Path to the UEFI binary to execute"
-    )
+    parser.add_argument("binary_file", help="Path to the UEFI binary to execute")
     parser.add_argument(
         "--target",
         help="Triplet which specifies what the target is",
     )
     parser.add_argument(
@@ -114,11 +116,16 @@
         help="Path to the directory where OVMF is located",
     )
     args = parser.parse_args()
     target = Target.default() if args.target is None else Target(args.target)
 
-    ovmfFile = os.path.join(args.ovmf_path or os.getenv("OVMF_PATH") or f"/usr/share/edk2/{target.efiArch().lower()}", target.ovmfPath())
+    ovmfFile = os.path.join(
+        args.ovmf_path
+        or os.getenv("OVMF_PATH")
+        or f"/usr/share/edk2/{target.efiArch().lower()}",
+        target.ovmfPath(),
+    )
 
     qemuArgs = [target.qemuBinary()]
     qemuArgs.extend(target.qemuArgs())
 
     qemuArgs.append("-drive")
@@ -133,16 +140,20 @@
 
     with tempfile.TemporaryDirectory() as tempdir:
         qemuArgs.append("-drive")
         qemuArgs.append(f"file=fat:rw:{tempdir},format=raw,media=disk")
 
-        os.mkdir(os.path.join(tempdir, 'EFI'))
-        os.mkdir(os.path.join(tempdir, 'EFI', 'BOOT'))
+        os.mkdir(os.path.join(tempdir, "EFI"))
+        os.mkdir(os.path.join(tempdir, "EFI", "BOOT"))
 
-        shutil.copyfile(args.binary_file, os.path.join(tempdir, 'EFI', 'BOOT', target.efiFileName()))
+        shutil.copyfile(
+            args.binary_file, os.path.join(tempdir, "EFI", "BOOT", target.efiFileName())
+        )
 
-        proc = subprocess.Popen(qemuArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+        proc = subprocess.Popen(
+            qemuArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
+        )
 
         num_tests = 0
         num_suites = 0
 
         while True:
@@ -159,21 +170,24 @@
             if not x is None:
                 num_tests = int(x.group(1))
                 num_suites = int(x.group(2))
                 continue
 
-            x = re.search(r"Ran ([0-9]+) tests?\.  PASS: ([0-9]+)  FAIL: ([0-9]+)", line)
+            x = re.search(
+                r"Ran ([0-9]+) tests?\.  PASS: ([0-9]+)  FAIL: ([0-9]+)", line
+            )
 
             if not x is None:
                 ran_tests = int(x.group(1))
                 passed_tests = int(x.group(2))
                 failed_tests = int(x.group(3))
 
-                assert (passed_tests + failed_tests == ran_tests)
+                assert passed_tests + failed_tests == ran_tests
                 assert ran_tests == num_tests
 
                 if failed_tests > 0:
                     raise Exception("A test failed")
                 break
 
+
 if __name__ == "__main__":
     main()

``````````

</details>


https://github.com/llvm/llvm-project/pull/120687


More information about the libc-commits mailing list