<s> import unittest <EOL> import sys <EOL> import os <EOL> import shutil <EOL> from sts . control_flow . mcs_finder import MCSFinder , EfficientMCSFinder <EOL> from sts . replay_event import InputEvent , InvariantViolation <EOL> from sts . event_dag import EventDag <EOL> import logging <EOL> sys . path . append ( os . path . dirname ( __file__ ) + "<STR_LIT>" ) <EOL> class MockSimulationConfig ( object ) : <EOL> def __init__ ( self , ignore_interposition = False ) : <EOL> self . ignore_interposition = ignore_interposition <EOL> class MockMCSFinderBase ( MCSFinder ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , event_dag , mcs ) : <EOL> super ( MockMCSFinderBase , self ) . __init__ ( MockSimulationConfig ( ) , event_dag , <EOL> invariant_check_name = "<STR_LIT>" ) <EOL> self . invariant_check = self . _invariant_check <EOL> self . new_dag = None <EOL> self . mcs = mcs <EOL> self . simulation = None <EOL> self . transform_dag = None <EOL> def log ( self , message ) : <EOL> self . _log . info ( message ) <EOL> def _invariant_check ( self , _ ) : <EOL> for e in self . mcs : <EOL> if e not in self . new_dag . _events_set : <EOL> return [ ] <EOL> return [ "<STR_LIT>" ] <EOL> def replay ( self , new_dag , hook = None , ignore_runtime_stats = False ) : <EOL> self . new_dag = new_dag <EOL> return self . invariant_check ( new_dag ) <EOL> class MockMCSFinder ( MockMCSFinderBase , MCSFinder ) : <EOL> def __init__ ( self , event_dag , mcs ) : <EOL> MockMCSFinderBase . __init__ ( self , event_dag , mcs ) <EOL> self . _log = logging . getLogger ( "<STR_LIT>" ) <EOL> class MockEfficientMCSFinder ( MockMCSFinderBase , EfficientMCSFinder ) : <EOL> def __init__ ( self , event_dag , mcs ) : <EOL> MockMCSFinderBase . __init__ ( self , event_dag , mcs ) <EOL> self . _log = logging . getLogger ( "<STR_LIT>" ) <EOL> class MockInputEvent ( InputEvent ) : <EOL> def __init__ ( self , fingerprint = None , ** kws ) : <EOL> super ( MockInputEvent , self ) . __init__ ( ** kws ) <EOL> self . _fingerprint = fingerprint <EOL> self . timed_out = False <EOL> @ property <EOL> def fingerprint ( self ) : <EOL> return self . _fingerprint <EOL> def proceed ( self , simulation ) : <EOL> return True <EOL> mcs_results_path = "<STR_LIT>" <EOL> class MCSFinderTest ( unittest . TestCase ) : <EOL> def test_basic ( self ) : <EOL> self . basic ( MockMCSFinder ) <EOL> def test_basic_efficient ( self ) : <EOL> self . basic ( MockEfficientMCSFinder ) <EOL> def basic ( self , mcs_finder_type ) : <EOL> trace = [ MockInputEvent ( fingerprint = ( "<STR_LIT:class>" , f ) ) for f in range ( <NUM_LIT:1> , <NUM_LIT:7> ) ] <EOL> trace . append ( InvariantViolation ( [ "<STR_LIT>" ] , persistent = True ) ) <EOL> dag = EventDag ( trace ) <EOL> mcs = [ trace [ <NUM_LIT:0> ] ] <EOL> mcs_finder = mcs_finder_type ( dag , mcs ) <EOL> try : <EOL> os . makedirs ( mcs_results_path ) <EOL> mcs_finder . init_results ( mcs_results_path ) <EOL> mcs_finder . simulate ( ) <EOL> finally : <EOL> shutil . rmtree ( mcs_results_path ) <EOL> self . assertEqual ( mcs , mcs_finder . dag . input_events ) <EOL> def test_straddle ( self ) : <EOL> self . straddle ( MockMCSFinder ) <EOL> def test_straddle_efficient ( self ) : <EOL> self . straddle ( MockEfficientMCSFinder ) <EOL> def straddle ( self , mcs_finder_type ) : <EOL> trace = [ MockInputEvent ( fingerprint = ( "<STR_LIT:class>" , f ) ) for f in range ( <NUM_LIT:1> , <NUM_LIT:7> ) ] <EOL> trace . append ( InvariantViolation ( [ "<STR_LIT>" ] , persistent = True ) ) <EOL> dag = EventDag ( trace ) <EOL> mcs = [ trace [ <NUM_LIT:0> ] , trace [ <NUM_LIT:5> ] ] <EOL> mcs_finder = mcs_finder_type ( dag , mcs ) <EOL> try : <EOL> os . makedirs ( mcs_results_path ) <EOL> mcs_finder . init_results ( mcs_results_path ) <EOL> mcs_finder . simulate ( ) <EOL> finally : <EOL> shutil . rmtree ( mcs_results_path ) <EOL> self . assertEqual ( mcs , mcs_finder . dag . input_events ) <EOL> def test_all ( self ) : <EOL> self . all ( MockMCSFinder ) <EOL> def test_all_efficient ( self ) : <EOL> self . all ( MockEfficientMCSFinder ) <EOL> def all ( self , mcs_finder_type ) : <EOL> trace = [ MockInputEvent ( fingerprint = ( "<STR_LIT:class>" , f ) ) for f in range ( <NUM_LIT:1> , <NUM_LIT:7> ) ] <EOL> trace . append ( InvariantViolation ( [ "<STR_LIT>" ] , persistent = True ) ) <EOL> dag = EventDag ( trace ) <EOL> mcs = trace [ <NUM_LIT:0> : <NUM_LIT:6> ] <EOL> mcs_finder = mcs_finder_type ( dag , mcs ) <EOL> try : <EOL> os . makedirs ( mcs_results_path ) <EOL> mcs_finder . init_results ( mcs_results_path ) <EOL> mcs_finder . simulate ( ) <EOL> finally : <EOL> shutil . rmtree ( mcs_results_path ) <EOL> self . assertEqual ( mcs , mcs_finder . dag . input_events ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
