Skip to content
Snippets Groups Projects
Commit fe506eb6 authored by Justus Müller's avatar Justus Müller :bee:
Browse files

fix: Revert to rolling pattern

parent 5b281def
No related branches found
No related tags found
No related merge requests found
...@@ -143,7 +143,7 @@ class DriveHandle: ...@@ -143,7 +143,7 @@ class DriveHandle:
return True return True
return False return False
def write_pattern(self, symbol: chr, path: str) -> None: def write_pattern(self, path: str) -> None:
""" """
Writes the pattern file to the disk Writes the pattern file to the disk
...@@ -151,33 +151,18 @@ class DriveHandle: ...@@ -151,33 +151,18 @@ class DriveHandle:
symbol (chr): The symbol the pattern file shall be filled with symbol (chr): The symbol the pattern file shall be filled with
path (str): The path to the pattern file path (str): The path to the pattern file
""" """
print(colored(f"[DriveHandle] Writing a file ({path}) with 0x{symbol.encode().hex()} pattern to fill the disk.", "light_grey")) print(colored(f"[DriveHandle] Writing a file ({path}) with a rolling pattern to fill the disk.", "light_grey"))
pattern_start_symbol : chr = 'A'
iteration : int = 0
(_, _, cluster_size) = self.get_allocation_unit_sizes()
progressbar = Spinner('[DriveHandle] Writing the pattern file') progressbar = Spinner('[DriveHandle] Writing the pattern file')
with open(path, "wb") as file_descriptor:
write_string = str(symbol) * 1024 * 1024 * 5 # 5 MiB while os.path.getsize(path)+cluster_size < self.get_free_drive_space():
file_descriptor = open(path, "w") current_pattern_symbol : chr = chr(ord(pattern_start_symbol)+iteration)
while True: file_descriptor.write(current_pattern_symbol.encode() * cluster_size)
try: iteration = (iteration + 1) % 26
file_descriptor.write(write_string)
file_descriptor.flush()
progressbar.next() progressbar.next()
except OSError as error:
if error.errno == errno.ENOSPC:
if len(write_string) > 1:
write_string = write_string[:(len(write_string) // 2)]
if (self.get_free_drive_space() == 0 and len(write_string) <= 1):
break
else:
break
else:
raise
progressbar.finish() progressbar.finish()
try:
file_descriptor.close()
except OSError as error:
if error.errno != errno.ENOSPC:
raise
print(colored("[DriveHandle] Completed writing the pattern file.", "light_grey")) print(colored("[DriveHandle] Completed writing the pattern file.", "light_grey"))
def create_overwrite_file(self, symbol: chr, path: str) -> None: def create_overwrite_file(self, symbol: chr, path: str) -> None:
......
...@@ -31,10 +31,9 @@ class SlackTest(DecisionTest): ...@@ -31,10 +31,9 @@ class SlackTest(DecisionTest):
# create pattern # create pattern
pattern_file_path: str = f'{self.drive_handle.get_path()}transsd-slacktest-pattern' pattern_file_path: str = f'{self.drive_handle.get_path()}transsd-slacktest-pattern'
self.drive_handle.write_pattern('A', pattern_file_path) self.drive_handle.write_pattern(pattern_file_path)
self.drive_handle.flush_cache()
print(colored("[SlackTest] Waiting 120s for the OS to flush the write cache.", "light_grey")) print(colored("[SlackTest] Waiting 120s for the OS to flush the write cache.", "light_grey"))
time.sleep(120)
pattern_file_clusters: list = [] pattern_file_clusters: list = []
if self._check_cluster_overlap: 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)
...@@ -43,9 +42,8 @@ class SlackTest(DecisionTest): ...@@ -43,9 +42,8 @@ class SlackTest(DecisionTest):
# delete file # delete file
self.drive_handle.delete_file(pattern_file_path) self.drive_handle.delete_file(pattern_file_path)
self.drive_handle.flush_cache()
print("[SlackTest] Waiting 120s for OS to clean up the disk...") print("[SlackTest] Waiting 120s for OS to clean up the disk...")
time.sleep(120) time.sleep(60)
print(colored("[SlackTest] File should be removed from disk without remainder.", "light_grey")) print(colored("[SlackTest] File should be removed from disk without remainder.", "light_grey"))
# create overwriting file # create overwriting file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment