diff options
author | Ian Romanick <[email protected]> | 2020-05-11 12:33:24 -0700 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-05-14 16:47:08 +0000 |
commit | f4638cfdad3199bd97cf8ca7070008186bff456a (patch) | |
tree | ea78f5b9c9a78a181764008bd481540497a553ed | |
parent | 66e3c74f9c7ffdd7687d4304238b50c3ba35ef47 (diff) |
anv/tests: Don't rely on assert or changing NDEBUG in tests
This is the last part of the fix for #2903.
v2: Add test_common.h.
Fixes: f7c56475d25 ("anv/tests: compile to something sensible in release builds")
Reviewed-by: Jason Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4994>
-rw-r--r-- | src/intel/vulkan/tests/block_pool_grow_first.c | 13 | ||||
-rw-r--r-- | src/intel/vulkan/tests/block_pool_no_free.c | 13 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool.c | 3 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool_free_list_only.c | 5 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool_no_free.c | 5 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool_padding.c | 15 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool_test_helper.h | 2 | ||||
-rw-r--r-- | src/intel/vulkan/tests/test_common.h | 34 |
8 files changed, 59 insertions, 31 deletions
diff --git a/src/intel/vulkan/tests/block_pool_grow_first.c b/src/intel/vulkan/tests/block_pool_grow_first.c index 0c300a91059..073587dc7f7 100644 --- a/src/intel/vulkan/tests/block_pool_grow_first.c +++ b/src/intel/vulkan/tests/block_pool_grow_first.c @@ -21,9 +21,8 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include "anv_private.h" +#include "test_common.h" int main(int argc, char **argv) { @@ -44,20 +43,20 @@ int main(int argc, char **argv) pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache); anv_block_pool_init(&pool, &device, 4096, initial_size); - assert(pool.size == initial_size); + ASSERT(pool.size == initial_size); uint32_t padding; int32_t offset = anv_block_pool_alloc(&pool, block_size, &padding); /* Pool will have grown at least space to fit the new allocation. */ - assert(pool.size > initial_size); - assert(pool.size >= initial_size + block_size); + ASSERT(pool.size > initial_size); + ASSERT(pool.size >= initial_size + block_size); /* The whole initial size is considered padding and the allocation should be * right next to it. */ - assert(padding == initial_size); - assert(offset == initial_size); + ASSERT(padding == initial_size); + ASSERT(offset == initial_size); /* Use the memory to ensure it is valid. */ void *map = anv_block_pool_map(&pool, offset, block_size); diff --git a/src/intel/vulkan/tests/block_pool_no_free.c b/src/intel/vulkan/tests/block_pool_no_free.c index b4b82693ae8..e0961ab3b9e 100644 --- a/src/intel/vulkan/tests/block_pool_no_free.c +++ b/src/intel/vulkan/tests/block_pool_no_free.c @@ -21,11 +21,10 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include <pthread.h> #include "anv_private.h" +#include "test_common.h" #define NUM_THREADS 16 #define BLOCKS_PER_THREAD 1024 @@ -51,24 +50,24 @@ static void *alloc_blocks(void *_job) block = anv_block_pool_alloc(job->pool, block_size, NULL); data = anv_block_pool_map(job->pool, block, block_size); *data = block; - assert(block >= 0); + ASSERT(block >= 0); job->blocks[i] = block; block = anv_block_pool_alloc_back(job->pool, block_size); data = anv_block_pool_map(job->pool, block, block_size); *data = block; - assert(block < 0); + ASSERT(block < 0); job->back_blocks[i] = -block; } for (unsigned i = 0; i < BLOCKS_PER_THREAD; i++) { block = job->blocks[i]; data = anv_block_pool_map(job->pool, block, block_size); - assert(*data == block); + ASSERT(*data == block); block = -job->back_blocks[i]; data = anv_block_pool_map(job->pool, block, block_size); - assert(*data == block); + ASSERT(*data == block); } return NULL; @@ -102,7 +101,7 @@ static void validate_monotonic(int32_t **blocks) break; /* That next element had better be higher than the previous highest */ - assert(blocks[min_thread_idx][next[min_thread_idx]] > highest); + ASSERT(blocks[min_thread_idx][next[min_thread_idx]] > highest); highest = blocks[min_thread_idx][next[min_thread_idx]]; next[min_thread_idx]++; diff --git a/src/intel/vulkan/tests/state_pool.c b/src/intel/vulkan/tests/state_pool.c index 41cb8757617..23209d62541 100644 --- a/src/intel/vulkan/tests/state_pool.c +++ b/src/intel/vulkan/tests/state_pool.c @@ -21,11 +21,10 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include <pthread.h> #include "anv_private.h" +#include "test_common.h" #define NUM_THREADS 8 #define STATES_PER_THREAD_LOG2 10 diff --git a/src/intel/vulkan/tests/state_pool_free_list_only.c b/src/intel/vulkan/tests/state_pool_free_list_only.c index af9b3338d67..9e0d2fa751f 100644 --- a/src/intel/vulkan/tests/state_pool_free_list_only.c +++ b/src/intel/vulkan/tests/state_pool_free_list_only.c @@ -21,11 +21,10 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include <pthread.h> #include "anv_private.h" +#include "test_common.h" #define NUM_THREADS 8 #define STATES_PER_THREAD_LOG2 12 @@ -55,7 +54,7 @@ int main(int argc, char **argv) struct anv_state states[NUM_THREADS * STATES_PER_THREAD]; for (unsigned i = 0; i < NUM_THREADS * STATES_PER_THREAD; i++) { states[i] = anv_state_pool_alloc(&state_pool, 16, 16); - assert(states[i].offset != 0); + ASSERT(states[i].offset != 0); } for (unsigned i = 0; i < NUM_THREADS * STATES_PER_THREAD; i++) diff --git a/src/intel/vulkan/tests/state_pool_no_free.c b/src/intel/vulkan/tests/state_pool_no_free.c index c74458bfb50..680d8ba83ba 100644 --- a/src/intel/vulkan/tests/state_pool_no_free.c +++ b/src/intel/vulkan/tests/state_pool_no_free.c @@ -21,11 +21,10 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include <pthread.h> #include "anv_private.h" +#include "test_common.h" #define NUM_THREADS 16 #define STATES_PER_THREAD 1024 @@ -103,7 +102,7 @@ static void run_test() break; /* That next element had better be higher than the previous highest */ - assert(jobs[max_thread_idx].offsets[next[max_thread_idx]] > highest); + ASSERT(jobs[max_thread_idx].offsets[next[max_thread_idx]] > highest); highest = jobs[max_thread_idx].offsets[next[max_thread_idx]]; next[max_thread_idx]++; diff --git a/src/intel/vulkan/tests/state_pool_padding.c b/src/intel/vulkan/tests/state_pool_padding.c index 07ea41802a8..76884d0b77f 100644 --- a/src/intel/vulkan/tests/state_pool_padding.c +++ b/src/intel/vulkan/tests/state_pool_padding.c @@ -21,9 +21,8 @@ * IN THE SOFTWARE. */ -#undef NDEBUG - #include "anv_private.h" +#include "test_common.h" int main(int argc, char **argv) { @@ -50,30 +49,30 @@ int main(int argc, char **argv) struct anv_state state = anv_state_pool_alloc(&state_pool, pool_size, 16); /* The pool must have grown */ - assert(bp->size > pool_size); + ASSERT(bp->size > pool_size); /* And the state must have been allocated at the end of the original size */ - assert(state.offset == pool_size); + ASSERT(state.offset == pool_size); /* A new allocation that fits into the returned empty space should have an * offset within the original pool size */ state = anv_state_pool_alloc(&state_pool, 4096, 16); - assert(state.offset + state.alloc_size <= pool_size); + ASSERT(state.offset + state.alloc_size <= pool_size); /* We should be able to allocate pool->block_size'd chunks in the returned area */ int left_chunks = pool_size / 4096 - 2; for (int i = 0; i < left_chunks; i++) { state = anv_state_pool_alloc(&state_pool, 4096, 16); - assert(state.offset + state.alloc_size <= pool_size); + ASSERT(state.offset + state.alloc_size <= pool_size); } /* Now the next chunk to be allocated should make the pool grow again */ pool_size = bp->size; state = anv_state_pool_alloc(&state_pool, 4096, 16); - assert(bp->size > pool_size); - assert(state.offset == pool_size); + ASSERT(bp->size > pool_size); + ASSERT(state.offset == pool_size); anv_state_pool_finish(&state_pool); } diff --git a/src/intel/vulkan/tests/state_pool_test_helper.h b/src/intel/vulkan/tests/state_pool_test_helper.h index 0e56431303f..f22a28ecc6f 100644 --- a/src/intel/vulkan/tests/state_pool_test_helper.h +++ b/src/intel/vulkan/tests/state_pool_test_helper.h @@ -46,7 +46,7 @@ static void *alloc_states(void *void_job) for (unsigned i = 0; i < chunk_size; i++) { states[i] = anv_state_pool_alloc(job->pool, 16, 16); memset(states[i].map, 139, 16); - assert(states[i].offset != 0); + ASSERT(states[i].offset != 0); } for (unsigned i = 0; i < chunk_size; i++) diff --git a/src/intel/vulkan/tests/test_common.h b/src/intel/vulkan/tests/test_common.h new file mode 100644 index 00000000000..3f883e3bdcd --- /dev/null +++ b/src/intel/vulkan/tests/test_common.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2020 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> + +#define ASSERT(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "%s:%d: Test assertion `%s` failed.\n", \ + __FILE__, __LINE__, # cond); \ + abort(); \ + } \ + } while (false) |