⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stafprocessservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                 sizeof(masterVarPoolList) / sizeof(const STAFVariablePool *);    // If USEPROCESSVARS isn't set, then adjust the varPoolList[Size] being used    if (parsedResult->optionTimes("USEPROCESSVARS") == 0)    {        varPoolList = &masterVarPoolList[1];        --varPoolListSize;    }    // Resolve the rest of the options    STAFRC_t rc = RESOLVE_OPTIONAL_STRING_OPTION("WORKLOAD", process->workload);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("SHELL", process->shellCommand);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("COMMAND", process->command);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("WORKDIR", process->workdir);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("PARMS", process->parms);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("TITLE", process->title);    if (!rc) rc = RESOLVE_OPTIONAL_UINT_OPTION("PRIORITY", priority);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("KEY", process->key);    if (!rc) rc = RESOLVE_OPTIONAL_UINT_OPTION("HANDLE", theHandle);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("NAME", name);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("MACHINE", machine);    if (!rc) rc = RESOLVE_DEFAULT_UINT_OPTION("WAIT", timeout,                                              STAF_EVENT_SEM_INDEFINITE_WAIT);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("STOPUSING", stopMethodString);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("FOCUS", focusString);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("USERNAME", process->username);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("PASSWORD", password);    if (!rc)    {        if (parsedResult->optionTimes("STDIN") != 0)        {            startData.stdinMode = kSTAFProcessIOReadFile;            rc = RESOLVE_OPTIONAL_STRING_OPTION("STDIN", stdInp);        }    }    if (!rc)    {        if (parsedResult->optionTimes("STDOUT") != 0)        {            startData.stdoutMode = kSTAFProcessIOReplaceFile;            rc = RESOLVE_OPTIONAL_STRING_OPTION("STDOUT", stdOut);        }        else if (parsedResult->optionTimes("STDOUTAPPEND") != 0)        {            startData.stdoutMode = kSTAFProcessIOAppendFile;            rc = RESOLVE_OPTIONAL_STRING_OPTION("STDOUTAPPEND", stdOut);        }    }    if (!rc)    {        if (parsedResult->optionTimes("STDERR") != 0)        {            startData.stderrMode = kSTAFProcessIOReplaceFile;            rc = RESOLVE_OPTIONAL_STRING_OPTION("STDERR", stdErr);        }        else if (parsedResult->optionTimes("STDERRAPPEND") != 0)        {            startData.stderrMode = kSTAFProcessIOAppendFile;            rc = RESOLVE_OPTIONAL_STRING_OPTION("STDERRAPPEND", stdErr);        }    }    if (!rc)    {        // Make sure files specified for stdout and stderr are not the same        if ((stdOut.length() != 0) && (stdErr.length() != 0) &&            (stdOut == stdErr))        {            // XXX: Would be nice to have an API to call that checks if the            // two files are the same in a platform independent way and that            // would check for other variations like / vs \ and \ vs \\. For            // now, do a case-insensitive check in Win32/STAFProcess.            return STAFServiceResult(                kSTAFInvalidValue, "You cannot specify the same file name "                "for stdout and stderr.", 0);        }    }        if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("STATICHANDLENAME",                                                 staticHandleName);    if (rc)    {        return STAFServiceResult(rc, errorBuffer);    }    if (parsedResult->optionTimes("RETURNSTDOUT") != 0)    {        if (stdOut.length() == 0)        {            // STDOUT name not specified so create a temp file.            // Use Replace File mode by default.            startData.stdoutMode = kSTAFProcessIOReplaceFile;            // Get a temporary file name            STAFString_t tempFileNameT;            STAFString_t errorBufferT;            unsigned int osRC = 0;            rc = STAFUtilCreateTempFile(                fTempDirectory.getImpl(), STAFString("out").getImpl(),                requestInfo.fRequestNumber, &tempFileNameT, &errorBufferT, &osRC);            if (rc)            {                return STAFServiceResult(                    rc, STAFString(errorBufferT, STAFString::kShallow) +                    " for STDOUT, OSRC: " + osRC);            }            stdOut = STAFString(tempFileNameT, STAFString::kShallow);            TempFileInfo tempFileInfo;            tempFileInfo.name = stdOut;            if (startMode == kWait)            {                // Delete the temp file after waiting for the process to end                tempFileInfo.deleteFlag = false;            }            else            {                // Delete the temp file after the queue has been updated                tempFileInfo.deleteFlag = true;            }            process->stdoutTempFileInfo = tempFileInfo;        }        process->retFileList.push_back(stdOut);    }    if (parsedResult->optionTimes("RETURNSTDERR") != 0)    {        if (stdErr.length() == 0)        {            // STDERR name not specified so create a temp file.            // Use Replace File mode by default.            startData.stderrMode = kSTAFProcessIOReplaceFile;            // Get a temporary file name            STAFString_t tempFileNameT;            STAFString_t errorBufferT;            unsigned int osRC = 0;            rc = STAFUtilCreateTempFile(                fTempDirectory.getImpl(), STAFString("err").getImpl(),                requestInfo.fRequestNumber, &tempFileNameT, &errorBufferT, &osRC);            if (rc)            {                // Delete temp file created for Stdout before returning                if (process->stdoutTempFileInfo.name.length() != 0)                    deleteTempFile(process->stdoutTempFileInfo.name);                return STAFServiceResult(                    rc, STAFString(errorBufferT, STAFString::kShallow) +                    " for STDERR, OSRC: " + osRC);            }            stdErr = STAFString(tempFileNameT, STAFString::kShallow);            TempFileInfo tempFileInfo;            tempFileInfo.name = stdErr;            if (startMode == kWait)            {                // Delete the temp file after waiting for the process to end                tempFileInfo.deleteFlag = false;            }            else            {                // Delete the temp file after the queue has been updated                tempFileInfo.deleteFlag = true;            }            process->stderrTempFileInfo = tempFileInfo;        }        process->retFileList.push_back(stdErr);    }    if (parsedResult->optionTimes("STDERRTOSTDOUT") != 0)        startData.stderrMode = kSTAFProcessIOStdout;    for (int fileIndex = 1;         !rc && (fileIndex <= parsedResult->optionTimes("RETURNFILE"));         ++fileIndex)    {        STAFString returnFile;        rc = RESOLVE_INDEXED_STRING_OPTION("RETURNFILE", fileIndex, returnFile);        if (!rc) process->retFileList.push_back(returnFile);    }    if (!rc && process->shellCommand.length() != 0)    {        if (isShellCommandValid(process->shellCommand) != kSTAFOk)        {            rc = kSTAFInvalidValue;            errorBuffer = STAFString("Invalid shell command: ") +                process->shellCommand;        }    }    if (!rc)    {        if (stopMethodString.length() > 0)        {            rc = getStopMethodFromString(process->stopMethod, stopMethodString);            if (rc)            {                rc = kSTAFInvalidValue;                errorBuffer = STAFString("Invalid stop using method: ") +                    stopMethodString;            }        }        else        {            process->stopMethod = STAFProcessService::getDefaultStopMethod();        }    }        if (!rc)    {        if (focusString.length() > 0)        {            rc = getConsoleFocusFromString(process->consoleFocus, focusString);            if (rc)            {                rc = kSTAFInvalidValue;                errorBuffer = STAFString("Invalid focus: ") + focusString +                    "\nValid values are Minimized, Background, or Foreground.";            }        }        else        {            process->consoleFocus = STAFProcessService::getDefaultConsoleFocus();        }    }    if (rc)    {        // Delete the temporary StdOut/StdErr files if used before returning        deleteTempFiles(*process, true);        return STAFServiceResult(rc, errorBuffer);    }    process->startStamp = STAFTimestamp::now();    process->state = kRunning;    process->notificationList = STAFNotificationListPtr(                                new STAFNotificationList(),                                STAFNotificationListPtr::INIT);    if (doNotify && useName)        process->notificationList->reg(machine, name, priority);    else if (doNotify)        process->notificationList->reg(machine, theHandle, priority);    if (startMode == kWait)        process->notify = STAFEventSemPtr(new STAFEventSem(),                                          STAFEventSemPtr::INIT);    std::deque<STAFString> userEnvList;    STAFRefPtr<STAFStringConst_t> userEnvArray;    char *envBuf = 0;    // Note:  Due to a MS compiler bug, had to reverse the order of the    // conditions in the following if.  The static check had to be first.    if ((process->handleType == kStatic) ||        (parsedResult->optionTimes("ENV") != 0))    {        // Create a STAFProcessEnvMap from the global environment map so that        // the key (the environment variable name) can be case-insensitive        // if designated by the operating system.        STAFProcessEnvMap envMap;        for (STAFEnvMap::iterator emIter = gEnvMapPtr->begin();             emIter != gEnvMapPtr->end(); ++emIter)        {            STAFString envName = emIter->first;            STAFString envNameKey = envName;                        if (!fEnvVarCaseSensitive)                envNameKey.upperCase();            STAFString envValue = emIter->second;            envMap[envNameKey] = STAFProcessEnvData(envName, envValue);        }        // Add all the user specified variables to the envMap        for (int i = 1; i <= parsedResult->optionTimes("ENV"); ++i)        {            // XXX: CVR: Should we really be resolving things here?            STAFString envVar;            rc = RESOLVE_INDEXED_STRING_OPTION("ENV", i, envVar);            if (rc)            {                // Delete the temporary StdOut/StdErr files if used                deleteTempFiles(*process, true);                return STAFServiceResult(rc, errorBuffer);            }            unsigned int equalPos = envVar.find(kUTF8_EQUAL);            STAFString envName(envVar.subString(0, equalPos));            STAFString envNameKey = envName;            STAFString envValue;            if (equalPos != STAFString::kNPos)                envValue = envVar.subString(equalPos + 1);            if (!fEnvVarCaseSensitive)            {                envNameKey.upperCase();            }            // Retain original env variable name if already exists            if (envMap.find(envNameKey) != envMap.end())                envMap[envNameKey].envValue = envValue;            else                envMap[envNameKey] = STAFProcessEnvData(envName, envValue);            // Store only the user specified variables here for use by            // CreateProcessAsUser() called in Win32's STAFProcess.            userEnvList.push_back(envVar);        }        if (process->handleType == kStatic)        {            // Allocate the handle and set the environment variable            gHandleManagerPtr->addAndGetStaticHandle(process->handle,                                                     staticHandleName,                                                     varPool);            envMap["STAF_STATIC_HANDLE"] = STAFProcessEnvData(                "STAF_STATIC_HANDLE", process->handle);            userEnvList.push_back(STAFString("STAF_STATIC_HANDLE=") +                                  process->handle);        }        // Now, walk through the list and combine the entries back into        // Name=Value form, get the current code page representation and        // figure out how big a buffer we need        int size = 0;        std::deque<STAFStringBufferPtr> envList;        for (STAFProcessEnvMap::iterator iter2 = envMap.begin();            iter2 != envMap.end(); ++iter2)        {            STAFProcessEnvData envData = iter2->second;            STAFString envCombo = envData.envName + kUTF8_EQUAL +                envData.envValue;            STAFStringBufferPtr envComboPtr = envCombo.toCurrentCodePage();            size += envComboPtr->length() + 1;  // Add one for the null byte            envList.push_back(envComboPtr);        }        // Allocate the buffer        size += 1;                             // Add one for the trailing null        envBuf = new char[size];        // Walk the list and add the entries to the buffer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -