/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include #include #include #ifdef __linux__ #include #include #include #include bool testMallocFromChild() { int fd[2]; pid_t childpid; bool testResult = false; // create pipe descriptors pipe(fd); childpid = fork(); if (childpid > 0) { // Parent close(fd[1]); // parent will wait to read the device cnt read(fd[0], &testResult, sizeof(testResult)); // close the read-descriptor close(fd[0]); // wait for child exit wait(NULL); return testResult; } else if (!childpid) { // Child // writing only, no need for read-descriptor close(fd[0]); char* A_d = nullptr; hipError_t ret = hipMalloc(&A_d, 1024); printf("hipMalloc returned : %s\n", hipGetErrorString(ret)); if (ret == hipSuccess) testResult = true; else testResult = false; if (A_d != nullptr) { hipFree(A_d); } // send the value on the write-descriptor: write(fd[1], &testResult, sizeof(testResult)); hipFree(A_d); // close the write descriptor: close(fd[1]); exit(0); } return false; } HIP_TEST_CASE(ChildMalloc) { auto res = testMallocFromChild(); REQUIRE(res == true); } #endif