Rework the timeout of the CGI script.

The previous implementation was fine to catch timeout of third-party
tools (like dot), but to good to catch timeout in Spot itself, because
Python will not deliver a SIGALRM while a native function (e.g. Spot's
translation) is running.  So we fork() the Python process, with a
parent that does nothing but wait for the termination of the child or
for an alarm.  On SIGALRM, the parent kills all children.

* wrap/python/ajax/spot.in: Adjust to fork.
* wrap/python/tests/alarm.py: New test file to test this
scenario in a more controled environment.
* wrap/python/tests/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2012-06-04 16:38:42 +02:00
parent 75862a3284
commit 7b7a946485
4 changed files with 86 additions and 7 deletions

View file

@ -30,6 +30,7 @@ TESTS_ENVIRONMENT = ./run
check_SCRIPTS = run
TESTS = \
alarm.py \
ltlsimple.py \
ltlparse.py \
bddnqueen.py \

68
wrap/python/tests/alarm.py Executable file
View file

@ -0,0 +1,68 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2012 Laboratoire de Recherche et Développement
# de l'Epita
#
# This file is part of Spot, a model checking library.
#
# Spot 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 2 of the License, or
# (at your option) any later version.
#
# Spot 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 Spot; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
import spot
import time
import signal
import sys
import os
def alarm_handler(signum, frame):
sys.stdout.write("signaled\n")
os.kill(child, signal.SIGTERM)
exit(0)
f = """!(G(F(P_Rbt2.observe)&& F(P_Rbt3.observe) &&
F(P_rbt1.observe)&& F(P_Rbt1.plus || P_Rbt1.moins || P_Rbt1.stop)&&
F(P_Rbt3.plus || P_Rbt3.moins || P_Rbt3.stop) && F(P_Rbt2.plus ||
P_Rbt2.moins || P_Rbt2.stop))-> G((F "map[0]==1") && (F "map[1]==1")
&& (F "map[2]==1") && (F "map[3]==1") && (F "map[4]==1") && (F
"map[5]==1") && (F "map[6]==1") && (F "map[7]==1") && (F "map[8]==1")
&& (F "map[9]==1") && (F "map[0]==2") && (F "map[1]==2") && (F
"map[2]==2") && (F "map[3]==2") && (F "map[4]==2") && (F "map[5]==2")
&& (F "map[6]==2") && (F "map[7]==2") && (F "map[8]==2") && (F
"map[9]==2") && (F "map[0]==3") && (F "map[1]==3") && (F "map[2]==3")
&& (F "map[3]==3") && (F "map[4]==3") && (F "map[5]==3") && (F
"map[6]==3") && (F "map[7]==3") && (F "map[8]==3") && (F
"map[9]==3")))"""
e = spot.default_environment.instance()
p = spot.empty_parse_error_list()
f = spot.parse(f, p, e)
d = spot.bdd_dict()
spot.unblock_signal(signal.SIGALRM)
spot.unblock_signal(signal.SIGTERM)
os.setpgrp()
child = os.fork()
if child != 0:
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(2)
os.waitpid(child, 0)
# If the child returns, before we get the alarm it's a bug.
exit(1)
# This is expected to take WAY more that 2s.
print "Before"
spot.ltl_to_tgba_fm(f, d, True)
print "After"
exit(1)