Skip to content

Commit 97a17b9

Browse files
committed
asynchronous stepper_a working with revised pmt
also revise observation_queue, stepper, stepper_o, stepper_util
1 parent f4ce884 commit 97a17b9

10 files changed

Lines changed: 102 additions & 1630 deletions

File tree

pymodel/observation_queue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
"""
44

55
import collections
6+
import threading
67

7-
observation_queue = collections.deque() # initially empty
8+
# stepper sets asynch = True to make pmt wait for asynch observable actions
9+
asynch = False # default: pmt doesn't wait for observable actions
10+
11+
queue = collections.deque() # initially empty
12+
13+
# initially clear, stepper sets when new item in queue, pmt clears when remove
14+
event = threading.Event()

pymodel/pmt.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import signal
1212
import traceback
1313
import TesterOptions
14-
from observation_queue import observation_queue
14+
import observation_queue as observation
1515

1616
from ProductModelProgram import ProductModelProgram
1717

@@ -63,8 +63,9 @@ def RunTest(options, mp, stepper, strategy, f, krun):
6363
# print 'Current state: %s' % mp.Current() # DEBUG
6464

6565
# observable action
66-
if observation_queue: # if queue not empty
67-
(aname, args) = observation_queue.popleft()
66+
if observation.queue: # if queue not empty
67+
# print 'observable action branch, call observation.queue.popleft()'
68+
(aname, args) = observation.queue.popleft()
6869
observable_action = True
6970
# print '< test runner gets', (aname, args)
7071
if not mp.ActionEnabled(aname, args):
@@ -83,9 +84,17 @@ def RunTest(options, mp, stepper, strategy, f, krun):
8384
(aname, args) = strategy.SelectAction(enabled)
8485
# exit conditions
8586
if not aname:
86-
if not cleanup:
87-
infoMessage = 'no more actions enabled'
88-
break
87+
if observation.asynch:
88+
# print 'asynch branch, call observation.wait()' # DEBUG
89+
observation.event.wait() # FIXME add timeout
90+
# FIXME? If another event occurs right now, we will miss it!
91+
observation.event.clear() # got this event, prepare for next
92+
continue # get observable action from queue
93+
# if not asynch, come directly here
94+
# if asynch, only reach here if event.wait() times out
95+
if not cleanup:
96+
infoMessage = 'no more actions enabled'
97+
break
8998
elif cleanup and mp.Accepting():
9099
break
91100
else:

samples/Socket/README.txt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ The sample includes these modules:
4242
- stepper, stepper_o, and stepper_a: three different steppers (also
4343
called test harnesses or adapters) that use the model program and
4444
scenarios to test actual sockets on localhost (via the Python
45-
standard library socket module). Also, Sender.py, Receiver.py,
46-
etc.: other code for exercising the standard library socket module.
45+
standard library socket module). Also, stepper_util, code used
46+
by all three steppers.
4747

4848
- socket_simulator and socket_simulator_a: two simulators that can
4949
optionally replace the Python standard library socket module in the
@@ -343,7 +343,6 @@ synchronous msocket. It is a graph of the msocket model program
343343
composed with the synchronous scenario machine, using the domains in
344344
the deterministic module.
345345

346-
347346
The stepper test harness
348347

349348
The stepper module is a test harness (sometimes called an adapter)
@@ -394,6 +393,14 @@ discuss stepper_o and stepper_a, that support all model behaviors
394393
correctly.
395394

396395

396+
The stepper_util test harness utilities
397+
398+
The stepper_util module defines constants and methods used by
399+
all three steppers, including methods to open and close sockets
400+
and to make a connection. The three stepper modules only
401+
handle the send and recv methods - that is their only difference.
402+
403+
397404
The test_stepper script
398405

399406
The test_stepper module is a test script with three test cases that
@@ -582,22 +589,25 @@ invoke send_call and recv_call.
582589

583590
The first test case does not use the synchronous scenario so it often
584591
blocks, times out, and fails. The second test case uses the
585-
synchronous scenario so it never blocks and always succeeds. With
586-
test_stepper, the second test case often fails, but here it always
592+
synchronous scenario so it never blocks and always succeeds. With our
593+
test_stepper, the second test case often failed because the results
594+
were nondeterministically chosen by the model, but here it always
587595
succeeds because the return values are chosen by the implementation
588596
rather than the model, and the test outcomes are determined by
589597
checking those return values with the enabling conditions in the
590598
model. The third case always succeeds for the same reason. The third
591599
test case names the deterministic configuration, but it is not
592-
necessary because here the return values are chosen by the implemenation,
593-
not the model.
600+
necessary because here the return values are chosen by the
601+
implemenation, not the model.
594602

595603

596604
The stepper_a asynchronous stepper module
597605

598-
The stepper_a module supports nondeterminism and asynchrony. Each
599-
call to the implementation runs in its own thread, so it can wait
600-
without blocking the test run. ...
606+
The stepper_a module supports nondeterminism and asynchrony. It is
607+
similar to stepper_o, but here each call to the implementation runs in
608+
its own thread, so the implementation can block at that call
609+
without blocking the whole test run. This enables pmt to make another
610+
call that results in unblocking the earlier call.
601611

602612

603613
The socket_simulator module

samples/Socket/fsmpy/socketFSM.py

Lines changed: 0 additions & 189 deletions
This file was deleted.

samples/Socket/fsmpy/synchronous_graph.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)