text stringlengths 12 786k |
|---|
type string ' = string [ @@ deriving qcheck ] qcheck |
let test_string ( ) = test_compare ~ msg " : Gen . string <=> deriving string " ~ eq : Alcotest . string Gen . string gen_string ' |
type char ' = char [ @@ deriving qcheck ] qcheck |
let test_char ( ) = test_compare ~ msg " : Gen . char <=> deriving char " ~ eq : Alcotest . char Gen . char gen_char ' |
type bool ' = bool [ @@ deriving qcheck ] qcheck |
let test_bool ( ) = test_compare ~ msg " : Gen . bool <=> deriving bool " ~ eq : Alcotest . bool Gen . bool gen_bool ' |
type float ' = float [ @@ deriving qcheck ] qcheck |
let test_float ( ) = test_compare ~ msg " : Gen . float <=> deriving float " ~ eq ( : Alcotest . float 0 ) . Gen . float gen_float ' |
type int32 ' = int32 [ @@ deriving qcheck ] qcheck |
let test_int32 ( ) = test_compare ~ msg " : Gen . int32 <=> deriving int32 " ~ eq : Alcotest . int32 Gen . ui32 gen_int32 ' |
type int64 ' = int64 [ @@ deriving qcheck ] qcheck |
let test_int64 ( ) = test_compare ~ msg " : Gen . int64 <=> deriving int64 " ~ eq : Alcotest . int64 Gen . ui64 gen_int64 ' |
type ' a option ' = ' a option [ @@ deriving qcheck ] qcheck |
let test_option ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . option <=> deriving option " ~ eq : Alcotest ( . option int ) int ( Gen . option zero ) zero ( gen_option ' zero ) zero |
type ' a array ' = ' a array [ @@ deriving qcheck ] qcheck |
let test_array ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . array <=> deriving array " ~ eq : Alcotest ( . array int ) int ( Gen . array zero ) zero ( gen_array ' zero ) zero |
type ' a list ' = ' a list [ @@ deriving qcheck ] qcheck |
let test_list ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . list <=> deriving list " ~ eq : Alcotest ( . list int ) int ( Gen . list zero ) zero ( gen_list ' zero ) zero |
let ( ) = Alcotest . run " Test_Primitives " [ ( " Primitives " , Alcotest [ . test_case " test_int " ` Quick test_int ; test_case " test_unit " ` Quick test_unit ; test_case " test_string " ` Quick test_string ; test_case " test_char " ` Quick test_char ; test_case... |
let pp_priority fmt { Priority . weight ; stream_dependency ; exclusive } = Format . fprintf fmt " Weight : % d ; Parent : % ld ; Exclusive : % B " weight stream_dependency exclusive |
let priority = Alcotest . of_pp pp_priority |
let node = ( module struct open Scheduler . PriorityTreeNode type t = parent let pp formatter ( Parent t ) t = Format . pp_print_text formatter ( Scheduler . stream_id t |> Int32 . to_string ) to_string let equal ( Parent h1 ) h1 ( Parent h2 ) h2 = Stream_identifier ( . Scheduler ( . ... |
let default_error_handler ? request : _ _err _handle = ( ) |
let new_p w = { Priority . exclusive = false ; stream_dependency = 0l ; weight = w } |
let test_reqd stream_id = Stream . create ~ max_frame_size : Config . default . read_buffer_size stream_id Serialize . Writer ( . create 0x400 ) 0x400 default_error_handler ( fun ~ active : _ _ -> ( ) ) |
let repeat ( Scheduler . PriorityTreeNode . Connection root ) root queue num = let rec loop q n acc = if n = 0 then acc else match Scheduler . PriorityQueue . pop q with | None -> failwith " invalid queue " | Some ( ( k , ( Scheduler . Stream p as p_node ) p_node ) p_node , q ' ) ... |
let add_stream root ( ? priority = Priority . default_priority ) default_priority reqd = ignore @@ Scheduler . add root ~ priority ~ initial_recv_window_size : Settings . WindowSize . default_initial_window_size ~ initial_send_window_size : Settings . WindowSize . default_initial_window_size req... |
let test_priority_queue ( ) = let root = Scheduler . make_root ~ capacity : 1000 ( ) in add_stream root ~ priority ( : new_p 201 ) 201 ( test_reqd 1l ) 1l ; add_stream root ~ priority ( : new_p 101 ) 101 ( test_reqd 3l ) 3l ; add_stream root ~ priority ( : new_p 1 ) ... |
let test_reprioritize ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 5 ( ) in add_stream root ( test_reqd 1l ) 1l ; add_stream root ( test_reqd 3l ) 3l ; add_stream root ( test_reqd 5l ) 5l ; let new_priority = { Priority . default_priority with weigh... |
let test_reprioritize_exclusive ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 5 ( ) in add_stream root ( test_reqd 1l ) 1l ; add_stream root ( test_reqd 3l ) 3l ; add_stream root ( test_reqd 5l ) 5l ; let stream7 = test_reqd 7l in let stream7_priority ... |
let depend_on stream_id = { Priority . default_priority with stream_dependency = stream_id } |
let set_up_dep_tree root = add_stream root ( test_reqd 1l ) 1l ; add_stream root ~ priority ( : depend_on 1l ) 1l ( test_reqd 3l ) 3l ; add_stream root ~ priority ( : depend_on 1l ) 1l ( test_reqd 5l ) 5l ; add_stream root ~ priority ( : depend_on 5l ) 5l ( test_reqd 7... |
let test_reprioritize_to_dependency ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 6 ( ) in set_up_dep_tree root ; let ( Stream stream1 as stream1_node ) stream1_node = Scheduler . get_node root 1l |> opt_exn in let stream5_node = Scheduler . get_node root 5l |> op... |
let test_reprioritize_to_dependency_exclusive ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 6 ( ) in set_up_dep_tree root ; let stream5_node = Scheduler . get_node root 5l |> opt_exn in let ( Stream stream7 as stream7_node ) stream7_node = Scheduler . get_node root ... |
let priority_queue_tests = [ " Priority queue tests " , ` Quick , test_priority_queue ] |
let reprioritization_tests = [ " Reprioritize simple " , ` Quick , test_reprioritize ; " Reprioritize simple exclusive " , ` Quick , test_reprioritize_exclusive ; " Reprioritize to dependency " , ` Quick , test_reprioritize_to_dependency ; ( " Reprioritize to dependency exclusive " ... |
let ( ) = Alcotest . run " httpaf unit tests " [ " Reprioritization tests " , reprioritization_tests ; " Priority_Queue_Tests " , priority_queue_tests ] |
module Aspect = struct type t = Hashing_Blake2b | Hashing_Sha256 let compare ( x : t ) ( y : t ) = match ( x , y ) with | ( Hashing_Sha256 , Hashing_Sha256 ) -> 0 | ( Hashing_Blake2b , Hashing_Blake2b ) -> 0 | ( Hashing_Blake2b , Hashing_Sha256 ) -> - 1 | ( Hashing_Sha... |
type workload = Blake2b of { nbytes : int } | Sha256 of { nbytes : int } |
type config = { max_bytes : int } |
module Probing_bench = struct let name = " Probing_test " let info = " Testing probing benchmarks " let tags = [ " example " ] type nonrec config = config let default_config = { max_bytes = 1 lsl 16 } let config_encoding = let open Data_encoding in conv ( fun { max_bytes } -> max_by... |
let bench_opts = let open Measure in { flush_cache = ` Dont ; stabilize_gc = false ; seed = Some 1337 ; nsamples = 30 ; determinizer = Percentile 50 ; cpu_affinity = None ; bench_number = 10 ; minor_heap_size = ` words ( 256 * 1024 ) ; config_dir = None ; } |
let do_bench ( ) = let bench : ( config , workload ) Benchmark . poly = ( module Probing_bench ) in let _workload_data = Measure . perform_benchmark bench_opts bench in true |
let tests = [ Test . tztest_assert " probing bench " ` Quick do_bench ] |
let ts = all_emacs_children ( ) in print_s [ % message " " ~ _ ( : ts : t list ) ] ; [ % expect { | ( " #< process Async scheduler " ) > } ] ; | List . iter ts ~ f ( : fun t -> print_s [ % message " " ~ name ( : name t : string ) ] ) ; [ % exp... |
let sleep ? buffer ( ) = create " / bin / sleep " [ " 100 " ] ~ name " : sleeper " ? buffer ( ) |
let show t = print_s [ % message " " ~ name ( : name t : string ) ~ buffer ( : buffer t : Buffer . t option ) ~ command ( : command t : string list option ) ~ is_in_all_emacs_children ( : List . mem ( all_emacs_children ( ) ) t ~ equal : bool ) ~ pid_is_positive : ( ... |
let wait_until f = let timeout_at = Time . ( add ( now ( ) ) ( Span . of_sec 1 . ) ) in while_ ( fun ( ) -> ( not ( f ( ) ) ) && Time . ( now ( ) < timeout_at ) ) ~ do_ ( : fun ( ) -> Timer . sleep_for ( 0 . 01 |> sec_ns ) ) ; ; let tes... |
let print_current_buffer_contents ( ) = print_string ( Current_buffer . contents ( ) |> Text . to_utf8_bytes ) ; ; |
let test_call_result_exn ? input ( ? output = Call . Output . Before_point_in_current_buffer ) ? working_directory ( ) ~ args ~ prog = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> let result = call_result_exn prog args ? input ~ output ? working_directory in print_s ... |
let show_file_contents file = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Point . insert_file_contents_exn file ; print_current_buffer_contents ( ) ) ; ; require_does_raise [ % here ] ( fun ( ) -> test_call_result_exn ( ) ~ prog " :/ zzz " ~ args [ ... |
let input_region ~ start ~ end_ ~ delete = Call . Region_input . Region { start = Position . of_int_exn start ; end_ = Position . of_int_exn end_ ; delete } ; ; |
let test result = print_s [ % message ( result : Call . Result . t ) ] ; print_endline " output " ; : print_current_buffer_contents ( ) ; Current_buffer . erase ( ) ; ; Point . insert " echo " ; test ( call_region_exn " cat " [ ] ~ output : Before_point_in_cur... |
module Query_response_tracker = Bonsai . Effect . For_testing . Query_response_tracker let var = Bonsai . Var . create 0 in let value = Bonsai . Var . value var in let component = return @@ Value . cutoff value ~ equal ( : fun a b -> a % 2 = b % 2 ) in let handle = Handle . create (... |
type thing = | Loading of string | Search_results of int let open Bonsai . Let_syntax in let component current_page = match % sub current_page with | Loading x -> Bonsai . read ( let % map x = x in " loading " ^ x ) | Search_results s -> Bonsai . read ( let % map s = s in sprintf " searc... |
let edge_poll_shared ~ get_expect_output = let effect_tracker = Query_response_tracker . create ( ) in let effect = Bonsai . Effect . For_testing . of_query_response_tracker effect_tracker in let var = Bonsai . Var . create " hello " in let component = Bonsai . Edge . Poll . effect_on_ch... |
let chain_computation = let % sub a = Bonsai . const " x " in let % sub b , set_b = Bonsai . state [ % here ] ( module String ) ~ default_model " : " in let % sub c , set_c = Bonsai . state [ % here ] ( module String ) ~ default_model " : " in let % sub d , set_d =... |
module M = struct type t = { a : string ; b : int } [ @@ deriving sexp_of , fields ] end let id = Bonsai . Dynamic_scope . create ~ sexp_of : M . sexp_of_t ~ name " : my - id " ~ fallback { : a = " hi " ; b = 5 } ( ) in let a = Bonsai . Dynamic_scope . derived id... |
let ( ) = Backtrace . elide := true |
let _ = Profile . should_profile := true |
module type Monad = sig include Monad . S val sync_or_async : _ t Sync_or_async . t end |
let clock = Private . Clock . create ~ now : Time_ns . epoch |
let advance_clock_by by = Clock . advance clock ~ by |
let ( ) = Private . clock := clock |
module Make_test ( M : Monad ) = struct open M . Let_syntax let test ? hide_if_less_than ( ) = let non_async_profile ( ) = profile ? hide_if_less_than Sync ( lazy [ % message " non_async_profile " ] ) ( fun ( ) -> advance_clock_by ( sec 0 . 1 ) ) in let bar ( ) = p... |
module Test_profile = Make_test ( struct include Monad . Ident let sync_or_async = Sync_or_async . Sync end ) |
module Test_profile_async = Make_test ( struct include Deferred let sync_or_async = Sync_or_async . Async end ) Test_profile . test ( ) ; [ % expect { | ( 1_000_000us foo " 1970 - 01 - 01 00 : 00 : 00Z " ( ( 20 % 200_000us bar ) ( 50 % 500_000us baz ( ( 40 % 20... |
let call_profile ( ) = profile Sync ( lazy [ % sexp " context " ] ) ( fun ( ) -> advance_clock_by ( sec 1 . ) ; print_endline " function supplied to [ profile ] ran " ) ; ; Ref . set_temporarily output_profile ( fun string -> call_profile ( ) ; print_endline st... |
let profile_sync ( ) = profile Sync ( lazy [ % message " foo " ] ) ( fun ( ) -> advance_clock_by ( sec 1 . ) ) ; ; require_does_not_raise [ % here ] ~ cr : CR_soon ( fun ( ) -> Ref . set_temporarily sexp_of_time_ns ( fun _ -> raise_s [ % message " raising "... |
let fail = Fail None |
let error msg = Fail ( Some msg ) |
let test_cases = [ ] |
let cmp_result result1 result2 = match ( result1 , result2 ) with |
let make_single_test_case ( code , expected_result ) = in try in in |
module Hash_Properties ( Desc : sig val name : string end ) struct let pp_bytes fmt d = Format . fprintf fmt " % S " ( Bytes . to_string d ) let test_prop_incremental_one ( msg_s : string ) = let st = X . init ( ) in let msg = Bytes . of_string msg_s in X . update st msg ; let ex... |
module SHA256_Props = Hash_Properties ( struct let name = " SHA256 " end ) ( Hacl . Hash . SHA256 ) |
module SHA512_Props = Hash_Properties ( struct let name = " SHA512 " end ) ( Hacl . Hash . SHA512 ) |
let ( ) = Alcotest . run " tezos - crypto - shaX - props " [ ( " SHA256_Props " , qcheck_wrap SHA256_Props . tests ) ; ( " SHA512_Props " , qcheck_wrap SHA512_Props . tests ) ; ] |
module Signature_Properties ( Desc : sig val name : string end ) struct let test_prop_sign_check ( s : string ) = let ( _ , pk , sk ) = X . generate_key ( ) in let data = Bytes . of_string s in let signed = X . sign sk data in X . check pk signed data let test_prop_sign_check = Test... |
module Ed25519_Props = Signature_Properties ( struct let name = " Ed25519 " end ) ( Ed25519 ) |
module P256_Props = Signature_Properties ( struct let name = " P256 " end ) ( P256 ) |
module Secp256k1_Props = Signature_Properties ( struct let name = " Secp256k1 " end ) ( Secp256k1 ) |
let ( ) = let open Signature in let f ( algo , name ) = let module X = struct include Signature let generate_key ? seed ( ) = generate_key ~ algo ? seed ( ) end in let module XProps = Signature_Properties ( struct let name = " Signature_ " ^ name end ) ( X ) in ( name , qchec... |
module Pk_Properties ( Desc : sig val name : string end ) struct let test_prop_sign_check ( sk_bytes : string ) = match X . sk_of_bytes @@ Bytes . of_string sk_bytes with | Some sk -> let pk = X . neuterize sk in let pk_bytes = X . to_bytes pk in let pk1 = X . pk_of_bytes_without_validation ... |
module P256_Props = Pk_Properties ( struct let name = " P256 " end ) ( Hacl . P256 ) |
let ( ) = Alcotest . run " tezos - crypto - signature - pk " [ ( " P256_Pros " , qcheck_wrap P256_Props . tests ) ] |
let test_protoc ctxt = let read filename = let path = Filename . concat ( Filename . dirname Sys . executable_name ) filename in let file = open_in path in let contents = really_input_string file ( in_channel_length file ) in close_in file ; Str . global_replace ( Str . regexp " " ) +$... |
let suite = " Test protoc " >:: test_protoc |
let all_env_versions = Protocol . [ V0 ; V1 ; V2 ; V3 ] |
let env_v_eq_check ( ) = List . iter ( fun v -> assert ( Protocol . compare_version v v = 0 ) ) all_env_versions |
let env_v_lt_check ( ) = let rec check = function | [ ] -> ( ) | v :: vs -> assert ( List . for_all ( fun w -> Protocol . compare_version v w < 0 ) vs ) ; check vs in check all_env_versions |
let env_v_gt_check ( ) = let rec check = function | [ ] -> ( ) | v :: vs -> assert ( List . for_all ( fun w -> Protocol . compare_version w v > 0 ) vs ) ; check vs in check all_env_versions |
let env_v_comparison_checks = let open Alcotest in [ test_case " equal " ` Quick env_v_eq_check ; test_case " less - than " ` Quick env_v_lt_check ; test_case " greater - than " ` Quick env_v_gt_check ; ] |
let ( ) = Alcotest . run " Protocol " [ ( " environment - version - comparison " , env_v_comparison_checks ) ] |
module Util = struct [ %% declare_roles a , b , c , d ] [ %% declare_labels msg , left , right , middle , ping , pong , fini ] end |
let test_projection_success ( ) = assert_equal ( ) @@ ignore @@ extract @@ ( a --> b ) msg finish ; assert_equal ~ msg " : simple " ( ) @@ ignore @@ extract @@ choice_at a [ % disj b ( left , right ) ] ( a , ( a --> b ) left finish ) ( a , ( a --> b ) right... |
let suite = " Protcol combinators expected " >::: [ " test_projection_success " >:: test_projection_success ] ; ; |
let _results = run_test_tt_main suite in ( ) |
module Util = struct [ %% declare_roles_prefixed a , b , c , d ] [ %% declare_labels msg , left , right , middle , ping , pong , fini ] end |
let test_failfast_bottom ( ) = let bottom ( ) = loop_with [ a ; b ; c ] ( fun t -> t ) in assert_raises UnguardedLoop ~ msg " : bottom " ( fun _ -> ignore @@ extract @@ bottom ( ) ) ; assert_raises UnguardedLoop ~ msg " : bottom after comm " ( fun _ -> ignore @@ ext... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.