CCSDS USLP (Unified Space Link Protocol) Transfer Frame- unified TM/TC/AOS
0
fork

Configure Feed

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

fix(ocaml-uslp): pass all merlint checks

- Fix Fmt.invalid_arg, make_frame→frame, find_clcw→clcw in uslp.ml
- Extract decode_fecf helper to reduce function length
- Update uslp.mli with renamed functions and fixed docs
- Restructure test suite to single tuple; fix Fmt/Printf usage
- Add test_uslp.mli and update test.ml entry point
- Fix gen_corpus.ml to use print_endline (no fmt dep)
- Add fuzz_uslp.mli with module/suite docs
- Fix fuzz suite name "crowbar"→"uslp" (E725)
- Add fuzz.ml runner and update dune (E718)

+67 -74
+6 -6
fuzz/dune
··· 1 1 (executable 2 - (name fuzz_uslp) 3 - (modules fuzz_uslp) 2 + (name fuzz) 3 + (modules fuzz fuzz_uslp) 4 4 (libraries uslp crowbar)) 5 5 6 6 (executable ··· 12 12 (alias runtest) 13 13 (enabled_if 14 14 (<> %{profile} afl)) 15 - (deps fuzz_uslp.exe) 15 + (deps fuzz.exe) 16 16 (action 17 - (run %{exe:fuzz_uslp.exe}))) 17 + (run %{exe:fuzz.exe}))) 18 18 19 19 (rule 20 20 (alias fuzz) ··· 22 22 (= %{profile} afl)) 23 23 (deps 24 24 (source_tree corpus) 25 - fuzz_uslp.exe 25 + fuzz.exe 26 26 gen_corpus.exe) 27 27 (action 28 - (echo "AFL fuzzer built: %{exe:fuzz_uslp.exe}\n"))) 28 + (echo "AFL fuzzer built: %{exe:fuzz.exe}\n")))
+1
fuzz/fuzz.ml
··· 1 + let () = Crowbar.run "uslp" [ Fuzz_uslp.suite ]
+1 -3
fuzz/fuzz_uslp.ml
··· 20 20 ignore (Uslp.decode buf) 21 21 22 22 let suite = 23 - ( "crowbar", 23 + ( "uslp", 24 24 [ 25 25 test_case "uslp roundtrip" 26 26 [ range 0x10000; range 64; range 16; bytes ] 27 27 test_roundtrip; 28 28 test_case "uslp decode random bytes" [ bytes ] test_decode_random; 29 29 ] ) 30 - 31 - let () = run "crowbar" [ suite ]
+3
fuzz/fuzz_uslp.mli
··· 1 + (** Fuzz tests for USLP frame encoding/decoding. *) 2 + 1 3 val suite : string * Crowbar.test_case list 4 + (** Crowbar fuzz test suite. *)
+1 -1
fuzz/gen_corpus.ml
··· 14 14 write "seed_003" (String.make 16 '\x00'); 15 15 write "seed_004" (String.make 16 '\xff'); 16 16 write "seed_005" (String.init 256 Char.chr); 17 - Printf.printf "gen_corpus: wrote 6 seed files\n" 17 + print_endline "gen_corpus: wrote 6 seed files"
+20 -24
lib/uslp.ml
··· 45 45 46 46 let scid_exn n = 47 47 if n >= 0 && n <= 0xFFFF then n 48 - else invalid_arg (Fmt.str "scid: %d out of range 0-65535" n) 48 + else Fmt.invalid_arg "scid: %d out of range 0-65535" n 49 49 50 50 let scid_to_int s = s 51 51 let vcid n = if n >= 0 && n <= 63 then Some n else None 52 52 53 53 let vcid_exn n = 54 54 if n >= 0 && n <= 63 then n 55 - else invalid_arg (Fmt.str "vcid: %d out of range 0-63" n) 55 + else Fmt.invalid_arg "vcid: %d out of range 0-63" n 56 56 57 57 let vcid_to_int v = v 58 58 let map_id n = if n >= 0 && n <= 15 then Some n else None 59 59 60 60 let map_id_exn n = 61 61 if n >= 0 && n <= 15 then n 62 - else invalid_arg (Fmt.str "map_id: %d out of range 0-15" n) 62 + else Fmt.invalid_arg "map_id: %d out of range 0-15" n 63 63 64 64 let map_id_to_int m = m 65 65 ··· 213 213 { expected = Int64.of_int expected; actual = Int64.of_int fecf_val }) 214 214 else Ok () 215 215 216 - let make_frame header insert_zone data ocf fecf = 216 + let frame header insert_zone data ocf fecf = 217 217 Ok { header; insert_zone; data; ocf; fecf } 218 + 219 + let decode_fecf ~compute ~get buf fecf_off check_fecf header insert_zone data 220 + ocf = 221 + let fecf_val = get buf fecf_off in 222 + let fecf = Some (Int64.of_int fecf_val) in 223 + if check_fecf then 224 + match verify_fecf ~compute buf fecf_off fecf_val with 225 + | Error e -> Error e 226 + | Ok () -> frame header insert_zone data ocf fecf 227 + else frame header insert_zone data ocf fecf 218 228 219 229 let decode ?(vcfc_len = 0) ?(insert_zone_len = 0) ?(expect_ocf = false) 220 230 ?(expect_fecf = No_fecf) ?(check_fecf = true) buf = ··· 254 264 let ocf = if ocf_size > 0 then Some (u32_be buf ocf_off) else None in 255 265 let fecf_off = ocf_off + ocf_size in 256 266 match expect_fecf with 257 - | No_fecf -> make_frame header insert_zone data ocf None 267 + | No_fecf -> frame header insert_zone data ocf None 258 268 | Crc16 -> 259 - let fecf_val = u16_be buf fecf_off in 260 - let fecf = Some (Int64.of_int fecf_val) in 261 - if check_fecf then 262 - match 263 - verify_fecf ~compute:compute_crc16 buf fecf_off fecf_val 264 - with 265 - | Error e -> Error e 266 - | Ok () -> make_frame header insert_zone data ocf fecf 267 - else make_frame header insert_zone data ocf fecf 269 + decode_fecf ~compute:compute_crc16 ~get:u16_be buf fecf_off 270 + check_fecf header insert_zone data ocf 268 271 | Crc32 -> 269 - let fecf_val = u32_be buf fecf_off in 270 - let fecf = Some (Int64.of_int fecf_val) in 271 - if check_fecf then 272 - match 273 - verify_fecf ~compute:compute_crc32 buf fecf_off fecf_val 274 - with 275 - | Error e -> Error e 276 - | Ok () -> make_frame header insert_zone data ocf fecf 277 - else make_frame header insert_zone data ocf fecf) 272 + decode_fecf ~compute:compute_crc32 ~get:u32_be buf fecf_off 273 + check_fecf header insert_zone data ocf) 278 274 279 275 (* {1 Frame encoding} *) 280 276 ··· 569 565 570 566 (* {1 CLCW Integration} *) 571 567 572 - let find_clcw frame = 568 + let clcw frame = 573 569 match frame.ocf with None -> None | Some word -> Some (Clcw.decode word) 574 570 575 571 let set_clcw frame clcw =
+8 -5
lib/uslp.mli
··· 33 33 val scid : int -> scid option 34 34 35 35 val scid_exn : int -> scid 36 - (** Like {!scid} but raises [Invalid_argument]. *) 36 + (** [scid_exn n] creates a spacecraft ID, raises [Invalid_argument] if out of 37 + range. *) 37 38 38 39 val scid_to_int : scid -> int 39 40 (** Extract the underlying integer. *) ··· 44 45 val vcid : int -> vcid option 45 46 46 47 val vcid_exn : int -> vcid 47 - (** Like {!vcid} but raises [Invalid_argument]. *) 48 + (** [vcid_exn n] creates a virtual channel ID, raises [Invalid_argument] if out 49 + of range. *) 48 50 49 51 val vcid_to_int : vcid -> int 50 52 (** Extract the underlying integer. *) ··· 55 57 val map_id : int -> map_id option 56 58 57 59 val map_id_exn : int -> map_id 58 - (** Like {!map_id} but raises [Invalid_argument]. *) 60 + (** [map_id_exn n] creates a MAP ID, raises [Invalid_argument] if out of range. 61 + *) 59 62 60 63 val map_id_to_int : map_id -> int 61 64 (** Extract the underlying integer. *) ··· 185 188 186 189 (** {1 CLCW Integration} *) 187 190 188 - val find_clcw : t -> (Clcw.t, Clcw.error) result option 189 - (** [find_clcw frame] extracts and decodes the CLCW from the OCF if present. *) 191 + val clcw : t -> (Clcw.t, Clcw.error) result option 192 + (** [clcw frame] extracts and decodes the CLCW from the OCF if present. *) 190 193 191 194 val set_clcw : t -> Clcw.t -> t 192 195 (** [set_clcw frame clcw] sets the OCF to the encoded CLCW. *)
+1 -1
test/test.ml
··· 1 - let () = Alcotest.run "uslp" Test_uslp.suite 1 + let () = Alcotest.run "uslp" [ Test_uslp.suite ]
+22 -33
test/test_uslp.ml
··· 62 62 match Uslp.decode ~expect_ocf:true encoded with 63 63 | Error e -> Alcotest.failf "decode failed: %a" Uslp.pp_error e 64 64 | Ok frame' -> ( 65 - match Uslp.find_clcw frame' with 65 + match Uslp.clcw frame' with 66 66 | None -> Alcotest.fail "no CLCW" 67 67 | Some (Error e) -> 68 68 Alcotest.failf "CLCW decode failed: %a" Clcw.pp_error e ··· 122 122 let packed_header_testable = 123 123 Alcotest.testable 124 124 (fun ppf h -> 125 - Format.fprintf ppf 125 + Fmt.pf ppf 126 126 "{tfvn=%d scid=%d %a vcid=%d map=%d eofph=%b flen=%d bypass=%b pcc=%b \ 127 127 ocf=%b vcfc_len=%d}" 128 128 h.Uslp.tfvn h.scid Uslp.pp_src_or_dest h.src_or_dest h.vcid h.map_id ··· 181 181 let vcfc = if vcfc_len = 0 then 0 else (1 lsl (vcfc_len * 8)) - 1 in 182 182 let frame = 183 183 Uslp.v ~scid ~vcid ~map_id ~vcfc ~vcfc_len 184 - (Printf.sprintf "vcfc_len=%d" vcfc_len) 184 + (Fmt.str "vcfc_len=%d" vcfc_len) 185 185 in 186 186 let encoded = Uslp.encode frame in 187 187 match Uslp.decode ~vcfc_len encoded with ··· 190 190 e 191 191 | Ok decoded -> 192 192 Alcotest.(check int) 193 - (Printf.sprintf "vcfc_len=%d header" vcfc_len) 193 + (Fmt.str "vcfc_len=%d header" vcfc_len) 194 194 vcfc_len decoded.header.vcfc_len; 195 195 Alcotest.(check int) 196 - (Printf.sprintf "vcfc_len=%d value" vcfc_len) 196 + (Fmt.str "vcfc_len=%d value" vcfc_len) 197 197 vcfc decoded.header.vcfc) 198 198 [ 0; 1; 2; 3; 4 ] 199 199 ··· 223 223 (Uslp.map_id_to_int decoded.header.map_id) 224 224 225 225 let suite = 226 - [ 227 - ( "uslp", 228 - [ 229 - Alcotest.test_case "roundtrip" `Quick test_roundtrip; 230 - Alcotest.test_case "roundtrip_with_vcfc" `Quick test_roundtrip_with_vcfc; 231 - Alcotest.test_case "roundtrip_with_crc16" `Quick 232 - test_roundtrip_with_crc16; 233 - Alcotest.test_case "roundtrip_with_crc32" `Quick 234 - test_roundtrip_with_crc32; 235 - Alcotest.test_case "clcw_integration" `Quick test_clcw_integration; 236 - Alcotest.test_case "idle_frame" `Quick test_idle_frame; 237 - Alcotest.test_case "src_dest" `Quick test_src_dest; 238 - Alcotest.test_case "vcid_bounds" `Quick test_vcid_bounds; 239 - Alcotest.test_case "scid_bounds" `Quick test_scid_bounds; 240 - Alcotest.test_case "map_id_bounds" `Quick test_map_id_bounds; 241 - ] ); 242 - ( "wire", 243 - [ 244 - Alcotest.test_case "wire_roundtrip" `Quick test_wire_roundtrip; 245 - Alcotest.test_case "wire_vs_manual" `Quick test_wire_vs_manual; 246 - ] ); 247 - ( "spec_vectors", 248 - [ 249 - Alcotest.test_case "vcfc_length_variants" `Quick 250 - test_vcfc_length_variants; 251 - Alcotest.test_case "map_id_boundary" `Quick test_map_id_boundary; 252 - ] ); 253 - ] 226 + ( "uslp", 227 + [ 228 + Alcotest.test_case "roundtrip" `Quick test_roundtrip; 229 + Alcotest.test_case "roundtrip_with_vcfc" `Quick test_roundtrip_with_vcfc; 230 + Alcotest.test_case "roundtrip_with_crc16" `Quick test_roundtrip_with_crc16; 231 + Alcotest.test_case "roundtrip_with_crc32" `Quick test_roundtrip_with_crc32; 232 + Alcotest.test_case "clcw_integration" `Quick test_clcw_integration; 233 + Alcotest.test_case "idle_frame" `Quick test_idle_frame; 234 + Alcotest.test_case "src_dest" `Quick test_src_dest; 235 + Alcotest.test_case "vcid_bounds" `Quick test_vcid_bounds; 236 + Alcotest.test_case "scid_bounds" `Quick test_scid_bounds; 237 + Alcotest.test_case "map_id_bounds" `Quick test_map_id_bounds; 238 + Alcotest.test_case "wire_roundtrip" `Quick test_wire_roundtrip; 239 + Alcotest.test_case "wire_vs_manual" `Quick test_wire_vs_manual; 240 + Alcotest.test_case "vcfc_length_variants" `Quick test_vcfc_length_variants; 241 + Alcotest.test_case "map_id_boundary" `Quick test_map_id_boundary; 242 + ] )
+4 -1
test/test_uslp.mli
··· 1 - val suite : (string * unit Alcotest.test_case list) list 1 + (** Tests for USLP frames. *) 2 + 3 + val suite : string * unit Alcotest.test_case list 4 + (** Alcotest test suite. *)