[PPL-devel] [GIT] ppl/ppl(master): Added a test for deterministic timeouts in the C language interface.
Enea Zaffanella
zaffanella at cs.unipr.it
Sun Jul 12 18:59:34 CEST 2009
Module: ppl/ppl
Branch: master
Commit: 42c630cd1c01b837e94a1285dcde2f3f23a1b4b4
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=42c630cd1c01b837e94a1285dcde2f3f23a1b4b4
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Sun Jul 12 18:58:15 2009 +0200
Added a test for deterministic timeouts in the C language interface.
---
interfaces/C/tests/Makefile.am | 19 +++++--
interfaces/C/tests/weightwatch1.c | 102 +++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 5 deletions(-)
diff --git a/interfaces/C/tests/Makefile.am b/interfaces/C/tests/Makefile.am
index 6e53a36..bdb7233 100644
--- a/interfaces/C/tests/Makefile.am
+++ b/interfaces/C/tests/Makefile.am
@@ -82,25 +82,34 @@ dummy.cc
watchdog1_SRCS = watchdog1.c
+weightwatch1_SRCS = weightwatch1.c
+
noinst_HEADERS = \
ppl_c_test.h
if BUILD_WATCHDOG_LIBRARY
WATCHDOG_TESTS = \
-watchdog1
-
-watchdog1_SOURCES = $(watchdog1_SRCS)
+watchdog1 \
+weightwatch1
-watchdog1_CPPFLAGS = \
+WATCHDOG_LIBRARY_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_builddir)/Watchdog \
-I$(top_builddir)/Watchdog/src
-watchdog1_LDADD = \
+WATCHDOG_LIBRARY_LDADD = \
$(LDADD) \
$(top_builddir)/Watchdog/src/libpwl.la
+watchdog1_SOURCES = $(watchdog1_SRCS)
+watchdog1_CPPFLAGS = $(WATCHDOG_LIBRARY_CPPFLAGS)
+watchdog1_LDADD = $(WATCHDOG_LIBRARY_LDADD)
+
+weightwatch1_SOURCES = $(weightwatch1_SRCS)
+weightwatch1_CPPFLAGS = $(WATCHDOG_LIBRARY_CPPFLAGS)
+weightwatch1_LDADD = $(WATCHDOG_LIBRARY_LDADD)
+
endif BUILD_WATCHDOG_LIBRARY
TESTS = $(NORMAL_TESTS) $(WATCHDOG_TESTS)
diff --git a/interfaces/C/tests/weightwatch1.c b/interfaces/C/tests/weightwatch1.c
new file mode 100644
index 0000000..be17725
--- /dev/null
+++ b/interfaces/C/tests/weightwatch1.c
@@ -0,0 +1,102 @@
+/* Test the deterministic timeout facility of the PPL C interface library.
+ Copyright (C) 2001-2009 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The PPL is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#include "ppl_c.h"
+#include <stdlib.h>
+
+void
+open_hypercube(int dimension, ppl_Polyhedron_t ph) {
+ int i;
+ mpz_t z_one;
+ mpz_t z_minus_one;
+ ppl_Coefficient_t coeff_one;
+ ppl_Coefficient_t coeff_minus_one;
+ ppl_Linear_Expression_t le;
+ ppl_Constraint_t c;
+ ppl_Constraint_System_t cs;
+
+ mpz_init_set_si(z_one, 1);
+ mpz_init_set_si(z_minus_one, -1);
+ ppl_new_Coefficient(&coeff_one);
+ ppl_assign_Coefficient_from_mpz_t(coeff_one, z_one);
+ ppl_new_Coefficient(&coeff_minus_one);
+ ppl_assign_Coefficient_from_mpz_t(coeff_minus_one, z_minus_one);
+ ppl_new_Linear_Expression_with_dimension(&le, dimension);
+ ppl_new_Constraint_System(&cs);
+ for (i = 0; i < dimension; ++i) {
+ ppl_Linear_Expression_add_to_coefficient(le, i, coeff_one);
+ /* Variable(i) > 0 */
+ ppl_new_Constraint(&c, le, PPL_CONSTRAINT_TYPE_GREATER_THAN);
+ ppl_Constraint_System_insert_Constraint(cs, c);
+ ppl_delete_Constraint(c);
+ /* Variable(i) < 1 */
+ ppl_Linear_Expression_add_to_inhomogeneous(le, coeff_minus_one);
+ ppl_new_Constraint(&c, le, PPL_CONSTRAINT_TYPE_LESS_THAN);
+ ppl_Constraint_System_insert_Constraint(cs, c);
+ ppl_delete_Constraint(c);
+ /* Zero `le' */
+ ppl_Linear_Expression_add_to_coefficient(le, i, coeff_minus_one);
+ ppl_Linear_Expression_add_to_inhomogeneous(le, coeff_one);
+ }
+ ppl_Polyhedron_add_constraints(ph, cs);
+ ppl_delete_Constraint_System(cs);
+ ppl_delete_Linear_Expression(le);
+ ppl_delete_Coefficient(coeff_minus_one);
+ ppl_delete_Coefficient(coeff_one);
+ mpz_clear(z_minus_one);
+ mpz_clear(z_one);
+}
+
+void
+weighted_compute_open_hypercube_generators(unsigned weight,
+ int max_dimension) {
+ int i;
+ int result;
+ ppl_const_Generator_System_t gs;
+ ppl_Polyhedron_t ph;
+
+ for (i = 0; i <= max_dimension; ++i) {
+ ppl_new_NNC_Polyhedron_from_space_dimension(&ph, i, 0);
+ open_hypercube(i, ph);
+ ppl_set_deterministic_timeout(weight);
+ result = ppl_Polyhedron_get_generators(ph, &gs);
+ ppl_reset_deterministic_timeout();
+ ppl_delete_Polyhedron(ph);
+ if (result == PPL_TIMEOUT_EXCEPTION)
+ /* Deterministic timeout expired */
+ return;
+ else if (result != 0)
+ /* Unexpected error */
+ exit(1);
+ }
+ /* Should not reach this point */
+ exit(1);
+}
+
+int
+main() {
+ ppl_initialize();
+ weighted_compute_open_hypercube_generators(1000, 20);
+ ppl_finalize();
+ return 0;
+}
+
More information about the PPL-devel
mailing list