<commit_before>(*
Copyright (2010-2014) INCUBAID BVBA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)

open OUnit_XML
open OUnit
open Node_cfg

type local_action =
  | ShowUsage
  | RunAllTests
  | RunAllTestsXML
  | RunSomeTests
  | ListTests
  | SystemTests
  | ShowVersion
  | DumpTlog
  | StripTlog
  | ReplayTlogs
  | DumpStore
  | MakeTlog
  | MarkTlog
  | CloseTlog
  | TruncateTlog
  | CompressTlog
  | UncompressTlog
  | BENCHMARK
  | LOAD
  | SET
  | GET
  | DELETE
  | DELETE_PREFIX
  | NOP
  | WHO_MASTER
  | EXPECT_PROGRESS_POSSIBLE
  | STATISTICS
  | PREFIX
  | USER_FUNCTION
  | Collapse_remote
  | Backup_db
  | Optimize_db
  | Defrag_db
  | NumberOfValues
  | InitNursery
  | MigrateNurseryRange
  | DeleteNurseryCluster
  | PING
  | InjectAsHead
  | NODE_VERSION
  | Drop_master
  | NODE_STATE
  | RANGE_ENTRIES
  | REV_RANGE_ENTRIES

type server_action =
  | Node
  | TestNode

type action =
  | LocalAction of local_action
  | ServerAction of server_action;;

let do_path p = Printf.printf "%s\n" (OUnit.string_of_path p)

let list_tests() =
  List.iter do_path (OUnit.test_case_paths All_test.suite)

let show_version ()=
  let open Arakoon_version in
  let () =
    Printf.printf "version: %i.%i.%i\n" major minor patch;
    Printf.printf "git_revision: %S\n" git_revision;
    Printf.printf "compiled: %S\n" compile_time;
    Printf.printf "machine: %S\n" machine;
    Printf.printf "compiler_version : %S\n" compiler_version;
    Printf.printf "tlogEntriesPerFile: %i\n" !Tlogcommon.tlogEntriesPerFile;
    Printf.printf "dependencies:\n%s\n" dependencies in
  ()

let interpret_test_results =
  List.fold_left
    (fun acc r ->
     match r with
     | RSuccess _ -> acc
     | RFailure _
     | RError _
     | RSkip _
     | RTodo _ -> 1)
    0

let run_all_tests () =
  All_test.configure_logging();
  let tests = All_test.suite in
  let results = run_test_tt tests in
  interpret_test_results results

let run_all_tests_xml filename =
  All_test.configure_logging();
  let tests = All_test.suite in
  let result = { result_list = [];
                 total_time = 0.0;
                 total_success = 0;
                 total_failures = 0;
                 total_errors = 0;
                 total_disabled = 0;
                 tmp_start = 0.0;
                 tmp_result = RSuccess []
               } in
  let results = perform_timed_tests result tests in
  let () = print_xml result filename in
  interpret_test_results results

let run_system_tests () =
  All_test.configure_logging();
  let tests = System_tests.suite in
  let results = OUnit.run_test_tt tests in
  interpret_test_results results


let run_some_tests repeat_count filter =
  All_test.configure_logging();
  Printf.printf "running tests matching '%s'\n" filter;
  let parts = Str.split_delim (Str.regexp "\\.") filter in
  let show_count num =
    if repeat_count > 1 then Printf.printf "-- iteration %d\n" (repeat_count - num + 1)
  in
  let rec do_n_times f results = function
    | 0 -> results
    | n ->
      let () = show_count n in
      let results' = f () in
      do_n_times f (List.append results' results) (n-1)
  in
  match OUnit.test_filter parts All_test.suite  with
    | Some test ->
      begin
        List.iter do_path (OUnit.test_case_paths test);
        let results = do_n_times (fun () -> OUnit.run_test_tt_main test) [] repeat_count in
        interpret_test_results results
      end

    | None -> failwith (Printf.sprintf "no test matches '%s'" filter);;


let main () =
  Ssl_threads.init ();
  Ssl.init ~thread_safe:true ();

  Lwt.async_exception_hook :=
    (fun exn -> Logger.ign_info_f_ ~exn "Caught async exception")

  let _ = Bz2.version in
  let () = Sys.set_signal Sys.sigpipe Sys.Signal_ignore in
  let () = Random.self_init () in
  let () = Client_log.enable_lwt_logging_for_client_lib_code () in
  let usage_buffer = Buffer.create 1024 in
  let app = Buffer.add_string usage_buffer in
  let usage =
    let bin = Sys.argv.(0) in
    app ("usage: " ^ bin ^ " --<command>\n");
    app ("\nIf you're clueless, try " ^ bin ^ " --help\n");
    Buffer.contents usage_buffer
  in
  let action = ref (LocalAction ShowUsage)
  and filename = ref "toy.db"
  and xml_filename = ref "output.xml"
  and filter = ref ""
  and node_id = ref ""
  and key = ref ""
  and value = ref ""
  and value_option = ref None
  and ip = ref "127.0.0.1"
  and port = ref 4000<commit_msg>fix ssl tests (basically, add a semi-colon)<commit_after>(*
Copyright (2010-2014) INCUBAID BVBA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)

open OUnit_XML
open OUnit
open Node_cfg

type local_action =
  | ShowUsage
  | RunAllTests
  | RunAllTestsXML
  | RunSomeTests
  | ListTests
  | SystemTests
  | ShowVersion
  | DumpTlog
  | StripTlog
  | ReplayTlogs
  | DumpStore
  | MakeTlog
  | MarkTlog
  | CloseTlog
  | TruncateTlog
  | CompressTlog
  | UncompressTlog
  | BENCHMARK
  | LOAD
  | SET
  | GET
  | DELETE
  | DELETE_PREFIX
  | NOP
  | WHO_MASTER
  | EXPECT_PROGRESS_POSSIBLE
  | STATISTICS
  | PREFIX
  | USER_FUNCTION
  | Collapse_remote
  | Backup_db
  | Optimize_db
  | Defrag_db
  | NumberOfValues
  | InitNursery
  | MigrateNurseryRange
  | DeleteNurseryCluster
  | PING
  | InjectAsHead
  | NODE_VERSION
  | Drop_master
  | NODE_STATE
  | RANGE_ENTRIES
  | REV_RANGE_ENTRIES

type server_action =
  | Node
  | TestNode

type action =
  | LocalAction of local_action
  | ServerAction of server_action;;

let do_path p = Printf.printf "%s\n" (OUnit.string_of_path p)

let list_tests() =
  List.iter do_path (OUnit.test_case_paths All_test.suite)

let show_version ()=
  let open Arakoon_version in
  let () =
    Printf.printf "version: %i.%i.%i\n" major minor patch;
    Printf.printf "git_revision: %S\n" git_revision;
    Printf.printf "compiled: %S\n" compile_time;
    Printf.printf "machine: %S\n" machine;
    Printf.printf "compiler_version : %S\n" compiler_version;
    Printf.printf "tlogEntriesPerFile: %i\n" !Tlogcommon.tlogEntriesPerFile;
    Printf.printf "dependencies:\n%s\n" dependencies in
  ()

let interpret_test_results =
  List.fold_left
    (fun acc r ->
     match r with
     | RSuccess _ -> acc
     | RFailure _
     | RError _
     | RSkip _
     | RTodo _ -> 1)
    0

let run_all_tests () =
  All_test.configure_logging();
  let tests = All_test.suite in
  let results = run_test_tt tests in
  interpret_test_results results

let run_all_tests_xml filename =
  All_test.configure_logging();
  let tests = All_test.suite in
  let result = { result_list = [];
                 total_time = 0.0;
                 total_success = 0;
                 total_failures = 0;
                 total_errors = 0;
                 total_disabled = 0;
                 tmp_start = 0.0;
                 tmp_result = RSuccess []
               } in
  let results = perform_timed_tests result tests in
  let () = print_xml result filename in
  interpret_test_results results

let run_system_tests () =
  All_test.configure_logging();
  let tests = System_tests.suite in
  let results = OUnit.run_test_tt tests in
  interpret_test_results results


let run_some_tests repeat_count filter =
  All_test.configure_logging();
  Printf.printf "running tests matching '%s'\n" filter;
  let parts = Str.split_delim (Str.regexp "\\.") filter in
  let show_count num =
    if repeat_count > 1 then Printf.printf "-- iteration %d\n" (repeat_count - num + 1)
  in
  let rec do_n_times f results = function
    | 0 -> results
    | n ->
      let () = show_count n in
      let results' = f () in
      do_n_times f (List.append results' results) (n-1)
  in
  match OUnit.test_filter parts All_test.suite  with
    | Some test ->
      begin
        List.iter do_path (OUnit.test_case_paths test);
        let results = do_n_times (fun () -> OUnit.run_test_tt_main test) [] repeat_count in
        interpret_test_results results
      end

    | None -> failwith (Printf.sprintf "no test matches '%s'" filter);;


let main () =
  Ssl_threads.init ();
  Ssl.init ~thread_safe:true ();

  let () =Lwt.async_exception_hook :=
    (fun exn -> Logger.ign_info_f_ ~exn "Caught async exception")
  in
  let _ = Bz2.version in
  let () = Sys.set_signal Sys.sigpipe Sys.Signal_ignore in
  let () = Random.self_init () in
  let () = Client_log.enable_lwt_logging_for_client_lib_code () in
  let usage_buffer = Buffer.create 1024 in
  let app = Buffer.add_string usage_buffer in
  let usage =
    let bin = Sys.argv.(0) in
    app ("usage: " ^ bin ^ " --<command>\n");
    app ("\nIf you're clueless, try " ^ bin ^ " --help\n");
    Buffer.contents usage_buffer
  in
  let action = ref (LocalAction ShowUsage)
  and filename = ref "toy.db"
  and xml_filename = ref "output.xml"
  and filter = ref ""
  and node_id = ref ""
  and key = ref ""
  and value = ref ""
  and value_option = ref None
  and ip = ref "127.0.0.1"
  and port = ref 4000
{'fraction_non_alphanumeric': 0.09119625025473813, 'fraction_numerical': 0.008559201141226819, 'mean_word_length': 2.9322916666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6839883', 'n_tokens_mistral': 3411, 'n_tokens_neox': 3300, 'n_words': 929}