[Mesa-dev] [PATCH v3 34/48] util/tests: Use define instead of VLA

Dylan Baker dylan at pnwbakers.com
Tue Aug 7 00:51:14 UTC 2018


To allow the this test to be built with MSVC, which doesn't support
VLAs.
---
 src/util/tests/hash_table/clear.c             | 13 +++++++------
 src/util/tests/hash_table/delete_management.c | 13 +++++++------
 src/util/tests/hash_table/insert_many.c       | 11 ++++++-----
 src/util/tests/hash_table/meson.build         |  1 +
 src/util/tests/hash_table/random_entry.c      |  7 ++++---
 src/util/tests/string_buffer/meson.build      |  1 +
 6 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/src/util/tests/hash_table/clear.c b/src/util/tests/hash_table/clear.c
index 526700bfb0f..19494844608 100644
--- a/src/util/tests/hash_table/clear.c
+++ b/src/util/tests/hash_table/clear.c
@@ -23,6 +23,8 @@
 
 #include "hash_table.h"
 
+#define SIZE 1000
+
 static void *make_key(uint32_t i)
 {
       return (void *)(uintptr_t)(1 + i);
@@ -54,13 +56,12 @@ int main()
 {
    struct hash_table *ht;
    struct hash_entry *entry;
-   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]);
    }
@@ -70,19 +71,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 127d81b3ca9..e3be9fb3d99 100644
--- a/src/util/tests/hash_table/delete_management.c
+++ b/src/util/tests/hash_table/delete_management.c
@@ -30,6 +30,8 @@
 #include <assert.h>
 #include "hash_table.h"
 
+#define SIZE 10000
+
 static uint32_t
 key_value(const void *key)
 {
@@ -47,8 +49,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;
@@ -56,7 +57,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);
@@ -69,7 +70,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);
@@ -79,8 +80,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 b07e40842bf..6bd35d5c0c7 100644
--- a/src/util/tests/hash_table/insert_many.c
+++ b/src/util/tests/hash_table/insert_many.c
@@ -30,6 +30,8 @@
 #include <assert.h>
 #include "hash_table.h"
 
+#define SIZE 10000
+
 static uint32_t
 key_value(const void *key)
 {
@@ -47,8 +49,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;
@@ -56,18 +57,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 c7b03f19c56..93605d1e77f 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 at _test'.format(t),
       files('@0 at .c'.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 d1bc44aeb30..2b81d081271 100644
--- a/src/util/tests/hash_table/random_entry.c
+++ b/src/util/tests/hash_table/random_entry.c
@@ -30,6 +30,8 @@
 #include <assert.h>
 #include "hash_table.h"
 
+#define SIZE 10000
+
 static uint32_t
 key_value(const void *key)
 {
@@ -53,8 +55,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;
@@ -62,7 +63,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);
diff --git a/src/util/tests/string_buffer/meson.build b/src/util/tests/string_buffer/meson.build
index 9f42e3550ae..4e5a2c605cd 100644
--- a/src/util/tests/string_buffer/meson.build
+++ b/src/util/tests/string_buffer/meson.build
@@ -23,6 +23,7 @@ test(
   executable(
     'string_buffer_test',
     'string_buffer_test.cpp',
+    cpp_args : [cpp_msvc_compat_args],
     dependencies : [dep_thread, dep_dl, idep_gtest],
     include_directories : inc_common,
     link_with : [libmesa_util],
-- 
2.18.0



More information about the mesa-dev mailing list