def test_update_metrics_true_dist_min(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_compare_predicate(5, 0, 0, Compare.EQ) assert (0, 5) in tracer.get_trace().true_distances.items() tracer.executed_compare_predicate(4, 0, 0, Compare.EQ) assert (0, 4) in tracer.get_trace().true_distances.items()
def test_cmp(cmp, val1, val2, true_dist, false_dist): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) tracer.executed_compare_predicate(val1, val2, 0, cmp) assert (0, true_dist) in tracer.get_trace().true_distances.items() assert (0, false_dist) in tracer.get_trace().false_distances.items()
def test_update_metrics_covered(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) tracer.executed_compare_predicate(1, 0, 0, Compare.EQ) tracer.executed_compare_predicate(1, 0, 0, Compare.EQ) assert (0, 2) in tracer.get_trace().executed_predicates.items()
def test_no_branchless_code_object_register_multiple(): tracer = ExecutionTracer() tracer.register_code_object(MagicMock()) tracer.register_code_object(MagicMock()) tracer.register_predicate(MagicMock(code_object_id=0)) tracer.register_predicate(MagicMock(code_object_id=0)) assert tracer.get_known_data().branch_less_code_objects == {1}
def test_bool_distance_false(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) tracer.executed_bool_predicate(False, 0) assert (0, 1.0) in tracer.get_trace().true_distances.items() assert (0, 0.0) in tracer.get_trace().false_distances.items()
def test_update_metrics_false_dist_min(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_compare_predicate(3, 1, 0, Compare.NE) assert (0, 2) in tracer.get_trace().false_distances.items() tracer.executed_compare_predicate(2, 1, 0, Compare.NE) assert (0, 1) in tracer.get_trace().false_distances.items()
def test_update_metrics_false_dist_min(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) tracer.executed_compare_predicate(3, 1, 0, Compare.NE) assert (0, 2) in tracer.get_trace().false_distances.items() tracer.executed_compare_predicate(2, 1, 0, Compare.NE) assert (0, 1) in tracer.get_trace().false_distances.items()
def test_update_metrics_true_dist_min(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) tracer.executed_compare_predicate(5, 0, 0, Compare.EQ) assert (0, 5) in tracer.get_trace().true_distances.items() tracer.executed_compare_predicate(4, 0, 0, Compare.EQ) assert (0, 4) in tracer.get_trace().true_distances.items()
def test_enable_disable_bool(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) assert len(tracer.get_trace().executed_predicates) == 0 tracer._disable() tracer.executed_bool_predicate(True, 0) assert len(tracer.get_trace().executed_predicates) == 0 tracer._enable() tracer.executed_bool_predicate(True, 0) assert len(tracer.get_trace().executed_predicates) == 1
def test_enable_disable_cmp(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) assert len(tracer.get_trace().executed_predicates) == 0 tracer._disable() tracer.executed_compare_predicate(0, 0, 0, Compare.EQ) assert len(tracer.get_trace().executed_predicates) == 0 tracer._enable() tracer.executed_compare_predicate(0, 0, 0, Compare.EQ) assert len(tracer.get_trace().executed_predicates) == 1
def test_enable_disable_cmp(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) assert len(tracer.get_trace().executed_predicates) == 0 tracer.disable() tracer.executed_compare_predicate(0, 0, 0, Compare.EQ) assert len(tracer.get_trace().executed_predicates) == 0 tracer.enable() tracer.executed_compare_predicate(0, 0, 0, Compare.EQ) assert len(tracer.get_trace().executed_predicates) == 1
def test_enable_disable_bool(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) assert len(tracer.get_trace().executed_predicates) == 0 tracer.disable() tracer.executed_bool_predicate(True, 0) assert len(tracer.get_trace().executed_predicates) == 0 tracer.enable() tracer.executed_bool_predicate(True, 0) assert len(tracer.get_trace().executed_predicates) == 1
def test_update_metrics_covered(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_compare_predicate(1, 0, 0, Compare.EQ) tracer.executed_compare_predicate(1, 0, 0, Compare.EQ) assert (0, 2) in tracer.get_trace().executed_predicates.items()
def test_predicate_exists(): tracer = ExecutionTracer() assert tracer.register_predicate(MagicMock(PredicateMetaData)) == 0 assert tracer.register_predicate(MagicMock(PredicateMetaData)) == 1 assert 0 in tracer.get_known_data().existing_predicates
def test_bool_distance_false(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_bool_predicate(False, 0) assert (0, 1.0) in tracer.get_trace().true_distances.items() assert (0, 0.0) in tracer.get_trace().false_distances.items()
def test_passed_bool_predicate(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_bool_predicate(True, 0) assert (0, 1) in tracer.get_trace().executed_predicates.items()
def test_unknown_comp(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) with pytest.raises(Exception): tracer.executed_compare_predicate(1, 1, 0, Compare.EXC_MATCH)
def test_update_metrics_assertions(true_dist, false_dist): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) with pytest.raises(AssertionError): tracer._update_metrics(false_dist, true_dist, 0)
def test_predicate_exists(): tracer = ExecutionTracer() assert tracer.register_predicate(MagicMock(code_object_id=0)) == 0 assert tracer.register_predicate(MagicMock(code_object_id=0)) == 1 assert 0 in tracer.get_known_data().existing_predicates
def test_unknown_comp(): tracer = ExecutionTracer() tracer.current_thread_ident = threading.currentThread().ident tracer.register_predicate(MagicMock(code_object_id=0)) with pytest.raises(Exception): tracer.executed_compare_predicate(1, 1, 0, Compare.EXC_MATCH)
def test_passed_bool_predicate(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(code_object_id=0)) tracer.current_thread_ident = threading.currentThread().ident tracer.executed_bool_predicate(True, 0) assert (0, 1) in tracer.get_trace().executed_predicates.items()
def test_passed_cmp_predicate(): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_compare_predicate(1, 0, 0, Compare.EQ) assert (0, 1) in tracer.get_trace().executed_predicates.items()
def test_cmp(cmp, val1, val2, true_dist, false_dist): tracer = ExecutionTracer() tracer.register_predicate(MagicMock(PredicateMetaData)) tracer.executed_compare_predicate(val1, val2, 0, cmp) assert (0, true_dist) in tracer.get_trace().true_distances.items() assert (0, false_dist) in tracer.get_trace().false_distances.items()