def test_flow_tracking_labels_diverge(changes): """ Tests a case of divergence. Diverge to a, b with different ap diffs, then converge at c. """ flow_tracking = FlowTracking() flow_tracking.add_flow_to_label(ScopedName.from_string('a'), changes.to_a) flow_tracking.add_flow_to_label(ScopedName.from_string('b'), changes.to_b) # Label a. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('a')) flow_tracking.add_ap(changes.at_a) data_after_a = flow_tracking.get() flow_tracking.add_flow_to_label(ScopedName.from_string('c'), 0) # Label b. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('b')) flow_tracking.add_ap(changes.at_b) data_after_b = flow_tracking.get() flow_tracking.add_flow_to_label(ScopedName.from_string('c'), 0) # Label c. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('c')) data_at_c = flow_tracking.get() if changes.valid: assert data_after_a == data_after_b == data_at_c else: assert data_after_a != data_at_c and data_after_b != data_at_c
def test_flow_tracking_converge_references(refs): flow_tracking = FlowTracking() flow_tracking.add_flow_to_label(ScopedName.from_string('a'), RegChangeUnknown()) flow_tracking.add_flow_to_label(ScopedName.from_string('b'), RegChangeUnknown()) # Label a. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('a')) flow_tracking.add_reference( name=ScopedName.from_string('x'), ref=Reference( pc=0, value=refs.expr_a, ap_tracking_data=flow_tracking.get_ap_tracking(), )) flow_tracking.add_ap(13) flow_tracking.add_flow_to_label(ScopedName.from_string('c'), 0) # Label b. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('b')) flow_tracking.add_reference( name=ScopedName.from_string('x'), ref=Reference( pc=0, value=refs.expr_b, ap_tracking_data=flow_tracking.get_ap_tracking(), )) flow_tracking.add_ap(15) flow_tracking.add_flow_to_label(ScopedName.from_string('c'), 0) # Label c - convergence. flow_tracking.revoke() flow_tracking.converge_with_label(ScopedName.from_string('c')) if refs.valid: flow_tracking.resolve_reference(ScopedName.from_string('x')) else: with pytest.raises(FlowTrackingError): flow_tracking.resolve_reference(ScopedName.from_string('x'))