diff options
Diffstat (limited to 'ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode')
10 files changed, 108 insertions, 0 deletions
diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/.svnignore b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/.svnignore new file mode 100644 index 0000000000..125439c780 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/.svnignore @@ -0,0 +1,6 @@ +main +static +custom +*.a +*.so +*.result diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/Makefile b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/Makefile new file mode 100644 index 0000000000..00ffc63ad3 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/Makefile @@ -0,0 +1,36 @@ +default: compile run + +compile: + @for file in stub*.c; do \ + $(OCAMLC) -c $$file; \ + $(OCAMLMKLIB) -o `echo $$file | sed -e 's/stub/plug/' | sed -e 's/\.c//'` `basename $$file c`o; \ + done + @for file in plug*.ml; do \ + $(OCAMLC) -c $$file; \ + $(OCAMLMKLIB) -o `basename $$file .ml` `basename $$file ml`cmo; \ + done + @$(OCAMLC) -c main.ml + @$(OCAMLC) -o main dynlink.cma main.cmo + @$(OCAMLC) -o static -linkall plug1.cma plug2.cma -use-runtime $(PREFIX)/bin/ocamlrun + @$(OCAMLC) -o custom -custom -linkall plug2.cma plug1.cma -I . + +run: + @printf " ... testing 'main'" + @export LD_LIBRARY_PATH=`pwd` && ./main plug1.cma plug2.cma > main.result + @diff -q main.reference main.result > /dev/null || (echo " => failed" && exit 1) + @echo " => passed" + + @printf " ... testing 'static'" + @export LD_LIBRARY_PATH=`pwd` && ./static > static.result + @diff -q static.reference static.result > /dev/null || (echo " => failed" && exit 1) + @echo " => passed" + + @printf " ... testing 'custom'" + @export LD_LIBRARY_PATH=`pwd` && ./custom > custom.result + @diff -q custom.reference custom.result > /dev/null || (echo " => failed" && exit 1) + @echo " => passed" + +clean: defaultclean + @rm -f ./main ./static ./custom *.result + +include ../../makefiles/Makefile.common diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/custom.reference b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/custom.reference new file mode 100644 index 0000000000..f7eeb3aeb3 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/custom.reference @@ -0,0 +1,5 @@ +ABCDEF +This is stub2, calling stub1: +This is stub1! +Ok! +This is stub1! diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.ml b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.ml new file mode 100644 index 0000000000..bd980f1022 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.ml @@ -0,0 +1,17 @@ + Dynlink.init (); + Dynlink.allow_unsafe_modules true; + for i = 1 to Array.length Sys.argv - 1 do + let name = Sys.argv.(i) in + Printf.printf "Loading %s\n" name; flush stdout; + try + if name.[0] = '-' + then Dynlink.loadfile_private + (String.sub name 1 (String.length name - 1)) + else Dynlink.loadfile name + with + | Dynlink.Error err -> + Printf.printf "Dynlink error: %s\n" + (Dynlink.error_message err) + | exn -> + Printf.printf "Error: %s\n" (Printexc.to_string exn) + done diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.reference b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.reference new file mode 100644 index 0000000000..df46049bf3 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/main.reference @@ -0,0 +1,7 @@ +Loading plug1.cma +ABCDEF +Loading plug2.cma +This is stub1! +This is stub2, calling stub1: +This is stub1! +Ok! diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug1.ml b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug1.ml new file mode 100644 index 0000000000..3246045170 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug1.ml @@ -0,0 +1,4 @@ +external stub1: unit -> string = "stub1" + + +let () = print_endline (stub1 ()) diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug2.ml b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug2.ml new file mode 100644 index 0000000000..05f4fdaeda --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/plug2.ml @@ -0,0 +1,4 @@ +external stub2: unit -> unit = "stub2" + + +let () = stub2 () diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/static.reference b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/static.reference new file mode 100644 index 0000000000..32281bcf45 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/static.reference @@ -0,0 +1,5 @@ +ABCDEF +This is stub1! +This is stub2, calling stub1: +This is stub1! +Ok! diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub1.c b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub1.c new file mode 100644 index 0000000000..18ddf3f136 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub1.c @@ -0,0 +1,11 @@ +#include "caml/mlvalues.h" +#include "caml/memory.h" +#include "caml/alloc.h" +#include <stdio.h> + +value stub1() { + CAMLlocal1(x); + printf("This is stub1!\n"); + x = caml_copy_string("ABCDEF"); + return x; +} diff --git a/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub2.c b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub2.c new file mode 100644 index 0000000000..a118673543 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/lib-dynlink-bytecode/stub2.c @@ -0,0 +1,13 @@ +#include "caml/mlvalues.h" +#include "caml/memory.h" +#include "caml/alloc.h" +#include <stdio.h> + +extern value stub1(); + +value stub2() { + printf("This is stub2, calling stub1:\n"); + stub1(); + printf("Ok!\n"); + return Val_unit; +} |
