[PPL-devel] [GIT] ppl/ppl(master): Register OCaml interface exceptions; added a few tests.
Enea Zaffanella
zaffanella at cs.unipr.it
Mon Mar 30 22:05:04 CEST 2009
Module: ppl/ppl
Branch: master
Commit: 40af6c2c6af4cf7eb81231e5585ea4663a0fdbad
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=40af6c2c6af4cf7eb81231e5585ea4663a0fdbad
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Mon Mar 30 23:01:54 2009 +0200
Register OCaml interface exceptions; added a few tests.
The interface exceptions should be registered both in the .ml and .mli files.
Added a test for the invalid argument exception (negative space dimension)
and for the set/reset timeout functions.
---
.../OCaml/ppl_interface_generator_ocaml_ml.m4 | 8 ----
interfaces/OCaml/ppl_ocaml_common.defs.hh | 3 +-
interfaces/OCaml/ppl_ocaml_globals.ml | 20 ++++++++++
interfaces/OCaml/ppl_ocaml_globals.mli | 6 +++
interfaces/OCaml/tests/test1.ml | 39 ++++++++++++++------
5 files changed, 55 insertions(+), 21 deletions(-)
diff --git a/interfaces/OCaml/ppl_interface_generator_ocaml_ml.m4 b/interfaces/OCaml/ppl_interface_generator_ocaml_ml.m4
index 7379217..d3d5b5b 100644
--- a/interfaces/OCaml/ppl_interface_generator_ocaml_ml.m4
+++ b/interfaces/OCaml/ppl_interface_generator_ocaml_ml.m4
@@ -37,14 +37,6 @@ m4_include(`ppl_interface_generator_copyright')`'dnl
open Gmp
include Ppl_ocaml_globals
-exception Error of string
-let _ = Callback.register_exception "PPL_arithmetic_overflow" (Error "any string")
-let _ = Callback.register_exception "PPL_internal_error" (Error "any string")
-let _ = Callback.register_exception "PPL_unknown_standard_exception" (Error "any string")
-let _ = Callback.register_exception "PPL_not_an_unsigned_exception" (Error "any string")
-let _ = Callback.register_exception "PPL_timeout_error" (Error "any string")
-let _ = Callback.register_exception "PPL_unexpected_error" (Error "any string")
-
m4_divert(-1)
m4_pushdef(`m4_one_class_code', `type m4_downcase(m4_interface_class$1)
')
diff --git a/interfaces/OCaml/ppl_ocaml_common.defs.hh b/interfaces/OCaml/ppl_ocaml_common.defs.hh
index a893b20..9b8bbe1 100644
--- a/interfaces/OCaml/ppl_ocaml_common.defs.hh
+++ b/interfaces/OCaml/ppl_ocaml_common.defs.hh
@@ -199,8 +199,7 @@ catch(std::exception& e) { \
} \
catch(timeout_exception&) { \
reset_timeout(); \
- caml_raise_with_string(*caml_named_value("PPL_timeout_exception"), \
- "timeout expired"); \
+ caml_raise_constant(*caml_named_value("PPL_timeout_exception")); \
} \
catch(...) { \
caml_raise_constant(*caml_named_value("PPL_unexpected_error")); \
diff --git a/interfaces/OCaml/ppl_ocaml_globals.ml b/interfaces/OCaml/ppl_ocaml_globals.ml
index 1d9fb22..82bbefd 100644
--- a/interfaces/OCaml/ppl_ocaml_globals.ml
+++ b/interfaces/OCaml/ppl_ocaml_globals.ml
@@ -22,6 +22,26 @@ site: http://www.cs.unipr.it/ppl/ . *)
open Gmp
+exception PPL_arithmetic_overflow of string
+let _ = Callback.register_exception "PPL_arithmetic_overflow"
+ (PPL_arithmetic_overflow "any string")
+
+exception PPL_timeout_exception
+let _ = Callback.register_exception "PPL_timeout_exception"
+ (PPL_timeout_exception)
+
+exception PPL_internal_error of string
+let _ = Callback.register_exception "PPL_internal_error"
+ (PPL_internal_error "any string")
+
+exception PPL_unknown_standard_exception of string
+let _ = Callback.register_exception "PPL_unknown_standard_exception"
+ (PPL_unknown_standard_exception "any string")
+
+exception PPL_unexpected_error of string
+let _ = Callback.register_exception "PPL_unexpected_error"
+ (PPL_unexpected_error "any string")
+
type degenerate_element =
Universe
| Empty
diff --git a/interfaces/OCaml/ppl_ocaml_globals.mli b/interfaces/OCaml/ppl_ocaml_globals.mli
index dcc6d22..b0e2e01 100644
--- a/interfaces/OCaml/ppl_ocaml_globals.mli
+++ b/interfaces/OCaml/ppl_ocaml_globals.mli
@@ -22,6 +22,12 @@ site: http://www.cs.unipr.it/ppl/ . *)
open Gmp
+exception PPL_arithmetic_overflow of string
+exception PPL_timeout_exception
+exception PPL_internal_error of string
+exception PPL_unknown_standard_exception of string
+exception PPL_unexpected_error of string
+
type degenerate_element =
Universe
| Empty
diff --git a/interfaces/OCaml/tests/test1.ml b/interfaces/OCaml/tests/test1.ml
index 62b3571..05626bb 100644
--- a/interfaces/OCaml/tests/test1.ml
+++ b/interfaces/OCaml/tests/test1.ml
@@ -219,7 +219,7 @@ let congruence1 = (e2, e2 , (Z.from_int 1));;
let congruences1 = [e3, e2 , (Z.from_int 20)];;
let grid_generator1 = Grid_Point (e3, (Z.from_int 1));;
-let mip1 = ppl_new_MIP_Problem 10 constraints1 e3 Maximization;;
+let mip1 = ppl_new_MIP_Problem 10 constraints1 e3 Maximization;;
let objective_func = ppl_MIP_Problem_objective_function mip1;;
print_string_if_noisy "\n";;
print_linear_expression objective_func;;
@@ -383,6 +383,15 @@ let i = ppl_max_space_dimension()
in print_int_if_noisy i;;
print_string_if_noisy "\n";;
+(* Testing exceptions *)
+try
+ let _ = ppl_new_MIP_Problem_from_space_dimension (-10)
+ in print_string_if_noisy "Exception test failed"
+with Invalid_argument what ->
+ print_string_if_noisy "Exception test succeeded; caught exception is:\n";
+ print_string_if_noisy what;
+ print_string_if_noisy "\n";;
+
(* Testing timeouts *)
let lower = Coefficient(Gmp.Z.of_int 0)
and upper = Coefficient(Gmp.Z.of_int 1)
@@ -412,22 +421,30 @@ in (
compute_timeout_hypercube 0 2;
ppl_reset_timeout ();
print_string_if_noisy "ppl_reset_timeout test succeeded.\n"
- with x ->
- print_string_if_noisy "ppl_reset_timeout test seems to be failed!\n"
- end
-(* DEBUGGING
- ;
+ with
+ | PPL_timeout_exception ->
+ print_string_if_noisy "ppl_reset_timeout test seems to be failed:\n";
+ print_string_if_noisy "Unexpected PPL timeout exception caught.\n"
+ | _ ->
+ print_string_if_noisy "ppl_reset_timeout test seems to be failed.";
+ (* FIXME: print the contents of the exception. *)
+ print_string_if_noisy "\n"
+ end;
begin
try
- print_string "\nStarting ppl_set_timeout test:\n";
+ print_string_if_noisy "\nStarting ppl_set_timeout test:\n";
ppl_set_timeout 100;
compute_timeout_hypercube 0 100;
ppl_reset_timeout ();
- print_string "ppl_set_timeout test seems to be failed!\n"
- with x ->
- print_string "ppl_set_timeout test succeded\n"
+ print_string_if_noisy "ppl_set_timeout test seems to be failed!\n"
+ with
+ | PPL_timeout_exception ->
+ print_string_if_noisy "ppl_set_timeout test succeded\n";
+ print_string_if_noisy "Expected PPL timeout exception caught.\n"
+ | _ ->
+ print_string_if_noisy "ppl_set_timeout test failed:\n";
+ print_string_if_noisy "generic exception caught.\n"
end
-DEBUGGING *)
);;
(* Pointset_Powersed_Grid is not enabled by default, the following code is *)
More information about the PPL-devel
mailing list