From e51b96a9013433a29fd01b19230a28fcb248332c Mon Sep 17 00:00:00 2001
From: Aroy-Art <Aroy-Art@pm.me>
Date: Sat, 12 Apr 2025 13:24:21 +0200
Subject: [PATCH] Python Scripts: fix log wrintig & only write 25 GiB data to
 disk

---
 PythonScripts/test_disk.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/PythonScripts/test_disk.py b/PythonScripts/test_disk.py
index 11c3190..e9bb54c 100644
--- a/PythonScripts/test_disk.py
+++ b/PythonScripts/test_disk.py
@@ -9,14 +9,18 @@ from datetime import datetime
 def run_cmd(cmd, log_file, check=True, capture_output=True):
     print(f"Running: {cmd}")
     result = subprocess.run(cmd, shell=True, capture_output=capture_output, text=True)
+
     log_file.write(f"\n$ {cmd}\n")
     if result.stdout:
         log_file.write(result.stdout)
     if result.stderr:
         log_file.write(result.stderr)
+    log_file.flush()  # ✅ Flush after writing
+
     if check and result.returncode != 0:
-        print(f"Command failed: {cmd}\n{result.stderr}")
-        sys.exit(1)
+        print(f"[!] Non-zero exit code ({result.returncode}) for: {cmd}")
+        if result.stderr:
+            print(result.stderr.strip())
     return result.stdout.strip()
 
 
@@ -81,13 +85,13 @@ def run_badblocks(device, log_file):
 
 
 def fill_random(device, log_file):
-    print("Overwriting disk with random data...")
+    print("Writing 25 GiB of random data to disk...")
     run_cmd(
-        f"sudo dd if=/dev/urandom of={device} bs=1M status=progress",
+        f"sudo dd if=/dev/urandom of={device} bs=1M count=25600 status=progress",
         log_file,
         check=False,
     )
-    print("Random data written to disk.")
+    print("Random data write complete.")
 
 
 def run_fio(device, rw_mode, log_file, bs="4k", runtime=30):