Пример #1
0
static void exitFunc(BPatch_thread *thread, BPatch_exitType exit_type)
{
  dprintf("exitFunc called\n");
    // Read out the values of the variables.
  if(thread->getProcess()->terminationStatus() != exit_type) 
  {
    passedTest = false;
    return;
    
  }
  int exitCode = thread->getProcess()->getExitCode();
  int expectedExitCode = thread->getProcess()->getPid();
#if !defined(os_windows_test)
  expectedExitCode &= 0xFF;
#endif
  
  // Read out the values of the variables.
  if (exit_type == ExitedNormally) {
    if(expectedExitCode == exitCode) {
      if (verifyChildMemory(thread->getProcess(), "test4_1_global1", 1000001)) {
	logerror("Passed test #1 (exit callback)\n");
	passedTest = true;
      } else {
	logerror("**Failed** test #1 (exit callback)\n");
	logerror("    verifyChildMemory failed\n");
	passedTest = false;
      }
    } else {
      logerror("**Failed** test #1 (exit callback)\n");
      logerror("    exit code = %d, was not equal to expected %d\n", exitCode, 
	       expectedExitCode);
      passedTest = false;
    }
  } else if (exit_type == ExitedViaSignal) {
    logerror("**Failed** test #1 (exit callback), exited via signal %d\n",
	     thread->getProcess()->getExitSignal());
    passedTest = false;
  } else assert(false);
}
Пример #2
0
void exitFunc(BPatch_thread *thread, BPatch_exitType exit_type)
{
  dprintf("exitFunc called\n");
    // Read out the values of the variables.
    int exitCode = thread->getExitCode();

    assert(thread->terminationStatus() == exit_type);
    // Read out the values of the variables.
    if (inTest == 1) {
        if (exit_type == ExitedNormally) {
            if(thread->getPid() == exitCode) {
                if (verifyChildMemory(thread, "globalVariable1_1", 1000001)) {
                    printf("Passed test #1 (exit callback)\n");
                    passedTest[1] = true;
                } else {
                    printf("**Failed** test #1 (exit callback)\n");
                    printf("    verifyChildMemory failed\n");
                    passedTest[1] = false;
                }
            } else {
                printf("**Failed** test #1 (exit callback)\n");
                printf("    exit code = %d, was not equal to pid\n", exitCode);
                passedTest[1] = false;
            }
        } else if (exit_type == ExitedViaSignal) {
           printf("**Failed** test #1 (exit callback), exited via signal %d\n",
                   thread->getExitSignal());
            passedTest[1] = false;
        } else assert(false);
    } else if (inTest == 2) {
        static int exited = 0;
        exited++;
        if(exit_type == ExitedViaSignal) {
            printf("Failed test #2 (fork callback)\n");
            printf("    a process terminated via signal %d\n",
                   thread->getExitSignal());
            exited = 0;            
        } else if (thread->getPid() != exitCode) {
            printf("Failed test #2 (fork callback)\n");
            printf("    exit code was not equal to pid (%d != %d)\n", thread->getPid(), exitCode);            
            exited = 0;
        } else {
            dprintf("test #2, pid %d exited\n", exitCode);
            if ((test2Parent == thread) &&
                !verifyChildMemory(test2Parent, "globalVariable2_1", 2000002)) {
                failedTest[2] = true;
            }
            if ((test2Child == thread) &&
                !verifyChildMemory(test2Child, "globalVariable2_1", 2000003)) {
                failedTest[2] = true;
            }
            
            // See if all the processes are done
            if (exited == 2) {
                if (!failedTest[2]) {
                    printf("Passed test #2 (fork callback)\n");
                    passedTest[2] = true;
                } else {
                    printf("Failed test #2 (fork callback)\n");
                }
            }
        }
    } else if (inTest == 3) {
        // simple exec 
        if(exit_type == ExitedViaSignal) {
            printf("Failed test #3 (exec callback), exited via signal %d\n",
                   thread->getExitSignal());
        } else if (!verifyChildMemory(thread, "globalVariable3_1", 3000002)) {
            printf("Failed test #3 (exec callback)\n");
        } else {
            printf("Passed test #3 (exec callback)\n");
            passedTest[3] = true;
        }
    } else if (inTest == 4) {
        static int exited = 0;
        exited++;
        if (exit_type == ExitedViaSignal) {
            printf("Failed test #4 (fork callback)\n");
            printf("    process exited via signal %d\n",
                   thread->getExitSignal());
            failedTest[4] = true;            
        } else if (thread->getPid() != exitCode) {
            printf("Failed test #4 (fork callback)\n");
            printf("    exit code was not equal to pid\n");
            failedTest[4] = true;
        } else if (test4Parent == thread) {
            dprintf("test #4, pid %d exited\n", exitCode);
            if (!verifyChildMemory(test4Parent,"globalVariable4_1",4000002)){
                failedTest[4] = true;
            }
        } else if (test4Child == thread) {
            dprintf("test #4, pid %d exited\n", exitCode);
            if (!verifyChildMemory(test4Child, "globalVariable4_1", 4000003)) {
                failedTest[4] = true;
            }
        } else {
            // exit from unknown thread
            printf("Failed test #4 (fork callback)\n");
            printf("    exit from unknown pid = %d\n", exitCode);
            failedTest[4] = true;
        }
        // See if all the processes are done
        if (exited == 2) {
            if (!failedTest[4]) {
                printf("Passed test #4 (fork & exec)\n");
                passedTest[4] = true;
            } else {
                printf("Failed test #4 (fork & exec)\n");
            }
        }
    } else {
        printf("**Exit from unknown test case**\n");
    }
}