How to check parameters passed to cuda runtime API deep inside a function is correct when writing unit test?

Suppose I have a resource management class as below:

class CudaDeviceMem {
        CudaDeviceMem(size_t bytes) {
                cudaMalloc(&ptr, bytes);
        void release(){
       void *ptr;

I want to write a unit test to check whether memory is allocated as I wish. So I write pseudo-code as below:

//Google unit test
TEST(MyTest,  AllocTest){
      CudaDeviceMem mem(10);
      //Check cudaMalloc is called with parameter 10.
      //How to do this?


Any idea? Thanks a lot.

I would say it is not possible. But you can simply check the return status of cudaMalloc directly.

cudaError_t status = cudaMalloc(&ptr, bytes);
if(status != cudaSuccess){

(On a side note: If you want a tested wrapper for device allocations, you could use Thrust or RMM)