|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright 2016-2023 Netflix, Inc. |
| 4 | + * |
| 5 | + * Licensed under the BSD+Patent License (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://opensource.org/licenses/BSDplusPatent |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +#include <errno.h> |
| 20 | +#include <stddef.h> |
| 21 | +#include <stdint.h> |
| 22 | +#include <stdlib.h> |
| 23 | + |
| 24 | +#include "test.h" |
| 25 | + |
| 26 | +#include "libvmaf/libvmaf_cuda.h" |
| 27 | + |
| 28 | +#include "cuda/common.h" |
| 29 | + |
| 30 | +static char *test_cuda_buffer_alloc_arguments() |
| 31 | +{ |
| 32 | + VmafCudaState *cu_state; |
| 33 | + VmafCudaConfiguration cuda_cfg = { 0 }; |
| 34 | + int err = vmaf_cuda_state_init(&cu_state, cuda_cfg); |
| 35 | + mu_assert("problem during vmaf_cuda_state_init", !err); |
| 36 | + |
| 37 | + VmafCudaBuffer *buf = NULL; |
| 38 | + err = vmaf_cuda_buffer_alloc(cu_state, NULL, 1024); |
| 39 | + mu_assert("a NULL buffer pointer must give -EINVAL", err == -EINVAL); |
| 40 | + err = vmaf_cuda_buffer_alloc(NULL, &buf, 1024); |
| 41 | + mu_assert("a NULL state must give -EINVAL", err == -EINVAL); |
| 42 | + mu_assert("buffer must stay NULL after an argument error", !buf); |
| 43 | + |
| 44 | + err = vmaf_cuda_release(cu_state); |
| 45 | + mu_assert("problem during vmaf_cuda_release", !err); |
| 46 | + return NULL; |
| 47 | +} |
| 48 | + |
| 49 | +static char *test_cuda_buffer_alloc_out_of_memory() |
| 50 | +{ |
| 51 | + VmafCudaState *cu_state; |
| 52 | + VmafCudaConfiguration cuda_cfg = { 0 }; |
| 53 | + int err = vmaf_cuda_state_init(&cu_state, cuda_cfg); |
| 54 | + mu_assert("problem during vmaf_cuda_state_init", !err); |
| 55 | + |
| 56 | + /* a request no device can satisfy: it must fail with an error code, not abort */ |
| 57 | + VmafCudaBuffer *buf = NULL; |
| 58 | + err = vmaf_cuda_buffer_alloc(cu_state, &buf, SIZE_MAX / 2); |
| 59 | + mu_assert("an impossible allocation must fail with -ENOMEM", err == -ENOMEM); |
| 60 | + mu_assert("buffer must stay NULL after a failed allocation", !buf); |
| 61 | + |
| 62 | + /* the state is still usable afterwards: the context was popped */ |
| 63 | + err = vmaf_cuda_buffer_alloc(cu_state, &buf, 1 << 20); |
| 64 | + mu_assert("allocation after a failed one must succeed", !err); |
| 65 | + mu_assert("buffer was not returned", buf); |
| 66 | + mu_assert("buffer has the requested size", buf->size == (1 << 20)); |
| 67 | + err = vmaf_cuda_buffer_free(cu_state, buf); |
| 68 | + mu_assert("problem during vmaf_cuda_buffer_free", !err); |
| 69 | + free(buf); |
| 70 | + |
| 71 | + err = vmaf_cuda_release(cu_state); |
| 72 | + mu_assert("problem during vmaf_cuda_release", !err); |
| 73 | + return NULL; |
| 74 | +} |
| 75 | + |
| 76 | +char *run_tests() |
| 77 | +{ |
| 78 | + mu_run_test(test_cuda_buffer_alloc_arguments); |
| 79 | + mu_run_test(test_cuda_buffer_alloc_out_of_memory); |
| 80 | + return NULL; |
| 81 | +} |
0 commit comments