CCSDS File Delivery Protocol (CCSDS 727.0-B-5) for space file transfer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cfdp: fix merlint issues across lib and tests

- Replace Printf.sprintf/Format.fprintf with Fmt.str/Fmt.pf
- Rename test_ prefixed functions in interop tests
- Fix _buf bindings (used, shouldn't have underscore)
- Snake_case test suite name

+54 -54
+12 -12
lib/cfdp.ml
··· 1138 1138 if hdr.crc_present then begin 1139 1139 let full = Bytes.of_string (hdr_bytes ^ data) in 1140 1140 let crc = crc16_ccitt_sub full 0 (Bytes.length full) in 1141 - let crc_buf = Bytes.create 2 in 1142 - Bytes.set_uint16_be crc_buf 0 crc; 1143 - Bytes.to_string full ^ Bytes.to_string crc_buf 1141 + let crcbuf = Bytes.create 2 in 1142 + Bytes.set_uint16_be crcbuf 0 crc; 1143 + Bytes.to_string full ^ Bytes.to_string crcbuf 1144 1144 end 1145 1145 else hdr_bytes ^ data 1146 1146 ··· 1265 1265 }, 1266 1266 consumed )) 1267 1267 1268 - let decode_finished _buf off len = 1268 + let decode_finished buf off len = 1269 1269 if len < 2 then Error (Truncated { need = 2; have = len }) 1270 1270 else 1271 1271 match 1272 - Wire.Codec.decode finished_codec (Bytes.unsafe_of_string _buf) (off + 1) 1272 + Wire.Codec.decode finished_codec (Bytes.unsafe_of_string buf) (off + 1) 1273 1273 with 1274 1274 | Error e -> Error (wire_error_to_cfdp e) 1275 1275 | Ok pf -> ( ··· 1298 1298 }, 1299 1299 2 )) 1300 1300 1301 - let decode_ack _buf off len = 1301 + let decode_ack buf off len = 1302 1302 if len < 3 then Error (Truncated { need = 3; have = len }) 1303 1303 else 1304 1304 match 1305 - Wire.Codec.decode ack_codec (Bytes.unsafe_of_string _buf) (off + 1) 1305 + Wire.Codec.decode ack_codec (Bytes.unsafe_of_string buf) (off + 1) 1306 1306 with 1307 1307 | Error e -> Error (wire_error_to_cfdp e) 1308 1308 | Ok pa -> ( ··· 1369 1369 if len < min_len then Error (Truncated { need = min_len; have = len }) 1370 1370 else 1371 1371 (* Decode scope fields from off+1 (skip directive code) using byte_array *) 1372 - let scope_buf = Bytes.unsafe_of_string buf in 1372 + let scopebuf = Bytes.unsafe_of_string buf in 1373 1373 let sscope = be_bytes_to_int64 (String.sub buf (off + 1) fss_len) in 1374 1374 let escope = 1375 1375 be_bytes_to_int64 (String.sub buf (off + 1 + fss_len) fss_len) ··· 1380 1380 let curr_off = ref (off + 1 + (2 * fss_len)) in 1381 1381 for _ = 1 to seg_count do 1382 1382 let soff = 1383 - be_bytes_to_int64 (Bytes.sub_string scope_buf !curr_off fss_len) 1383 + be_bytes_to_int64 (Bytes.sub_string scopebuf !curr_off fss_len) 1384 1384 in 1385 1385 let eoff = 1386 1386 be_bytes_to_int64 1387 - (Bytes.sub_string scope_buf (!curr_off + fss_len) fss_len) 1387 + (Bytes.sub_string scopebuf (!curr_off + fss_len) fss_len) 1388 1388 in 1389 1389 segs := { start_offset = soff; end_offset = eoff } :: !segs; 1390 1390 curr_off := !curr_off + (2 * fss_len) ··· 1398 1398 }, 1399 1399 !curr_off - off ) 1400 1400 1401 - let decode_prompt _buf off len = 1401 + let decode_prompt buf off len = 1402 1402 if len < 2 then Error (Truncated { need = 2; have = len }) 1403 1403 else 1404 1404 match 1405 - Wire.Codec.decode prompt_codec (Bytes.unsafe_of_string _buf) (off + 1) 1405 + Wire.Codec.decode prompt_codec (Bytes.unsafe_of_string buf) (off + 1) 1406 1406 with 1407 1407 | Error e -> Error (wire_error_to_cfdp e) 1408 1408 | Ok pp ->
+2 -2
lib/eio/cfdp_eio.ml
··· 56 56 let hdr = Eio.Buf_read.take 4 buf_r in 57 57 let len = Int32.to_int (String.get_int32_be hdr 0) in 58 58 if len <= 0 || len > 1_048_576 then 59 - Error (Format.asprintf "invalid frame length: %d" len) 59 + Error (Fmt.str "invalid frame length: %d" len) 60 60 else Ok (Eio.Buf_read.take len buf_r) 61 61 62 62 (* ── PDU I/O ───────────────────────────────────────────────────────────── *) ··· 71 71 | Ok data -> ( 72 72 match Cfdp.decode data with 73 73 | Ok (pdu, _consumed) -> Ok pdu 74 - | Error e -> Error (Format.asprintf "%a" Cfdp.pp_error e)) 74 + | Error e -> Error (Fmt.str "%a" Cfdp.pp_error e)) 75 75 76 76 (* ── Helpers ───────────────────────────────────────────────────────────── *) 77 77
+1 -1
lib/eio/filestore_eio.ml
··· 33 33 | `Regular_file -> 34 34 Eio.Path.with_open_in p @@ fun file -> 35 35 Ok (Eio.File.size file |> Optint.Int63.to_int64) 36 - | _ -> Error (Io_error (Printf.sprintf "%s: not a regular file" path)) 36 + | _ -> Error (Io_error (Fmt.str "%s: not a regular file" path)) 37 37 with 38 38 | Eio.Io (Eio.Fs.E (Eio.Fs.Not_found _), _) -> Error (Not_found path) 39 39 | Eio.Io (Eio.Fs.E (Eio.Fs.Permission_denied _), _) ->
+7 -7
test/interop/dariol83/test.ml
··· 18 18 let string_to_hex s = 19 19 let buf = Buffer.create (String.length s * 2) in 20 20 String.iter 21 - (fun c -> Buffer.add_string buf (Printf.sprintf "%02x" (Char.code c))) 21 + (fun c -> Buffer.add_string buf (Fmt.str "%02x" (Char.code c))) 22 22 s; 23 23 Buffer.contents buf 24 24 ··· 94 94 | Ok rows -> rows 95 95 | Error e -> Alcotest.failf "CSV: %a" Csvt.pp_error e 96 96 97 - let test_decode () = 97 + let decode_ka () = 98 98 let rows = load_rows () in 99 99 List.iter 100 100 (fun (r : ka_row) -> ··· 116 116 | Ok _ -> Alcotest.failf "%s: expected Keep_alive directive" r.name) 117 117 rows 118 118 119 - let test_encode () = 119 + let encode_ka () = 120 120 let rows = load_rows () in 121 121 List.iter 122 122 (fun (r : ka_row) -> ··· 161 161 ( "decode", 162 162 [ 163 163 Alcotest.test_case 164 - (Printf.sprintf "decode %d KeepAlive PDUs" n) 165 - `Quick test_decode; 164 + (Fmt.str "decode %d KeepAlive PDUs" n) 165 + `Quick decode_ka; 166 166 ] ); 167 167 ( "encode", 168 168 [ 169 169 Alcotest.test_case 170 - (Printf.sprintf "encode %d KeepAlive PDUs" n) 171 - `Quick test_encode; 170 + (Fmt.str "encode %d KeepAlive PDUs" n) 171 + `Quick encode_ka; 172 172 ] ); 173 173 ]
+29 -29
test/interop/spacepackets/test.ml
··· 29 29 let string_to_hex s = 30 30 let buf = Buffer.create (String.length s * 2) in 31 31 String.iter 32 - (fun c -> Buffer.add_string buf (Printf.sprintf "%02x" (Char.code c))) 32 + (fun c -> Buffer.add_string buf (Fmt.str "%02x" (Char.code c))) 33 33 s; 34 34 Buffer.contents buf 35 35 ··· 196 196 |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 197 197 |> finish)) 198 198 199 - let test_decode_eof () = 199 + let decode_eof () = 200 200 let rows = 201 201 match Csvt.decode_file eof_codec (trace "eof.csv") with 202 202 | Ok rows -> rows ··· 247 247 Alcotest.failf "%s: expected EOF directive" r.name) 248 248 rows 249 249 250 - let test_encode_eof () = 250 + let encode_eof () = 251 251 let rows = 252 252 match Csvt.decode_file eof_codec (trace "eof.csv") with 253 253 | Ok rows -> rows ··· 372 372 |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 373 373 |> finish)) 374 374 375 - let test_decode_metadata () = 375 + let decode_metadata () = 376 376 let rows = 377 377 match Csvt.decode_file metadata_codec (trace "metadata.csv") with 378 378 | Ok rows -> rows ··· 411 411 Alcotest.failf "%s: expected Metadata directive" r.name) 412 412 rows 413 413 414 - let test_encode_metadata () = 414 + let encode_metadata () = 415 415 let rows = 416 416 match Csvt.decode_file metadata_codec (trace "metadata.csv") with 417 417 | Ok rows -> rows ··· 528 528 Alcotest.failf "unexpected directive for ACK subtype: %a" 529 529 Cfdp.pp_directive_code d 530 530 531 - let test_decode_ack () = 531 + let decode_ack () = 532 532 let rows = 533 533 match Csvt.decode_file ack_codec (trace "ack.csv") with 534 534 | Ok rows -> rows ··· 573 573 Alcotest.failf "%s: expected ACK directive" r.name) 574 574 rows 575 575 576 - let test_encode_ack () = 576 + let encode_ack () = 577 577 let rows = 578 578 match Csvt.decode_file ack_codec (trace "ack.csv") with 579 579 | Ok rows -> rows ··· 683 683 |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 684 684 |> finish)) 685 685 686 - let test_decode_finished () = 686 + let decode_finished () = 687 687 let rows = 688 688 match Csvt.decode_file finished_codec (trace "finished.csv") with 689 689 | Ok rows -> rows ··· 733 733 Alcotest.failf "%s: expected Finished directive" r.name) 734 734 rows 735 735 736 - let test_encode_finished () = 736 + let encode_finished () = 737 737 let rows = 738 738 match Csvt.decode_file finished_codec (trace "finished.csv") with 739 739 | Ok rows -> rows ··· 843 843 |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 844 844 |> finish)) 845 845 846 - let test_decode_file_data () = 846 + let decode_file_data () = 847 847 let rows = 848 848 match Csvt.decode_file file_data_codec (trace "file_data.csv") with 849 849 | Ok rows -> rows ··· 869 869 (r.name ^ " data") expected_data (Bytes.to_string fd.data)) 870 870 rows 871 871 872 - let test_encode_file_data () = 872 + let encode_file_data () = 873 873 let rows = 874 874 match Csvt.decode_file file_data_codec (trace "file_data.csv") with 875 875 | Ok rows -> rows ··· 990 990 Cfdp.segment_request (Int64.of_string a) (Int64.of_string b) 991 991 | _ -> Alcotest.failf "bad segment format: %s" seg) 992 992 993 - let test_decode_nak () = 993 + let decode_nak () = 994 994 let rows = 995 995 match Csvt.decode_file nak_codec (trace "nak.csv") with 996 996 | Ok rows -> rows ··· 1030 1030 Alcotest.failf "%s: expected NAK directive" r.name) 1031 1031 rows 1032 1032 1033 - let test_encode_nak () = 1033 + let encode_nak () = 1034 1034 let rows = 1035 1035 match Csvt.decode_file nak_codec (trace "nak.csv") with 1036 1036 | Ok rows -> rows ··· 1144 1144 |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 1145 1145 |> finish)) 1146 1146 1147 - let test_decode_keep_alive () = 1147 + let decode_keep_alive () = 1148 1148 let rows = 1149 1149 match 1150 1150 Csvt.decode_file keep_alive_codec (dariol83_trace "keep_alive.csv") ··· 1168 1168 | Ok _ -> Alcotest.failf "%s: expected Keep_alive directive" r.name) 1169 1169 rows 1170 1170 1171 - let test_encode_keep_alive () = 1171 + let encode_keep_alive () = 1172 1172 let rows = 1173 1173 match 1174 1174 Csvt.decode_file keep_alive_codec (dariol83_trace "keep_alive.csv") ··· 1285 1285 Alcotest.run "cfdp-interop-spacepackets" 1286 1286 [ 1287 1287 ( "eof-decode", 1288 - [ Alcotest.test_case "decode EOF reference" `Quick test_decode_eof ] ); 1288 + [ Alcotest.test_case "decode EOF reference" `Quick decode_eof ] ); 1289 1289 ( "eof-encode", 1290 1290 [ 1291 1291 Alcotest.test_case "encode EOF matches reference" `Quick 1292 - test_encode_eof; 1292 + encode_eof; 1293 1293 ] ); 1294 1294 ( "metadata-decode", 1295 1295 [ 1296 1296 Alcotest.test_case "decode Metadata reference" `Quick 1297 - test_decode_metadata; 1297 + decode_metadata; 1298 1298 ] ); 1299 1299 ( "metadata-encode", 1300 1300 [ 1301 1301 Alcotest.test_case "encode Metadata matches reference" `Quick 1302 - test_encode_metadata; 1302 + encode_metadata; 1303 1303 ] ); 1304 1304 ( "ack-decode", 1305 - [ Alcotest.test_case "decode ACK reference" `Quick test_decode_ack ] ); 1305 + [ Alcotest.test_case "decode ACK reference" `Quick decode_ack ] ); 1306 1306 ( "ack-encode", 1307 1307 [ 1308 1308 Alcotest.test_case "encode ACK matches reference" `Quick 1309 - test_encode_ack; 1309 + encode_ack; 1310 1310 ] ); 1311 1311 ( "finished-decode", 1312 1312 [ 1313 1313 Alcotest.test_case "decode Finished reference" `Quick 1314 - test_decode_finished; 1314 + decode_finished; 1315 1315 ] ); 1316 1316 ( "finished-encode", 1317 1317 [ 1318 1318 Alcotest.test_case "encode Finished matches reference" `Quick 1319 - test_encode_finished; 1319 + encode_finished; 1320 1320 ] ); 1321 1321 ( "file-data-decode", 1322 1322 [ 1323 1323 Alcotest.test_case "decode File Data reference" `Quick 1324 - test_decode_file_data; 1324 + decode_file_data; 1325 1325 ] ); 1326 1326 ( "file-data-encode", 1327 1327 [ 1328 1328 Alcotest.test_case "encode File Data matches reference" `Quick 1329 - test_encode_file_data; 1329 + encode_file_data; 1330 1330 ] ); 1331 1331 ( "nak-decode", 1332 - [ Alcotest.test_case "decode NAK reference" `Quick test_decode_nak ] ); 1332 + [ Alcotest.test_case "decode NAK reference" `Quick decode_nak ] ); 1333 1333 ( "nak-encode", 1334 1334 [ 1335 1335 Alcotest.test_case "encode NAK matches reference" `Quick 1336 - test_encode_nak; 1336 + encode_nak; 1337 1337 ] ); 1338 1338 ( "keep-alive-encode", 1339 1339 [ 1340 1340 Alcotest.test_case "encode KeepAlive matches dariol83" `Quick 1341 - test_encode_keep_alive; 1341 + encode_keep_alive; 1342 1342 ] ); 1343 1343 ( "keep-alive-decode", 1344 1344 [ 1345 1345 Alcotest.test_case "decode KeepAlive dariol83 reference" `Quick 1346 - test_decode_keep_alive; 1346 + decode_keep_alive; 1347 1347 ] ); 1348 1348 ( "keep-alive-spacepackets-bug", 1349 1349 [
+3 -3
test/test_eio.ml
··· 28 28 else 29 29 let len = Int32.to_int (String.get_int32_be buf 0) in 30 30 if len < 0 || len > 1_048_576 then 31 - Error (Format.asprintf "invalid frame length: %d" len) 31 + Error (Fmt.str "invalid frame length: %d" len) 32 32 else if String.length buf < 4 + len then 33 33 Error 34 - (Format.asprintf "truncated frame: need %d, have %d" (4 + len) 34 + (Fmt.str "truncated frame: need %d, have %d" (4 + len) 35 35 (String.length buf)) 36 36 else Ok (String.sub buf 4 len) 37 37 ··· 366 366 (* ═══════════════════════════════════════════════════════════════════════ *) 367 367 368 368 let suite = 369 - ( "cfdp-eio", 369 + ( "cfdp_eio", 370 370 [ 371 371 (* Wire framing *) 372 372 Alcotest.test_case "frame empty" `Quick test_frame_empty;