From 15624fcf55bff9d16f3eaa461e4a3010bbe0e4ba Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 15 Sep 2015 17:57:40 -0700 Subject: [PATCH] anv/tests: Refactor the block_pool_no_free test This simply breaks the monotonicity check out into its own function --- src/vulkan/tests/block_pool_no_free.c | 49 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/vulkan/tests/block_pool_no_free.c b/src/vulkan/tests/block_pool_no_free.c index d40504c4a87..71eb90103ef 100644 --- a/src/vulkan/tests/block_pool_no_free.c +++ b/src/vulkan/tests/block_pool_no_free.c @@ -46,23 +46,8 @@ static void *alloc_blocks(void *_job) return NULL; } -static void run_test() +static void validate_monotonic(uint32_t **blocks) { - struct anv_device device; - struct anv_block_pool pool; - - pthread_mutex_init(&device.mutex, NULL); - anv_block_pool_init(&pool, &device, 16); - - for (unsigned i = 0; i < NUM_THREADS; i++) { - jobs[i].pool = &pool; - jobs[i].id = i; - pthread_create(&jobs[i].thread, NULL, alloc_blocks, &jobs[i]); - } - - for (unsigned i = 0; i < NUM_THREADS; i++) - pthread_join(jobs[i].thread, NULL); - /* A list of indices, one per thread */ unsigned next[NUM_THREADS]; memset(next, 0, sizeof(next)); @@ -76,8 +61,8 @@ static void run_test() if (next[i] >= BLOCKS_PER_THREAD) continue; - if (thread_max < jobs[i].blocks[next[i]]) { - thread_max = jobs[i].blocks[next[i]]; + if (thread_max < blocks[i][next[i]]) { + thread_max = blocks[i][next[i]]; max_thread_idx = i; } } @@ -89,11 +74,35 @@ static void run_test() break; /* That next element had better be higher than the previous highest */ - assert(jobs[max_thread_idx].blocks[next[max_thread_idx]] > highest); + assert(blocks[max_thread_idx][next[max_thread_idx]] > highest); - highest = jobs[max_thread_idx].blocks[next[max_thread_idx]]; + highest = blocks[max_thread_idx][next[max_thread_idx]]; next[max_thread_idx]++; } +} + +static void run_test() +{ + struct anv_device device; + struct anv_block_pool pool; + + pthread_mutex_init(&device.mutex, NULL); + anv_block_pool_init(&pool, &device, 16); + + for (unsigned i = 0; i < NUM_THREADS; i++) { + jobs[i].pool = &pool; + jobs[i].id = i; + pthread_create(&jobs[i].thread, NULL, alloc_blocks, &jobs[i]); + } + + for (unsigned i = 0; i < NUM_THREADS; i++) + pthread_join(jobs[i].thread, NULL); + + uint32_t *block_ptrs[NUM_THREADS]; + for (unsigned i = 0; i < NUM_THREADS; i++) + block_ptrs[i] = jobs[i].blocks; + + validate_monotonic(block_ptrs); anv_block_pool_finish(&pool); pthread_mutex_destroy(&device.mutex); -- 2.30.2