def test_ph_tail_large(seed, key, data): """Compare PH compression for the last block, when it has enough data to fully contain the last 16-byte chunk.""" expected = ph_compress_one_block(key, seed, split_block(data)) n_bytes = len(data) # Copy to exactly-sized malloced buffers to help ASan. block = FFI.new("char[]", n_bytes) FFI.memmove(block, data, n_bytes) params = FFI.new("struct umash_params[1]") for i, param in enumerate(key): params[0].ph[i] = param actual = C.ph_last_block(params[0].ph, seed, block, n_bytes) assert expected == actual.bits[0] + (actual.bits[1] << 64), ( actual.bits[0], actual.bits[1], )
def test_ph_tail_short(seed, key, prefix, data): """Compare PH compression for the last block, when we must steal some data from the previous chunk.""" expected = ph_compress_one_block( key, seed, split_block(prefix * (C.UMASH_PH_PARAM_COUNT // 2) + data) ) offset = len(prefix) n_bytes = len(data) # Copy to exactly-sized malloced buffers to help ASan. block = FFI.new("char[]", offset + n_bytes) FFI.memmove(block, prefix + data, offset + n_bytes) params = FFI.new("struct umash_params[1]") for i, param in enumerate(key): params[0].ph[i] = param actual = C.ph_last_block(params[0].ph, seed, block + offset, n_bytes) assert expected == actual.bits[0] + (actual.bits[1] << 64), ( actual.bits[0], actual.bits[1], )