util/tests: Use define instead of VLA
To allow the this test to be built with MSVC, which doesn't support VLAs. Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
ff9bf223c2
commit
76338933e9
5 changed files with 25 additions and 20 deletions
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "hash_table.h"
|
||||
|
||||
#define SIZE 1000
|
||||
|
||||
static void *make_key(uint32_t i)
|
||||
{
|
||||
return (void *)(uintptr_t)(1 + i);
|
||||
|
|
@ -55,13 +57,12 @@ static void delete_function(struct hash_entry *entry)
|
|||
int main()
|
||||
{
|
||||
struct hash_table *ht;
|
||||
const uint32_t size = 1000;
|
||||
bool flags[size];
|
||||
bool flags[SIZE];
|
||||
uint32_t i;
|
||||
|
||||
ht = _mesa_hash_table_create(NULL, key_hash, key_equal);
|
||||
|
||||
for (i = 0; i < size; ++i) {
|
||||
for (i = 0; i < SIZE; ++i) {
|
||||
flags[i] = false;
|
||||
_mesa_hash_table_insert(ht, make_key(i), &flags[i]);
|
||||
}
|
||||
|
|
@ -71,19 +72,19 @@ int main()
|
|||
|
||||
/* Check that delete_function was called and that repopulating the table
|
||||
* works. */
|
||||
for (i = 0; i < size; ++i) {
|
||||
for (i = 0; i < SIZE; ++i) {
|
||||
assert(flags[i]);
|
||||
flags[i] = false;
|
||||
_mesa_hash_table_insert(ht, make_key(i), &flags[i]);
|
||||
}
|
||||
|
||||
/* Check that exactly the right set of entries is in the table. */
|
||||
for (i = 0; i < size; ++i) {
|
||||
for (i = 0; i < SIZE; ++i) {
|
||||
assert(_mesa_hash_table_search(ht, make_key(i)));
|
||||
}
|
||||
|
||||
hash_table_foreach(ht, entry) {
|
||||
assert(key_id(entry->key) < size);
|
||||
assert(key_id(entry->key) < SIZE);
|
||||
}
|
||||
|
||||
_mesa_hash_table_destroy(ht, NULL);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include <assert.h>
|
||||
#include "hash_table.h"
|
||||
|
||||
#define SIZE 10000
|
||||
|
||||
static uint32_t
|
||||
key_value(const void *key)
|
||||
{
|
||||
|
|
@ -49,8 +51,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
struct hash_table *ht;
|
||||
struct hash_entry *entry;
|
||||
unsigned size = 10000;
|
||||
uint32_t keys[size];
|
||||
uint32_t keys[SIZE];
|
||||
uint32_t i;
|
||||
|
||||
(void) argc;
|
||||
|
|
@ -58,7 +59,7 @@ main(int argc, char **argv)
|
|||
|
||||
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
keys[i] = i;
|
||||
|
||||
_mesa_hash_table_insert(ht, keys + i, NULL);
|
||||
|
|
@ -71,7 +72,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* Make sure that all our entries were present at the end. */
|
||||
for (i = size - 100; i < size; i++) {
|
||||
for (i = SIZE - 100; i < SIZE; i++) {
|
||||
entry = _mesa_hash_table_search(ht, keys + i);
|
||||
assert(entry);
|
||||
assert(key_value(entry->key) == i);
|
||||
|
|
@ -81,8 +82,8 @@ main(int argc, char **argv)
|
|||
for (entry = _mesa_hash_table_next_entry(ht, NULL);
|
||||
entry != NULL;
|
||||
entry = _mesa_hash_table_next_entry(ht, entry)) {
|
||||
assert(key_value(entry->key) >= size - 100 &&
|
||||
key_value(entry->key) < size);
|
||||
assert(key_value(entry->key) >= SIZE - 100 &&
|
||||
key_value(entry->key) < SIZE);
|
||||
}
|
||||
assert(ht->entries == 100);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include <assert.h>
|
||||
#include "hash_table.h"
|
||||
|
||||
#define SIZE 10000
|
||||
|
||||
static uint32_t
|
||||
key_value(const void *key)
|
||||
{
|
||||
|
|
@ -49,8 +51,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
struct hash_table *ht;
|
||||
struct hash_entry *entry;
|
||||
unsigned size = 10000;
|
||||
uint32_t keys[size];
|
||||
uint32_t keys[SIZE];
|
||||
uint32_t i;
|
||||
|
||||
(void) argc;
|
||||
|
|
@ -58,18 +59,18 @@ main(int argc, char **argv)
|
|||
|
||||
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
keys[i] = i;
|
||||
|
||||
_mesa_hash_table_insert(ht, keys + i, NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
entry = _mesa_hash_table_search(ht, keys + i);
|
||||
assert(entry);
|
||||
assert(key_value(entry->key) == i);
|
||||
}
|
||||
assert(ht->entries == size);
|
||||
assert(ht->entries == SIZE);
|
||||
|
||||
_mesa_hash_table_destroy(ht, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ foreach t : ['clear', 'collision', 'delete_and_lookup', 'delete_management',
|
|||
executable(
|
||||
'@0@_test'.format(t),
|
||||
files('@0@.c'.format(t)),
|
||||
c_args : [c_msvc_compat_args],
|
||||
dependencies : [dep_thread, dep_dl],
|
||||
include_directories : [inc_include, inc_util],
|
||||
link_with : libmesa_util,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include <assert.h>
|
||||
#include "hash_table.h"
|
||||
|
||||
#define SIZE 10000
|
||||
|
||||
static uint32_t
|
||||
key_value(const void *key)
|
||||
{
|
||||
|
|
@ -55,8 +57,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
struct hash_table *ht;
|
||||
struct hash_entry *entry;
|
||||
unsigned size = 10000;
|
||||
uint32_t keys[size];
|
||||
uint32_t keys[SIZE];
|
||||
uint32_t i, random_value;
|
||||
|
||||
(void) argc;
|
||||
|
|
@ -64,7 +65,7 @@ main(int argc, char **argv)
|
|||
|
||||
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
keys[i] = i;
|
||||
|
||||
_mesa_hash_table_insert(ht, keys + i, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue