Przeglądaj źródła

anv/tests: Refactor the block_pool_no_free test

This simply breaks the monotonicity check out into its own function
tags/12.0-branchpoint
Jason Ekstrand 10 lat temu
rodzic
commit
15624fcf55
1 zmienionych plików z 29 dodań i 20 usunięć
  1. 29
    20
      src/vulkan/tests/block_pool_no_free.c

+ 29
- 20
src/vulkan/tests/block_pool_no_free.c Wyświetl plik

@@ -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);

Ładowanie…
Anuluj
Zapisz