diff --git a/hash_longterm.py b/hash_longterm.py index 13229917cdf866ebfbd124532c40938300632938..68f75606fef6a20b539e4007cc9ba047658f5d76 100644 --- a/hash_longterm.py +++ b/hash_longterm.py @@ -70,11 +70,14 @@ if __name__ == "__main__": print(colored(log("[Hash-Longtermstudy] Starting the hash run!"), "light_blue")) drive_handle.copy_demo_files() print(colored(log("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer."), "cyan")) + drive_handle.flush_cache() time.sleep(120) # create hash print(colored(log(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}"), "light_blue")) # delete data drive_handle.remove_demo_files() + # flush the cache + drive_handle.flush_cache() # set drive to read only drive_handle.set_read_only(True) # repeadetly create the hash diff --git a/src/drive_handle.py b/src/drive_handle.py index a1df2c224b4d9219a37590848cbf95d2f5ef3dc1..a0a6be74a6e37a6f79935d76fee7a013e0507da0 100644 --- a/src/drive_handle.py +++ b/src/drive_handle.py @@ -173,3 +173,7 @@ class DriveHandle: print(colored(f"[DriveHandle] Setting drive {self._drive_letter}'s read-only state to {read_only}.", "light_grey")) powershell_bool: str = "$true" if read_only else "$false" subprocess.check_output(['powershell.exe', f'Get-Disk -Number (Get-Partition -DriveLetter {self._drive_letter}).DiskNumber | Set-Disk -IsReadOnly {powershell_bool}']) + + def flush_cache(self) -> None: + print(colored("[DriveHandle] Flushing drive's write cache.", "light_grey")) + subprocess.check_output(['powershell.exe', f'Write-VolumeCache -DriveLetter {self._drive_letter}']) diff --git a/src/tests/hash_test.py b/src/tests/hash_test.py index 772b4cabf7ed7c88f5cd75ddd86da323ab19d406..e4f6f01e6f0447a45cb076ccd91eaab7507294bf 100644 --- a/src/tests/hash_test.py +++ b/src/tests/hash_test.py @@ -19,11 +19,13 @@ class HashTest(DecisionTest): print(colored("[HashTest] Running the hash test!", 'light_blue')) print(colored("[HashTest] Copying the demo files.", 'light_grey')) 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 cache.", "light_grey")) + self._drive_handle.flush_cache() time.sleep(120) print(colored(f"[HashTest] The current hash of the drive is equal to {self._drive_handle.generate_hash()}", "yellow")) print(colored("[HashTest] Deleting the demo files.", 'light_grey')) self._drive_handle.remove_demo_files() + self._drive_handle.flush_cache() self._drive_handle.set_read_only(True) detected_wear_levelling: bool = False prior_hash: str = None diff --git a/src/tests/slack_test.py b/src/tests/slack_test.py index d65e625ae21a4a99fa48c9f270f26c23ffdc2ff1..805f03b9b09f4b65260c5ee9bd8392d242b1f4ae 100644 --- a/src/tests/slack_test.py +++ b/src/tests/slack_test.py @@ -23,6 +23,7 @@ class SlackTest(DecisionTest): # create rolling pattern pattern_file_path: str = f'{self._drive_handle.get_path()}transsd-slacktest-pattern' self._drive_handle.write_pattern(pattern_file_path) + self._drive_handle.flush_cache() pattern_file_clusters: list = [] if self._check_cluster_overlap: pattern_file_clusters = self._drive_handle.get_clusters_for_file(pattern_file_path) @@ -32,6 +33,7 @@ class SlackTest(DecisionTest): # delete file self._drive_handle.delete_file(pattern_file_path) print("[SlackTest] Waiting 120s for OS to clean up the disk...") + self._drive_handle.flush_cache() time.sleep(120) print(colored("[SlackTest] File should be removed from disk without remainder.", "light_grey"))