Skip to content

Commit 483d6be

Browse files
committed
wip rename
1 parent a0f90e7 commit 483d6be

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

src/sys/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(executable
1111
(name stm_tests)
1212
(modules stm_tests)
13-
(libraries STM)
13+
(libraries qcheck-stm.sequential qcheck-stm.domain)
1414
(preprocess
1515
(pps ppx_deriving.show)))
1616

src/sys/stm_tests.ml

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
open QCheck
2-
open STM
2+
open STM_base
33

44
module SConf =
55
struct
6-
76
type cmd =
87
| File_exists of string list
98
| Mkdir of string list * string * int
109
| Rmdir of string list * string
1110
| Readdir of string list
11+
| Rename of string
1212
| Touch of string list * string * int
1313
[@@deriving show { with_path = false }]
1414

1515
module Map_names = Map.Make (String)
1616

17-
type permission = {
18-
owner: int;
19-
group: int;
20-
other: int;
21-
}
22-
2317
type filesys =
2418
| Directory of {perm: int; fs_map: filesys Map_names.t}
2519
| File of {perm: int}
@@ -32,9 +26,10 @@ struct
3226

3327
let arb_cmd _s =
3428
let name_gen = Gen.(oneofl ["aaa" ; "bbb" ; "ccc" ; "ddd" ; "eee"]) in
29+
(* ameliorer ca avec d'autre caracteres, *)
30+
(* let name_gen = Gen.small_string in *)
3531
let path_gen = Gen.map (fun path -> path) (Gen.list_size (Gen.int_bound 5) name_gen) in (* can be empty *)
3632
let perm_gen = Gen.(oneofl [0o777]) in
37-
(* 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 *)
3833
QCheck.make ~print:show_cmd
3934
Gen.(oneof
4035
[
@@ -57,13 +52,13 @@ struct
5752
if path = []
5853
then Some (File f)
5954
else None
60-
| Directory d ->
61-
(match path with
62-
| [] -> Some (Directory d)
63-
| hd :: tl ->
64-
(match Map_names.find_opt hd d.fs_map with
65-
| None -> None
66-
| Some fs -> find_opt fs tl))
55+
| Directory d ->
56+
(match path with
57+
| [] -> Some (Directory d)
58+
| hd :: tl ->
59+
(match Map_names.find_opt hd d.fs_map with
60+
| None -> None
61+
| Some fs -> find_opt fs tl))
6762

6863
let mem fs path =
6964
match find_opt fs path with
@@ -118,6 +113,36 @@ struct
118113
else
119114
Directory {d with fs_map = (update_map_name d.fs_map next_in_path nfs)}))
120115

116+
let rec rename fs o_path old_name n_path new_name =
117+
match fs with
118+
| File _ -> fs
119+
| Directory d ->
120+
(match o_path, n_path with
121+
| [], [] ->
122+
(match Map_names.find_opt old_name d.fs_map with
123+
| None -> Directory d
124+
| Some tmp_fs ->
125+
let new_map = Map_names.add new_name tmp_fs d.fs_map in
126+
let new_map = Map_names.remove old_name new_map in
127+
Directory {d with fs_map = new_map})
128+
| o_next_in_path :: o_tl_path, n_next_in_path :: n_tl_path ->
129+
if not (o_next_in_path = n_next_in_path)
130+
then fs
131+
else
132+
(match Map_names.find_opt o_next_in_path d.fs_map with
133+
| None -> fs
134+
| Some sub_fs ->
135+
let nfs = rename sub_fs o_tl_path old_name n_tl_path new_name in
136+
if nfs = sub_fs
137+
then fs
138+
else
139+
let new_map = Map_names.remove o_next_in_path d.fs_map in
140+
let new_map = Map_names.add o_next_in_path nfs new_map in
141+
Directory {d with fs_map = new_map})
142+
| _ , _ -> fs)
143+
| _ -> fs
144+
145+
121146
let rec touch fs path new_file_name perm =
122147
match fs with
123148
| File _ -> fs
@@ -245,13 +270,12 @@ struct
245270
| _,_ -> false
246271
end
247272

248-
module SysSTM = STM.Make(SConf)
273+
module Sys_seq = STM_sequential.Make(SConf)
274+
module Sys_dom = STM_domain.Make(SConf)
249275

250-
;;
251-
Util.set_ci_printing ()
252276
;;
253277
QCheck_base_runner.run_tests_main
254278
(let count = 1000 in
255-
[SysSTM.agree_test ~count ~name:"STM Sys test sequential";
256-
(* SysSTM.neg_agree_test_par ~count ~name:"STM Sys test parallel" *)
279+
[Sys_seq.agree_test ~count ~name:"STM Sys test sequential";
280+
(* Sys_dom.neg_agree_test_par ~count ~name:"STM Sys test parallel" *)
257281
])

0 commit comments

Comments
 (0)