mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
Make XOR64 test also test alignment issues
This commit is contained in:
@@ -10,9 +10,8 @@ import zlib
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
from io import BytesIO
|
||||
from itertools import cycle
|
||||
|
||||
from kitty.fast_data_types import base64_decode, base64_encode, load_png_data, shm_unlink, shm_write, xor_data64
|
||||
from kitty.fast_data_types import base64_decode, base64_encode, has_avx2, has_sse4_2, load_png_data, shm_unlink, shm_write, test_xor64
|
||||
|
||||
from . import BaseTest, parse_bytes
|
||||
|
||||
@@ -184,17 +183,28 @@ def make_send_command(screen):
|
||||
class TestGraphics(BaseTest):
|
||||
|
||||
def test_xor_data(self):
|
||||
base_data = b'\x01' * 64
|
||||
key = b'\x02' * 64
|
||||
sizes = []
|
||||
if has_sse4_2:
|
||||
sizes.append(2)
|
||||
if has_avx2:
|
||||
sizes.append(3)
|
||||
sizes.append(0)
|
||||
|
||||
def xor(skey, data):
|
||||
ckey = cycle(bytearray(skey))
|
||||
return bytes(bytearray(k ^ d for k, d in zip(ckey, bytearray(data))))
|
||||
def t(key, data, align_offset=0):
|
||||
expected = test_xor64(key, data, 1, 0)
|
||||
for which_function in sizes:
|
||||
actual = test_xor64(key, data, which_function, align_offset)
|
||||
self.ae(expected, actual, f'{align_offset=} {len(data)=}')
|
||||
|
||||
base_data = os.urandom(61)
|
||||
key = os.urandom(64)
|
||||
for base in (b'', base_data, base_data * 3):
|
||||
t(key, b'')
|
||||
|
||||
for base in (b'abc', base_data):
|
||||
for extra in range(len(base_data)):
|
||||
data = base + base_data[:extra]
|
||||
self.assertEqual(xor(key, data), xor_data64(key, data))
|
||||
for align_offset in range(64):
|
||||
data = base + base_data[:extra]
|
||||
t(key, data, align_offset)
|
||||
|
||||
def test_disk_cache(self):
|
||||
s = self.create_screen()
|
||||
|
||||
Reference in New Issue
Block a user