text
stringlengths
12
786k
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let compat2_3 = match Sundials . Config . sundials_version with | 2 , _ , _ -> true | 3 , _ , _ -> true | _ -> false
module Dense_tests = struct type k = Matrix . standard type m = Matrix . Dense . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = nk Matrix . dense type nvec = Nvector_serial . t let rewrap = Matrix . wrap_dense let check_matrix a b tol = let ca , cb = Matrix . ( ...
module Test = Test_matrix . Test ( Dense_tests ) ( Nvector_serial . Ops )
let main ( ) = let fails = ref 0 in if Array . length Sys . argv < 4 then ( printf " ERROR : THREE ( 3 ) Input required : matrix rows , matrix cols , print timing @\ n " ; exit ( - 1 ) ) ; let matrows = int_of_string Sys . argv . ( 1 ) in if matrows <= 0 then ( p...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let rand_float ( ) = ( float_of_int ( Test_matrix . rand ( ) ) . / float_of_int ( Test_matrix . rand_max ) )
module Sparse_tests ( S : sig type sformat end ) = struct type k = Matrix . standard type m = S . sformat Matrix . Sparse . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = ( S . sformat , nk ) Matrix . sparse type nvec = Nvector_serial . t let rewrap = Mat...
let clone a = Matrix . ( wrap_sparse ( ( get_ops a ) . m_clone ( unwrap a ) ) )
let test_sunmatscaleadd2 check_vector a b x y z = let tol = match Sundials . Config . sundials_version with | 2 , _ , _ | 3 , 1 , 0 | 3 , 1 , 1 | 3 , 1 , 2 -> 1e - 14 | _ -> 100 . 0 . * Sundials . Config . unit_roundoff in try let c = clone a in let u = Nvector_...
let test_sunmatscaleaddi2 check_vector a x y = let tol = match Sundials . Config . sundials_version with | 2 , _ , _ | 3 , 1 , 0 | 3 , 1 , 1 | 3 , 1 , 2 -> 1e - 14 | _ -> 100 . 0 . * Sundials . Config . unit_roundoff in try let b = clone a in let z = Nvector_ser...
let test_sunsparsematrix_convert ( type s ) ( check_matrix : ( s , ' a ) Matrix . sparse -> ( s , ' a ) Matrix . sparse -> float -> bool ) ( am : ( s , ' a ) Matrix . sparse ) = let tol = 200 . 0 . * Sundials . Config . unit_roundoff in let a = Matrix . unw...
let int_of_mattype ( type s ) : s Matrix . Sparse . sformat -> int = function | Matrix . Sparse . CSC -> 0 | Matrix . Sparse . CSR -> 1
let rec main ( ) = if Array . length Sys . argv < 5 then ( printf " ERROR : FOUR ( 4 ) Input required : matrix rows , matrix cols , matrix type ( 0 / 1 ) , print timing @\ n " ; exit ( - 1 ) ) ; let matrows = int_of_string Sys . argv . ( 1 ) in if matrows <= ...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let sungte500 = let n , _ , _ = Sundials_configuration . sundials_version in n >= 5
let tol = if sungte500 then 100 . 0 . * sqrt ( Config . unit_roundoff ) else 1 . 0e - 4
let mxiter = if sungte500 then 20 else 10
let ytrue = if sungte500 then one else zero
let conv_test _ ( del : RealArray . t ) tol _ _ = if Nvector_serial . DataOps . maxnorm del <= tol then NLS . Success else NLS . Continue
let fp_function_lt500 y f _ = f . { 0 } <- ( one . / three ) . * cos ( y . { 1 } . * y . { 2 } ) . + ( one . / six ) ; f . { 1 } <- ( one . / nine ) . * sqrt ( y . { 0 } . * y . { 0 } . + sin ( y . { 2 } ) . + one...
let fp_function ( y0 , ycur ) ycor gvec _ = Nvector_serial . DataOps . linearsum one y0 one ycor ycur ; let x = ycur . { 0 } in let y = ycur . { 1 } in let z = ycur . { 2 } in gvec . { 0 } <- ( one . / three ) . * cos ( ( y . - one ) . * z ) . + (...
let check_ans data tol = printf " Computed solution :\ n " ; printf " y1 = % g \ n " data . { 0 } ; printf " y2 = % g \ n " data . { 1 } ; printf " y3 = % g \ n " data . { 2 } ; let ex = abs_float ( data . { 0 } . - xtrue ) in let ey = abs_float ( ...
let main ( ) = let argc = Array . length Sys . argv in let maa = if argc > 1 then int_of_string Sys . argv . ( 1 ) else 0 in let damping = if argc > 2 then float_of_string Sys . argv . ( 2 ) else 1 . 0 in if sungte500 then begin printf " Solve the nonlinear system :\ n " ; ...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let jac _ y j = j . { 0 , 0 } <- two . * y . { 0 } ; j . { 1 , 0 } <- two . * y . { 1 } ; j . { 2 , 0 } <- two . * y . { 2 } ; j . { 0 , 1 } <- four . * y . { 0 } ; j . { 1 , 1 } <- two . * y . { 1 } ; j...
type ' k integrator_mem_rec = { y0 : Nvector_serial . t ; ycur : Nvector_serial . t ; ycor : Nvector_serial . t ; w : Nvector_serial . t ; x : Nvector_serial . t ; a : ' k Matrix . dense ; ls : ( Matrix . Dense . t , ' k , [ ` Dls ] ) LS . serial_t ; }
let lsetup imem _ _ = jac zero ( Nvector . unwrap imem . ycur ) ( Matrix . ( Dense . unwrap ( unwrap imem . a ) ) ) ; LS . setup imem . ls imem . a ; true
let lsolve imem b _ = LS . solve imem . ls imem . a imem . x ( Nvector_serial . wrap b ) zero ; NVOps . scale one ( Nvector_serial . unwrap imem . x ) b
let conv_test _ _ del tol ewt _ = let delnrm = NVOps . wrmsnorm del ewt in if delnrm <= tol then NLS . Success else NLS . Continue
let res imem y f _ = let y1 , y2 , y3 = if Sundials_impl . Version . lt500 then y . { 0 } , y . { 1 } , y . { 2 } else begin Nvector_serial . Ops . linearsum one imem . y0 one imem . ycor imem . ycur ; let ycur = Nvector . unwrap imem . ycur in ycur . { 0 } , ...
let main ( ) = let x = Nvector_serial . make neq 0 . 0 in let y0 = Nvector_serial . wrap ( RealArray . of_array [ | half ; half ; half ] ) | in let ycur = Nvector . clone y0 in let ycor = Nvector_serial . make neq zero in let w = Nvector_serial . make neq one in let a = Matrix ....
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let wrong_k message = fun _ -> assert_failure message
let with_text_limit n f = let limit = ! Text . length_limit in Text . length_limit := n ; try f ( ) ; Text . length_limit := limit with exn -> Text . length_limit := limit ; raise exn
let expect_error : ? allow_recovery : int -> location -> Error . t -> ( Error . parse_handler -> unit ) -> unit = fun ( ? allow_recovery = 0 ) l error f -> let errors = ref 0 in let report l ' error ' _ k = errors := ! errors + 1 ; if ! errors > 1 + allow_recovery then sprintf...
let expect_sequence ( ? prefix = false ) id to_string sequence = let assert_failure s = assert_failure ( id ^ " \ n " ^ s ) in let sequence = ref sequence in let invalid = ref false in let receive s throw = if ! invalid then ( ) else match ! sequence with | [ ] -> if not prefix then be...
let iter iterate s = Kstream . iter iterate s ( function | Exit -> ( ) | exn -> raise exn ) ignore
type ' a general_signal = S of ' a | E of Error . t
let expect_signals ? prefix signal_to_string id signals = let to_string = function | l , c , S s -> sprintf " line % i , column % i : % s " l c ( signal_to_string s ) | l , c , E e -> sprintf " line % i , column % i : % s " l c ( Error . to_string e ) in let receive , ende...
let expect_strings id strings = let to_string = function | S s -> s | E e -> Error . to_string e in let receive , ended = expect_sequence id to_string strings in let report _ e throw k = receive ( E e ) throw ; k ( ) in let string s throw k = receive ( S s ) throw ; k ( ) in report , ...
require [ % here ] ( equal ( intern " foo " ) ( intern " foo " ) ) ; return ( ) ; ; require [ % here ] ( not ( equal ( intern " foo " ) ( intern " bar " ) ) ) ; return ( ) ; ; require [ % here ] ( not ( equal ( create ~ name " : fo...
let test_bracket_succeed ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = assert_equal ! state ` test_end ; state := ` torn_down in Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; state := ` tes...
let test_bracket_fail ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = state := ` torn_down in try Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; assert_equal 5 6 ) teardown ( ) ; with TestFa...
let test_bracket_error ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = state := ` torn_down in try Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; raise TestException ) teardown ( ) ; with Test...
let suite = " sync " >::: [ " test_bracket_succeed " >:: test_bracket_succeed ; " test_bracket_fail " >:: test_bracket_fail ; " test_bracket_error " >:: test_bracket_error ; ]
let prn = function | Synchronised { is_chain_stuck = true } -> " Synchronised ( stuck ) " | Not_synchronised -> " Not synchronised " | Synchronised { is_chain_stuck = false } -> " Synchronised ( not stuck ) "
let forge_peer_id ( ) = let identity = P2p_identity . generate_with_pow_target_0 ( ) in identity . peer_id
let forge_timestamp ( ? delay = 0 ) ( ) = let time = Time . System . to_protocol @@ Systime_os . now ( ) in Time . Protocol . add time ( Int64 . of_int delay )
let forge_value ? delay ? timestamp ? peer ( ) = let peer = match peer with Some peer -> peer | None -> forge_peer_id ( ) in let timestamp = match timestamp with | Some timestamp -> timestamp | None -> forge_timestamp ? delay ( ) in ( timestamp , peer )
let test_threshold_negative ( ) = let heuristic = create ~ threshold ( :- 1 ) ~ latency : 120 in Assert . equal ~ prn ( get_status heuristic ) Not_synchronised ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn ( get_status heuristic ) Not_synchronised ; update heurist...
let test_threshold_is_zero ( ) = let heuristic = create ~ threshold : 0 ~ latency : 120 in Assert . equal ~ prn ( get_status heuristic ) ( Synchronised { is_chain_stuck = false } ) ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn ( get_status heuristic ) ( Synch...
let test_threshold_is_one ( ) = let heuristic = create ~ threshold : 1 ~ latency : 120 in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn ( Synchronised { is_chain_stuck = false } ) ( get_status heurist...
let test_threshold_is_one_update_in_the_past ( ) = let latency = 120 in let heuristic = create ~ threshold : 1 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; let peer = forge_peer_id ( ) in update heuristic @@ forge_value ~ peer ( ) ; Assert . equal ~ ...
let test_threshold_is_one_value_in_the_past ( ) = let latency = 120 in let heuristic = create ~ threshold : 1 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update heuristic @@ forge_value ~ delay ( : latency * - 2 ) ( ) ; Assert . equal ~ prn Not_s...
let test_threshold_is_one_always_takes_best_timestamp ( ) = let latency = 120 in let heuristic = create ~ threshold : 1 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn ( Synchronised { is_chain_st...
let test_threshold_is_two ( ) = let latency = 120 in let heuristic = create ~ threshold : 2 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; let peer = forge_peer_id ( ) in update heuristic @@ forge_value ~ peer ( ) ; Assert . equal ~ prn Not_synchronise...
let test_threshold_is_two_one_in_the_past ( ) = let latency = 120 in let heuristic = create ~ threshold : 2 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ...
let test_threshold_is_two_one_in_the_past_and_one_more ( ) = let latency = 120 in let heuristic = create ~ threshold : 2 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; let peer = forge_peer_id ( ) in update heuristic @@ forge_value ~ peer ~ delay ( :- 3 ) ...
let test_threshold_is_two_two_in_the_past ( ) = let latency = 120 in let heuristic = create ~ threshold : 2 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; let timestamp = forge_timestamp ~ delay ( : latency * - 3 ) ( ) in update heuristic @@ forge_value...
let test_threshold_is_three ( ) = let latency = 120 in let heuristic = create ~ threshold : 3 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update heuristic @@ forge_value ( ) ; Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; update h...
let test_threshold_is_three_and_stuck ( ) = let latency = 120 in let heuristic = create ~ threshold : 3 ~ latency in Assert . equal ~ prn Not_synchronised ( get_status heuristic ) ; let peer1 = forge_peer_id ( ) in let timestamp = forge_timestamp ~ delay ( : latency * - 2 ) ( ) i...
let test_counterexample_1 ( ) = let latency = 100 in let heuristic = create ~ threshold : 3 ~ latency in let p9 = forge_peer_id ( ) in let fresh = forge_peer_id ( ) in let p2 = forge_peer_id ( ) in let p7 = forge_peer_id ( ) in let p8 = forge_peer_id ( ) in let delay = - 279 in l...
let tests_raw : ( string * ( unit -> unit ) ) list = [ ( " Threshold negative " , test_threshold_negative ) ; ( " Threshold is zero " , test_threshold_is_zero ) ; ( " Threshold is one , update in the present " , test_threshold_is_one ) ; ( " Threshold is one , u...
let tests = List . map ( fun ( s , f ) -> Alcotest_lwt . test_case_sync s ` Quick f ) tests_raw
let test_bp_create ( ) = let latency = 100 in let called = ref false in let when_status_changes _ = called := true ; Lwt . return_unit in let _heuristic = create ~ when_status_changes ~ threshold : 3 ~ latency ( ) in Assert . equal ! called false ; Lwt . return_unit
let test_bp_activate ( ) = let latency = 100 in let called = ref false in let when_status_changes _ = called := true ; Lwt . return_unit in let heuristic = create ~ when_status_changes ~ threshold : 3 ~ latency ( ) in activate heuristic >>= fun ( ) -> Assert . equal ! called true ; L...
let test_bp_create_2 ( ) = let latency = 100 in let status_changes_called = ref false in let bootstrapped_changes_called = ref false in let when_status_changes _ = status_changes_called := true ; Lwt . return_unit in let when_bootstrapped_changes b = Assert . equal b true ; bootstrapped_changes_cal...
let test_bp_activate_2 ( ) = let latency = 100 in let status_changes_called = ref false in let bootstrapped_changes_called = ref false in let when_status_changes _ = status_changes_called := true ; Lwt . return_unit in let when_bootstrapped_changes b = Assert . equal b true ; bootstrapped_changes_c...
let test_force_bootstrapped ( ) = let latency = 100 in let bootstrapped_changes_called = ref 0 in let when_bootstrapped_changes b = let expected_value = if ! bootstrapped_changes_called = 0 then false else true in Assert . equal b expected_value ; incr bootstrapped_changes_called ; Lwt . return_un...
let test_force_bootstrapped_2 ( ) = let latency = 100 in let bootstrapped_changes_called = ref 0 in let when_bootstrapped_changes b = Assert . equal b false ; incr bootstrapped_changes_called ; Lwt . return_unit in let heuristic = create ~ when_bootstrapped_changes ~ threshold : 1 ~ latency ( ...
let test_force_bootstrapped_3 ( ) = let latency = 100 in let bootstrapped_changes_called = ref 0 in let when_bootstrapped_changes _b = incr bootstrapped_changes_called ; Lwt . return_unit in let heuristic = create ~ when_bootstrapped_changes ~ threshold : 1 ~ latency ( ) in activate heuristic ...
let test_is_bootstrapped ( ) = let latency = 100 in let heuristic = create ~ threshold : 1 ~ latency ( ) in activate heuristic >>= fun ( ) -> Assert . equal ( is_bootstrapped heuristic ) false ; Lwt . return_unit
let test_is_bootstrapped_2 ( ) = let latency = 100 in let heuristic = create ~ threshold : 0 ~ latency ( ) in activate heuristic >>= fun ( ) -> Assert . equal ( is_bootstrapped heuristic ) true ; Lwt . return_unit
let test_is_bootstrapped_3 ( ) = let latency = 100 in let heuristic = create ~ threshold : 1 ~ latency ( ) in activate heuristic >>= fun ( ) -> force_bootstrapped heuristic true >>= fun ( ) -> Assert . equal ( is_bootstrapped heuristic ) true ; Lwt . return_unit
let test_bootstrapped ( ) = let latency = 100 in let heuristic = create ~ threshold : 0 ~ latency ( ) in activate heuristic >>= fun ( ) -> bootstrapped heuristic
let test_bootstrapped_2 ( ) = let latency = 100 in let heuristic = create ~ threshold : 1 ~ latency ( ) in activate heuristic >>= fun ( ) -> let p = bootstrapped heuristic in Assert . equal ( Lwt . state p ) Lwt . Sleep ; force_bootstrapped heuristic true >>= fun ( ) -> p
let test_threshold_is_three_and_stuck_with_callbacks ( ) = let latency = 120 in let status_changes = ref 0 in let when_status_changes status = let expected_value = if ! status_changes = 0 then Not_synchronised else if ! status_changes = 1 then Synchronised { is_chain_stuck = true } else if ! stat...
let wrap f _switch ( ) = f ( )
let tests_lwt_raw : ( string * ( Lwt_switch . t -> unit -> unit Lwt . t ) ) list = [ ( " test bp create " , wrap test_bp_create ) ; ( " test bp create 2 " , wrap test_bp_create_2 ) ; ( " test bp activate " , wrap test_bp_activate ) ; ( " test bp activate 2 " ...
let tests_lwt = List . map ( fun ( s , f ) -> Alcotest_lwt . test_case s ` Quick f ) tests_lwt_raw
module type S = sig type status = Chain_validator_worker_state . Event . synchronisation_status = | Synchronised of { is_chain_stuck : bool } | Not_synchronised type t val update : t -> Time . Protocol . t * P2p_peer . Id . t -> unit val get_status : t -> status val create : threshold : in...
module Reference : S = struct type status = Chain_validator_worker_state . Event . synchronisation_status = | Synchronised of { is_chain_stuck : bool } | Not_synchronised type t = { threshold : int ; latency : int ; mutable candidates : ( Time . Protocol . t * P2p_peer . Id . t ) l...
let forge_peer_id ( ) = let identity = P2p_identity . generate_with_pow_target_0 ( ) in identity . peer_id
let peer_id = let open QCheck2 . Gen in let static = [ " P1 " ; " P2 " ; " P3 " ; " P4 " ; " P5 " ; " P6 " ; " P7 " ; " P8 " ; " P9 " ] |> List . map ( fun name -> pure ( forge_peer_id ( ) , name ) ) in delay ( fun ( ) -> oneof ( pur...