@@ -92,6 +92,8 @@ def parse_args():
92
92
parser .add_argument ('--profile' , action = 'store_true' , help = "Profile actions." )
93
93
parser .add_argument ('--profileProbs' , action = 'store_true' ,
94
94
help = "Use action profile to prefer less-taken actions." )
95
+ parser .add_argument ('--trackStates' , action = 'store_true' ,
96
+ help = "Keep track of actual states." )
95
97
parser .add_argument (
96
98
'--stopSaturated' ,
97
99
action = 'store_true' ,
@@ -915,6 +917,9 @@ def buildActivePool():
915
917
if config .useHints :
916
918
activePool .extend ([x [0 ] for x in hintPool [- config .exploitBestHint :]])
917
919
920
+ if config .trackStates :
921
+ activePool .extend (statePool )
922
+
918
923
if config .verbose or config .verboseExploit :
919
924
print ('FULL POOL SIZE' , len (fullPool ) + len (hintPool ),
920
925
'ACTIVE POOL SIZE' , len (activePool ))
@@ -1000,6 +1005,7 @@ def tryExploit():
1000
1005
def collectExploitable ():
1001
1006
global fullPool , activePool , branchCoverageCount , statementCoverageCount
1002
1007
global localizeSFail , localizeBFail , reducePool , hintValueCounts , poolCount
1008
+ global lastWasNewState
1003
1009
1004
1010
if config .useHints :
1005
1011
# We are assuming hints are all normalized to the same scale!
@@ -1013,6 +1019,11 @@ def collectExploitable():
1013
1019
else :
1014
1020
hintValueCounts [hval ] = 1
1015
1021
1022
+ if config .trackStates :
1023
+ if lastWasNewState :
1024
+ print ("COLLECTING DUE TO NEW STATE" )
1025
+ statePool .append (list (sut .test ()))
1026
+
1016
1027
if (not config .noCoverageExploit ) and (
1017
1028
(len (sut .newBranches ()) != 0 ) or (len (sut .newStatements ()) != 0 )):
1018
1029
if config .verbose or config .verboseExploit :
@@ -1039,6 +1050,7 @@ def collectExploitable():
1039
1050
def printStatus (elapsed , step = None ):
1040
1051
global sut , nops , activePool , fullPool , testsWithNoNewCoverage , stepsWithNoNewCoverage
1041
1052
global testsWithNewCoverage , exploitsWithNewCoverage , totalExploits
1053
+ global allSeenStates , testsWithNoNewStates , testsWithNewStates
1042
1054
print (sut .SUTName () + ":" , "TEST #" + str (ntests ), end = ' ' )
1043
1055
if step is not None :
1044
1056
print ("STEP #" + str (step ), end = ' ' )
@@ -1049,6 +1061,10 @@ def printStatus(elapsed, step=None):
1049
1061
len (sut .allBranches ()), "branches ]" , end = ' ' )
1050
1062
if testsWithNoNewCoverage > 0 :
1051
1063
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 = ' ' )
1052
1068
if config .exploit is not None :
1053
1069
print ("[ POOLS: full" , len (fullPool ), "active" , len (activePool ), "]" , end = ' ' )
1054
1070
print (nops , "TOTAL ACTIONS (" + str (round (nops / elapsed , 2 )) + "/s)" , end = ' ' )
@@ -1080,6 +1096,7 @@ def main():
1080
1096
global stepsWithNoNewCoverage
1081
1097
global sequences
1082
1098
global dnull , oldStdout , oldStderr
1099
+ global allSeenStates , testsWithNoNewStates , testsWithNewStates , statePool , lastWasNewState
1083
1100
1084
1101
dnull = open (os .devnull , 'w' )
1085
1102
oldStdout = sys .stdout
@@ -1394,6 +1411,12 @@ def main():
1394
1411
neverExploited = True
1395
1412
totalExploits = 0
1396
1413
1414
+ if config .trackStates :
1415
+ allSeenStates = [sut .state ()[:- 1 ]]
1416
+ testsWithNoNewStates = 0
1417
+ testsWithNewStates = 0
1418
+ statePool = []
1419
+
1397
1420
while (config .maxTests == - 1 ) or (ntests < config .maxTests ):
1398
1421
1399
1422
if config .checkDeterminism :
@@ -1465,6 +1488,8 @@ def main():
1465
1488
continue
1466
1489
1467
1490
anyNewCoverage = False
1491
+ if config .trackStates :
1492
+ anyNewStates = False
1468
1493
1469
1494
currentSequence = None
1470
1495
@@ -1476,6 +1501,7 @@ def main():
1476
1501
thisOps = 0
1477
1502
1478
1503
for step in range (0 , config .depth ):
1504
+ lastWasNewState = False
1479
1505
if config .verbose :
1480
1506
print ("GENERATING STEP" , step , end = ' ' )
1481
1507
sys .stdout .flush ()
@@ -1600,10 +1626,19 @@ def main():
1600
1626
sys .stdout = dnull
1601
1627
sys .stderr = dnull
1602
1628
stepOk = sut .safely (a )
1629
+
1603
1630
if config .silentSUT :
1604
1631
sys .stdout = oldStdout
1605
1632
sys .stderr = oldStderr
1606
1633
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
+
1607
1642
if config .checkDeterminism :
1608
1643
trajectory .append (sut .trajectoryItem ())
1609
1644
@@ -1797,6 +1832,12 @@ def main():
1797
1832
else :
1798
1833
testsWithNoNewCoverage += 1
1799
1834
1835
+ if config .trackStates :
1836
+ if anyNewStates :
1837
+ testsWithNewStates += 1
1838
+ else :
1839
+ testsWithNoNewStates += 1
1840
+
1800
1841
if config .saveSwarmCoverage is not None :
1801
1842
swarmf .write ("CONFIG:\n " )
1802
1843
for sclass in sut .swarmConfig ():
0 commit comments