open Space_wire let encode codec v = let ws = Wire.Codec.wire_size codec in let buf = Bytes.create ws in Wire.Codec.encode codec v buf 0; Bytes.unsafe_to_string buf let decode codec s = Wire.Codec.decode codec (Bytes.of_string s) 0 let test_superblock_roundtrip () = let sb = Superblock.v ~tenant_id:1 ~total_blocks:1024 ~dp_start:33 ~dp_size:991 ~epoch:1000000L ~uuid:(String.make 16 '\xAB') in let encoded = encode Superblock.codec sb in Alcotest.(check int) "superblock size" 48 (String.length encoded); let decoded = decode Superblock.codec encoded in Alcotest.(check bool) "roundtrip" true (Superblock.equal sb decoded) let test_superblock_magic () = let sb = Superblock.v ~tenant_id:1 ~total_blocks:1024 ~dp_start:33 ~dp_size:991 ~epoch:0L ~uuid:(String.make 16 '\x00') in Alcotest.(check bool) "magic ok" true (Superblock.check_magic sb); let bad = { sb with magic = 0 } in Alcotest.(check bool) "magic bad" false (Superblock.check_magic bad) let test_superblock_crc () = let sb = Superblock.v ~tenant_id:1 ~total_blocks:1024 ~dp_start:33 ~dp_size:991 ~epoch:0L ~uuid:(String.make 16 '\x00') in Alcotest.(check bool) "crc ok" true (Superblock.check_crc sb); let bad = { sb with tenant_id = 999 } in Alcotest.(check bool) "crc bad" false (Superblock.check_crc bad) let test_superblock_layout () = let sb = Superblock.v ~tenant_id:1 ~total_blocks:1024 ~dp_start:33 ~dp_size:991 ~epoch:0L ~uuid:(String.make 16 '\x00') in let encoded = encode Superblock.codec sb in (* magic = 0x53504F53 big-endian *) Alcotest.(check int) "magic[0]" 0x53 (Char.code encoded.[0]); Alcotest.(check int) "magic[1]" 0x50 (Char.code encoded.[1]); Alcotest.(check int) "magic[2]" 0x4F (Char.code encoded.[2]); Alcotest.(check int) "magic[3]" 0x53 (Char.code encoded.[3]); (* format_version = 0x01 at offset 4 *) Alcotest.(check int) "version" 0x01 (Char.code encoded.[4]) let suite = ( "superblock", [ Alcotest.test_case "roundtrip" `Quick test_superblock_roundtrip; Alcotest.test_case "magic" `Quick test_superblock_magic; Alcotest.test_case "crc" `Quick test_superblock_crc; Alcotest.test_case "layout" `Quick test_superblock_layout; ] )