Changeset 99110 in vbox for trunk/src/VBox
- Timestamp:
- Mar 22, 2023 10:15:12 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTProcCreateEx.cpp
r98103 r99110 48 48 #include <iprt/message.h> 49 49 #include <iprt/param.h> 50 #include <iprt/path.h> /* For CWD testing. */ 50 51 #include <iprt/pipe.h> 51 52 #include <iprt/string.h> … … 93 94 94 95 96 static int tstRTCreateProcExCwdChild(int argc, char **argv) 97 { 98 int rc = RTR3InitExeNoArguments(0); 99 if (RT_FAILURE(rc)) 100 return RTMsgInitFailure(rc); 101 102 int cErrors = 0; 103 104 if (argc < 3) 105 return RTEXITCODE_FAILURE; 106 107 const char *pszCWD = argv[2]; 108 109 /* Validate if we really are in the CWD the parent told us. */ 110 char szCWD[RTPATH_MAX]; 111 rc = RTPathGetCurrent(szCWD, sizeof(szCWD)); 112 if (RT_FAILURE(rc)) 113 { 114 RTStrmPrintf(g_pStdErr, "childcwd: Unabled retrieve CWD, rc = %Rrc\n", rc); 115 return RTEXITCODE_FAILURE; 116 } 117 118 if (RTStrCmp(szCWD, pszCWD)) 119 { 120 RTStrmPrintf(g_pStdErr, "childcwd: CWD is '%s', but expected '%s'\n", pszCWD, pszCWD); 121 return RTEXITCODE_FAILURE; 122 } 123 124 /* Check if we can query information of the current CWD. */ 125 char *pszUser = NULL; 126 if ( argc >= 4 127 && argv[3][0] != '\0') 128 { 129 pszUser = argv[3]; 130 } 131 132 RTFSOBJINFO objInfo; 133 rc = RTPathQueryInfo(pszCWD, &objInfo, RTFSOBJATTRADD_NOTHING); 134 if (pszUser) 135 RTStrmPrintf(g_pStdOut, "childcwd: Accessing CWD '%s' via user '%s' -> %Rrc\n", pszCWD, pszUser, rc); 136 else 137 RTStrmPrintf(g_pStdOut, "childcwd: Accesing CWD '%s' -> %Rrc\n", pszCWD, rc); 138 if (RT_FAILURE(rc)) 139 cErrors++; 140 141 return cErrors == 0 ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 142 } 143 144 static void tstRTCreateProcExCwd(const char *pszAsUser, const char *pszPassword) 145 { 146 RTTestISub("Current working directory (CWD)"); 147 148 const char *apszArgs[5] = 149 { 150 g_szExecName, 151 "--testcase-child-cwd", 152 "<invalid-cwd>", 153 pszAsUser, 154 NULL 155 }; 156 157 bool const fMayPanic = RTAssertSetMayPanic(false); 158 bool const fQuiet = RTAssertSetQuiet(true); 159 160 RTPROCESS hProc; 161 uint32_t fFlags = 0; 162 /* Missing RTPROC_FLAGS_CWD. */ 163 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, fFlags, 164 NULL, NULL, NULL, pszAsUser, pszPassword, 165 (void *)apszArgs[2] /* pvExtraData (CWD) */, &hProc), 166 VERR_INVALID_PARAMETER); 167 168 /* RTPROC_FLAGS_CWD set, but CWD missing as pvExtradata. */ 169 fFlags = RTPROC_FLAGS_CWD; 170 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, fFlags, 171 NULL, NULL, NULL, pszAsUser, pszPassword, 172 NULL, &hProc), 173 VINF_SUCCESS); 174 175 /* CWD is "<invalid-cwd>" from above, should fail. */ 176 RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND }; 177 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); 178 179 char szCWD[RTPATH_MAX]; 180 181 /* Try current CWD, whatever that is. */ 182 RTTESTI_CHECK_RC_OK_RETV(RTPathGetCurrent(szCWD, sizeof(szCWD))); 183 apszArgs[2] = szCWD; 184 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, fFlags, 185 NULL, NULL, NULL, pszAsUser, pszPassword, 186 (void *)szCWD /* pvExtraData (CWD) */, &hProc), 187 VINF_SUCCESS); 188 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); 189 if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0) 190 RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus); 191 192 /* Try temporary directory. */ 193 RTTESTI_CHECK_RC_OK_RETV(RTPathTemp(szCWD, sizeof(szCWD))); 194 apszArgs[2] = szCWD; 195 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, fFlags, 196 NULL, NULL, NULL, pszAsUser, pszPassword, 197 (void *)szCWD /* pvExtraData (CWD) */, &hProc), 198 VINF_SUCCESS); 199 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); 200 if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0) 201 RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus); 202 203 /* Try user home. */ 204 RTTESTI_CHECK_RC_OK_RETV(RTPathUserHome(szCWD, sizeof(szCWD))); 205 apszArgs[2] = szCWD; 206 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, fFlags, 207 NULL, NULL, NULL, pszAsUser, pszPassword, 208 (void *)szCWD /* pvExtraData (CWD) */, &hProc), 209 VINF_SUCCESS); 210 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); 211 if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0) 212 RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus); 213 214 RTAssertSetMayPanic(fMayPanic); 215 RTAssertSetQuiet(fQuiet); 216 } 217 95 218 static int tstRTCreateProcEx6Child(int argc, char **argv) 96 219 { … … 665 788 if (argc >= 2 && !strcmp(argv[1], "--testcase-child-6")) 666 789 return tstRTCreateProcEx6Child(argc, argv); 790 if (argc >= 2 && !strcmp(argv[1], "--testcase-child-cwd")) 791 return tstRTCreateProcExCwdChild(argc, argv); 667 792 668 793 /* … … 702 827 tstRTCreateProcEx5(pszAsUser, pszPassword); 703 828 tstRTCreateProcEx6(pszAsUser, pszPassword); 829 tstRTCreateProcExCwd(pszAsUser, pszPassword); 704 830 705 831 /** @todo Cover files, ++ */
Note:
See TracChangeset
for help on using the changeset viewer.