SWDEV-295037 - Fix passed() in DTests

passed() should not call exit(0) which will prevent object
destructor being called.

Change-Id: Ibaee0d85cb616727dc5db557bb9422702670b688
This commit is contained in:
Tao Sang
2021-07-13 23:39:01 -04:00
committed by Tao Sang
parent 63586279ba
commit c74e2da333
12 changed files with 22 additions and 45 deletions
@@ -60,10 +60,9 @@ class IpcMemHandleTest {
pid_t pid;
size_t N = 1024;
size_t Nbytes = N * sizeof(int);
int *A_d = NULL, out = 0;
int out = 0;
int *A_h, *C_h;
int Num_devices = 0, Data_mismatch, CanAccessPeer = 0;
int *Ad1 = NULL, *Ad2 = NULL;
IpcMemHandleTest();
bool Test();
~IpcMemHandleTest();
@@ -84,6 +83,7 @@ bool IpcMemHandleTest::Test() {
HIPCHECK_NO_RETURN(status, hipGetDeviceCount(&Num_devices));
for (int i = 0; i < Num_devices; ++i) {
if (shrd_mem->IfTestPassed == true) {
int *A_d = NULL;
HIPCHECK_NO_RETURN(status, hipSetDevice(i));
HIPCHECK_NO_RETURN(status, hipMalloc(&A_d, Nbytes));
HIPCHECK_NO_RETURN(status, hipIpcGetMemHandle((hipIpcMemHandle_t *) &shrd_mem->memHandle,
@@ -116,6 +116,8 @@ bool IpcMemHandleTest::Test() {
}
for (int i = 0; i < Num_devices; ++i) {
Data_mismatch = 0;
int *Ad1 = NULL;
int *Ad2 = NULL;
HIPCHECK_NO_RETURN(status, hipSetDevice(i));
HIPCHECK_NO_RETURN(status, hipMalloc(&Ad2, Nbytes));
HIPCHECK_NO_RETURN(status, hipIpcOpenMemHandle((void **) &Ad1, shrd_mem->memHandle,
@@ -147,8 +149,8 @@ bool IpcMemHandleTest::Test() {
}
}
HIPCHECK_NO_RETURN(status, hipIpcCloseMemHandle(reinterpret_cast<void*>(Ad1)));
HIPCHECK_NO_RETURN(status, hipFree(Ad2));
}
HIPCHECK_NO_RETURN(status, hipFree(Ad2));
if ((out=sem_post(sem_ob2)) == -1) {
shrd_mem->IfTestPassed = false;
printf("sem_post() call on sem_ob2 failed");
@@ -210,11 +212,8 @@ IpcMemHandleTest::IpcMemHandleTest() {
IpcMemHandleTest::~IpcMemHandleTest() {
munmap(shrd_mem, sizeof(hip_ipc_t));
HIPCHECK(hipFree((A_d)));
free(A_h);
free(C_h);
HIPCHECK(hipFree((Ad1)));
HIPCHECK(hipFree((Ad2)));
}
#endif
@@ -275,9 +275,7 @@ void spawnProc(int deviceCount, const std::vector<char>& buffer) {
TestPassed &= testhipModuleLoadUnloadFunc(buffer);
}
#endif
if (TestPassed) {
passed();
} else {
if (!TestPassed) {
failed("hipMallocChild_Concurrency_MultiGpu Failed!");
}
}
@@ -309,4 +307,5 @@ int main(int argc, char* argv[]) {
globTestID = 3;
spawnProc(numDevices, buffer);
}
passed();
}
+3 -1
View File
@@ -67,9 +67,11 @@ inline int hip_skip_retcode() {
return HIP_SKIP_RETURN_CODE;
}
// This must be called in the end of main() to indicate test passed with success.
// If it's called somewhere else, compiling issues or unexpected result will arise.
#define passed() \
printf("%sPASSED!%s\n", KGRN, KNRM); \
exit(0);
return 0;
// The real "assert" would have written to stderr. But it is
// sufficient to just fflush here without getting pedantic. This also