int main() { Assignment assignment1("2-28-2016", "Linked Lists", "2-20-2016", assigned); cout << assignment1.get_description() << endl; system("Pause"); return 0; }
test_results_t test1_25_Mutator::executeTest() { // Used as hack for Fortran to allow assignment of a pointer to an int BPatch::bpatch->setTypeChecking (false); // First verify that we can find a local variable in test1_25_call1 const char *funcName = "test1_25_call1"; BPatch_Vector<BPatch_function *> found_funcs; if ((NULL == appImage->findFunction(funcName, found_funcs)) || !found_funcs.size()) { logerror(" Unable to find function %s\n", funcName); return FAILED; } if (1 < found_funcs.size()) { logerror("%s[%d]: WARNING : found %d functions named %s. Using the first.\n", __FILE__, __LINE__, found_funcs.size(), funcName); } BPatch_Vector<BPatch_point *> *point25_1 = found_funcs[0]->findPoint(BPatch_entry); assert(point25_1); // assert(point25_1 && (point25_1->size() == 1)); BPatch_variableExpr *gvar[8]; for (int i=1; i <= 7; i++) { char name[80]; sprintf (name, "test1_25_globalVariable%d", i); gvar [i] = findVariable (appImage, name, point25_1); if (!gvar[i]) { logerror("**Failed** test #25 (unary operaors)\n"); logerror(" can't find variable %s\n", name); return FAILED; } } // globalVariable25_2 = &globalVariable25_1 #if !defined(rs6000_ibm_aix4_1_test) \ && !defined(i386_unknown_linux2_0_test) \ && !defined(x86_64_unknown_linux2_4_test) /* Blind duplication - Ray */ \ && !defined(ppc64_linux_test) \ && !defined(i386_unknown_nt4_0_test) \ && !defined(os_freebsd_test) // without type info need to inform BPatch_type *type = appImage->findType("void *"); assert(type); gvar[2]->setType(type); #endif BPatch_arithExpr assignment1(BPatch_assign, *gvar[2], BPatch_arithExpr(BPatch_addr, *gvar[1])); appAddrSpace->insertSnippet(assignment1, *point25_1); // globalVariable25_3 = *globalVariable25_2 // Need to make sure this happens after the first one BPatch_arithExpr assignment2(BPatch_assign, *gvar[3], BPatch_arithExpr(BPatch_deref, *gvar[2])); appAddrSpace->insertSnippet(assignment2, *point25_1, BPatch_callBefore, BPatch_lastSnippet); // globalVariable25_5 = -globalVariable25_4 BPatch_arithExpr assignment3(BPatch_assign, *gvar[5], BPatch_arithExpr(BPatch_negate, *gvar[4])); appAddrSpace->insertSnippet(assignment3, *point25_1); // globalVariable25_7 = -globalVariable25_6 BPatch_arithExpr assignment4(BPatch_assign, *gvar[7], BPatch_arithExpr(BPatch_negate, *gvar[6])); appAddrSpace->insertSnippet(assignment4, *point25_1); // Check removed because MIPS is no longer supported // #endif // !MIPS BPatch::bpatch->setTypeChecking (true); return PASSED; }
test_results_t test1_28_Mutator::executeTest() { int i; if (isMutateeFortran(appImage)) { return SKIPPED; } // Create the types BPatch_type *intType = appImage->findType("int"); assert(intType); BPatch_Vector<char *> names; BPatch_Vector<BPatch_type *> types; names.push_back(const_cast<char*>("field1")); names.push_back(const_cast<char*>("field2")); types.push_back(intType); types.push_back(intType); // struct28_1 { int field1, int field 2; } BPatch_type *struct28_1 = BPatch::bpatch->createStruct("test1_28_struct1", names, types); BPatch_type *union28_1 = BPatch::bpatch->createUnion("testUnion27_1", names, types); assert(union28_1); names.push_back(const_cast<char*>("field3")); names.push_back(const_cast<char*>("field4")); BPatch_type *intArray = BPatch::bpatch->createArray("intArray", intType, 0, 9); types.push_back(intArray); types.push_back(struct28_1); // struct28_2 { int field1, int field 2, int field3[10],struct26_1 field4 } BPatch_type *struct28_2 = BPatch::bpatch->createStruct("test1_28_struct2", names, types); BPatch_type *type28_2 = BPatch::bpatch->createTypedef("type28_2", struct28_2); // now create variables of these types. BPatch_variableExpr *globalVariable28_1 = appImage->findVariable("test1_28_globalVariable1"); if (!globalVariable28_1) { logerror("[%s:%u] - Unable to find variable test1_28_globalVariable1\n", __FILE__, __LINE__); return FAILED; } globalVariable28_1->setType(type28_2); BPatch_variableExpr *globalVariable28_8 = appImage->findVariable("test1_28_globalVariable8"); if (!globalVariable28_8) { logerror("[%s:%u] - Unable to find variable test1_28_globalVariable8\n", __FILE__, __LINE__); return FAILED; } globalVariable28_8->setType(union28_1); // Next verify that we can find a local variable in call28 const char *fname = "test1_28_call1"; BPatch_Vector<BPatch_function *> found_funcs; if ((NULL == appImage->findFunction(fname, found_funcs)) || !found_funcs.size()) { logerror(" Unable to find function %s\n", fname); return FAILED; } if (1 < found_funcs.size()) { logerror("%s[%d]: WARNING : found %d functions named %s. Using the first.\n", __FILE__, __LINE__, found_funcs.size(), fname); } BPatch_Vector<BPatch_point *> *point28 = found_funcs[0]->findPoint(BPatch_entry); assert(point28 && (point28->size() == 1)); // FIXME We didn't look up a local variable!? BPatch_variableExpr *gvar[8]; for (i=1; i <= 7; i++) { char name[80]; sprintf(name, "test1_28_globalVariable%d", i); gvar[i] = appImage->findVariable(name); if (!gvar[i]) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" can't find variable %s\n", name); return FAILED; } } // start of code for globalVariable28 BPatch_Vector<BPatch_variableExpr *> *fields = gvar[1]->getComponents(); assert(fields && (fields->size() == 4)); for (i=0; i < 4; i++) { char fieldName[80]; sprintf(fieldName, "field%d", i+1); if (strcmp(fieldName, (*fields)[i]->getName())) { logerror("field %d of the struct is %s, not %s\n", i+1, fieldName, (*fields)[i]->getName()); return FAILED; } } // globalVariable28 = globalVariable28.field1 BPatch_arithExpr assignment1(BPatch_assign, *gvar[2], *((*fields)[0])); appAddrSpace->insertSnippet(assignment1, *point28); // globalVariable28 = globalVariable28.field2 BPatch_arithExpr assignment2(BPatch_assign, *gvar[3], *((*fields)[1])); appAddrSpace->insertSnippet(assignment2, *point28); // globalVariable28 = globalVariable28.field3[0] BPatch_arithExpr assignment3(BPatch_assign, *gvar[4], BPatch_arithExpr(BPatch_ref, *((*fields)[2]), BPatch_constExpr(0))); appAddrSpace->insertSnippet(assignment3, *point28); // globalVariable28 = globalVariable28.field3[5] BPatch_arithExpr assignment4(BPatch_assign, *gvar[5], BPatch_arithExpr(BPatch_ref, *((*fields)[2]), BPatch_constExpr(5))); appAddrSpace->insertSnippet(assignment4, *point28); BPatch_Vector<BPatch_variableExpr *> *subfields = (*fields)[3]->getComponents(); assert(subfields != NULL); // globalVariable28 = globalVariable28.field4.field1 BPatch_arithExpr assignment5(BPatch_assign, *gvar[6], *((*subfields)[0])); appAddrSpace->insertSnippet(assignment5, *point28); // globalVariable28 = globalVariable28.field4.field2 BPatch_arithExpr assignment6(BPatch_assign, *gvar[7], *((*subfields)[1])); appAddrSpace->insertSnippet(assignment6, *point28); // BPatch_Vector<BPatch_variableExpr *> *unionfields = globalVariable28_8->getComponents(); int n=1; int val1, val2, val3; ((*unionfields)[0])->writeValue(&n,true); ((*unionfields)[0])->readValue(&val1); if (val1 != 1) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" union field1 has wrong value after first set\n"); return FAILED; } n=2; ((*unionfields)[1])->writeValue(&n,true); ((*unionfields)[1])->readValue(&val2); if (val2 != 2) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" union field2 has wrong value after second set\n"); return FAILED; } ((*unionfields)[1])->readValue(&val3); if (val3 != 2) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" union field1 has wrong value after second set\n"); return FAILED; } // create a scalar BPatch_type *newScalar1 = BPatch::bpatch->createScalar("scalar1", 8); assert(newScalar1); int scalarSize = newScalar1->getSize(); if (scalarSize != 8) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" created scalar is %d bytes, expected %d\n", scalarSize, 8); return FAILED; } // create an enum BPatch_Vector<char *> enumItems; BPatch_Vector<int> enumVals; enumItems.push_back(const_cast<char*>("item1")); enumItems.push_back(const_cast<char*>("item2")); enumItems.push_back(const_cast<char*>("item3")); enumVals.push_back(42); enumVals.push_back(43); enumVals.push_back(44); BPatch_type *newEnum1 = BPatch::bpatch->createEnum("enum1", enumItems); BPatch_type *newEnum2 = BPatch::bpatch->createEnum("enum2", enumItems, enumVals); if (!newEnum1 || !newEnum2) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" failed to create enums as expected\n"); return FAILED; } if (!newEnum1->isCompatible(newEnum1)) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" identical enums reported incompatible\n"); return FAILED; } if (newEnum1->isCompatible(newEnum2)) { logerror("**Failed** test #28 (user defined fields)\n"); logerror(" different enums declared compatible\n"); return FAILED; } return PASSED; }