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); }
OsStatus TestProcessMgr() { OsStatus retval = OS_FAILED; OsProcessMgr processManager; //now lets try that with the ProcessMgr 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 = "MyPing1Out.txt"; OsPath MyPing2OutputFile = "MyPing2Out.txt"; OsPath errFile = "pingerr.txt"; processManager.setIORedirect(inputFile,MyPing1OutputFile,errFile); UtlString MyPing1("MyPing1"); UtlString MyPing2("MyPing2"); OsPath startupDir = "."; cout << "Starting process " << MyPing1.data() << endl; if (processManager.startProcess(MyPing1,appName,params,startupDir) == OS_SUCCESS) { if (processManager.getAliasState(MyPing1) == PROCESS_STARTED) { processManager.setIORedirect(inputFile,MyPing2OutputFile,errFile); cout << "Starting process " << MyPing2.data() << endl; if (processManager.startProcess(MyPing2,appName,params,startupDir) == OS_SUCCESS) { if (processManager.getAliasState(MyPing2) == PROCESS_STARTED) { cout << "Waiting 5 secs before killing process MyPing1...\n"; OsTask::delay(5000); if (processManager.stopProcess(MyPing1) != OS_SUCCESS) cout << "ERROR:Couldn't kill MyPing1 process!\n"; else { cout << "Successfull take down of MyPing1 process!\n"; cout << "Waiting 5 secs before killing process MyPing2...\n"; OsTask::delay(5000); alias = "MyPing2"; if (processManager.stopProcess(MyPing2) != OS_SUCCESS) { cout << "ERROR:Couldn't kill MyPing2 process!\n"; } else { cout << "Successfull take down of MyPing2 process!\n"; retval = OS_SUCCESS; } } } else cerr << "ERROR: process manager says process 2 is NOT running!\n"; } else cerr << "ERROR: Unable to start process 2 in TestProcessMgr\n"; } else cerr << "ERROR: process manager says process 1 is NOT running!\n"; } else cerr << "ERROR: Unable to start process 1 in TestProcessMgr\n"; return retval; }