コード例 #1
0
ファイル: OsProcessTest.cpp プロジェクト: LordGaav/sipxecs
    void testLaunch()
    {
        OsStatus stat;

        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

        OsProcess process;

        UtlString envKey =   "TESTKEY1";
        UtlString envValue = "TESTVALUE1";
        process.setEnv(envKey,envValue);

        envKey =  "TESTKEY2";
        envValue ="TESTVALUE2";
        process.setEnv(envKey,envValue);

        envKey = "TESTKEY3";
        envValue = "TESTVALUE3";
        process.setEnv(envKey,envValue);

        OsPath startupDir = ".";

        //std::cout << "Launching process: " << appName.data() << std::endl;
        stat = process.launch(appName,params,startupDir);
        CPPUNIT_ASSERT_MESSAGE("Launched application", stat == OS_SUCCESS);
        CPPUNIT_ASSERT_MESSAGE("Application running", process.isRunning());

        int priority;
        process.setPriority(1);
        process.getPriority(priority);
        KNOWN_BUG("INTERMITTENT on F8 with 64Bit changes", "XECS-480");
        CPPUNIT_ASSERT_MESSAGE("Set priority ok", priority == 1);

        OsProcess newProcess;
        stat = OsProcess::getByPID(process.getPID(), newProcess);
        CPPUNIT_ASSERT_MESSAGE("Got process pid ok", stat == OS_SUCCESS);

        //std::cout << "Waiting 5 secs before killing process..." << std::endl;
        OsTask::delay(5000);
        stat = newProcess.kill();
        CPPUNIT_ASSERT_MESSAGE("Able to kill process", stat == OS_SUCCESS);
    }
コード例 #2
0
ファイル: main.cpp プロジェクト: ClydeFroq/sipxecs
OsStatus  TestProcessClass()
{

    OsStatus retval = OS_FAILED;

    cout << "Starting Process Class Method Test...\n";

    //try to launch dir
    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

    //try and launch IE
    UtlString envKey =   "TESTKEY1";
    UtlString envValue = "TESTVALUE1";
    process.setEnv(envKey,envValue);

    envKey =  "TESTKEY2";
    envValue ="TESTVALUE2";
    process.setEnv(envKey,envValue);

    envKey = "TESTKEY3";
    envValue = "TESTVALUE3";
    process.setEnv(envKey,envValue);

    OsPath startupDir = ".";

    cout << "Launching process: " << appName.data() << endl;
    if (process.launch(appName,params,startupDir) == OS_SUCCESS)
    {
        if (process.isRunning())
        {
            cout << "Successful launch. " << endl;

            //try to set the prio to 1
            int prio;
            process.getPriority(prio);
            cout << "Current priority = " << prio << endl;
            process.setPriority(1);

            process.getPriority(prio);
            cout << "New priority (should say 1) = " << prio << endl;



            OsProcess newProcess;

            //see if we can get the process we started by pid
            if (OsProcess::getByPID(process.getPID(),newProcess) == OS_SUCCESS)
            {
                //wait a bit
                cout << "Waiting 5 secs before killing process..." << endl;
                OsTask::delay(5000);
                //ok, now kill that bad boy...
                if (newProcess.kill() == OS_SUCCESS)
                    cout << "Killed\n";
                else
                    cout << "ERROR: Could not kill process!\n";

                retval = OS_SUCCESS;
            }
        }
        else
            cout << "ERROR: Process says it's not running!\n";
    }
    else
    {
        cout << "ERROR: Could not create process " << appName.data() << endl;
    }

    cout << "DONE Process Class Method Test.\n";

    return retval;
}