From 4730f6f9438d05051239939cb56a3265afc8a1ef Mon Sep 17 00:00:00 2001
From: Justus Mueller <justus.mueller@fau.de>
Date: Thu, 13 Jun 2024 21:21:17 +0200
Subject: [PATCH] revert: Revert to rolling pattern

---
 src/drive_handle.py     |  2 +-
 src/tests/slack_test.py | 52 +++++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/src/drive_handle.py b/src/drive_handle.py
index 3ba65a5..28e2672 100644
--- a/src/drive_handle.py
+++ b/src/drive_handle.py
@@ -157,7 +157,7 @@ class DriveHandle:
         progressbar = Spinner('[DriveHandle] Writing the pattern file')
         with open(path, "wb") as file_descriptor:
             while os.path.getsize(path) + cluster_size < self.get_free_drive_space():
-                current_pattern_symbol: chr = chr(ord(pattern_start_symbol) + iteration)
+                current_pattern_symbol : chr = chr(ord(pattern_start_symbol) + iteration)
                 file_descriptor.write(current_pattern_symbol.encode() * cluster_size)
                 iteration = (iteration + 1) % 26
                 progressbar.next()
diff --git a/src/tests/slack_test.py b/src/tests/slack_test.py
index d0c2e16..370d493 100644
--- a/src/tests/slack_test.py
+++ b/src/tests/slack_test.py
@@ -1,7 +1,7 @@
 import time
-from termcolor import colored
 from src.drive_handle import DriveHandle
 from src.tests.decision_test import DecisionTest
+from termcolor import colored
 
 
 class SlackTest(DecisionTest):
@@ -12,12 +12,12 @@ class SlackTest(DecisionTest):
     @property
     def WEIGHT(self):
         return 2
-
+    
     def __init__(self, drive_handle: DriveHandle, check_cluster_overlap: bool) -> None:
         self._drive_handle = drive_handle
         self._check_cluster_overlap = check_cluster_overlap
-
-    def determine_SSD_indication(self) -> bool:
+    
+    def determine_probability(self) -> bool:
         """
         Determines wether the drive abstracted by the DriveHandle uses SSD technology
         with the help of slack space analysis
@@ -26,32 +26,30 @@ class SlackTest(DecisionTest):
             SSD_indication (bool): True, if the analysis found indications for SSD usage, False otherwise
 
         """
-
         print(colored("[SlackTest] Running the slack test!", 'light_blue'))
 
-        # create pattern
-        pattern_file_path: str = f'{self.drive_handle.get_path()}transsd-slacktest-pattern'
-        self.drive_handle.write_pattern(pattern_file_path)
-        print(colored("[SlackTest] Waiting 120s for the OS to flush the write cache.", "light_grey"))
+        # create rolling pattern
+        pattern_file_path: str = f'{self._drive_handle.get_path()}transsd-slacktest-pattern'
+        self._drive_handle.write_pattern(pattern_file_path)
 
         pattern_file_clusters: list = []
         if self._check_cluster_overlap:
-            pattern_file_clusters = self.drive_handle.get_clusters_for_file(pattern_file_path)
+            pattern_file_clusters = self._drive_handle.get_clusters_for_file(pattern_file_path)
             print(colored(f"[SlackTest] First cluster of the pattern file ({pattern_file_path}) is {pattern_file_clusters[0]}", "light_grey"))
             print(colored(f"[SlackTest] Last cluster of the pattern file ({pattern_file_path}) is {pattern_file_clusters[-1]}", "light_grey"))
 
         # delete file
-        self.drive_handle.delete_file(pattern_file_path)
-        print("[SlackTest] Waiting 120s for OS to clean up the disk...")
+        self._drive_handle.delete_file(pattern_file_path)
+        print("[SlackTest] Waiting 60s for OS to clean up the disk...")
         time.sleep(60)
         print(colored("[SlackTest] File should be removed from disk without remainder.", "light_grey"))
 
         # create overwriting file
-        overwrite_file_path: str = f'{self.drive_handle.get_path()}transsd-slacktest-overwrite'
-        self.drive_handle.create_overwrite_file('!', overwrite_file_path)
-        overwrite_file_clusters: list = self.drive_handle.get_clusters_for_file(overwrite_file_path)
+        overwrite_file_path: str = f'{self._drive_handle.get_path()}transsd-slacktest-overwrite'
+        self._drive_handle.create_overwrite_file('!', overwrite_file_path)
+        overwrite_file_clusters : list = self._drive_handle.get_clusters_for_file(overwrite_file_path)
         print(colored(f"[SlackTest] The cluster numbers associated with the overwrite file ({overwrite_file_path}) are {overwrite_file_clusters}", "light_grey"))
-        overwrite_file_last_cluster: int = self.drive_handle.read_cluster(overwrite_file_clusters[-1])
+        overwrite_file_last_cluster: int = self._drive_handle.read_cluster(overwrite_file_clusters[-1])
 
         if self._check_cluster_overlap:
             if overwrite_file_clusters[-1] in pattern_file_clusters:
@@ -60,19 +58,19 @@ class SlackTest(DecisionTest):
                 print(colored("[SlackTest] The last cluster of the overwrite file is disjoint with these of the pattern file.", "red"))
                 # If both clusters are not part, this test is useless
                 raise RuntimeError("SlackTest could not be performed.")
-
+        
         # analyse the slack space
-        (sector_size, sectors_per_cluster, _) = self.drive_handle.get_allocation_unit_sizes()
+        (sector_size, sectors_per_cluster, _) = self._drive_handle.get_allocation_unit_sizes()
 
         half_cluster: int = sector_size * (sectors_per_cluster // 2)
         print("[SlackTest] Showing the RAM slack:")
-        print(colored(overwrite_file_last_cluster[half_cluster:half_cluster + (sector_size // 2)].hex(' ', 1), "light_grey"), end=' ')
-        print(colored(overwrite_file_last_cluster[half_cluster + (sector_size // 2):half_cluster + sector_size].hex(' ', 1), 'green'))
+        print(colored(overwrite_file_last_cluster[half_cluster:half_cluster+(sector_size//2)].hex(' ', 1), "light_grey"), end=' ')
+        print(colored(overwrite_file_last_cluster[half_cluster+(sector_size//2):half_cluster+sector_size].hex(' ', 1), 'green'))
         print("[SlackTest] Showing the drive slack:")
-        print(colored(overwrite_file_last_cluster[half_cluster + sector_size:].hex(' ', 1), 'yellow'))
-
-        found_non_zero_byte: bool = False
-        for hex_value in overwrite_file_last_cluster[half_cluster + sector_size:].hex():
+        print(colored(overwrite_file_last_cluster[half_cluster+sector_size:].hex(' ', 1),'yellow'))
+        
+        found_non_zero_byte : bool = False
+        for hex_value in overwrite_file_last_cluster[half_cluster+sector_size:].hex():
             if hex_value != '0':
                 found_non_zero_byte = True
                 break
@@ -82,12 +80,10 @@ class SlackTest(DecisionTest):
         else:
             print(colored("[SlackTest] All bytes are zero!", "red"))
 
-        print(colored("[SlackTest] Cleaning up files.", "light_grey"))
-        self.drive_handle.delete_file(overwrite_file_path)
-        self.drive_handle.flush_cache()
 
         print(colored("[SlackTest] Slack test completed.", "light_blue"))
-        return not found_non_zero_byte
+        return found_non_zero_byte
+    
 
     @property
     def drive_handle(self) -> DriveHandle:
-- 
GitLab