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

feat: Replace random files with demo files

parent ca80176e
Branches
Tags
No related merge requests found
...@@ -24,21 +24,17 @@ if __name__ == "__main__": ...@@ -24,21 +24,17 @@ if __name__ == "__main__":
arguments: dict = dict(arg.split('=') for arg in sys.argv[1:]) arguments: dict = dict(arg.split('=') for arg in sys.argv[1:])
drive_letter: chr = None drive_letter: chr = None
file_amount: int = 10 wait_time: int = 60 * 60 # every hour
wait_time: int = 21600 # 6 hours (4 times a day)
format_drive: bool = False format_drive: bool = False
threshold: int = 2 threshold: int = 6
max_iterations: int = 20 # max 5 days (after that change should be visible) max_iterations: int = 60 * 60 * 24 * 7 # 1 week
max_memory: int = 1_024 max_memory: int = 256
for argument in arguments.keys(): for argument in arguments.keys():
match(argument): match(argument):
case("drive_letter"): case("drive_letter"):
drive_letter = arguments.get("drive_letter") drive_letter = arguments.get("drive_letter")
case("file_amount"):
file_amount = int(arguments.get("file_amount"))
case("wait_time"): case("wait_time"):
wait_time = int(arguments.get("wait_time")) wait_time = int(arguments.get("wait_time"))
...@@ -72,17 +68,13 @@ if __name__ == "__main__": ...@@ -72,17 +68,13 @@ if __name__ == "__main__":
# write random data to the disk # write random data to the disk
print(colored(log("[Hash-Longtermstudy] Starting the hash run!"), "light_blue")) print(colored(log("[Hash-Longtermstudy] Starting the hash run!"), "light_blue"))
drive_handle.generate_random_data(file_amount, 10_000) drive_handle.copy_demo_files()
print(colored(log("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer."), "cyan")) print(colored(log("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer."), "cyan"))
time.sleep(120) time.sleep(120)
# create hash # create hash
print(colored(log(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}"), "light_blue")) print(colored(log(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}"), "light_blue"))
# delete data # delete data
drive_handle.delete_file(f"{drive_handle.get_path()}transsd-random-1") drive_handle.remove_demo_files()
drive_handle.delete_file(f"{drive_handle.get_path()}transsd-random-2")
drive_handle.delete_file(f"{drive_handle.get_path()}transsd-random-3")
drive_handle.delete_file(f"{drive_handle.get_path()}transsd-random-4")
drive_handle.delete_file(f"{drive_handle.get_path()}transsd-random-5")
# set drive to read only # set drive to read only
drive_handle.set_read_only(True) drive_handle.set_read_only(True)
# repeadetly create the hash # repeadetly create the hash
......
...@@ -18,7 +18,7 @@ if __name__ == "__main__": ...@@ -18,7 +18,7 @@ if __name__ == "__main__":
slack_test: bool = True slack_test: bool = True
drive_letter: chr = '' drive_letter: chr = ''
format_drive: bool = False format_drive: bool = False
check_cluster_overlap: bool = True check_cluster_overlap: bool = False
max_memory: int = 1_024 # 1 GB max_memory: int = 1_024 # 1 GB
for argument in arguments.keys(): for argument in arguments.keys():
......
...@@ -4,3 +4,4 @@ pywin32==306 ...@@ -4,3 +4,4 @@ pywin32==306
termcolor==2.4.0 termcolor==2.4.0
progress==1.6 progress==1.6
pyuac==0.0.3 pyuac==0.0.3
setuptools==70.0.0
\ No newline at end of file
from hashlib import sha1
import os
import random
import psutil
import ctypes import ctypes
import os
import shutil
import subprocess import subprocess
from termcolor import colored from distutils.dir_util import copy_tree
from hashlib import sha1
import psutil
from progress.spinner import Spinner from progress.spinner import Spinner
from termcolor import colored
class DriveHandle: class DriveHandle:
...@@ -130,18 +132,13 @@ class DriveHandle: ...@@ -130,18 +132,13 @@ class DriveHandle:
file_descriptor.write(symbol.encode() * file_size) file_descriptor.write(symbol.encode() * file_size)
print(colored("[DriveHandle] Completed writing the overwrite file.", "light_grey")) print(colored("[DriveHandle] Completed writing the overwrite file.", "light_grey"))
def generate_random_data(self, amount: int, max_file_size: int) -> None: def copy_demo_files(self) -> None:
print(colored(f"[DriveHandle] Writing {amount} random files to the disk.", "light_grey")) working_dir = os.path.abspath(os.path.join((os.path.dirname(os.path.abspath(__file__))), os.pardir))
for file_number in range(1, amount + 1): copy_tree(f'{working_dir}\\demo', f'{self._drive_letter}:\\demo')
print(colored(f"[DriveHandle] Writing file {self._drive_letter}:\\transsd-random-{file_number}.", "light_grey"))
file_size = random.randint(8, max_file_size) def remove_demo_files(self) -> None:
written_size = 0 if (os.path.isdir(f'{self._drive_letter}:\\demo')):
while written_size < file_size: shutil.rmtree(f'{self._drive_letter}:\\demo')
with open(f"{self._drive_letter}:\\transsd-random-{file_number}", "wt") as file:
hex_value = random.randint(65, 122)
hex_size = random.randint(1, 10)
file.write(chr(hex_value) * hex_size)
written_size += hex_size
def delete_file(self, path: str) -> None: def delete_file(self, path: str) -> None:
print(colored(f"[DriveHandle] Deleting file {path}.", "light_grey")) print(colored(f"[DriveHandle] Deleting file {path}.", "light_grey"))
......
...@@ -17,18 +17,13 @@ class HashTest(DecisionTest): ...@@ -17,18 +17,13 @@ class HashTest(DecisionTest):
def determine_SSD_indication(self) -> float: def determine_SSD_indication(self) -> float:
print(colored("[HashTest] Running the hash test!", 'light_blue')) print(colored("[HashTest] Running the hash test!", 'light_blue'))
print(colored("[HashTest] Generating random files.", 'light_grey')) print(colored("[HashTest] Copying the demo files.", 'light_grey'))
self._drive_handle.generate_random_data(10, 10_000) self._drive_handle.copy_demo_files()
print(colored("[HashTest] Waiting 120s for the OS to flush the write buffer.", "light_grey")) print(colored("[HashTest] Waiting 120s for the OS to flush the write buffer.", "light_grey"))
time.sleep(120) time.sleep(120)
print(colored(f"[HashTest] The current hash of the drive is equal to {self._drive_handle.generate_hash()}", "yellow")) print(colored(f"[HashTest] The current hash of the drive is equal to {self._drive_handle.generate_hash()}", "yellow"))
print(colored("[HashTest] Deleting some files.", 'light_grey')) print(colored("[HashTest] Deleting the demo files.", 'light_grey'))
self._drive_handle.delete_file(f"{self._drive_handle.get_path()}transsd-random-1") self._drive_handle.remove_demo_files()
self._drive_handle.delete_file(f"{self._drive_handle.get_path()}transsd-random-2")
self._drive_handle.delete_file(f"{self._drive_handle.get_path()}transsd-random-3")
self._drive_handle.delete_file(f"{self._drive_handle.get_path()}transsd-random-4")
self._drive_handle.delete_file(f"{self._drive_handle.get_path()}transsd-random-5")
print(colored("[HashTest] Deleted files 1 to 5.", 'light_grey'))
self._drive_handle.set_read_only(True) self._drive_handle.set_read_only(True)
detected_wear_levelling: bool = False detected_wear_levelling: bool = False
prior_hash: str = None prior_hash: str = None
...@@ -50,13 +45,13 @@ class HashTest(DecisionTest): ...@@ -50,13 +45,13 @@ class HashTest(DecisionTest):
else: else:
print(colored(f"[HashTest] The threshold of 2 changes before measuring is not exceeded yet. Currently at iteration {iteration}. Continuing...", "green")) print(colored(f"[HashTest] The threshold of 2 changes before measuring is not exceeded yet. Currently at iteration {iteration}. Continuing...", "green"))
prior_hash = current_hash prior_hash = current_hash
if iteration >= 20: # 5 days of observation at max if iteration >= 168: # 7 days of observation at max
print(colored(f"[HashTest] Reached iteration {iteration} (max iterations was set to 20). Stopping the test.", "light_blue")) print(colored(f"[HashTest] Reached iteration {iteration} (max iterations was set to 168). Stopping the test.", "light_blue"))
detected_wear_levelling = False detected_wear_levelling = False
break break
print(colored("[HashTest] Waiting 6h until generating the next hash.", "light_grey")) print(colored("[HashTest] Waiting 1h until generating the next hash.", "light_grey"))
time.sleep(60 * 60 * 6) time.sleep(60 * 60)
# release drive # release drive
self._drive_handle.set_read_only(False) self._drive_handle.set_read_only(False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment