Skip to content

Commit

Permalink
testing mlock
Browse files Browse the repository at this point in the history
  • Loading branch information
radu committed Jun 23, 2024
1 parent 8b9ac74 commit a2ff0bf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 13 deletions.
7 changes: 0 additions & 7 deletions examples/mlock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import array
import platform
import random
import os
Expand Down Expand Up @@ -56,23 +55,17 @@ def setup_memory_limit():
arr[:] = os.urandom(len(arr))
arr_np = np.zeros(len(arr), dtype=np.uint8)
arr_np[:] = arr
array_array = array.array('B', (random.randint(0, 255) for _ in range(int(size * 1024 * 1024))))
print(f"Testing size: {size} MB")
print("mlock bytearray")
mlock(arr)
print("mlock np array")
mlock(arr_np)
print("mlock array.array")
mlock(array_array)

zeroize1(arr)
zeroize1(arr_np)
zeroize1(array_array)
assert arr == bytearray(int(size * 1024 * 1024))
assert all(arr_np == 0)
assert all(byte == 0 for byte in array_array)

finally:
munlock(arr)
munlock(arr_np)
munlock(array_array)
6 changes: 0 additions & 6 deletions tests/test_zeroize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,20 @@ def test_zeroize1_sizes(self):
arr[:] = os.urandom(len(arr))
arr_np = np.zeros(len(arr), dtype=np.uint8)
arr_np[:] = arr
array_array = array.array('B', (random.randint(0, 255) for _ in range(int(size * 1024 * 1024))))
print(f"Testing size: {size} MB")
print("mlock bytearray")
mlock(arr)
print("mlock np array")
mlock(arr_np)
print("mlock array.array")
mlock(array_array)

zeroize1(arr)
zeroize1(arr_np)
zeroize1(array_array)
self.assertEqual(arr, bytearray(int(size * 1024 * 1024)))
self.assertEqual(True, all(arr_np == 0))
self.assertEqual(True, all(byte == 0 for byte in array_array))

finally:
munlock(arr)
munlock(arr_np)
munlock(array_array)


if __name__ == "__main__":
Expand Down

0 comments on commit a2ff0bf

Please sign in to comment.