1+ (* TEST
2+
3+ (*
4+ This test is temporarily disabled on the MinGW and MSVC ports,
5+ because since fdstatus has been wrapped in an OCaml program,
6+ it does not work as well as before.
7+ Presumably this is because the OCaml runtime opens files, so that handles
8+ that have actually been closed at execution look open and make the
9+ test fail.
10+
11+ One possible fix for this would be to make it possible for ocamltest to
12+ compile C-only programs, which will be a bit of work to handle the
13+ output of msvc and will also duplicate what the ocaml compiler itslef
14+ already does.
15+ *)
16+
17+ include unix
18+ files = "fdstatus_aux.c fdstatus_main.ml"
19+
20+ *libunix
21+ ** setup-ocamlc.byte-build-env
22+ program = "${test_build_directory}/cloexec.byte"
23+ *** ocamlc.byte
24+ program = "${test_build_directory}/fdstatus.exe"
25+ all_modules = "fdstatus_aux.c fdstatus_main.ml"
26+ **** ocamlc.byte
27+ program = "${test_build_directory}/cloexec.byte"
28+ all_modules= "cloexec.ml"
29+ ***** check-ocamlc.byte-output
30+ ****** run
31+ ******* check-program-output
32+
33+ ** setup-ocamlopt.byte-build-env
34+ program = "${test_build_directory}/cloexec.opt"
35+ *** ocamlopt.byte
36+ program = "${test_build_directory}/fdstatus.exe"
37+ all_modules = "fdstatus_aux.c fdstatus_main.ml"
38+ **** ocamlopt.byte
39+ program = "${test_build_directory}/cloexec.opt"
40+ all_modules= "cloexec.ml"
41+ ***** check-ocamlopt.byte-output
42+ ****** run
43+ ******* check-program-output
44+
45+ *)
46+
147(* This is a terrible hack that plays on the internal representation
248 of file descriptors. The result is a number (as a string)
349 that the fdstatus.exe auxiliary program can use to check whether
4- the fd is open. *)
50+ the fd is open. Moreover, since fdstatus.exe is an OCaml program,
51+ we must take into account that the Windows OCaml runtime opens a few handles
52+ for its own use, hence we do likewise to try to get handle numbers
53+ Windows will not allocate to the OCaml runtime of fdstatus.exe *)
554
655let string_of_fd (fd : Unix.file_descr ) : string =
756 match Sys. os_type with
@@ -13,8 +62,15 @@ let string_of_fd (fd: Unix.file_descr) : string =
1362 Int64. to_string (Obj. magic fd : int64 )
1463 | _ -> assert false
1564
65+ let status_checker = " fdstatus.exe"
66+
1667let _ =
1768 let f0 = Unix. (openfile " tmp.txt" [O_WRONLY ; O_CREAT ; O_TRUNC ] 0o600 ) in
69+ let untested1 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
70+ let untested2 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
71+ let untested3 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
72+ let untested4 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
73+ let untested5 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
1874 let f1 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_KEEPEXEC ] 0 ) in
1975 let f2 = Unix. (openfile " tmp.txt" [O_RDONLY ; O_CLOEXEC ] 0 ) in
2076 let d0 = Unix. dup f0 in
@@ -41,11 +97,16 @@ let _ =
4197 p0;p0';p1;p1';p2;p2';
4298 s0;s1;s2;
4399 x0;x0';x1;x1';x2;x2' |] in
100+ let untested =
101+ [untested1; untested2; untested3; untested4; untested5]
102+ in
44103 let pid =
45104 Unix. create_process
46- (Filename. concat Filename. current_dir_name " fdstatus.exe " )
47- (Array. append [| " fdstatus " |] (Array. map string_of_fd fds))
105+ (Filename. concat Filename. current_dir_name status_checker )
106+ (Array. append [| status_checker |] (Array. map string_of_fd fds))
48107 Unix. stdin Unix. stdout Unix. stderr in
49108 ignore (Unix. waitpid [] pid);
50- Array. iter (fun fd -> try Unix. close fd with Unix. Unix_error _ -> () ) fds;
109+ let close fd = try Unix. close fd with Unix. Unix_error _ -> () in
110+ Array. iter close fds;
111+ List. iter close untested;
51112 Sys. remove " tmp.txt"
0 commit comments