diff options
author | Dylan Baker <[email protected]> | 2018-05-22 15:00:35 -0700 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2019-05-03 10:58:17 -0700 |
commit | 76338933e98209dbf278a2eee14f4dee66ec2374 (patch) | |
tree | c3079bc2f32783017c1d7e072e30aaac2344d60a /src/util/tests | |
parent | ff9bf223c24143260a975f45963eb90f40565c57 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/util/tests')
-rw-r--r-- | src/util/tests/hash_table/clear.c | 13 | ||||
-rw-r--r-- | src/util/tests/hash_table/delete_management.c | 13 | ||||
-rw-r--r-- | src/util/tests/hash_table/insert_many.c | 11 | ||||
-rw-r--r-- | src/util/tests/hash_table/meson.build | 1 | ||||
-rw-r--r-- | src/util/tests/hash_table/random_entry.c | 7 |
5 files changed, 25 insertions, 20 deletions
diff --git a/src/util/tests/hash_table/clear.c b/src/util/tests/hash_table/clear.c index 101fe3717fc..e61f60ece1b 100644 --- a/src/util/tests/hash_table/clear.c +++ b/src/util/tests/hash_table/clear.c @@ -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); diff --git a/src/util/tests/hash_table/delete_management.c b/src/util/tests/hash_table/delete_management.c index f6e2fa8416e..92e995ecd53 100644 --- a/src/util/tests/hash_table/delete_management.c +++ b/src/util/tests/hash_table/delete_management.c @@ -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); diff --git a/src/util/tests/hash_table/insert_many.c b/src/util/tests/hash_table/insert_many.c index c033843137f..c146b039cca 100644 --- a/src/util/tests/hash_table/insert_many.c +++ b/src/util/tests/hash_table/insert_many.c @@ -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); diff --git a/src/util/tests/hash_table/meson.build b/src/util/tests/hash_table/meson.build index d4de448aea5..1ad3be3d063 100644 --- a/src/util/tests/hash_table/meson.build +++ b/src/util/tests/hash_table/meson.build @@ -27,6 +27,7 @@ foreach t : ['clear', 'collision', 'delete_and_lookup', 'delete_management', executable( '@0@_test'.format(t), files('@[email protected]'.format(t)), + c_args : [c_msvc_compat_args], dependencies : [dep_thread, dep_dl], include_directories : [inc_include, inc_util], link_with : libmesa_util, diff --git a/src/util/tests/hash_table/random_entry.c b/src/util/tests/hash_table/random_entry.c index a046eda3070..4902a999de6 100644 --- a/src/util/tests/hash_table/random_entry.c +++ b/src/util/tests/hash_table/random_entry.c @@ -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); |