<commit_before>(*
 * Copyright (C) 2006-2009 Citrix Systems Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *)
open Printf
open Pervasiveext
open Threadext

type inject_error_ty =
	| Inject_error_create
	| Inject_crash
	| Inject_shutdown

let boot_delay = ref 0. (* seconds per boot *)
let shutdown_delay = ref 0. (* seconds per shutdown *)

let debug_level = ref 3
let inject_error = ref []

let xiu_path = ref "" (* passed into udev scripts we fork *)

let random_inject_error ty = (Random.int 1024 > 950) && (List.mem ty !inject_error)

(* returned in physinfo, and can be set in the config file *)
let nb_cpu_nodes = ref 1
let nb_cpu_sockets = ref 1
let nb_cpu_cores = ref 2
let nb_cpu_threads = ref 1
let cpu_usage = ref 1000L
let cpu_speed_mhz = ref (1 * 1000) (* by default 1 ghz *)
let physical_free_kib = ref ((4 * 1024 - 1) * 1024) (* by default ~4gb of free memory *)
let physical_memory_kib = ref (4 * 1024 * 1024) (* by default 4gb of memory *)
let host_m = Mutex.create ()

let extra_kib = 512

(** utility *)
let create_unix_socket name =
	Unixext.unlink_safe name;
	Unixext.mkdir_rec (Filename.dirname name) 0o700;
	let sockaddr = Unix.ADDR_UNIX(name) in
	let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
	Unix.bind sock sockaddr;
	Unix.listen sock 1;
	sock

let with_xs f =
	let xs = Xs.daemon_open () in
	finally (fun () -> f xs) (fun () -> Xs.close xs)

let with_xs_retry f =
	let retry = ref true in
	while !retry do
		retry := false;
		try with_xs f
		with
		| Xb.End_of_file -> eprintf "xenstored: end of file; retrying in 5s\n%!"; Thread.delay 5.; retry := true
		| Xs.Failed_to_connect -> eprintf "xenstored: end of file; retrying in 10s\n%!"; Thread.delay 10.; retry := true<commit_msg>CA-34888: the Java bindings tests expect there to be enough memory to install from a Win7 (64 bit) template plus a bit. Bump up the default size of the simulated host in xiu.<commit_after>(*
 * Copyright (C) 2006-2009 Citrix Systems Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *)
open Printf
open Pervasiveext
open Threadext

type inject_error_ty =
	| Inject_error_create
	| Inject_crash
	| Inject_shutdown

let boot_delay = ref 0. (* seconds per boot *)
let shutdown_delay = ref 0. (* seconds per shutdown *)

let debug_level = ref 3
let inject_error = ref []

let xiu_path = ref "" (* passed into udev scripts we fork *)

let random_inject_error ty = (Random.int 1024 > 950) && (List.mem ty !inject_error)

(* returned in physinfo, and can be set in the config file *)
let nb_cpu_nodes = ref 1
let nb_cpu_sockets = ref 1
let nb_cpu_cores = ref 2
let nb_cpu_threads = ref 1
let cpu_usage = ref 1000L
let cpu_speed_mhz = ref (1 * 1000) (* by default 1 ghz *)
let physical_free_kib = ref ((16 * 1024 - 1) * 1024) (* by default ~16gb of free memory *)
let physical_memory_kib = ref (16 * 1024 * 1024) (* by default 16gb of memory *)
let host_m = Mutex.create ()

let extra_kib = 512

(** utility *)
let create_unix_socket name =
	Unixext.unlink_safe name;
	Unixext.mkdir_rec (Filename.dirname name) 0o700;
	let sockaddr = Unix.ADDR_UNIX(name) in
	let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
	Unix.bind sock sockaddr;
	Unix.listen sock 1;
	sock

let with_xs f =
	let xs = Xs.daemon_open () in
	finally (fun () -> f xs) (fun () -> Xs.close xs)

let with_xs_retry f =
	let retry = ref true in
	while !retry do
		retry := false;
		try with_xs f
		with
		| Xb.End_of_file -> eprintf "xenstored: end of file; retrying in 5s\n%!"; Thread.delay 5.; retry := true
		| Xs.Failed_to_connect -> eprintf "xenstored: end of file; retrying in 10s\n%!"; Thread.delay 10.; retry := true
{'fraction_non_alphanumeric': 0.08779209434374317, 'fraction_numerical': 0.03319502074688797, 'mean_word_length': 3.8516949152542375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1151851', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1494, 'n_words': 617}