From d75762f1c833453d6cef137012aaed922035239b Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 29 Feb 2000 17:41:12 +0000 Subject: [PATCH] Separation du test bigarray/C/Fortran (car peu portable!) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2892 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- test/Moretest/Makefile | 34 +++++++++++++++----- test/Moretest/bigarrays.ml | 28 ----------------- test/Moretest/bigarrfml.ml | 63 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 test/Moretest/bigarrfml.ml diff --git a/test/Moretest/Makefile b/test/Moretest/Makefile index 528ff8732..11d5e5184 100644 --- a/test/Moretest/Makefile +++ b/test/Moretest/Makefile @@ -45,29 +45,47 @@ cm.out: cmcaml.ml cmstub.c cmmain.c $(CAMLOPT) -output-obj -o cm.o cmcaml.ml $(NATIVECC) -g -o cm.out cm.o -I$(LIBDIR) -DNO_BYTECODE_FILE cmstub.c cmmain.c ../../asmrun/libasmrun.a $(CCLIBS) -bigarrays.byt: bigarrf.o bigarrfstub.o \ - ../../otherlibs/bigarray/bigarray.cma \ +bigarrays.byt: ../../otherlibs/bigarray/bigarray.cma \ ../../otherlibs/bigarray/libbigarray.a bigarrays.ml $(CAMLC) -custom -o bigarrays.byt \ -I ../../otherlibs/bigarray \ -I ../../otherlibs/unix \ unix.cma bigarray.cma bigarrays.ml \ - bigarrf.o bigarrfstub.o \ ../../otherlibs/bigarray/libbigarray.a \ - ../../otherlibs/unix/libunix.a \ - ../../byterun/libcamlrun.a -cclib -lg2c + ../../otherlibs/unix/libunix.a -bigarrays.out: bigarrf.o bigarrfstub.o \ - ../../otherlibs/bigarray/bigarray.cmxa \ +bigarrays.out: ../../otherlibs/bigarray/bigarray.cmxa \ ../../otherlibs/bigarray/libbigarray.a bigarrays.ml $(CAMLOPT) $(OPTFLAGS) -o bigarrays.out \ -I ../../otherlibs/bigarray \ -I ../../otherlibs/unix \ unix.cmxa bigarray.cmxa bigarrays.ml \ + ../../otherlibs/bigarray/libbigarray.a \ + ../../otherlibs/unix/libunix.a + +bigarrf.byt: bigarrf.o bigarrfstub.o \ + ../../otherlibs/bigarray/bigarray.cma \ + ../../otherlibs/bigarray/libbigarray.a bigarrfml.ml + $(CAMLC) -custom -o bigarrf.byt \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cma bigarray.cma bigarrf.ml \ bigarrf.o bigarrfstub.o \ ../../otherlibs/bigarray/libbigarray.a \ ../../otherlibs/unix/libunix.a \ - ../../asmrun/libasmrun.a -cclib -lg2c + ../../byterun/libcamlrun.a -cclib -lg2c + +bigarrf.out: bigarrf.o bigarrfstub.o \ + ../../otherlibs/bigarray/bigarray.cma \ + ../../otherlibs/bigarray/libbigarray.a bigarrfml.ml + $(CAMLOPT) $(OPTFLAGS) -o bigarrf.out \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cma bigarray.cma bigarrf.ml \ + bigarrf.o bigarrfstub.o \ + ../../otherlibs/bigarray/libbigarray.a \ + ../../otherlibs/unix/libunix.a \ + ../../byterun/libcamlrun.a -cclib -lg2c bigarrf.o: bigarrf.f g77 -c bigarrf.f diff --git a/test/Moretest/bigarrays.ml b/test/Moretest/bigarrays.ml index 702dcb95e..cd73c31ca 100644 --- a/test/Moretest/bigarrays.ml +++ b/test/Moretest/bigarrays.ml @@ -24,13 +24,6 @@ let test test_number answer correct_answer = printf " %d..." test_number end -(* External C and Fortran functions *) - -external c_filltab : unit -> (float, float64_elt, c_layout) Array2.t = "c_filltab" -external c_printtab : (float, float64_elt, c_layout) Array2.t -> unit = "c_printtab" -external fortran_filltab : unit -> (float, float32_elt, fortran_layout) Array2.t = "fortran_filltab" -external fortran_printtab : (float, float32_elt, fortran_layout) Array2.t -> unit = "fortran_printtab" - (* One-dimensional arrays *) let _ = @@ -601,27 +594,6 @@ let _ = test 2 !ok true; Sys.remove mapped_file; -(* I/O *) - - print_newline(); - testing_function "------ Foreign function interface --------"; - testing_function "Passing an array to C"; - c_printtab (make_array2 float64 c_layout 0 6 8 float); - testing_function "Accessing a C array"; - let a = c_filltab () in - test 1 a.{0,0} 0.0; - test 2 a.{1,0} 100.0; - test 3 a.{0,1} 1.0; - test 4 a.{5,4} 504.0; - testing_function "Passing an array to Fortran"; - fortran_printtab (make_array2 float32 fortran_layout 1 5 4 float); - testing_function "Accessing a Fortran array"; - let a = fortran_filltab () in - test 1 a.{1,1} 101.0; - test 2 a.{2,1} 201.0; - test 3 a.{1,2} 102.0; - test 4 a.{5,4} 504.0; - () (********* End of test *********) diff --git a/test/Moretest/bigarrfml.ml b/test/Moretest/bigarrfml.ml new file mode 100644 index 000000000..c91562284 --- /dev/null +++ b/test/Moretest/bigarrfml.ml @@ -0,0 +1,63 @@ +open Bigarray +open Printf + +(* Test harness *) + +let error_occurred = ref false + +let function_tested = ref "" + +let testing_function s = + function_tested := s; + print_newline(); + print_string s; + print_newline() + +let test test_number answer correct_answer = + flush stdout; + flush stderr; + if answer <> correct_answer then begin + eprintf "*** Bad result (%s, test %d)\n" !function_tested test_number; + flush stderr; + error_occurred := true + end else begin + printf " %d..." test_number + end + +(* External C and Fortran functions *) + +external c_filltab : unit -> (float, float64_elt, c_layout) Array2.t = "c_filltab" +external c_printtab : (float, float64_elt, c_layout) Array2.t -> unit = "c_printtab" +external fortran_filltab : unit -> (float, float32_elt, fortran_layout) Array2.t = "fortran_filltab" +external fortran_printtab : (float, float32_elt, fortran_layout) Array2.t -> unit = "fortran_printtab" + +let _ = + + let make_array2 kind layout ind0 dim1 dim2 fromint = + let a = Array2.create kind layout dim1 dim2 in + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + a.{i,j} <- (fromint (i * 1000 + j)) + done + done; + a in + + print_newline(); + testing_function "------ Foreign function interface --------"; + testing_function "Passing an array to C"; + c_printtab (make_array2 float64 c_layout 0 6 8 float); + testing_function "Accessing a C array"; + let a = c_filltab () in + test 1 a.{0,0} 0.0; + test 2 a.{1,0} 100.0; + test 3 a.{0,1} 1.0; + test 4 a.{5,4} 504.0; + testing_function "Passing an array to Fortran"; + fortran_printtab (make_array2 float32 fortran_layout 1 5 4 float); + testing_function "Accessing a Fortran array"; + let a = fortran_filltab () in + test 1 a.{1,1} 101.0; + test 2 a.{2,1} 201.0; + test 3 a.{1,2} 102.0; + test 4 a.{5,4} 504.0; +