Skip to content
Snippets Groups Projects
Commit dde15bba authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[tests] ptests more robust wrt filenames + check frama-c behavior on foo".c

Especially the pre-processing command-line with `-D__FC_FILE_ASSERT`
in presence of such filename.
parent 5453a262
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ let system = ...@@ -31,6 +31,7 @@ let system =
else else
fun f -> fun f ->
Unix.system f Unix.system f
module Filename = struct module Filename = struct
include Filename include Filename
let concat = let concat =
...@@ -56,6 +57,8 @@ module Filename = struct ...@@ -56,6 +57,8 @@ module Filename = struct
cygpath r cygpath r
else else
fun a b -> temp_file a b fun a b -> temp_file a b
let robust f = String.escaped f
end end
let string_del_suffix suffix s = let string_del_suffix suffix s =
...@@ -963,7 +966,7 @@ let get_macros cmd = ...@@ -963,7 +966,7 @@ let get_macros cmd =
"PTEST_DIR", SubDir.get cmd.directory; "PTEST_DIR", SubDir.get cmd.directory;
"PTEST_RESULT", "PTEST_RESULT",
SubDir.get cmd.directory ^ "/" ^ redefine_name "result"; SubDir.get cmd.directory ^ "/" ^ redefine_name "result";
"PTEST_FILE", ptest_file; "PTEST_FILE", Filename.robust ptest_file;
"PTEST_NAME", ptest_name; "PTEST_NAME", ptest_name;
"PTEST_NUMBER", string_of_int cmd.n; "PTEST_NUMBER", string_of_int cmd.n;
] ]
...@@ -971,14 +974,16 @@ let get_macros cmd = ...@@ -971,14 +974,16 @@ let get_macros cmd =
Macros.add_list macros cmd.macros Macros.add_list macros cmd.macros
let basic_command_string = let basic_command_string =
let contains_toplevel_or_frama_c = let contains_toplevel_or_frama_c =
Str.regexp "[^( ]*\\(\\(toplevel\\)\\|\\(viewer\\)\\|\\(frama-c\\)\\).*" Str.regexp "[^( ]*\\(\\(toplevel\\)\\|\\(viewer\\)\\|\\(frama-c\\)\\).*"
in in
fun command -> fun command ->
let macros = get_macros command in let macros = get_macros command in
let logfiles = List.map (Macros.expand macros) command.log_files in let logfiles = List.map (Macros.expand macros) command.log_files in
command.log_files <- logfiles; command.log_files <- logfiles;
let has_ptest_file_t, toplevel = Macros.does_expand macros command.toplevel in let has_ptest_file_t, toplevel =
Macros.does_expand macros command.toplevel
in
let has_ptest_file_o, options = Macros.does_expand macros command.options in let has_ptest_file_o, options = Macros.does_expand macros command.options in
let toplevel = if !use_byte then opt_to_byte toplevel else toplevel in let toplevel = if !use_byte then opt_to_byte toplevel else toplevel in
let options = let options =
...@@ -994,8 +999,10 @@ let basic_command_string = ...@@ -994,8 +999,10 @@ let basic_command_string =
let options = if !use_byte then opt_to_byte_options options else options in let options = if !use_byte then opt_to_byte_options options else options in
if has_ptest_file_t || has_ptest_file_o || command.execnow then if has_ptest_file_t || has_ptest_file_o || command.execnow then
toplevel ^ " " ^ options toplevel ^ " " ^ options
else else begin
toplevel ^ " " ^ get_ptest_file command ^ " " ^ options let file = Filename.robust @@ get_ptest_file command in
toplevel ^ " " ^ file ^ " " ^ options
end
(* Searches for executable [s] in the directories contained in the PATH (* Searches for executable [s] in the directories contained in the PATH
environment variable. Returns [None] if not found, or environment variable. Returns [None] if not found, or
...@@ -1073,18 +1080,23 @@ let command_string command = ...@@ -1073,18 +1080,23 @@ let command_string command =
in in
let command_string = basic_command_string command in let command_string = basic_command_string command in
let command_string = let command_string =
command_string ^ " 2>" ^ stderr command_string ^ " 2>" ^ (Filename.robust stderr)
in in
let command_string = match filter with let command_string = match filter with
| None -> command_string | None -> command_string
| Some filter -> command_string ^ " | " ^ filter | Some filter -> command_string ^ " | " ^ filter
in in
let command_string = command_string ^ " >" ^ log_prefix ^ ".res.log" in let res = Filename.robust (log_prefix ^ ".res.log") in
let command_string = command_string ^ " >" ^ res in
let command_string = match filter with let command_string = match filter with
| None -> command_string | None -> command_string
| Some filter -> | Some filter ->
Printf.sprintf "%s && %s < %s >%s && rm -f %s" Printf.sprintf "%s && %s < %s >%s && rm -f %s"
command_string filter stderr errlog stderr command_string
filter
(Filename.robust stderr)
(Filename.robust errlog)
(Filename.robust stderr)
in in
command_string command_string
...@@ -1367,8 +1379,8 @@ let compare_one_file cmp log_prefix oracle_prefix log_kind = ...@@ -1367,8 +1379,8 @@ let compare_one_file cmp log_prefix oracle_prefix log_kind =
-1 -1
end else end else
let ext = log_ext log_kind in let ext = log_ext log_kind in
let log_file = log_prefix ^ ext ^ ".log" in let log_file = Filename.robust (log_prefix ^ ext ^ ".log") in
let oracle_file = oracle_prefix ^ ext ^ ".oracle" in let oracle_file = Filename.robust (oracle_prefix ^ ext ^ ".oracle") in
if log_kind = Err && not (Sys.file_exists oracle_file) then if log_kind = Err && not (Sys.file_exists oracle_file) then
check_file_is_empty_or_nonexisting (Command_error (cmp,log_kind)) ~log_file check_file_is_empty_or_nonexisting (Command_error (cmp,log_kind)) ~log_file
else begin else begin
...@@ -1391,8 +1403,8 @@ let compare_one_log_file dir file = ...@@ -1391,8 +1403,8 @@ let compare_one_log_file dir file =
Condition.signal shared.diff_available; Condition.signal shared.diff_available;
unlock() unlock()
end else end else
let log_file = SubDir.make_result_file dir file in let log_file = Filename.robust (SubDir.make_result_file dir file) in
let oracle_file = SubDir.make_oracle_file dir file in let oracle_file = Filename.robust (SubDir.make_oracle_file dir file) in
let cmp_string = !do_cmp ^ " " ^ log_file ^ " " ^ oracle_file ^ " > /dev/null 2> /dev/null" in let cmp_string = !do_cmp ^ " " ^ log_file ^ " " ^ oracle_file ^ " > /dev/null 2> /dev/null" in
if !verbosity >= 2 then lock_printf "%% cmplog: %s / %s@." (SubDir.get dir) file; if !verbosity >= 2 then lock_printf "%% cmplog: %s / %s@." (SubDir.get dir) file;
ignore (launch_and_check_compare_file (Log_error (dir,file)) ignore (launch_and_check_compare_file (Log_error (dir,file))
...@@ -1465,28 +1477,33 @@ let do_diff = function ...@@ -1465,28 +1477,33 @@ let do_diff = function
| Command_error (diff, kind) -> | Command_error (diff, kind) ->
let log_prefix = log_prefix diff in let log_prefix = log_prefix diff in
let log_ext = log_ext kind in let log_ext = log_ext kind in
let log_file = Filename.robust (log_prefix ^ log_ext ^ ".log") in
let command_string = command_string diff in let command_string = command_string diff in
lock_printf "%tCommand:@\n%s@." print_default_env command_string; lock_printf "%tCommand:@\n%s@." print_default_env command_string;
if !behavior = Show if !behavior = Show
then ignore (launch ("cat " ^ log_prefix ^ log_ext ^ ".log")) then ignore (launch ("cat " ^ log_file))
else else
let oracle_prefix = oracle_prefix diff in let oracle_prefix = oracle_prefix diff in
let diff_string = let oracle_file =
!do_diffs ^ " " ^ Filename.robust (oracle_prefix ^ log_ext ^ ".oracle")
oracle_prefix ^ log_ext ^ ".oracle " ^
log_prefix ^ log_ext ^ ".log"
in in
let diff_string = !do_diffs ^ " " ^ oracle_file ^ " " ^ log_file in
ignore (launch diff_string) ignore (launch diff_string)
| Target_error execnow -> | Target_error execnow ->
lock_printf "Custom command failed: %s@\n" execnow.ex_cmd lock_printf "Custom command failed: %s@\n" execnow.ex_cmd
| Log_error(dir, file) -> | Log_error(dir, file) ->
let result_file = SubDir.make_result_file dir file in let result_file =
Filename.robust (SubDir.make_result_file dir file)
in
lock_printf "Log of %s:@." result_file; lock_printf "Log of %s:@." result_file;
if !behavior = Show if !behavior = Show
then ignore (launch ("cat " ^ result_file)) then ignore (launch ("cat " ^ result_file))
else else
let oracle_file =
Filename.robust (SubDir.make_oracle_file dir file)
in
let diff_string = let diff_string =
!do_diffs ^ " " ^ SubDir.make_oracle_file dir file ^ " " ^ result_file !do_diffs ^ " " ^ oracle_file ^ " " ^ result_file
in in
ignore (launch diff_string) ignore (launch diff_string)
...@@ -1519,7 +1536,10 @@ let default_config () = ...@@ -1519,7 +1536,10 @@ let default_config () =
if Sys.file_exists general_config_file if Sys.file_exists general_config_file
then begin then begin
let scan_buffer = Scanf.Scanning.from_file general_config_file in let scan_buffer = Scanf.Scanning.from_file general_config_file in
scan_options (SubDir.create ~with_subdir:false Filename.current_dir_name) scan_buffer (default_config ()) scan_options
(SubDir.create ~with_subdir:false Filename.current_dir_name)
scan_buffer
(default_config ())
end end
else default_config () else default_config ()
......
#include "share/libc/assert.h"
int test = 1;
int main () {
assert(test);
}
[kernel] Parsing tests/syntax/foo".c (with preprocessing)
/* Generated by Frama-C */
#include "assert.h"
int test = 1;
int main(void)
{
int __retres;
__FC_assert(test != 0,"tests/syntax/foo\".c",6,"test");
__retres = 0;
return __retres;
}
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