void testManager()
    {
        OsStatus stat;
        printf("Creating process lock file in dir: %s\n", TEST_DIR);
        OsProcessMgr processManager(TEST_DIR);

        UtlString alias = "MyPing1";

        UtlString appName = "ping";
        UtlString params[10];
        params[0] = "127.0.0.1";
#ifdef _WIN32  //need to do this only on win32, linux already does this by default
        params[1] = "-t";
#endif
    
        OsPath inputFile = ""; //this means it will use standard input
        OsPath MyPing1OutputFile = "testManager1.out";
        OsPath MyPing2OutputFile = "testManager2.out";
        OsPath errFile = "testManager.err";
    
        processManager.setIORedirect(inputFile, MyPing1OutputFile, errFile);
        
        UtlString MyPing1("MyPing1");
        UtlString MyPing2("MyPing2");
        OsPath startupDir = "";

        stat = processManager.startProcess(MyPing1, appName, params, startupDir);
        CPPUNIT_ASSERT_MESSAGE("Started first proccess", stat == OS_SUCCESS);

        CPPUNIT_ASSERT_EQUAL_MESSAGE("Alias state", PROCESS_STARTED, 
            processManager.getAliasState(MyPing1));
        
        processManager.setIORedirect(inputFile, MyPing2OutputFile, errFile);
        stat = processManager.startProcess(MyPing2, appName, params, startupDir);
        CPPUNIT_ASSERT_MESSAGE("Started 2nd proccess", stat == OS_SUCCESS);

        CPPUNIT_ASSERT_EQUAL_MESSAGE("2nd alias state", PROCESS_STARTED, 
            processManager.getAliasState(MyPing2));
        
        //std::cout << "Waiting 2 secs before killing process MyPing1...\n";
        OsTask::delay(2000);
      
        stat = processManager.stopProcess(MyPing1);
        CPPUNIT_ASSERT_MESSAGE("Killed 1st process", stat == OS_SUCCESS);

        //std::cout << "Waiting 2 secs before killing process MyPing2...\n";
        OsTask::delay(2000);
        
        stat = processManager.stopProcess(MyPing2);
        CPPUNIT_ASSERT_MESSAGE("Killed 2nd process", stat == OS_SUCCESS);
    }
Beispiel #2
0
// will check if user input is valid
// if user input has no arguements, default 10 seconds will be used
// if user input has more than 3 arguments or the second argument is
// not a valid integer, then error is printed and program exits
void checkInput(int numArg, char *arg) {
	if (numArg = 1) {
		procesanager(10);
		return;
	}	
	int i;
      	char* end;
      	long val = rtol(arg, &end, 10);  // check the whole argument
      	if (numArg == 2 && !end[0] && val >= 0){
        	processManager(val);
		return;
      	} 
	else {
		printf(ERROR: Usage = a3 or a3 [number >= 0]\n");
		exit(0);
	}	
  	
}