def test_iss131_2(self): trace = CTrace() cb1 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(2)], None, [TestGrounding._get_fmwkov("", "void doA()", False)]) trace.add_msg(cb1) cb2 = CCallback(1, 1, "", "void doB()", [TestGrounding._get_int(1)], None, [TestGrounding._get_fmwkov("", "void doB()", False)]) trace.add_msg(cb2) cb3 = CCallback(1, 1, "", "void doC()", [TestGrounding._get_int(1)], None, [TestGrounding._get_fmwkov("", "void doC()", False)]) trace.add_msg(cb3) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC ([CB] [ENTRY] [l] void doA() | [CB] [ENTRY] [l] void doB()) |- [CB] [ENTRY] [f] void doC()" ) real_ground_spec = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] [2] void doA() |- [CB] [ENTRY] [1] void doC();" + "SPEC [CB] [ENTRY] [1] void doB() |- [CB] [ENTRY] [1] void doC()") ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec))
def test_iss161(self): trace = CTrace() cb1 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(2)], None, [TestGrounding._get_fmwkov("", "void doA()", False)]) trace.add_msg(cb1) cb2 = CCallback(1, 1, "", "void doB()", [TestGrounding._get_int(1)], None, [TestGrounding._get_fmwkov("", "void doB()", False)]) trace.add_msg(cb2) cb3 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(3)], None, [TestGrounding._get_fmwkov("", "void doA()", False)]) trace.add_msg(cb3) gs = GroundSpecs(trace) #specs = Spec.get_specs_from_string("SPEC [CB] [ENTRY] [l] void doA(); (! [CB] [ENTRY] [l] void doA()) |- [CB] [ENTRY] [l2] void doB()") specs = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] [l] void doA(); [CB] [ENTRY] [l] void doA() |- [CB] [ENTRY] [l2] void doB()" ) real_ground_spec = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] [l] void doA(); (! [CB] [ENTRY] [l] void doA()) |- [CB] [ENTRY] [l] void doB()" ) ground_specs = gs.ground_spec(specs[0]) for g in ground_specs: g.print_spec(sys.stdout) print ""
def test_regexp_and(self): trace = CTrace() cb = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()], None, [TestGrounding._get_fmwkov("", "void m1()", False)]) ci1 = CCallin(1, 1, "", "void doA()", [TestGrounding._get_int(1)], None) ci2 = CCallin(1, 1, "", "void doB()", [TestGrounding._get_int(1)], None) ci3 = CCallin(1, 1, "", "void doC()", [TestGrounding._get_int(2)], None) cb.add_msg(ci1) cb.add_msg(ci2) cb.add_msg(ci3) trace.add_msg(cb) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC ([CI] [ENTRY] [l] void doA() & [CI] [ENTRY] [l] void doB()) |- [CI] [ENTRY] [f] void doC()" ) real_ground_spec = Spec.get_specs_from_string( "SPEC ([CI] [ENTRY] [1] void doA() & [CI] [ENTRY] [1] void doB()) |- [CI] [ENTRY] [2] void doC()" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec))
def test_only_methods(self): trace = CTrace() cb = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()], None, [TestGrounding._get_fmwkov("", "void m1()", False)]) ci1 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None) ci2 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None) ci3 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None) cb.add_msg(ci1) cb.add_msg(ci2) cb.add_msg(ci3) trace.add_msg(cb) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] void m2() |- [CB] [EXIT] void m1()") ground_specs = gs.ground_spec(specs[0]) self.assertTrue(1 == len(ground_specs)) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC ! ([CB] [ENTRY] void m3()) |- [CB] [ENTRY] void m1()") ground_specs = gs.ground_spec(specs[0]) self.assertTrue(1 == len(ground_specs)) self.assertTrue( new_star(new_true()) == get_regexp_node(ground_specs[0].ast)) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] void m3() |- [CB] [ENTRY] void m1()") ground_specs = gs.ground_spec(specs[0]) self.assertTrue(0 == len(ground_specs))
def check_sg(test): (r, t, expected_specs_str) = test trace = TestGrounding.get_trace(t) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string(r) ground_specs = gs.ground_spec(specs[0]) expected_ground_specs = Spec.get_specs_from_string(expected_specs_str) if expected_ground_specs is None: expected_ground_specs = [] assert (TestGrounding._eq_specs(ground_specs, expected_ground_specs))
def test_int(self): trace = CTrace() cb = CCallback( 1, 1, "", "void m1(%s)" % TraceConverter.JAVA_INT, [TestGrounding._get_null(), TestGrounding._get_int(2)], None, [ TestGrounding._get_fmwkov( "", "void m1(%s)" % TraceConverter.JAVA_INT, False) ]) trace.add_msg(cb) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC TRUE |- [CB] [ENTRY] void m1(2 : %s)" % TraceConverter.JAVA_INT) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(1 == len(ground_specs))
def test_constants(self): trace = CTrace() cb = CCallback(1, 1, "edu.colorado.test", "void inheritedMethodMethod(int)", [TestGrounding._get_null(), TestGrounding._get_int(2)], None, [ TestGrounding._get_fmwkov( "android", "void inheritedMethod(int)", False) ]) trace.add_msg(cb) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC ! ([CB] [ENTRY] void android.inheritedMethodA(3 : int)) |- [CB] [ENTRY] void android.inheritedMethod(2 : int)" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(len(ground_specs) == 1)
def test_array_types(self): test_path = os.path.dirname(cbverifier.test.examples.__file__) t1 = os.path.join(test_path, "trace_array.json") trace = CTraceSerializer.read_trace_file_name(t1, True) self.assertTrue(trace is not None) spec_file_path = os.path.join(test_path, "spec_array.spec") specs = Spec.get_specs_from_files([spec_file_path]) self.assertTrue(specs is not None) self.assertTrue(len(specs) == 1) real_ground_spec = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] [1] java.lang.String android.app.Activity.getString(2131427336 : int,4fe67f6 : java.lang.Object[],efe45f6 : java.lang.Test[][]) |- [CI] [ENTRY] [1] java.lang.String android.app.Activity.getString(2131427336 : int, 4fe67f6 : java.lang.Object[],efe45f6 : java.lang.Test[][])" ) self.assertTrue(real_ground_spec is not None) gs = GroundSpecs(trace) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(ground_specs is not None) self.assertTrue(1 == len(ground_specs)) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec))
def test_boolean(self): trace = CTrace() cb = CCallback( 1, 1, "", "void m1(%s)" % TraceConverter.JAVA_BOOLEAN, [TestGrounding._get_null(), TestGrounding._get_true()], None, [ TestGrounding._get_fmwkov( "", "void m1(%s)" % TraceConverter.JAVA_BOOLEAN, False) ]) trace.add_msg(cb) cb = CCallback( 1, 1, "", "void m2(%s)" % TraceConverter.JAVA_BOOLEAN, [TestGrounding._get_null(), TestGrounding._get_false()], None, [ TestGrounding._get_fmwkov( "", "void m2(%s)" % TraceConverter.JAVA_BOOLEAN, False) ]) trace.add_msg(cb) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC TRUE |- [CB] [ENTRY] void m2(FALSE : %s)" % (TraceConverter.JAVA_BOOLEAN)) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(1 == len(ground_specs))
def test_ground_bindings(self): trace = CTrace() cb1 = CCallback( 1, 1, "", "void doSomethingCb()", [TestGrounding._get_obj("1", "string")], None, [TestGrounding._get_fmwkov("", "void doSomethingCb()", False)]) trace.add_msg(cb1) ci1 = CCallin(1, 1, "", "void doSomethingCi(string)", [ TestGrounding._get_obj("1", "string"), TestGrounding._get_obj("2", "string") ], None) cb1.add_msg(ci1) ci2 = CCallin(1, 1, "", "void otherCi(string)", [ TestGrounding._get_obj("4", "string"), TestGrounding._get_obj("1", "string") ], None) cb1.add_msg(ci2) ci3 = CCallin(1, 1, "", "void doSomethingCi(string)", [ TestGrounding._get_obj("1", "string"), TestGrounding._get_obj("4", "string") ], None) cb1.add_msg(ci3) cb2 = CCallback( 1, 1, "", "void doSomethingCb2()", [TestGrounding._get_obj("1", "string")], TestGrounding._get_obj("1", "string"), [TestGrounding._get_fmwkov("", "void doSomethingCb2()", False)]) trace.add_msg(cb2) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] [l] void doSomethingCi(z : string) |- [CI] [ENTRY] [z] void otherCi(f : string)" ) real_ground_spec = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] [1] void doSomethingCi(4 : string) |- [CI] [ENTRY] [4] void otherCi(1 : string)" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec)) # WARNING: the results is sensitive to the order of the atoms in the OR gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] [l] void doSomethingCi(# : string) |- [CI] [ENTRY] [#] void otherCi(# : string)" ) real_ground_spec_1 = Spec.get_specs_from_string( "SPEC ([CI] [ENTRY] [1] void doSomethingCi(4 : string) | " + "[CI] [ENTRY] [1] void doSomethingCi(2 : string)) " + "|- [CI] [ENTRY] [4] void otherCi(1 : string)") real_ground_spec_2 = Spec.get_specs_from_string( "SPEC ([CI] [ENTRY] [1] void doSomethingCi(2 : string) | " + "[CI] [ENTRY] [1] void doSomethingCi(4 : string)) " + "|- [CI] [ENTRY] [4] void otherCi(1 : string)") ground_specs = gs.ground_spec(specs[0]) self.assertTrue( TestGrounding._eq_specs(ground_specs, real_ground_spec_1) or TestGrounding._eq_specs(ground_specs, real_ground_spec_2)) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] [l] void doSomethingCb() |- [CI] [ENTRY] [#] void otherCi(l : string)" ) real_ground_spec = Spec.get_specs_from_string( "SPEC [CB] [ENTRY] [1] void doSomethingCb() |- [CI] [ENTRY] [4] void otherCi(1 : string)" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec)) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC TRUE |- [CI] [ENTRY] [l1] void doSomethingCi(l1 : string)") ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, [])) # doSomethingCi will be instantiated to FALSE gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CI] [ENTRY] [l1] void doSomethingCi(l1 : string) |- [CI] [ENTRY] [z] void otherCi(l : string)" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, [])) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC [CB] [EXIT] [l] void doSomethingCb() |- [CI] [EXIT] [#] void otherCi(l : string)" ) real_ground_spec = Spec.get_specs_from_string( "SPEC [CB] [EXIT] [1] void doSomethingCb() |- [CI] [EXIT] [4] void otherCi(1 : string)" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec)) gs = GroundSpecs(trace) specs = Spec.get_specs_from_string( "SPEC m = [CB] [EXIT] [l] void doSomethingCb2() |- m = [CB] [EXIT] [l] void doSomethingCb2()" ) real_ground_spec = Spec.get_specs_from_string( "SPEC 1 = [CB] [EXIT] [1] void doSomethingCb2() |- 1 = [CB] [EXIT] [1] void doSomethingCb2()" ) ground_specs = gs.ground_spec(specs[0]) self.assertTrue(TestGrounding._eq_specs(ground_specs, real_ground_spec))