def test_oh_tail_large(tag, key, data): """Compare OH compression for the last block, when it has enough data to fully contain the last 16-byte chunk.""" expected = oh_compress_one_block(key, split_block(data), tag << 64) 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].oh[i] = param actual = C.oh_last_block(params[0].oh, tag, block, n_bytes) assert expected == actual.bits[0] + (actual.bits[1] << 64), ( actual.bits[0], actual.bits[1], )
def test_oh_tail_short(tag, key, prefix, data): """Compare OH compression for the last block, when we must steal some data from the previous chunk.""" expected = oh_compress_one_block( key, split_block(prefix * (C.UMASH_OH_PARAM_COUNT // 2) + data), tag << 64) 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].oh[i] = param actual = C.oh_last_block(params[0].oh, tag, block + offset, n_bytes) assert expected == actual.bits[0] + (actual.bits[1] << 64), ( actual.bits[0], actual.bits[1], )