@@ -92,6 +92,8 @@ def parse_args():
9292 parser .add_argument ('--profile' , action = 'store_true' , help = "Profile actions." )
9393 parser .add_argument ('--profileProbs' , action = 'store_true' ,
9494 help = "Use action profile to prefer less-taken actions." )
95+ parser .add_argument ('--trackStates' , action = 'store_true' ,
96+ help = "Keep track of actual states." )
9597 parser .add_argument (
9698 '--stopSaturated' ,
9799 action = 'store_true' ,
@@ -915,6 +917,9 @@ def buildActivePool():
915917 if config .useHints :
916918 activePool .extend ([x [0 ] for x in hintPool [- config .exploitBestHint :]])
917919
920+ if config .trackStates :
921+ activePool .extend (statePool )
922+
918923 if config .verbose or config .verboseExploit :
919924 print ('FULL POOL SIZE' , len (fullPool ) + len (hintPool ),
920925 'ACTIVE POOL SIZE' , len (activePool ))
@@ -1000,6 +1005,7 @@ def tryExploit():
10001005def collectExploitable ():
10011006 global fullPool , activePool , branchCoverageCount , statementCoverageCount
10021007 global localizeSFail , localizeBFail , reducePool , hintValueCounts , poolCount
1008+ global lastWasNewState
10031009
10041010 if config .useHints :
10051011 # We are assuming hints are all normalized to the same scale!
@@ -1013,6 +1019,11 @@ def collectExploitable():
10131019 else :
10141020 hintValueCounts [hval ] = 1
10151021
1022+ if config .trackStates :
1023+ if lastWasNewState :
1024+ print ("COLLECTING DUE TO NEW STATE" )
1025+ statePool .append (list (sut .test ()))
1026+
10161027 if (not config .noCoverageExploit ) and (
10171028 (len (sut .newBranches ()) != 0 ) or (len (sut .newStatements ()) != 0 )):
10181029 if config .verbose or config .verboseExploit :
@@ -1039,6 +1050,7 @@ def collectExploitable():
10391050def printStatus (elapsed , step = None ):
10401051 global sut , nops , activePool , fullPool , testsWithNoNewCoverage , stepsWithNoNewCoverage
10411052 global testsWithNewCoverage , exploitsWithNewCoverage , totalExploits
1053+ global allSeenStates , testsWithNoNewStates , testsWithNewStates
10421054 print (sut .SUTName () + ":" , "TEST #" + str (ntests ), end = ' ' )
10431055 if step is not None :
10441056 print ("STEP #" + str (step ), end = ' ' )
@@ -1049,6 +1061,10 @@ def printStatus(elapsed, step=None):
10491061 len (sut .allBranches ()), "branches ]" , end = ' ' )
10501062 if testsWithNoNewCoverage > 0 :
10511063 print ("(no cov+ for" , testsWithNoNewCoverage , "tests)" , end = ' ' )
1064+ if config .trackStates :
1065+ print ("[" , len (allSeenStates ), "states ]" , end = ' ' )
1066+ if testsWithNoNewStates > 0 :
1067+ print ("(no states+ for" , testsWithNoNewStates , "tests)" , end = ' ' )
10521068 if config .exploit is not None :
10531069 print ("[ POOLS: full" , len (fullPool ), "active" , len (activePool ), "]" , end = ' ' )
10541070 print (nops , "TOTAL ACTIONS (" + str (round (nops / elapsed , 2 )) + "/s)" , end = ' ' )
@@ -1080,6 +1096,7 @@ def main():
10801096 global stepsWithNoNewCoverage
10811097 global sequences
10821098 global dnull , oldStdout , oldStderr
1099+ global allSeenStates , testsWithNoNewStates , testsWithNewStates , statePool , lastWasNewState
10831100
10841101 dnull = open (os .devnull , 'w' )
10851102 oldStdout = sys .stdout
@@ -1394,6 +1411,12 @@ def main():
13941411 neverExploited = True
13951412 totalExploits = 0
13961413
1414+ if config .trackStates :
1415+ allSeenStates = [sut .state ()[:- 1 ]]
1416+ testsWithNoNewStates = 0
1417+ testsWithNewStates = 0
1418+ statePool = []
1419+
13971420 while (config .maxTests == - 1 ) or (ntests < config .maxTests ):
13981421
13991422 if config .checkDeterminism :
@@ -1465,6 +1488,8 @@ def main():
14651488 continue
14661489
14671490 anyNewCoverage = False
1491+ if config .trackStates :
1492+ anyNewStates = False
14681493
14691494 currentSequence = None
14701495
@@ -1476,6 +1501,7 @@ def main():
14761501 thisOps = 0
14771502
14781503 for step in range (0 , config .depth ):
1504+ lastWasNewState = False
14791505 if config .verbose :
14801506 print ("GENERATING STEP" , step , end = ' ' )
14811507 sys .stdout .flush ()
@@ -1600,10 +1626,19 @@ def main():
16001626 sys .stdout = dnull
16011627 sys .stderr = dnull
16021628 stepOk = sut .safely (a )
1629+
16031630 if config .silentSUT :
16041631 sys .stdout = oldStdout
16051632 sys .stderr = oldStderr
16061633
1634+ if config .trackStates :
1635+ thisS = sut .state ()[:- 1 ]
1636+ if thisS not in allSeenStates :
1637+ print ("NEW STATE:" , thisS )
1638+ allSeenStates .append (thisS )
1639+ anyNewStates = True
1640+ lastWasNewState = True
1641+
16071642 if config .checkDeterminism :
16081643 trajectory .append (sut .trajectoryItem ())
16091644
@@ -1797,6 +1832,12 @@ def main():
17971832 else :
17981833 testsWithNoNewCoverage += 1
17991834
1835+ if config .trackStates :
1836+ if anyNewStates :
1837+ testsWithNewStates += 1
1838+ else :
1839+ testsWithNoNewStates += 1
1840+
18001841 if config .saveSwarmCoverage is not None :
18011842 swarmf .write ("CONFIG:\n " )
18021843 for sclass in sut .swarmConfig ():
0 commit comments