Skip to content

Commit 1a61ee5

Browse files
committed
ouf
1 parent d857015 commit 1a61ee5

File tree

1 file changed

+99
-51
lines changed

1 file changed

+99
-51
lines changed

src/sys/stm_tests.ml

Lines changed: 99 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ struct
2424
type sut = unit
2525

2626
let arb_cmd _s =
27-
let str_gen = Gen.(oneofl ["a" ; "b" ; "c"]) in
28-
let name_gen = Gen.(oneofl ["aaa" ; "bbb" ; "ccc" ; "ddd" ; "eee"]) in
29-
(* let path_gen = Gen.(oneofl [["root"] ; ["root" ; "aaa"] ; ["root" ; "bbb"] ; ["root" ; "b" ; "c" ; "b"]]) in *)
30-
let path_gen = Gen.map (fun path -> "root" :: path) (Gen.list_size (Gen.int_bound 5) name_gen) in
27+
let str_gen = Gen.(oneofl ["c"; "e"; "r"]) in
28+
(* let name_gen = Gen.(oneofl ["aaa" ; "bbb" ; "ccc" ; "ddd" ; "eee"]) in *)
29+
let path_gen = Gen.(oneofl [["root"] ; ["root"; "c"] ; ["root" ; "c" ; "e"] ; ["root" ; "r" ; "r"]]) in
30+
(* let path_gen = Gen.map (fun path -> "root" :: path) (Gen.list_size (Gen.int_bound 5) str_gen) in *)
3131
let perm_gen = Gen.(oneofl [0o777]) in
3232
(* let perm_gen = Gen.map3 (fun d1 d2 d3 -> d1*100 + d2*10 + d3*1) (Gen.int_bound 7) (Gen.int_bound 7) (Gen.int_bound 7) in *)
3333
QCheck.make ~print:show_cmd
@@ -60,95 +60,143 @@ struct
6060
else is_perm_ok tl path
6161
)
6262

63-
let rec find (fsl: filesys list) path name =
63+
(* let rec find (fsl: filesys list) path name =
6464
match fsl with
65-
| [] ->
66-
(* Format.printf "on a pas trouvé %s\n"name; *)
67-
None
68-
| Directory d :: tl -> (match path with
65+
| [] -> None
66+
| Directory d :: tl ->
67+
(match path with
6968
| [] -> if d.dir_name = name
7069
then Some (Directory d)
7170
else find tl path name
7271
| hd_path :: tl_path -> if d.dir_name = hd_path
7372
then if d.perm > 447
74-
then find d.fs_list tl_path name
75-
else None
73+
then find d.fs_list tl_path name
74+
else None
7675
else find tl path name)
7776
| File f :: _tl -> if path = [] && f.file_name = name
78-
then Some (File f)
79-
else None
77+
then Some (File f)
78+
else None *)
79+
80+
81+
82+
let rec find fs path name =
83+
match fs with
84+
| File f -> path = [] && f.file_name = name
85+
| Directory d ->
86+
match path with
87+
| [] -> name = d.dir_name
88+
| hd :: tl ->
89+
if hd = d.dir_name
90+
then List.exists (fun f -> find f tl name) d.fs_list
91+
else false
92+
93+
(* let rec mkdir (fsl: filesys list) path dir_name perm =
94+
match fsl with
95+
| [] -> []
96+
| Directory d :: tl -> (match path with
97+
| hd_path :: tl_path ->
98+
if (hd_path = d.dir_name) && (List.length path = 1)
99+
then (
100+
if perm > 447
101+
then (let update = Directory {d with fs_list =
102+
(Directory {perm; dir_name; fs_list = []} :: d.fs_list)} in
103+
update :: tl)
104+
else ( Directory d :: []))
105+
else if hd_path = d.dir_name
106+
then Directory {d with fs_list = (mkdir d.fs_list tl_path dir_name perm)} :: []
107+
else Directory d :: (mkdir tl path dir_name perm)
108+
| _ -> [])
109+
| File f :: tl -> File f :: (mkdir tl path dir_name perm) *)
110+
let get_name fs =
111+
match fs with
112+
| File f -> f.file_name
113+
| Directory d -> d.dir_name
114+
115+
let rec mkdir fs path dir_name perm =
116+
match fs with
117+
| File _f -> fs
118+
| Directory d ->
119+
match path with
120+
| [] ->
121+
if List.exists (fun fs -> get_name fs = dir_name) d.fs_list
122+
then fs
123+
else Directory {d with fs_list = (Directory {perm; dir_name; fs_list = []} :: d.fs_list)}
124+
| hd :: tl ->
125+
if hd = d.dir_name
126+
then Directory {d with fs_list = List.map (fun f -> mkdir f tl dir_name perm) d.fs_list}
127+
else fs
80128

81-
let rec mkdir (fsl: filesys list) path dir_name perm = match fsl with
82-
| [] -> []
83-
| Directory d :: tl -> (match path with
84-
| hd_path :: tl_path -> if (hd_path = d.dir_name) && (List.length path = 1)
85-
then (
86-
let b = perm > 447 in
87-
if b
88-
then (
89-
let update = Directory {d with fs_list = (Directory {perm; dir_name; fs_list = []} :: d.fs_list)} in
90-
update :: [])
91-
else Directory d :: [])
92-
else if hd_path = d.dir_name
93-
then Directory {d with fs_list = (mkdir d.fs_list tl_path dir_name perm)} :: []
94-
else Directory d :: (mkdir tl path dir_name perm)
95-
| _ -> [])
96-
| File f :: tl -> File f :: (mkdir tl path dir_name perm)
97129

98130
let next_state c fs =
99131
match c with
100-
| File_exists (_path, _name) -> fs
101-
| Mkdir (path, dir_name, perm) -> (match find [fs] path dir_name with
132+
| File_exists (_path, _name) -> fs
133+
| Mkdir (path, dir_name, perm) ->
134+
if find fs path dir_name
135+
then fs
136+
else mkdir fs path dir_name perm
137+
(* | Mkdir (path, dir_name, perm) -> (match find fs path dir_name with
102138
| Some _ -> fs
103-
| None -> List.hd (mkdir [fs] path dir_name perm))
139+
| None -> (match path with
140+
| _hd :: _tl -> let rev = List.rev path in
141+
(match find [fs] (List.rev (List.tl rev)) (List.hd rev) with
142+
| Some _ -> mkdir fs path dir_name perm
143+
| None -> fs)
144+
| _ -> Format.printf "Bonjour\n"; fs)) *)
145+
146+
let reset_root path = Sys.command ("rm -r -d -f " ^ path ^ " && sync")
104147

105-
let reset_root path = Sys.command ("rm -r -d -f " ^ path)
148+
let init_sut () = let content = Array.to_list (Sys.readdir (static_path)) in
149+
Format.printf "[initsut] content : %s\n%!" (String.concat " " content);
150+
try Sys.mkdir (static_path ^ "/" ^ "root") 0o777 with Sys_error _ -> ()
106151

107-
let init_sut () = try Sys.mkdir (static_path ^ "/" ^ "root") 0o777 with Sys_error _ -> ()
152+
let cleanup _ =
153+
Format.printf "___cleanup___\n";
154+
ignore (reset_root (static_path ^ "/" ^ "root"));
155+
let content = Array.to_list (Sys.readdir (static_path)) in
156+
Format.printf "[cleanup] content : %s\n%!" (String.concat " " content)
108157

109-
let cleanup _ =ignore (reset_root (static_path ^ "/" ^ "root"))
110158

111159
let precond _c _s = true
112160

113161
let run c _file_name = match c with
114162
| File_exists (path, name) -> Res (bool, Sys.file_exists (static_path ^ "/" ^ (String.concat "/" path) ^ "/" ^ name))
115163
| Mkdir (path, dir_name, perm) ->
116-
(* Format.printf "ce quon mkdir :: %s\n" (static_path ^ "/" ^ (String.concat "/" path) ^ "/" ^ dir_name); *)
117164
Res (result unit exn, protect (Sys.mkdir (static_path ^ "/" ^ (String.concat "/" path) ^ "/" ^ dir_name))perm)
118165

119-
let file_exists (fs: filesys) path name =
120-
match (find [fs] path name) with
121-
| Some _ -> true
122-
| None -> false
166+
let file_exists (fs: filesys) path name = find fs path name
123167

124168
let postcond c (fs: filesys) res =
125169
let p path dir_name = static_path ^ "/" ^ (String.concat "/" path) ^ "/" ^ dir_name in
126-
(* Format.printf "\n\n\nSTATUS >> %s\n" (show_filesys fs); *)
170+
Format.printf "\n\ncmd : %s \t\tfs : %s\n" (show_cmd c) (show_filesys fs);
127171
match c, res with
128172
| File_exists (path, name), Res ((Bool,_),b) ->
129-
(* Format.printf "\n\npath :: %s \t FILEXISTS COMMAND : %b\t %s\n" (p path name) (file_exists fs path name) (show_filesys fs); *)
130173
b = file_exists fs path name
131174

132175
| Mkdir (path, dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
133176
when s = (p path dir_name) ^ ": Permission denied" ->
134-
(* Format.printf "\n\npath :: %s \t PERM %s\n" ((p path dir_name) ^ ": Permission denied") (show_filesys fs); *)
135177
let b = not (is_perm_ok [fs] path) in
136178
assert (b);
137179
b
138180

139181
| Mkdir (path, dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
140182
when s = (p path dir_name) ^ ": File exists" ->
141-
(* Format.printf "\n\npath :: %s \t FILE EXIST %s\n" ((p path dir_name) ^ ": File exists" ) (show_filesys fs); *)
183+
Format.printf "---- %s existe deja\t\t\n\n 1\t fs = %s\n\n" dir_name (show_filesys fs);
142184
let b = file_exists fs path dir_name in
185+
(* Format.printf "taille de fsstr : %d \t\test ce que le dossier est deja dans state ? %b\n" (String.length) b; *)
186+
if not b then
187+
(
188+
Format.printf "\n AAAAAAAAAAAAAAAAAAAAAAAAAH c = %s\n\n" (show_cmd c)
189+
);
143190
assert (b);
144191
b
145192

146193
| Mkdir (path, dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
147194
when s = (p path dir_name) ^ ": No such file or directory" ->
148-
(* Format.printf "\n\npath :: %s \t NO SUCH %s\n" ((p path dir_name)^ ": No such file or directory") (show_filesys fs); *)
149-
let b = match path with
195+
let b = (match path with
150196
| [] -> false
151-
| hd_path :: tl_path -> not (file_exists fs tl_path hd_path) in
197+
| _hd_path :: _tl_path ->
198+
let rev = List.rev path in
199+
not (file_exists fs (List.rev (List.tl rev)) (List.hd rev))) in
152200
assert (b);
153201
b
154202

@@ -157,8 +205,8 @@ struct
157205
assert (not (file_exists fs path dir_name)); (*not already exists*)
158206
assert (match path with (*path is good*)
159207
| [] -> true
160-
| hd_path :: tl_path -> file_exists fs tl_path hd_path);
161-
(* Format.printf "\n\n OKKK\n" ; *)
208+
| _hd_path :: _tl_path -> let rev = List.rev path in
209+
file_exists fs (List.rev (List.tl rev)) (List.hd rev));
162210
true
163211
| Mkdir (_path, _dir_name, _perm), Res ((Result (Unit,Exn),_), _r) -> assert(false)
164212
| _,_ -> false
@@ -170,7 +218,7 @@ module SysSTM = STM.Make(SConf)
170218
Util.set_ci_printing ()
171219
;;
172220
QCheck_base_runner.run_tests_main
173-
(let count = 1000 in
221+
(let count = 10 in
174222
[SysSTM.agree_test ~count ~name:"STM Sys test sequential";
175-
(* SysSTM.agree_test_par ~count ~name:"STM Sys test parallel" *)
223+
(* SysSTM.neg_agree_test_par ~count ~name:"STM Sys test parallel" *)
176224
])

0 commit comments

Comments
 (0)