示例#1
0
test_results_t test1_8_Mutator::executeTest() 
{
	// Find the entry point to the procedure "test1_8_func1"
	const char *funcName = "test1_8_func1";
	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 *> *point8_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point8_1 || ((*point8_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect8_1;
	const char *globalVar = "test1_8_globalVariable1";
	BPatch_variableExpr *expr8_1 = findVariable(appImage, globalVar,
			point8_1);

	if (!expr8_1) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to locate variable %s\n", globalVar);
		return FAILED;
	}

	BPatch_arithExpr arith8_1 (BPatch_assign, *expr8_1, 
			BPatch_arithExpr(BPatch_plus, 
				BPatch_arithExpr(BPatch_plus, 
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(81), 
						BPatch_constExpr(82)),
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(83), 
						BPatch_constExpr(84))),
				BPatch_arithExpr(BPatch_plus, 
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(85), 
						BPatch_constExpr(86)),
					BPatch_arithExpr(BPatch_plus, BPatch_constExpr(87), 
						BPatch_constExpr(88)))));
	vect8_1.push_back(&arith8_1);

	checkCost(BPatch_sequence(vect8_1));
	if(!appAddrSpace->insertSnippet( BPatch_sequence(vect8_1), *point8_1))
        return FAILED;

	return PASSED;
}
task main()
{
	long red,green,blue;
	float jarakSementara = 0;
	// sensor sees light:
	resetTimer(timer1);
	int costWarna;
  while(true)
  {
		printLayar(red,green,blue);
		getColorRGB(colorSensor,red,green,blue);
		if(red < 20 && green < 20 && blue < 20)
    {
      // counter-steer left:
      motor[leftMotor]  = 25;
      motor[rightMotor] = 15;
    }
    // sensor sees dark:
    else if (red > 70 && green > 70 && blue > 70)
    {
    	//counter right
    	motor[leftMotor]  = 5;
      motor[rightMotor] = 25;
    }
    //sensor sees light
    else
    {
    	//go straight
      motor[leftMotor]  = 20;
      motor[rightMotor] = 20;
      sleep(200);
    	costWarna = checkCost(red,green,blue);
    	if (costWarna == 100) //intersection green
    	{
    		motor[leftMotor]  = 0;
      	motor[rightMotor] = 0;
      	sleep(1000);
      	displayTextLine(7,"detected intersection");
      } else if (costWarna == 101) //intersection green
    	{
    		turnLeft();
    		turnLeft();
      	sleep(1000);
      	displayTextLine(7,"detected stop turn around");
      }
      displayTextLine(6,"costWarna = %d",costWarna);


    }

    jarakSementara = getTimer(timer1, seconds);

    printJarak(jarakSementara);
  }
}
示例#3
0
文件: skills.cpp 项目: lordcirth/RPG
skillReturnType Skill::canCast(Creature &caster) {
    if (checkCost(caster) == false) {
        return SKILL_FAIL_COST;
    }
    else if (isUnlocked() == false) {
        return SKILL_NOT_UNLOCKED;
    }
    else {
        return SKILL_SUCCESS;
    }
}
示例#4
0
//
// Start Test Case #1 - (zero arg function call)
//
test_results_t test1_1_Mutator::executeTest() {
  const char *funcName = "test1_1_func1_1";
  const char* testName = "zero arg function call";
  int testNo = 1;

  // Find the entry point to the procedure "func1_1"
  
  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 *> *point1_1 = found_funcs[0]->findPoint(BPatch_entry);


  if (!point1_1 || ((*point1_1).size() == 0)) {
    logerror("**Failed** test #%d (%s)\n", testNo,testName);
    logerror("    Unable to find entry point to \"%s.\"\n", funcName);
    return FAILED;
  }

  BPatch_Vector<BPatch_function *> bpfv;
  const char *fn = "test1_1_call1_1";
  if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror("**Failed** test #%d (%s)\n", testNo, testName);
    logerror("    Unable to find function %s\n", fn);
    return FAILED;
  }
  BPatch_function *call1_func = bpfv[0];
  
  BPatch_Vector<BPatch_snippet *> call1_args;
  BPatch_funcCallExpr call1Expr(*call1_func, call1_args);

  checkCost(call1Expr);

  if(!appAddrSpace->insertSnippet(call1Expr, *point1_1))
      return FAILED;

  dprintf("Inserted snippet\n");

  return PASSED;
} // test1_1_Mutator::executeTest()
示例#5
0
test_results_t test1_5_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func5_2"
	const char *funcName = "test1_5_func2";

	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 *> *point5_1 = found_funcs[0]->findPoint(BPatch_entry);  

	if (!point5_1 || ((*point5_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	const char *funcName2 = "test1_5_func1";
	BPatch_Vector<BPatch_function *> found_funcs2;

	if ((NULL == appImage->findFunction(funcName2, found_funcs2))
			|| !found_funcs2.size()) 
	{
		logerror("    Unable to find function %s\n", funcName2);
		return FAILED;
	}

	if (1 < found_funcs2.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs2.size(), funcName2);
	}

	BPatch_Vector<BPatch_point *> *point5_2 = found_funcs2[0]->findPoint(BPatch_subroutine);  

	if (!point5_2 || ((*point5_2).size() == 0)) 
	{
		logerror("Unable to find subroutine call points in \"%s\".\n", funcName2);
		return FAILED;
	}

	const char *globalVar1 = "test1_5_globalVariable5_1";
	const char *globalVar2 = "test1_5_globalVariable5_2";
	BPatch_variableExpr *expr5_1 = findVariable (appImage, globalVar1, point5_1);
	BPatch_variableExpr *expr5_2 = findVariable (appImage, globalVar2, point5_1);

	if (!expr5_1 || !expr5_2) 
	{
		logerror("**Failed** test #5 (1f w.o. else)\n");
		logerror("    Unable to locate variable %s or ", globalVar1);
		logerror("    variable %s\n", globalVar2);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect5_1;

	// if (0 == 1) globalVariable5_1 = 52;
	BPatch_ifExpr expr5_3(BPatch_boolExpr(BPatch_eq, BPatch_constExpr(0),
				BPatch_constExpr(1)), 
			BPatch_arithExpr(BPatch_assign, *expr5_1,
				BPatch_constExpr(52)));

	// if (1 == 1) globalVariable5_2 = 53;
	BPatch_ifExpr expr5_4(BPatch_boolExpr(BPatch_eq, BPatch_constExpr(1),
				BPatch_constExpr(1)), 
			BPatch_arithExpr(BPatch_assign, *expr5_2,
				BPatch_constExpr(53)));

	vect5_1.push_back(&expr5_3);
	vect5_1.push_back(&expr5_4);

	BPatch_sequence expr5_5(vect5_1);
	checkCost(expr5_5);
	appAddrSpace->insertSnippet(expr5_5, *point5_1);

	return PASSED;
}
示例#6
0
//
// Start Test Case #3 - (overload operator)
//      
// static int mutatorTest(BPatch_thread *appThread, BPatch_image *appImage)
test_results_t test5_3_Mutator::executeTest() {

  BPatch_Vector<BPatch_function *> bpfv;
  const char *fn = "overload_op_test::func_cpp";
  if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror("**Failed** test #3 (overloaded operation)\n");
    logerror("    Unable to find function %s\n", fn);
    return FAILED;
  }
  BPatch_function *f1 = bpfv[0];  
  BPatch_Vector<BPatch_point *> *point3_1 = f1->findPoint(BPatch_subroutine);

  assert(point3_1);
  if (point3_1->size() == 0) {
    logerror("**Failed test5_3 (overload operation)\n");
    logerror("    Can't find overloaded operator call points\n");
    return FAILED;
  }

  unsigned int index = 0;
  char fn3[256];
  BPatch_function *func;
  while (index < point3_1->size()) {
     if ((func = (*point3_1)[index]->getCalledFunction()) != NULL &&
         !strcmp("overload_op_test::operator++", func->getName(fn3, 256)))
     {
        break;
     }
     index ++;
  }
  if(!func) {
    logerror("**Failed** test #3 (overload operation)\n");
    logerror("    Can't find the overload operator\n");
    return FAILED;
  }

  if (0 != strcmp("overload_op_test::operator++", func->getName(fn3, 256))) {
    logerror("**Failed** test #3 (overload operation)\n");
    logerror("    Can't find the overloaded operator\n");
    return FAILED;
  }
  // FIXME It caught fprintf...

  BPatch_Vector<BPatch_point *> *point3_2 = func->findPoint(BPatch_exit);
  assert(point3_2);
  
  bpfv.clear();
  const char *fn2 = "overload_op_test::call_cpp";
  if (NULL == appImage->findFunction(fn2, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror("**Failed** test #3 (overloaded operation)\n");
    logerror("    Unable to find function %s\n", fn2);
    return FAILED;
  }
  BPatch_function *call3_1 = bpfv[0];  
  
  BPatch_variableExpr *this2 = appImage->findVariable("test5_3_test3");
  if (this2 == NULL) {
    logerror( "**Failed** test #3 (overloaded operation)\n");
    logerror( "Unable to find variable \"test5_3_test3\"\n");
    return FAILED;
  }

  BPatch_Vector<BPatch_snippet *> opArgs;
  BPatch_arithExpr expr2_0(BPatch_addr, *this2);
  opArgs.push_back(&expr2_0);
  opArgs.push_back(new BPatch_retExpr());
  BPatch_funcCallExpr call3_1Expr(*call3_1, opArgs);
  
  checkCost(call3_1Expr);
  appAddrSpace->insertSnippet(call3_1Expr, *point3_2);
  //  int tag = 1;
  //  while (tag != 0) {}
  
  return PASSED;
}
示例#7
0
test_results_t test1_36_Mutator::executeTest() 
{
	const char *funcName = "test1_36_func1";
	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 *> *all_points36_1 =
		found_funcs[0]->findPoint(BPatch_subroutine);

	if (!all_points36_1 || (all_points36_1->size() < 1)) 
	{
		logerror("Unable to find point %s - subroutines.\n", funcName);
		return FAILED;
	}

	const char *funcName2 = "test1_36_call1";
	BPatch_point *point36_1 = NULL;

	for (unsigned i=0; i<(*all_points36_1).size(); i++) 
	{
		BPatch_point *cur_point = (*all_points36_1)[i];
		if (cur_point == NULL) 
			continue;

		BPatch_function *func = cur_point->getCalledFunction();
		char funcname[100];

		if (!func) 
			continue;

		if (func->getName(funcname, 99)) 
		{
			if (strstr(funcname, funcName2))
				point36_1 = cur_point;
		}
	}

	if (point36_1 == NULL) 
	{
		logerror("Unable to find callsite %s\n", funcName2);
		return FAILED;
	}

	BPatch_variableExpr *expr36_1 = findVariable(appImage,
			"test1_36_globalVariable1", 
			all_points36_1);
	BPatch_variableExpr *expr36_2 = findVariable(appImage,
			"test1_36_globalVariable2", 
			all_points36_1);
	BPatch_variableExpr *expr36_3 = findVariable(appImage,
			"test1_36_globalVariable3", 
			all_points36_1);
	BPatch_variableExpr *expr36_4 = findVariable(appImage,
			"test1_36_globalVariable4", 
			all_points36_1);
	BPatch_variableExpr *expr36_5 = findVariable(appImage,
			"test1_36_globalVariable5", 
			all_points36_1);
	BPatch_variableExpr *expr36_6 = findVariable(appImage,
			"test1_36_globalVariable6", 
			all_points36_1);
	BPatch_variableExpr *expr36_7 = findVariable(appImage,
			"test1_36_globalVariable7", 
			all_points36_1);
	BPatch_variableExpr *expr36_8 = findVariable(appImage,
			"test1_36_globalVariable8", 
			all_points36_1);
	BPatch_variableExpr *expr36_9 = findVariable(appImage,
			"test1_36_globalVariable9", 
			all_points36_1);
	BPatch_variableExpr *expr36_10 = findVariable(appImage,
			"test1_36_globalVariable10", 
			all_points36_1);

	if (expr36_1 == NULL || expr36_2 == NULL || expr36_3 == NULL ||
			expr36_4 == NULL || expr36_5 == NULL || expr36_6 == NULL ||
			expr36_7 == NULL || expr36_8 == NULL || expr36_9 == NULL ||
			expr36_10 == NULL)
	{
		logerror("**Failed** test #36 (callsite parameter referencing)\n");
		logerror("    Unable to locate at least one of "
				"test1_36_globalVariable{1...10}\n");
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet *> snippet_seq;
	snippet_seq.push_back(makeTest36paramExpr(expr36_1, 0));
	snippet_seq.push_back(makeTest36paramExpr(expr36_2, 1));
	snippet_seq.push_back(makeTest36paramExpr(expr36_3, 2));
	snippet_seq.push_back(makeTest36paramExpr(expr36_4, 3));
	snippet_seq.push_back(makeTest36paramExpr(expr36_5, 4));
	snippet_seq.push_back(makeTest36paramExpr(expr36_6, 5));
	snippet_seq.push_back(makeTest36paramExpr(expr36_7, 6));
	snippet_seq.push_back(makeTest36paramExpr(expr36_8, 7));
	snippet_seq.push_back(makeTest36paramExpr(expr36_9, 8));
	snippet_seq.push_back(makeTest36paramExpr(expr36_10, 9));
	
    BPatch_sequence seqExpr(snippet_seq);

	checkCost(seqExpr);
	appAddrSpace->insertSnippet(seqExpr, *point36_1);

	return PASSED;
}
示例#8
0
test_results_t test1_19_Mutator::executeTest() 
{
    // Avoid a race condition in fast & loose mode

    while (!appProc->isStopped())
	{
		BPatch::bpatch->waitForStatusChange();
    }

    appProc->continueExecution();

    if (waitUntilStopped(BPatch::bpatch, appProc, 19, "oneTimeCode") < 0)
	{
      return FAILED;
    }

    BPatch_Vector<BPatch_function *> bpfv;
    const char *fn = "test1_19_call1";

    if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
	|| NULL == bpfv[0])
	{
      logerror("    Unable to find function %s\n", fn);
      return FAILED;
    }

    BPatch_function *call19_1_func = bpfv[0];

    BPatch_Vector<BPatch_snippet *> nullArgs;
    BPatch_funcCallExpr call19_1Expr(*call19_1_func, nullArgs);
    checkCost(call19_1Expr);

    appProc->oneTimeCode(call19_1Expr);

    // Let the mutatee run to check the result
    appProc->continueExecution();

    // Wait for the next test

    if (waitUntilStopped(BPatch::bpatch, appProc, 19, "oneTimeCode") < 0)
	{
      return FAILED;
    }

    bpfv.clear();
    const char *fn2 = "test1_19_call2";

    if (NULL == appImage->findFunction(fn2, bpfv) || !bpfv.size()
	|| NULL == bpfv[0])
	{
      logerror("    Unable to find function %s\n", fn2);
      return FAILED;
    }

    BPatch_function *call19_2_func = bpfv[0];

    BPatch_funcCallExpr call19_2Expr(*call19_2_func, nullArgs);
    checkCost(call19_2Expr);

    int callbackFlag = 0;

    // Register a callback that will set the flag callbackFlag
    BPatchOneTimeCodeCallback oldCallback = 
       BPatch::bpatch->registerOneTimeCodeCallback(test19_oneTimeCodeCallback);

    appProc->oneTimeCodeAsync(call19_2Expr, (void *)&callbackFlag);

    while (!appProc->isTerminated() && !appProc->isStopped() )
    {
		BPatch::bpatch->waitForStatusChange();
    }
    
    // Continue mutatee after one-time code runs
    appProc->continueExecution();

    // Wait for the callback to be called
    while (!appProc->isTerminated() && !callbackFlag) {
        if( !BPatch::bpatch->waitForStatusChange() ) {
            logerror("   FAILED: could not wait for callback to be called\n");
            return FAILED;
        }
    }

    if( !callbackFlag ) {
        logerror("     FAILED: process %d terminated while waiting for async oneTimeCode\n",
                appProc->getPid());
        return FAILED;
    }

    // After the oneTimeCode is completed, there could be a crash due to bugs in
    // the RPC code, wait for termination
    while( !appProc->isTerminated() ) {
        if( !BPatch::bpatch->waitForStatusChange() ) {
            logerror("   FAILED: could not wait for process to terminate\n");
            return FAILED;
        }
    }

    // Restore old callback (if there was one)
	BPatch::bpatch->registerOneTimeCodeCallback(oldCallback);

    return PASSED;
} // test1_19_Mutator::executeTest()
示例#9
0
test_results_t test1_3_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func3_1"
	const char *funcName = "test1_3_func3_1";

	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 *> *point3_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point3_1 || ((*point3_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s.\"\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_function *> bpfv;
	const char *fn = "test1_3_call3_1";

	if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
			|| NULL == bpfv[0])
	{
		logerror("    Unable to find function %s\n", fn);
		return FAILED;
	}

	if (1 < bpfv.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, bpfv.size(), fn);
	}

	BPatch_function *call3_func = bpfv[0];

	BPatch_Vector<BPatch_snippet *> call3_args;

	BPatch_Vector<BPatch_point *> *call3_1 = call3_func->findPoint(BPatch_subroutine);

	if (!call3_1 || ((*call3_1).size() == 0)) 
	{
		logerror("    Unable to find subroutine calls in \"call3_1.\"\n");
		return FAILED;
	}

	const char *globalVar = "test1_3_globalVariable3_1";

	BPatch_variableExpr *expr3_1 = findVariable(appImage, globalVar, call3_1);

	if (!expr3_1) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to locate variable %s\n", globalVar);
		return FAILED;
	}

	// see if we can find the address
	if (expr3_1->getBaseAddr() <= 0) 
	{
		logerror("*Error*: address %p for %s is not valid\n",
				expr3_1->getBaseAddr(), globalVar);
	}

	BPatch_variableExpr *expr3_2 = appAddrSpace->malloc(*appImage->findType("int"));

	if (!expr3_2) 
	{
		logerror("**Failed** test #3 (passing variables)\n");
		logerror("    Unable to create new int variable\n");
		return FAILED;
	}

	BPatch_constExpr expr3_3 (expr3_1->getBaseAddr ());
	BPatch_constExpr expr3_4 (expr3_2->getBaseAddr ());

	int mutateeFortran = isMutateeFortran(appImage);

	if (mutateeFortran) 
	{
		call3_args.push_back (&expr3_3);
		call3_args.push_back (&expr3_4);
	} 
	else 
	{
		call3_args.push_back(expr3_1);
		call3_args.push_back(expr3_2);
	}

	BPatch_funcCallExpr call3Expr(*call3_func, call3_args);
	checkCost(call3Expr);
	appAddrSpace->insertSnippet(call3Expr, *point3_1);

	BPatch_arithExpr expr3_5(BPatch_assign, *expr3_2, BPatch_constExpr(32));
	checkCost(expr3_5);
	appAddrSpace->insertSnippet(expr3_5, *point3_1);

	dprintf("Inserted snippet3\n");

	return PASSED;
}
示例#10
0
test_results_t test1_9_Mutator::executeTest() 
{
	// Find the entry point to the procedure "test1_9_func1"
	const char *funcName = "test1_9_func1";
	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 *> *point9_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point9_1 || ((*point9_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_function *> bpfv;
	const char *fn = "test1_9_call1";
	if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
			|| NULL == bpfv[0])
	{
		logerror("    Unable to find function %s\n", fn);
		return FAILED;
	}

	BPatch_function *call9_func = bpfv[0];

	BPatch_Vector<BPatch_snippet *> call9_args;

	BPatch_variableExpr *expr9_1 = appAddrSpace->malloc (*appImage->findType ("int"));
	BPatch_constExpr constExpr9_1 (0);
	BPatch_arithExpr arithexpr9_1 (BPatch_assign, *expr9_1, BPatch_constExpr (91));
	appAddrSpace->insertSnippet (arithexpr9_1, *point9_1);

	int mutateeFortran = isMutateeFortran(appImage);

	if (mutateeFortran) 
	{
		constExpr9_1 = expr9_1->getBaseAddr ();
	} 
	else 
	{
		constExpr9_1 = 91;
	}

	call9_args.push_back(&constExpr9_1);

	BPatch_variableExpr *expr9_2 = appAddrSpace->malloc (*appImage->findType ("int"));
	BPatch_constExpr constExpr9_2 (0);
	BPatch_arithExpr arithexpr9_2 (BPatch_assign, *expr9_2, BPatch_constExpr (92));
	appAddrSpace->insertSnippet (arithexpr9_2, *point9_1);

	if (mutateeFortran) 
	{
		constExpr9_2 = expr9_2->getBaseAddr ();
	} 
	else 
	{
		constExpr9_2 = 92;
	}

	call9_args.push_back(&constExpr9_2);

	BPatch_variableExpr *expr9_3 = appAddrSpace->malloc (*appImage->findType ("int"));
	BPatch_constExpr constExpr9_3 (0);
	BPatch_arithExpr arithexpr9_3 (BPatch_assign, *expr9_3, BPatch_constExpr (93));
	appAddrSpace->insertSnippet (arithexpr9_3, *point9_1);

	if (mutateeFortran) 
	{
		constExpr9_3 = expr9_3->getBaseAddr ();
	} 
	else 
	{
		constExpr9_3 = 93;
	}

	call9_args.push_back(&constExpr9_3);

	BPatch_variableExpr *expr9_4 = appAddrSpace->malloc (*appImage->findType ("int"));
	BPatch_constExpr constExpr9_4 (0);
	BPatch_arithExpr arithexpr9_4 (BPatch_assign, *expr9_4, BPatch_constExpr (94));
	appAddrSpace->insertSnippet (arithexpr9_4, *point9_1);

	if (mutateeFortran) 
	{
		constExpr9_4 = expr9_4->getBaseAddr ();
	} 
	else 
	{
		constExpr9_4 = 94;
	}

	call9_args.push_back(&constExpr9_4);

	BPatch_variableExpr *expr9_5 = appAddrSpace->malloc (*appImage->findType ("int"));
	BPatch_constExpr constExpr9_5 (0);
	BPatch_arithExpr arithexpr9_5 (BPatch_assign, *expr9_5, BPatch_constExpr (95));
	appAddrSpace->insertSnippet (arithexpr9_5, *point9_1);

	if (mutateeFortran) 
	{
		constExpr9_5 = expr9_5->getBaseAddr ();
	} 
	else 
	{
		constExpr9_5 = 95;
	}

	call9_args.push_back(&constExpr9_5);

	BPatch_funcCallExpr call9Expr(*call9_func, call9_args);

	checkCost(call9Expr);
	appAddrSpace->insertSnippet(call9Expr, *point9_1, BPatch_callBefore, BPatch_lastSnippet);

	return PASSED;
}
示例#11
0
test_results_t test1_7_Mutator::executeTest() 
{
	// Find the entry point to the procedure "func7_2"
	const char *funcName = "test1_7_func2";
	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 *> *point7_1 = found_funcs[0]->findPoint(BPatch_entry);

	if (!point7_1 || ((*point7_1).size() == 0)) 
	{
		logerror("Unable to find entry point to \"%s\".\n", funcName);
		return FAILED;
	}

	BPatch_Vector<BPatch_snippet*> vect7_1;

	if ( genRelTest(appImage, vect7_1, BPatch_lt, 0, 1,
				"test1_7_globalVariable1") < 0)
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_lt, 1, 0,
				"test1_7_globalVariable2") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_eq, 2, 2,
				"test1_7_globalVariable3") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_eq, 2, 3,
				"test1_7_globalVariable4") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_gt, 4, 3,
				"test1_7_globalVariable5") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_gt, 3, 4,
				"test1_7_globalVariable6") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_le, 3, 4,
				"test1_7_globalVariable7") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_le, 4, 3,
				"test1_7_globalVariable8") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ne, 5, 6,
				"test1_7_globalVariable9") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ne, 5, 5,
				"test1_7_globalVariable10") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ge, 9, 7,
				"test1_7_globalVariable11") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_ge, 7, 9,
				"test1_7_globalVariable12") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_and, 1, 1,
				"test1_7_globalVariable13") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_and, 1, 0,
				"test1_7_globalVariable14") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_or, 1, 0,
				"test1_7_globalVariable15") < 0 )
		return FAILED;
	if ( genRelTest(appImage, vect7_1, BPatch_or, 0, 0,
				"test1_7_globalVariable16") < 0 )
		return FAILED;

	const char *funcName2 = "test1_7_func2";
	BPatch_Vector<BPatch_function *> found_funcs2;

	if ((NULL == appImage->findFunction(funcName2, found_funcs2))
			|| !found_funcs2.size()) 
	{
		logerror("    Unable to find function %s\n", funcName2);
		return FAILED;
	}

	if (1 < found_funcs2.size()) 
	{
		logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
				__FILE__, __LINE__, found_funcs2.size(), funcName2);
	}

	BPatch_Vector<BPatch_point *> *func7_1 = found_funcs2[0]->findPoint(BPatch_entry);

	if (!func7_1 || ((*func7_1).size() == 0)) 
	{
		logerror("Unable to find entry points in \"%s\".\n", funcName2);
		return FAILED;
	}

	BPatch_variableExpr *constVar0, *constVar1, *constVar2, *constVar3, *constVar4, 
						*constVar5, *constVar6, *constVar7, *constVar9;

	constVar0 = findVariable(appImage, "test1_7_constVar0", func7_1);
	constVar1 = findVariable(appImage, "test1_7_constVar1", func7_1);
	constVar2 = findVariable(appImage, "test1_7_constVar2", func7_1);
	constVar3 = findVariable(appImage, "test1_7_constVar3", func7_1);
	constVar4 = findVariable(appImage, "test1_7_constVar4", func7_1);
	constVar5 = findVariable(appImage, "test1_7_constVar5", func7_1);
	constVar6 = findVariable(appImage, "test1_7_constVar6", func7_1);
	constVar7 = findVariable(appImage, "test1_7_constVar7", func7_1);
	constVar9 = findVariable(appImage, "test1_7_constVar9", func7_1);

	if (!constVar0 || !constVar1 || !constVar2 || !constVar3 || !constVar4 ||
			!constVar5 || !constVar6 || !constVar7 || !constVar9 ) 
	{
		logerror("**Failed** test #7 (relational operators)\n");
		logerror("    Unable to locate one of test1_7_constVar?\n");
		return FAILED;
	}

	if ( genVRelTest(appImage, vect7_1, BPatch_lt, constVar0, constVar1,
				"test1_7_globalVariable1a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_lt, constVar1, constVar0,
				"test1_7_globalVariable2a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_eq, constVar2, constVar2,
				"test1_7_globalVariable3a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_eq, constVar2, constVar3,
				"test1_7_globalVariable4a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_gt, constVar4, constVar3,
				"test1_7_globalVariable5a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_gt, constVar3, constVar4,
				"test1_7_globalVariable6a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_le, constVar3, constVar4,
				"test1_7_globalVariable7a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_le, constVar4, constVar3,
				"test1_7_globalVariable8a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ne, constVar5, constVar6,
				"test1_7_globalVariable9a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ne, constVar5, constVar5,
				"test1_7_globalVariable10a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ge, constVar9, constVar7,
				"test1_7_globalVariable11a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_ge, constVar7, constVar9,
				"test1_7_globalVariable12a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_and, constVar1, constVar1,
				"test1_7_globalVariable13a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_and, constVar1, constVar0,
				"test1_7_globalVariable14a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_or, constVar1, constVar0,
				"test1_7_globalVariable15a") < 0 )
		return FAILED;
	if ( genVRelTest(appImage, vect7_1, BPatch_or, constVar0, constVar0,
				"test1_7_globalVariable16a") < 0 )
		return FAILED;

	dprintf("relops test vector length is %d\n", vect7_1.size());

	checkCost(BPatch_sequence(vect7_1));
	if(!appAddrSpace->insertSnippet( BPatch_sequence(vect7_1), *point7_1))
        return FAILED;

	return PASSED;
}
示例#12
0
//
// Start Test Case #8 - (declaration)
//   
test_results_t test5_8_Mutator::executeTest() {
  // Find the exit point to the procedure "func_cpp"
  BPatch_Vector<BPatch_function *> bpfv;
  const char *fn = "decl_test::func_cpp";
  if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror( "**Failed** test #8 (declaration)\n");
    logerror( "    Unable to find function %s\n", fn);
    return FAILED;
  }
  BPatch_function *f1 = bpfv[0];  
  BPatch_Vector<BPatch_point *> *point8_1 = f1->findPoint(BPatch_exit);
  if (!point8_1 || (point8_1->size() < 1)) {
    logerror( "Unable to find point decl_test::func_cpp - exit.\n");
    return FAILED;
  }

  bpfv.clear();
  const char *fn2 = "main";
  if (NULL == appImage->findFunction(fn2, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror( "**Failed** test #8 (declaration)\n");
    logerror( "    Unable to find function %s\n", fn2);
    return FAILED;
  }
  BPatch_function *f2 = bpfv[0];  
  BPatch_Vector<BPatch_point *> *point8_2 = f2->findPoint(BPatch_allLocations);
  if (!point8_2 || (point8_2->size() < 1)) {
    logerror( "Unable to find point in main.\n");
    return FAILED;
  }

  bpfv.clear();
  const char *fn3 = "decl_test::call_cpp";
  if (NULL == appImage->findFunction(fn3, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror( "**Failed** test #8 (declaration)\n");
    logerror( "    Unable to find function %s\n", fn3);
    return FAILED;
  }
  BPatch_function *call8_func = bpfv[0];  

  BPatch_variableExpr *this8 = appImage->findVariable("test5_8_test8");
  if (this8 == NULL) {
    logerror( "**Failed** test #8 (declaration)\n");
    logerror( "Unable to find variable \"test5_8_test8\"\n");
    return FAILED;
  }

  BPatch_Vector<BPatch_snippet *> call8_args;
  BPatch_arithExpr expr8_0(BPatch_addr, *this8);
  call8_args.push_back(&expr8_0);
  BPatch_constExpr expr8_1(8);
  call8_args.push_back(&expr8_1);
  BPatch_funcCallExpr call8Expr(*call8_func, call8_args);

  // find the variables of different scopes
  // What *exactly* are we testing here?  Just finding variables of various
  // types with different point parameters to findVariable()?
  BPatch_variableExpr *expr8_2=appImage->findVariable("CPP_DEFLT_ARG");
  BPatch_variableExpr *expr8_3=appImage->findVariable(*(*point8_2)[0], "test5_8_test8");
  BPatch_variableExpr *expr8_4=appImage->findVariable(*(*point8_1)[0], "CPP_DEFLT_ARG");
  if (!expr8_2 || !expr8_3 || !expr8_4) {
    logerror( "**Failed** test #8 (delcaration)\n");
    logerror( "    Unable to locate one of variables\n");
    return FAILED;
  }

    BPatch_Vector<BPatch_variableExpr *> *fields = expr8_3->getComponents();
    if (!fields || fields->size() == 0 ) {
          logerror( "**Failed** test #8 (declaration)\n");
          logerror( "  struct lacked correct number of elements\n");
          return FAILED;
     }

    unsigned int index = 0;
    while ( index < fields->size() ) {
	char fieldName[100];
	strcpy(fieldName, (*fields)[index]->getName());
       if ( !strcmp("CPP_TEST_UTIL_VAR", (*fields)[index]->getName()) ) {
           dprintf("Inserted snippet2\n");
           checkCost(call8Expr);
	   BPatchSnippetHandle *handle;
           handle = appAddrSpace->insertSnippet(call8Expr, *point8_1);
           return PASSED;
       }
       
       index ++;
    }
    logerror( "**Failed** test #8 (declaration)\n");
    logerror( "    Can't find inherited class member variables\n");
    return FAILED;
}
示例#13
0
//  
// Start Test Case #1 - (C++ argument pass)
//       
// static int mutatorTest(BPatch_thread *appThread, BPatch_image *appImage)
test_results_t test5_1_Mutator::executeTest() {

  BPatch_Vector<BPatch_function *> bpfv;
  const char *fn = "arg_test::call_cpp";
  if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
      || NULL == bpfv[0]){
    logerror("**Failed** test #1\n");
    logerror("    Unable to find function %s\n", fn);
    return FAILED;
  }
  BPatch_function *f1 = bpfv[0];  
  BPatch_Vector<BPatch_point *> *point1_1 = f1->findPoint(BPatch_subroutine);
       
   assert(point1_1);
   assert((*point1_1)[0]);

   // check the paramter passing modes
   BPatch_variableExpr *arg0 = appImage->findVariable(*(*point1_1)[0],
       "reference");
   BPatch_variableExpr *arg1 = appImage->findVariable(*(*point1_1)[0],
       "arg1");
   BPatch_variableExpr *arg2 = appImage->findVariable(*(*point1_1)[0],
       "arg2");
   BPatch_variableExpr *arg3 = appImage->findVariable(*(*point1_1)[0],
       "arg3");
   BPatch_variableExpr *arg4 = appImage->findVariable(*(*point1_1)[0],
       "m");

   if (!arg0 || !arg1 || !arg2 || !arg3 || !arg4) {
      logerror("**Failed** test #1 (argument passing)\n");
      if ( !arg0 )
         logerror("  can't find local variable 'reference'\n");
      if ( !arg1 )
         logerror("  can't find local variable 'arg1'\n");
      if ( !arg2 )
         logerror("  can't find local variable 'arg2'\n");
      if ( !arg3 )
         logerror("  can't find local variable 'arg3'\n");
      if ( !arg4 )
         logerror("  can't find local variable 'm'\n");
      return FAILED;
   }

   BPatch_type *type1_0 = const_cast<BPatch_type *> (arg0->getType());
   BPatch_type *type1_1 = const_cast<BPatch_type *> (arg1->getType());
   BPatch_type *type1_2 = const_cast<BPatch_type *> (arg2->getType());
   BPatch_type *type1_3 = const_cast<BPatch_type *> (arg4->getType());
   assert(type1_0 && type1_1 && type1_2 && type1_3);

   if (!type1_1->isCompatible(type1_3)) {
       logerror("**Failed** test #1 (C++ argument pass)\n");
       logerror("    type1_1 reported as incompatibile with type1_3\n");
       return FAILED;
   }

   if (!type1_2->isCompatible(type1_0)) {
        logerror("**Failed** test #1 (C++ argument pass)\n");
        logerror("    type1_2 reported as incompatibile with type1_0\n");
        return FAILED;
   }

   BPatch_arithExpr expr1_1(BPatch_assign, *arg3, BPatch_constExpr(1));
   checkCost(expr1_1);
   appAddrSpace->insertSnippet(expr1_1, *point1_1);

   // pass a paramter to a class member function
   bpfv.clear();
   const char *fn2 = "arg_test::func_cpp";
   if (NULL == appImage->findFunction(fn2, bpfv) || !bpfv.size()
       || NULL == bpfv[0]){
     logerror("**Failed** test #1 (C++ argument pass)\n");
     logerror("    Unable to find function %s\n", fn2);
     return FAILED;
   }
   BPatch_function *f2 = bpfv[0];  
   BPatch_Vector<BPatch_point *> *point1_2 = f2->findPoint(BPatch_subroutine);

   if (!point1_2 || (point1_2->size() < 1)) {
     logerror("**Failed** test #1 (C++ argument pass)\n");
      logerror("Unable to find point arg_test::func_cpp - exit.\n");
      return FAILED;
   }

   bpfv.clear();
   const char *fn3 = "arg_test::arg_pass";
   if (NULL == appImage->findFunction(fn3, bpfv) || !bpfv.size()
       || NULL == bpfv[0]) {
     logerror("**Failed** test #1 (C++ argument pass)\n");
     logerror("    Unable to find function %s\n", fn3);
     return FAILED;
   }
   BPatch_function *call1_func = bpfv[0];  

   BPatch_variableExpr *this1 = appImage->findVariable("test1");
   if (this1 == NULL) {
      logerror("**Failed** test #1 (C++ argument pass)\n");
      logerror("Unable to find variable \"test1\"\n");
      return FAILED;
   }

   BPatch_Vector<BPatch_snippet *> call1_args;
   BPatch_arithExpr expr1_2(BPatch_addr, *this1);
   call1_args.push_back(&expr1_2);
   BPatch_constExpr expr1_3(1);
   call1_args.push_back(&expr1_3);
   BPatch_funcCallExpr call1Expr(*call1_func, call1_args);

   checkCost(call1Expr);
   appAddrSpace->insertSnippet(call1Expr, *point1_2);
   return PASSED;
}