Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the use of cp in the testsuite #10327

Merged
merged 21 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7c0d049
ocamltest: rename the files variable to readonly_files
shindere Mar 25, 2021
e8cee96
ocamltest: introduce the subdirectories variable
shindere Mar 30, 2021
da1920e
Rewrite the lib-dynlink-native test to use ocamltest's subdirectories…
shindere Mar 31, 2021
ad828c2
Rewrite the lib-dynlink-pr4229 test to use ocamltest's subdirectories…
shindere Mar 31, 2021
2e5a4d0
Rewrite the lib-dynlink-pr4839 test to use ocamltest's subdirectories…
shindere Mar 31, 2021
3804a99
Slightly simplify the lib-dynlink-private test
shindere Apr 8, 2021
66297e6
Put lib-dynlink-private in a correct form
shindere Apr 8, 2021
e8a1b21
Rewrite the lib-dynlink-private test to use ocamltest's subdirectorie…
shindere Apr 8, 2021
97198d6
Rewrite the opaque test to use ocamltest's subdirectories variable
shindere Apr 8, 2021
6d69290
Rewrite the missing_set_of_closures test to use ocamltest's subdirect…
shindere Apr 8, 2021
ddd910d
Rewrite the tool-ocamldep-shadowing test to use ocamltest's subdirect…
shindere Apr 8, 2021
8b565ab
Rewrite the typing-missing-cmi test to use ocamltest's subdirectories…
shindere Apr 8, 2021
823a8e9
Slightly simplify the tool-ocamldep-modalias test
shindere Apr 15, 2021
c9181a1
no-alias-deps/aliases.ml: rename b.cmi.invalid to b.cmi
shindere Apr 15, 2021
c5a82d9
ocamltest: implement a copy action
shindere Apr 15, 2021
43ede50
Use the copy action in the opaque/test.ml test
shindere Apr 15, 2021
b16c2f5
Use the copy action in the missing_set_of_closures test
shindere Apr 15, 2021
d841571
Use the copy action in the tool-ocamldep-modalias/main.ml test
shindere Apr 15, 2021
9256944
Use the copy action in the tool-ocamlopt-save-ir/start_from_emit.ml test
shindere Apr 15, 2021
e5baa87
Get rid of the setup-links.sh script in the tool-ocamldep-modalias test
shindere Apr 21, 2021
7b44b53
Add a Changes entry
shindere Apr 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ Working version
specific solver functions.
(Jacques Garrigue and Takafumi Saikawa, review by Gabriel Scherer)

- #10327: Add a subdirectories variable and a copy action to ocamltest
(Sébastien Hinderer, review by David Allsopp)

- #10358: Use a hash table for the load path.
(Leo White, review by Gabriel Scherer)

Expand Down
19 changes: 16 additions & 3 deletions ocamltest/actions_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ let exit_status_of_variable env variable =
(Environments.safe_lookup variable env)
with _ -> 0

let files env = words_of_variable env Builtin_variables.files
let readonly_files env = words_of_variable env Builtin_variables.readonly_files

let subdirectories env = words_of_variable env Builtin_variables.subdirectories

let setup_symlinks test_source_directory build_directory files =
let symlink filename =
Expand All @@ -84,14 +86,25 @@ let setup_symlinks test_source_directory build_directory files =
Sys.make_directory build_directory;
List.iter f files

let setup_subdirectories source_directory build_directory subdirs =
let full_src_path name = Filename.concat source_directory name in
let full_dst_path name = Filename.concat build_directory name in
let cp_dir name =
Sys.copy_directory (full_src_path name) (full_dst_path name)
in
List.iter cp_dir subdirs

let setup_build_env add_testfile additional_files (_log : out_channel) env =
let source_dir = (test_source_directory env) in
let build_dir = (test_build_directory env) in
let some_files = additional_files @ (files env) in
let some_files = additional_files @ (readonly_files env) in
let files =
if add_testfile
then (testfile env) :: some_files
else some_files in
setup_symlinks (test_source_directory env) build_dir files;
setup_symlinks source_dir build_dir files;
let subdirs = subdirectories env in
setup_subdirectories source_dir build_dir subdirs;
Sys.chdir build_dir;
(Result.pass, env)

Expand Down
2 changes: 1 addition & 1 deletion ocamltest/actions_helpers.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val words_of_variable : Environments.t -> Variables.t -> string list

val exit_status_of_variable : Environments.t -> Variables.t -> int

val files : Environments.t -> string list
val readonly_files : Environments.t -> string list

val setup_symlinks : string -> string -> string list -> unit

Expand Down
29 changes: 29 additions & 0 deletions ocamltest/builtin_actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,34 @@ let file_exists_action _log env =
end
let file_exists = make "file-exists" file_exists_action

let copy_action log env =
let do_copy src dst =
let (entry_type, f) =
if Sys.is_directory src
then ("directory", Sys.copy_directory)
else ("file", Sys.copy_file)
in
Printf.fprintf log "Copying %s %s to %s\n%!" entry_type src dst;
f src dst
in
let src = Environments.lookup Builtin_variables.src env in
let dst = Environments.lookup Builtin_variables.dst env in
match (src, dst) with
| (None, _) | (_, None) ->
let reason = reason_with_fallback env "src or dst are undefined" in
let result = Result.fail_with_reason reason in
(result, env)
| (Some src, Some dst) ->
let f =
if String.ends_with ~suffix:"/" dst
then fun src -> do_copy src (dst ^ (Filename.basename src))
else fun src -> do_copy src dst
in
List.iter f (String.words src);
(Result.pass, env)

let copy = make "copy" copy_action

let initialize_test_exit_status_variables _log env =
Environments.add_bindings
[
Expand Down Expand Up @@ -281,4 +309,5 @@ let _ =
function_sections;
naked_pointers;
file_exists;
copy;
]
2 changes: 2 additions & 0 deletions ocamltest/builtin_actions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ val script : Actions.t
val check_program_output : Actions.t

val file_exists : Actions.t

val copy : Actions.t
16 changes: 13 additions & 3 deletions ocamltest/builtin_variables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ let cwd = Variables.make ("cwd",
let commandline = Variables.make ("commandline",
"Specify the commandline of a tool")

let dst = Variables.make ("dst", "Location where to copy files and directories")

let exit_status = Variables.make ("exit_status",
"Expected program exit status")

let file = Variables.make ("file",
"File whose existence should be tested")

let files = Variables.make ("files",
"Files used by the tests")
let readonly_files = Variables.make ("readonly_files",
"Files which are only read by the tests")

let make = Variables.make ("MAKE",
"Command used to invoke make")
Expand Down Expand Up @@ -79,10 +81,15 @@ let skip_header_bytes =
let script = Variables.make ("script",
"External script to run")

let src = Variables.make ("src", "Files and directories to copy")

let stdin = Variables.make ("stdin", "Default standard input")
let stdout = Variables.make ("stdout", "Default standard output")
let stderr = Variables.make ("stderr", "Default standard error")

let subdirectories = Variables.make ("subdirectories",
"Subdirectories to copy recursively from test source to test build directory")

let test_build_directory = Variables.make ("test_build_directory",
"Directory for files produced during a test")

Expand Down Expand Up @@ -112,22 +119,25 @@ let _ = List.iter Variables.register_variable
arguments;
cwd;
commandline;
dst;
exit_status;
file;
files;
readonly_files;
make;
ocamltest_response;
ocamltest_log;
output;
program; program2;
reason;
reference;
src;
skip_header_lines;
skip_header_bytes;
script;
stdin;
stdout;
stderr;
subdirectories;
test_build_directory;
test_file;
test_source_directory;
Expand Down
8 changes: 7 additions & 1 deletion ocamltest/builtin_variables.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ val cwd : Variables.t

val commandline : Variables.t

val dst : Variables.t

val exit_status : Variables.t

val file : Variables.t

val files : Variables.t
val readonly_files : Variables.t

val make : Variables.t

Expand All @@ -51,10 +53,14 @@ val skip_header_bytes : Variables.t

val script : Variables.t

val src : Variables.t

val stdin : Variables.t
val stdout : Variables.t
val stderr : Variables.t

val subdirectories : Variables.t

val test_build_directory : Variables.t
val test_build_directory_prefix : Variables.t

Expand Down
14 changes: 14 additions & 0 deletions ocamltest/ocamltest_stdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ module Sys = struct
with_output_file ~bin:true dest @@ fun oc ->
copy_chan ic oc

let rec copy_directory src dst =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation can be tripped up by symlinks - I don't think it matters, but we could pull Unix.stat into ocamltest_unix (as the machinery is there for other reasons) and reject directories containing symlinks?

let full_src_path name = Filename.concat src name in
let full_dst_path name = Filename.concat dst name in
make_directory dst;
let content = Array.to_list (readdir src) in
let is_directory d = is_directory (full_src_path d) in
let (subdirs, files) = List.partition is_directory content in
let cp_file name = copy_file (full_src_path name) (full_dst_path name) in
List.iter cp_file files;
let cp_dir name =
copy_directory (full_src_path name) (full_dst_path name)
in
List.iter cp_dir subdirs

let force_remove file =
if file_exists file then remove file

Expand Down
1 change: 1 addition & 0 deletions ocamltest/ocamltest_stdlib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module Sys : sig
val dump_file : out_channel -> ?prefix:string -> string -> unit
val copy_chan : in_channel -> out_channel -> unit
val copy_file : string -> string -> unit
val copy_directory : string -> string -> unit
val force_remove : string -> unit
val with_chdir : string -> (unit -> 'a) -> 'a
val getenv_with_default_value : string -> string -> string
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/afl-instrumentation/afltest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* native-compiler
** script
script = "sh ${test_source_directory}/has-afl-showmap.sh"
files = "harness.ml test.ml"
readonly_files = "harness.ml test.ml"
*** setup-ocamlopt.byte-build-env
**** ocamlopt.byte
module = "test.ml"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/arith.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "mainarith.c"
readonly_files = "mainarith.c"
arguments = "mainarith.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-float.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DFLOAT_CATCH -DFUN=catch_float main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-multiple.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=catch_multiple main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-rec-deadhandler.cmm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* TEST
flags = "-dlive"
files = "main.c"
readonly_files = "main.c"
arguments = "-DUNIT_INT -DFUN=catch_rec_deadhandler main.c"
* asmgen
** run
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-rec.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=catch_fact main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-try-float.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DFLOAT_CATCH -DFUN=catch_try_float main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/catch-try.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=catch_exit main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/checkbound.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DCHECKBOUND main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/even-odd-spill-float.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_FLOAT -DFUN=is_even main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/even-odd-spill.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=is_even main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/even-odd.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files= "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=is_even main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/fib.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=fib main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/immediates.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "mainimmed.c"
readonly_files = "mainimmed.c"
arguments = "-I ${test_source_directory} mainimmed.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/immediates.cmmpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define T TEST

(* T
files = "mainimmed.c"
readonly_files = "mainimmed.c"
arguments = "-I ${test_source_directory} mainimmed.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/integr.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_FLOAT -DFUN=test main.c"
* skip
reason = "This test is currently broken"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/pgcd.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=pgcd_30030 main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/quicksort.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DSORT -DFUN=quicksort main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/quicksort2.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DSORT -DFUN=quicksort main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/soli.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DUNIT_INT -DFUN=solitaire main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/tagged-fib.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_INT -DFUN=fib main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/tagged-integr.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DINT_FLOAT -DFUN=test main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/tagged-quicksort.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DSORT -DFUN=quicksort main.c"
* asmgen
*)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/asmgen/tagged-tak.cmm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
files = "main.c"
readonly_files = "main.c"
arguments = "-DUNIT_INT -DFUN=takmain main.c"
* asmgen
*)
Expand Down