This test should be by itself as it leaks memory intentionally
| 28 | |
| 29 | // This test should be by itself as it leaks memory intentionally |
| 30 | TEST(Memory, lock) { |
| 31 | size_t alloc_bytes, alloc_buffers; |
| 32 | size_t lock_bytes, lock_buffers; |
| 33 | |
| 34 | cleanSlate(); // Clean up everything done so far |
| 35 | |
| 36 | const dim_t num = step_bytes / sizeof(float); |
| 37 | |
| 38 | vector<float> in(num); |
| 39 | |
| 40 | af_array arr = 0; |
| 41 | ASSERT_SUCCESS(af_create_array(&arr, &in[0], 1, &num, f32)); |
| 42 | |
| 43 | deviceMemInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); |
| 44 | |
| 45 | ASSERT_EQ(alloc_buffers, 1u); |
| 46 | ASSERT_EQ(lock_buffers, 1u); |
| 47 | ASSERT_EQ(alloc_bytes, step_bytes); |
| 48 | ASSERT_EQ(lock_bytes, step_bytes); |
| 49 | |
| 50 | // arr1 gets released by end of the following code block |
| 51 | { |
| 52 | array a(arr); |
| 53 | a.lock(); |
| 54 | |
| 55 | // No new memory should be allocated |
| 56 | deviceMemInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); |
| 57 | |
| 58 | ASSERT_EQ(alloc_buffers, 1u); |
| 59 | ASSERT_EQ(lock_buffers, 1u); |
| 60 | ASSERT_EQ(alloc_bytes, step_bytes); |
| 61 | ASSERT_EQ(lock_bytes, step_bytes); |
| 62 | } |
| 63 | |
| 64 | // Making sure all unlocked buffers are freed |
| 65 | deviceGC(); |
| 66 | |
| 67 | deviceMemInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); |
| 68 | |
| 69 | ASSERT_EQ(alloc_buffers, 1u); |
| 70 | ASSERT_EQ(lock_buffers, 1u); |
| 71 | ASSERT_EQ(alloc_bytes, step_bytes); |
| 72 | ASSERT_EQ(lock_bytes, step_bytes); |
| 73 | } |
nothing calls this directly
no test coverage detected