Infrastructure for test suite.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9562 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
7539834933
commit
ec6686630c
|
@ -0,0 +1,54 @@
|
|||
# $Id$
|
||||
|
||||
BASEDIR=$(shell pwd)
|
||||
|
||||
default:
|
||||
@echo "Available targets:"
|
||||
@echo " all launches all tests"
|
||||
@echo " list FILE=f launches the tests referenced in file f (one path per line)"
|
||||
@echo " one DIR=p launches the tests located in path p"
|
||||
@echo " lib builds library modules"
|
||||
@echo " clean deletes generated files"
|
||||
@echo " report prints the report for the last execution, if any"
|
||||
|
||||
all:
|
||||
@for dir in tests/*; do \
|
||||
$(MAKE) one DIR=$$dir; \
|
||||
done 2>&1 | tee _log
|
||||
@$(MAKE) report
|
||||
|
||||
list:
|
||||
@if [ -z $(FILE) ]; then echo "No value set for variable 'FILE'."; exit 1; fi
|
||||
@if [ ! -f $(FILE) ]; then echo "File '$(FILE)' does not exist."; exit 1; fi
|
||||
@while read LINE; do \
|
||||
$(MAKE) one DIR=$$LINE; \
|
||||
done < $(FILE) 2>&1 | tee _log
|
||||
@$(MAKE) report
|
||||
|
||||
one: lib
|
||||
@if [ -z $(DIR) ]; then echo "No value set for variable 'DIR'."; exit 1; fi
|
||||
@if [ ! -d $(DIR) ]; then echo "Directory '$(DIR)' does not exist."; exit 1; fi
|
||||
@echo "Running tests from '$$DIR' ..."
|
||||
@$(MAKE) -C $(DIR) BASEDIR=$(BASEDIR)
|
||||
|
||||
lib: FORCE
|
||||
@$(MAKE) -s -C lib BASEDIR=$(BASEDIR)
|
||||
|
||||
clean: FORCE
|
||||
@$(MAKE) -C lib BASEDIR=$(BASEDIR) clean
|
||||
@for file in tests/*; do \
|
||||
if [ -d $$file ]; then \
|
||||
$(MAKE) -C $$file BASEDIR=$(BASEDIR) clean; \
|
||||
fi \
|
||||
done
|
||||
|
||||
report: FORCE
|
||||
@if [ ! -f _log ]; then echo "No '_log' file."; exit 1; fi
|
||||
@echo ''
|
||||
@echo 'Summary:'
|
||||
@echo ' ' `grep 'passed$$' _log | wc -l` 'test(s) passed'
|
||||
@echo ' ' `grep 'failed$$' _log | wc -l` 'test(s) failed'
|
||||
@echo ' ' `grep '^Error' _log | wc -l` 'compilation error(s)'
|
||||
@echo ' ' `grep '^Warning' _log | wc -l` 'compilation warning(s)'
|
||||
|
||||
FORCE:
|
|
@ -0,0 +1,7 @@
|
|||
# $Id$
|
||||
|
||||
compile: testing.cmi testing.cmo testing.cmx
|
||||
|
||||
clean: defaultclean
|
||||
|
||||
include ../makefiles/Makefile.common
|
|
@ -0,0 +1,96 @@
|
|||
(***********************************************************************)
|
||||
(* *)
|
||||
(* Objective Caml *)
|
||||
(* *)
|
||||
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
|
||||
(* *)
|
||||
(* Copyright 2006 Institut National de Recherche en Informatique et *)
|
||||
(* en Automatique. All rights reserved. This file is distributed *)
|
||||
(* under the terms of the Q Public License version 1.0. *)
|
||||
(* *)
|
||||
(***********************************************************************)
|
||||
|
||||
(* $Id: testing.ml,v 1.1 2006/01/12 12:52:14 weis Exp $ *)
|
||||
|
||||
(* Testing auxilliaries. *)
|
||||
|
||||
open Scanf;;
|
||||
|
||||
let all_tests_ok = ref true;;
|
||||
|
||||
let finish () =
|
||||
match !all_tests_ok with
|
||||
| true ->
|
||||
print_endline "\nAll tests succeeded."
|
||||
| _ ->
|
||||
print_endline "\n\n********* Test suite failed. ***********\n";;
|
||||
|
||||
at_exit finish;;
|
||||
|
||||
let test_num = ref (-1);;
|
||||
|
||||
let print_test_number () =
|
||||
print_int !test_num; print_string " "; flush stdout;;
|
||||
|
||||
let next_test () =
|
||||
incr test_num;
|
||||
print_test_number ();;
|
||||
|
||||
let print_test_fail () =
|
||||
all_tests_ok := false;
|
||||
print_string
|
||||
(Printf.sprintf "\n********* Test number %i failed ***********\n"
|
||||
!test_num);;
|
||||
|
||||
let print_failure_test_fail () =
|
||||
all_tests_ok := false;
|
||||
print_string
|
||||
(Printf.sprintf
|
||||
"\n********* Failure Test number %i incorrectly failed ***********\n"
|
||||
!test_num);;
|
||||
|
||||
let print_failure_test_succeed () =
|
||||
all_tests_ok := false;
|
||||
print_string
|
||||
(Printf.sprintf
|
||||
"\n********* Failure Test number %i failed to fail ***********\n"
|
||||
!test_num);;
|
||||
|
||||
let test b =
|
||||
next_test ();
|
||||
if not b then print_test_fail ();;
|
||||
|
||||
(* Applies f to x and checks that the evaluation indeed
|
||||
raises an exception that verifies the predicate [pred]. *)
|
||||
let test_raises_exc_p pred f x =
|
||||
next_test ();
|
||||
try
|
||||
ignore (f x);
|
||||
print_failure_test_succeed ();
|
||||
false
|
||||
with
|
||||
| x ->
|
||||
pred x || (print_failure_test_fail (); false);;
|
||||
|
||||
(* Applies f to x and checks that the evaluation indeed
|
||||
raises some exception. *)
|
||||
let test_raises_some_exc f = test_raises_exc_p (fun _ -> true) f;;
|
||||
let test_raises_this_exc exc = test_raises_exc_p (fun x -> x = exc);;
|
||||
|
||||
(* Applies f to x and checks that the evaluation indeed
|
||||
raises exception Failure s. *)
|
||||
|
||||
let test_raises_this_failure s f x =
|
||||
test_raises_exc_p (fun x -> x = Failure s) f x;;
|
||||
|
||||
(* Applies f to x and checks that the evaluation indeed
|
||||
raises the exception Failure. *)
|
||||
let test_raises_some_failure f x =
|
||||
test_raises_exc_p (function Failure _ -> true | _ -> false) f x;;
|
||||
|
||||
let failure_test f x s = test_raises_this_failure s f x;;
|
||||
let any_failure_test = test_raises_some_failure;;
|
||||
|
||||
let scan_failure_test f x =
|
||||
test_raises_exc_p (function Scan_failure _ -> true | _ -> false) f x;;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
(***********************************************************************)
|
||||
(* *)
|
||||
(* Objective Caml *)
|
||||
(* *)
|
||||
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
|
||||
(* *)
|
||||
(* Copyright 2006 Institut National de Recherche en Informatique et *)
|
||||
(* en Automatique. All rights reserved. This file is distributed *)
|
||||
(* under the terms of the Q Public License version 1.0. *)
|
||||
(* *)
|
||||
(***********************************************************************)
|
||||
|
||||
(* $Id: testing.mli,v 1.1 2006/01/12 12:52:14 weis Exp $ *)
|
||||
|
||||
(* Testing auxilliaries. *)
|
||||
|
||||
val test : bool -> unit;;
|
||||
(** [test e] tests that [e] evaluates to [true]. *)
|
||||
val failure_test : ('a -> 'b) -> 'a -> string -> bool;;
|
||||
(** [failure_test f x s] tests that [f x] raises the exception [Failure s]. *)
|
||||
|
||||
val test_raises_some_exc : ('a -> 'b) -> 'a -> bool;;
|
||||
(** [test_raises_some_exc f x] tests that [f x] raises an exception. *)
|
||||
|
||||
val test_raises_this_exc : exn -> ('a -> 'b) -> 'a -> bool;;
|
||||
(** [test_raises_this_exc exc f x] tests that [f x]
|
||||
raises the exception [exc]. *)
|
||||
|
||||
val test_raises_exc_p : (exn -> bool) -> ('a -> 'b) -> 'a -> bool;;
|
||||
(** [test_raises_exc_p p f x] tests that [f x] raises an exception that
|
||||
verifies predicate [p]. *)
|
||||
|
||||
val scan_failure_test : ('a -> 'b) -> 'a -> bool;;
|
||||
(** [scan_failure_test f x] tests that [f x] raises [Scanf.Scan_failure]. *)
|
|
@ -0,0 +1,66 @@
|
|||
# $Id$
|
||||
|
||||
TOPDIR=$(BASEDIR)/..
|
||||
|
||||
include $(TOPDIR)/config/Makefile
|
||||
|
||||
BOOTDIR=$(TOPDIR)/boot
|
||||
OCAMLRUN=$(BOOTDIR)/ocamlrun$(EXE)
|
||||
OCAML=$(OCAMLRUN) $(TOPDIR)/ocaml$(EXE)
|
||||
OCAMLC=$(OCAMLRUN) $(TOPDIR)/ocamlc$(EXE)
|
||||
OCAMLOPT=$(OCAMLRUN) $(TOPDIR)/ocamlopt$(EXE)
|
||||
OCAMLDOC=$(OCAMLRUN) $(TOPDIR)/ocamldoc/ocamldoc$(EXE)
|
||||
OCAMLLEX=$(OCAMLRUN) $(TOPDIR)/lex/ocamllex$(EXE)
|
||||
OCAMLMKLIB=$(OCAMLRUN) $(TOPDIR)/tools/ocamlmklib$(EXE)
|
||||
OCAMLYACC=$(TOPDIR)/yacc/ocamlyacc$(EXE)
|
||||
OCAMLBUILD=$(TOPDIR)/_build/ocamlbuild/ocamlbuild.native
|
||||
DUMPOBJ=$(OCAMLRUN) $(TOPDIR)/tool/dumpobj$(EXE)
|
||||
COMPFLAGS=
|
||||
FORTRAN_COMPILER=/sw/bin/gcc
|
||||
FORTRAN_LIBRARY=/sw/lib/gcc4.3/lib/libgfortran.a
|
||||
|
||||
defaultclean:
|
||||
@rm -f *.cm* *.$(O) *.$(SO) *.$(A)
|
||||
@for dsym in *.dSYM; do \
|
||||
if [ -d $$dsym ]; then \
|
||||
rm -fr $$dsym; \
|
||||
fi \
|
||||
done
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .mli .ml .mly .mll .cmi .cmo .cmx .cmm .cmxa .s .S .o .so
|
||||
|
||||
.mli.cmi:
|
||||
@$(OCAMLC) -c $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.ml.cmi:
|
||||
@$(OCAMLC) -c $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.ml.cmo:
|
||||
@if [ -f $<i ]; then $(OCAMLC) -c $(COMPFLAGS) $(ADD_COMPFLAGS) $<i; fi
|
||||
@$(OCAMLC) -c $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.ml.cmx:
|
||||
@$(OCAMLOPT) -c $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.cmx.so:
|
||||
@$(OCAMLOPT) -o $@ -shared $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.cmxa.so:
|
||||
@$(OCAMLOPT) -o $@ -shared -linkall $(COMPFLAGS) $(ADD_COMPFLAGS) $<
|
||||
|
||||
.mly.ml:
|
||||
@$(OCAMLYACC) -q $< 2> /dev/null
|
||||
|
||||
.mll.ml:
|
||||
@$(OCAMLLEX) -q $< > /dev/null
|
||||
|
||||
.cmm.o:
|
||||
@$(OCAMLRUN) ./codegen $*.cmm > $*.s
|
||||
@$(AS) $(ASFLAGS) -o $*.o $*.s
|
||||
|
||||
.S.o:
|
||||
@$(ASPP) $(ASPPFLAGS) -o $*.o $*.S
|
||||
|
||||
.s.o:
|
||||
@$(ASPP) $(ASPPFLAGS) -o $*.o $*.s
|
|
@ -0,0 +1,19 @@
|
|||
# $Id$
|
||||
|
||||
default: compile
|
||||
|
||||
compile:
|
||||
@for file in *.ml; do \
|
||||
echo -n " ... testing '$$file'"; \
|
||||
if [ `echo $$file | grep bad` ]; then \
|
||||
$(OCAMLC) -c -w a $$file 2> /dev/null && (echo " => failed" && exit 1) || echo " => passed"; \
|
||||
else \
|
||||
test -f `basename $$file ml`mli && $(OCAMLC) -c -w a `basename $$file ml`mli; \
|
||||
$(OCAMLC) -c -w a $$file 2> /dev/null || (echo " => failed" && exit 1); \
|
||||
test -f `basename $$file ml`reference && $(OCAMLC) `basename $$file ml`cmo && ./a.out > `basename $$file ml`result && (diff -q `basename $$file ml`reference `basename $$file ml`result || (echo " => failed" && exit 1)); \
|
||||
echo " => passed"; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
clean: defaultclean
|
||||
@rm -f ./a.out *.cm* *.result
|
|
@ -0,0 +1,36 @@
|
|||
# $Id$
|
||||
|
||||
CMI_FILES=$(patsubst %,%.cmi,$(MODULES))
|
||||
CMO_FILES=$(patsubst %,%.cmo,$(MODULES))
|
||||
CMX_FILES=$(patsubst %,%.cmx,$(MODULES))
|
||||
CMA_FILES=$(patsubst %,%.cma,$(LIBRARIES))
|
||||
CMXA_FILES=$(patsubst %,%.cmxa,$(LIBRARIES))
|
||||
ML_FILES=$(patsubst %,%.ml,$(LEX_MODULES) $(YACC_MODULES))
|
||||
O_FILES=$(patsubst %,%.$(O),$(C_FILES))
|
||||
|
||||
GENERATED_SOURCES=$(patsubst %,%.ml,$(LEX_MODULES)) $(patsubst %,%.ml,$(YACC_MODULES)) $(patsubst %,%.mli,$(YACC_MODULES))
|
||||
|
||||
ifdef C_FILES
|
||||
ADD_CFLAGS+=-custom
|
||||
endif
|
||||
|
||||
default: compile run
|
||||
|
||||
compile: $(ML_FILES) $(CMO_FILES) $(CMX_FILES) $(MAIN_MODULE).cmo $(MAIN_MODULE).cmx
|
||||
@for file in $(C_FILES); do \
|
||||
$(NATIVECC) $(NATIVECCCOMPOPTS) -c -I$(TOPDIR)/byterun $$file.c; \
|
||||
done;
|
||||
@$(OCAMLC) $(ADD_COMPFLAGS) $(ADD_CFLAGS) -o program.byte $(O_FILES) $(CMA_FILES) $(CMO_FILES) $(patsubst %,%.cmo,$(ADD_MODULES)) $(MAIN_MODULE).cmo
|
||||
@$(OCAMLOPT) $(ADD_COMPFLAGS) -o program.native $(O_FILES) $(CMXA_FILES) $(CMX_FILES) $(patsubst %,%.cmx,$(ADD_MODULES)) $(MAIN_MODULE).cmx
|
||||
|
||||
run:
|
||||
@echo -n " ... testing with ocamlc"
|
||||
@./program.byte $(EXEC_ARGS) > $(MAIN_MODULE).result || (echo " => failed" && exit 1)
|
||||
@diff -q $(MAIN_MODULE).reference $(MAIN_MODULE).result > /dev/null || (echo " => failed" && exit 1)
|
||||
@echo -n " ocamlopt"
|
||||
@./program.native $(EXEC_ARGS) > $(MAIN_MODULE).result || (echo " => failed" && exit 1)
|
||||
@diff -q $(MAIN_MODULE).reference $(MAIN_MODULE).result > /dev/null || (echo " => failed" && exit 1)
|
||||
@echo " => passed"
|
||||
|
||||
clean: defaultclean
|
||||
@rm -f *.result ./program.* $(GENERATED_SOURCES) $(O_FILES)
|
|
@ -0,0 +1,43 @@
|
|||
# $Id$
|
||||
|
||||
CC=$(NATIVECC) $(NATIVECCCOMPOPTS)
|
||||
FC=$(FORTAN_COMPILER)
|
||||
CMO_FILES=$(patsubst %,%.cmo,$(MODULES))
|
||||
CMX_FILES=$(patsubst %,%.cmx,$(MODULES))
|
||||
CMA_FILES=$(patsubst %,%.cma,$(LIBRARIES))
|
||||
CMXA_FILES=$(patsubst %,%.cmxa,$(LIBRARIES))
|
||||
O_FILES=$(patsubst %,%.$(O),$(C_FILES) $(F_FILES))
|
||||
ifdef C_FILES
|
||||
ADD_CFLAGS+=-custom
|
||||
endif
|
||||
ifdef F_FILES
|
||||
ADD_CFLAGS+=$(FORTRAN_LIBRARY)
|
||||
ADD_OPTFLAGS+=$(FORTRAN_LIBRARY)
|
||||
endif
|
||||
|
||||
run-all:
|
||||
@for file in $(C_FILES); do \
|
||||
$(CC) -c -I$(PREFIX)/lib/ocaml/caml $$file.c; \
|
||||
done;
|
||||
@for file in $(F_FILES); do \
|
||||
$(FORTRAN_COMPILER) -c -I$(PREFIX)/lib/ocaml/caml $$file.f; \
|
||||
done;
|
||||
@for file in *.ml; do \
|
||||
echo -n " ... testing '$$file':"; \
|
||||
$(MAKE) run-file DESC=ocamlc COMP='$(OCAMLC)' COMPFLAGS='$(ADD_COMPFLAGS) $(ADD_CFLAGS) $(O_FILES) -w a $(CMA_FILES) -I ../../lib $(CMO_FILES)' FILE=$$file PROGRAM_ARGS=$(PROGRAM_ARGS) && \
|
||||
$(MAKE) run-file DESC=ocamlopt COMP=$(PREFIX)/bin/ocamlopt COMPFLAGS='$(ADD_COMPFLAGS) $(ADD_OPTFLAGS) $(O_FILES) -w a $(CMXA_FILES) -I ../../lib $(CMX_FILES)' FILE=$$file PROGRAM_ARGS=$(PROGRAM_ARGS) && \
|
||||
if [ ! -z $(UNSAFE) ]; then \
|
||||
$(MAKE) run-file DESC=ocamlc-unsafe COMP=$(PREFIX)/bin/ocamlc COMPFLAGS='-w a -unsafe -I ../../li $(CMO_FILES)' FILE=$$file && \
|
||||
$(MAKE) run-file DESC=ocamlopt-unsafe COMP=$(PREFIX)/bin/ocamlopt COMPFLAGS='-w a -unsafe -I ../../lib $(CMX_FILES)' FILE=$$file; \
|
||||
fi && \
|
||||
echo " => passed"; \
|
||||
done;
|
||||
|
||||
run-file:
|
||||
@echo -n " $(DESC)"
|
||||
@$(COMP) $(COMPFLAGS) $(FILE) -o program
|
||||
@./program $(PROGRAM_ARGS) > `basename $(FILE) ml`result
|
||||
@diff -q `basename $(FILE) ml`reference `basename $(FILE) ml`result > /dev/null || (echo " => failed" && exit 1)
|
||||
|
||||
clean: defaultclean
|
||||
@rm -f *.result ./program
|
|
@ -0,0 +1,16 @@
|
|||
# $Id$
|
||||
|
||||
default:
|
||||
@for file in *.ml; do \
|
||||
$(OCAML) < $$file > $$file.result 2>&1; \
|
||||
if [ -f $$file.principal.reference ]; then \
|
||||
$(OCAML) -principal < $$file > $$file.principal.result 2>&1; \
|
||||
fi; \
|
||||
done
|
||||
@for file in *.reference; do \
|
||||
echo -n " ... testing '$$file':"; \
|
||||
diff -q $$file `basename $$file reference`result || (echo " => failed" && exit 1) && echo " => passed"; \
|
||||
done
|
||||
|
||||
clean: defaultclean
|
||||
@rm -f *.result
|
Loading…
Reference in New Issue