Skip to content
Snippets Groups Projects
Commit 0973b02b authored by erwan's avatar erwan
Browse files

test: add fault injection functions

parent ab4e6980
No related branches found
No related tags found
No related merge requests found
Showing
with 50 additions and 100 deletions
../../../test/dune-project2copy
\ No newline at end of file
(lang dune 3.0)
...@@ -5,5 +5,11 @@ ...@@ -5,5 +5,11 @@
let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *) let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *)
let legitimate = None (* None => only silent configuration are legitimate *) let legitimate = None (* None => only silent configuration are legitimate *)
let fault = None (* None => the simulation stop once a legitimate configuration is reached *)
open State
let fault = Some (fun i _ _ ->
{
d = Random.int State.d;
par = Random.int i
})
let init_search_utils = None let init_search_utils = None
...@@ -12,7 +12,7 @@ let clash_number pidl get = ...@@ -12,7 +12,7 @@ let clash_number pidl get =
let potential = Some clash_number let potential = Some clash_number
(* let potential = None *) (* let potential = None *)
let legitimate = None let legitimate = None
let fault = None let fault = Some (fun d _pid _st -> Random.int d)
let md = max_degree () let md = max_degree ()
......
(* Time-stamp: <modified the 14/04/2022 (at 17:17) by Erwan Jahier> *) (* Time-stamp: <modified the 31/01/2024 (at 16:34) by Erwan Jahier> *)
(* This is algo 3.1 in the book *) (* This is algo 3.1 in the book *)
open Algo open Algo
...@@ -7,9 +7,9 @@ let k = if is_directed () then ...@@ -7,9 +7,9 @@ let k = if is_directed () then
else else
max_degree () + 1 max_degree () + 1
let (init_state: int -> string -> 'v) = fun i _ -> Random.int i let (init_state: int -> string -> 'v) = fun i _ -> Random.int i
let (colors : 'v neighbor list -> 'v list) = fun nl -> let (colors : 'v neighbor list -> 'v list) = fun nl ->
List.map (fun n -> state n) nl List.map (fun n -> state n) nl
(* Returns the free colors is ascending order (n.log(n)) (* Returns the free colors is ascending order (n.log(n))
...@@ -32,10 +32,10 @@ let (free : 'v neighbor list -> 'v list) = fun nl -> ...@@ -32,10 +32,10 @@ let (free : 'v neighbor list -> 'v list) = fun nl ->
in in
aux [] n_colors (k-1) aux [] n_colors (k-1)
let (enable_f: 'v -> 'v neighbor list -> action list) = let (enable_f: int -> int neighbor list -> action list) =
fun c nl -> fun c nl ->
if List.exists (fun n -> state n = c) nl then ["conflict"] else [] if List.exists (fun n -> state n = c) nl then ["conflict"] else []
let (step_f : 'v -> 'v neighbor list -> action -> 'v) = let (step_f : int -> int neighbor list -> action -> int) =
fun _ nl _ -> fun _ nl _ ->
List.hd (free nl) (* Returns the smallest possible color *) List.hd (free nl) (* Returns the smallest possible color *)
...@@ -100,7 +100,7 @@ let cost : pid list -> (pid -> t * (t neighbor * pid) list) -> float = ...@@ -100,7 +100,7 @@ let cost : pid list -> (pid -> t * (t neighbor * pid) list) -> float =
let potential = Some cost let potential = Some cost
let fault = None let fault = Some (fun _d _pid st -> { st with v = Random.int (card())} )
(* For the Dijkstra ring, a configuration is legitimate iff there is (* For the Dijkstra ring, a configuration is legitimate iff there is
exactly one token. exactly one token.
......
...@@ -23,7 +23,7 @@ let (legitimate: pid list -> (pid -> t * (t neighbor * pid) list) -> bool) = ...@@ -23,7 +23,7 @@ let (legitimate: pid list -> (pid -> t * (t neighbor * pid) list) -> bool) =
let legitimate = Some legitimate let legitimate = Some legitimate
let potential = None let potential = None
let fault = None (* None => the simulation stop once a legitimate configuration is reached *) let fault = Some(fun _ _ st -> { st with s = (Random.bool ()) })
open Algo open Algo
......
...@@ -79,7 +79,12 @@ let (pf: pid list -> (pid -> ('a * ('a neighbor * pid) list)) -> float) = ...@@ -79,7 +79,12 @@ let (pf: pid list -> (pid -> ('a * ('a neighbor * pid) list)) -> float) =
let potential = Some pf let potential = Some pf
let legitimate = None (* None => only silent configuration are legitimate *) let legitimate = None (* None => only silent configuration are legitimate *)
let fault = None let fault = Some(fun _ pid _ ->
{
isRoot = pid = "Root"; (* ZZZ: The root of the tree should be named "Root"! *)
alpha = Random.int (2*k+1);
par = if pid="Root" then -1 else 0 (* the input tree should be sorted alphabetically (wrt a bf traversal) *)
})
open State open State
let maxi = 2*k+1 let maxi = 2*k+1
......
let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *) let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *)
let fault = None (* None => the simulation stop once a legitimate configuration is reached *)
let init_search_utils = None (* To provide to use --init-search *) let init_search_utils = None (* To provide to use --init-search *)
let legitimate = None (* XXX this is wrong: FIXME *) let legitimate = None (* XXX this is wrong: FIXME *)
open State
let fault = Some (fun _nl _ _ ->
{ color_0 = Random.bool () ; phase_pos = Random.bool () ; orient_left = Random.bool () }
)
(* Time-stamp: <modified the 07/07/2023 (at 15:24) by Erwan Jahier> *) (* Time-stamp: <modified the 18/10/2023 (at 17:07) by Erwan Jahier> *)
(* Uniform deterministic self-stabilizing ring-orientation on odd-length rings (* Uniform deterministic self-stabilizing ring-orientation on odd-length rings
Hoepman, Jaap-Henk Hoepman, Jaap-Henk
WDAG'1994 WDAG'1994
https://core.ac.uk/download/pdf/301654088.pdf
hyp: central daemon hyp: central daemon
*) *)
......
-- include "../lustre/oracle_utils.lus" -- include "../lustre/oracle_utils.lus"
include "../../salut/lib/utils.lus" include "../../salut/lib/utils.lus"
include "../../salut/test/ring-orientation/state.lus"
type state = { color_0 : bool ; phase_pos : bool ; orient_left : bool }; -- type state = { color_0 : bool ; phase_pos : bool ; orient_left : bool };
function to_state( color_0 : bool ; phase_pos : bool ; orient_left : bool ) function to_state( color_0 : bool ; phase_pos : bool ; orient_left : bool )
returns(res : state); returns(res : state);
...@@ -12,6 +13,8 @@ tel; ...@@ -12,6 +13,8 @@ tel;
-- This oracle checks th 5.5 (via lurette)
node ring_orientation_oracle<<const an:int; const pn:int>> node ring_orientation_oracle<<const an:int; const pn:int>>
(legitimate:bool; Enab, Acti: bool^an^pn; Config:state^card ; round:bool; round_nb:int) (legitimate:bool; Enab, Acti: bool^an^pn; Config:state^card ; round:bool; round_nb:int)
returns (ok:bool); returns (ok:bool);
......
# Time-stamp: <modified the 17/01/2023 (at 14:22) by Erwan Jahier> # Time-stamp: <modified the 13/02/2024 (at 21:04) by Erwan Jahier>
DECO_PATTERN="0-:unison.ml" DECO_PATTERN="0-:unison.ml"
-include ./Makefile.dot -include ./Makefile.dot
...@@ -20,11 +20,9 @@ test2: ring.cmxs ...@@ -20,11 +20,9 @@ test2: ring.cmxs
$(sasa) -l 50 ring.dot -rif $(sasa) -l 50 ring.dot -rif
test3: test3:
cp state_with_fault.ml state.ml
rm fig41.cmxs rm fig41.cmxs
make fig41.cmxs make fig41.cmxs
$(sasa) -l 5 fig41.dot -sd -rif $(sasa) -l 5 fig41.dot -sd -rif
cp state_no_fault.ml state.ml
rm fig41.cmxs rm fig41.cmxs
sasaopt=-sd sasaopt=-sd
......
let fault = None (* None => the simulation stop once a legitimate configuration is reached *)
let fault = Some(fun _ _ _ -> Random.int State.m)
let legitimate pidl from_pid = let legitimate pidl from_pid =
(* a legitimate configuration is reached when all states have the same values *) (* a legitimate configuration is reached when all states have the same values *)
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
type t = int type t = int
let to_string = (fun s -> Printf.sprintf "c=%i" s) let to_string = (fun s -> Printf.sprintf "c=%i" s)
(* let m=10 (* max 2 (1+2*diameter ()) *) *)
let diameter = Algo.diameter ()
let m = max 2 (2*diameter-1)
let (of_string: (string -> t) option) = let (of_string: (string -> t) option) =
Some (fun s -> Some (fun s ->
let res = Scanf.sscanf s "c=%d" (fun i -> i ) in let res = Scanf.sscanf s "c=%d" (fun i -> i ) in
...@@ -13,8 +17,6 @@ let copy x = x ...@@ -13,8 +17,6 @@ let copy x = x
let actions = ["g"] let actions = ["g"]
let potential = None let potential = None
let fault = None
let legitimate pidl from_pid = let legitimate pidl from_pid =
(* a legitimate configuration is reached when all states have the same values *) (* a legitimate configuration is reached when all states have the same values *)
let v = fst(from_pid (List.hd pidl)) in let v = fst(from_pid (List.hd pidl)) in
...@@ -22,8 +24,6 @@ let legitimate pidl from_pid = ...@@ -22,8 +24,6 @@ let legitimate pidl from_pid =
(fun acc pid -> acc && fst(from_pid pid) = v) (fun acc pid -> acc && fst(from_pid pid) = v)
true true
(List.tl pidl) (List.tl pidl)
let legitimate = Some legitimate let legitimate = Some legitimate
type t = int
let to_string = (fun s -> Printf.sprintf "c=%i" s)
let (of_string: (string -> t) option) =
Some (fun s ->
let res = Scanf.sscanf s "c=%d" (fun i -> i ) in
res
)
let copy x = x
let actions = ["g"]
let potential = None
let fault = None
let legitimate pidl from_pid =
(* a legitimate configuration is reached when all states have the same values *)
let v = fst(from_pid (List.hd pidl)) in
List.fold_left
(fun acc pid -> acc && fst(from_pid pid) = v)
true
(List.tl pidl)
let legitimate = Some legitimate
type t = int
let to_string = (fun s -> Printf.sprintf "c=%i" s)
let (of_string: (string -> t) option) =
Some (fun s ->
let res = Scanf.sscanf s "c=%d" (fun i -> i ) in
res
)
let copy x = x
let actions = ["g"]
let potential = None
let fault m _ e =
if Random.bool () then Random.int m else e
let fault = Some fault
let legitimate pidl from_pid =
(* a legitimate configuration is reached when all states have the same values *)
let v = fst(from_pid (List.hd pidl)) in
List.fold_left
(fun acc pid -> acc && fst(from_pid pid) = v)
true
(List.tl pidl)
let legitimate = Some legitimate
(* Time-stamp: <modified the 22/11/2022 (at 13:59) by Erwan Jahier> *) (* Time-stamp: <modified the 13/02/2024 (at 20:55) by Erwan Jahier> *)
open Algo open Algo
(* let m=10 (* max 2 (1+2*diameter ()) *) *) let m = State.m
let diameter = Algo.diameter ()
let m = max 2 (2*diameter-1)
let (init_state: int -> string -> 'v) = let (init_state: int -> string -> 'v) =
fun _ _ -> fun _ _ ->
...@@ -15,17 +12,14 @@ let (init_state: int -> string -> 'v) = ...@@ -15,17 +12,14 @@ let (init_state: int -> string -> 'v) =
let new_clock_value nl clock = let new_clock_value nl clock =
let cl = List.map (fun n -> state n) nl in let cl = List.map (fun n -> state n) nl in
let min_clock = List.fold_left min clock cl in let min_clock = List.fold_left min clock cl in
(min_clock + 1) mod m (min_clock + 1) mod m
let (enable_f: 'v -> 'v neighbor list -> action list) = let (enable_f: 'v -> 'v neighbor list -> action list) =
fun clock nl -> fun clock nl ->
if (new_clock_value nl clock) <> clock then ["g"] else [] if (new_clock_value nl clock) <> clock then ["g"] else []
let (step_f : 'v -> 'v neighbor list -> action -> 'v) = let (step_f : 'v -> 'v neighbor list -> action -> 'v) =
fun clock nl a -> fun clock nl a ->
let v = new_clock_value nl clock in let v = new_clock_value nl clock in
match a with match a with
| _ -> v | _ -> v
#use "genExpeMakefiles.ml";; #use "genExpeMakefiles.ml";;
precision := 0.1;; precision := 0.1;;
(* 0.1 means that we simulate until the onfidence Interval size of (* 0.1 means that we simulate until the confidence Interval size of
the 3 complexity numbers under estimation is smaller than 10% of the 3 complexity numbers under estimation is smaller than 10% of
their current estimation. their current estimation.
...@@ -11,7 +11,7 @@ timeout_in_sec := 60;; (* ditto *) ...@@ -11,7 +11,7 @@ timeout_in_sec := 60;; (* ditto *)
let algos = ["../../test/alea-coloring-alt"; let algos = ["../../test/alea-coloring-alt";
"../../test/alea-coloring-unif"; "../../test/alea-coloring-unif";
"../../test/alea-coloring"] "../../test/alea-coloring"]
let daemons = ["-sd";"-lcd";"-dd"] let daemons = ["-sd";"-lcd";"-dd"]
let cliques = List.init 5 (fun n -> Clique (10*(n+1))) (* [10; 20; ...; 50] *) let cliques = List.init 5 (fun n -> Clique (10*(n+1))) (* [10; 20; ...; 50] *)
let rings = List.init 5 (fun n -> Ring (100*(n+1))) (* [100; 200; ...; 500] *) let rings = List.init 5 (fun n -> Ring (100*(n+1))) (* [100; 200; ...; 500] *)
let er = List.init 5 (fun n -> ER (20*(n+1), 0.4)) (* [20; 40; ...; 100] *) let er = List.init 5 (fun n -> ER (20*(n+1), 0.4)) (* [20; 40; ...; 100] *)
...@@ -22,7 +22,7 @@ let gen_make_rules () = gen_makefile "Makefile.expe-rules" daemons algos network ...@@ -22,7 +22,7 @@ let gen_make_rules () = gen_makefile "Makefile.expe-rules" daemons algos network
#use "parseLog.ml";; #use "parseLog.ml";;
let gen_pdf () = let gen_pdf () =
let gl = ["clique"; "ring"; "er"] in let gl = ["clique"; "ring"; "er"] in
List.iter (fun n -> sh ("rm -f "^n^".data")) gl; (* because parse_log appends data *) List.iter (fun n -> sh ("rm -f "^n^".data")) gl; (* because parse_log appends data *)
parse_log ["Uniform When Activated", "alea-coloring-unif"] gl daemons; parse_log ["Uniform When Activated", "alea-coloring-unif"] gl daemons;
parse_log ["Smallest When Activated","alea-coloring"] gl daemons; parse_log ["Smallest When Activated","alea-coloring"] gl daemons;
parse_log ["Always the Biggest", "alea-coloring-alt"] gl daemons; parse_log ["Always the Biggest", "alea-coloring-alt"] gl daemons;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment