[Mesa-dev] [RFC PATCH] main/tests: add inverse lookup test

Emil Velikov emil.l.velikov at gmail.com
Thu Nov 5 16:20:54 PST 2015


Seems that we've been forgetting to update this test, leading to
decreased usefulness. Thus lets add a test which walks over the mesa
generated enums and checks the string (if non "0x" prefixed) against the
local table.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---

I'm not 100% sure on the purpose of this test, although without this the 
local table can easily bitrot.

Ian can you share your initial goal with this/these test(s). Should we 
extend it with this patch, nuke it altogether or else ?

Note: with this in place we get ~400 missing symbols and `make check' 
fails.

-Emil


 src/mesa/main/tests/enum_strings.cpp | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/tests/enum_strings.cpp b/src/mesa/main/tests/enum_strings.cpp
index 48b6ec2..6e46851 100644
--- a/src/mesa/main/tests/enum_strings.cpp
+++ b/src/mesa/main/tests/enum_strings.cpp
@@ -29,7 +29,7 @@ extern "C" {
 }
 
 struct enum_info {
-   int value;
+   unsigned int value;
    const char *name;
 };
 
@@ -43,6 +43,36 @@ TEST(EnumStrings, LookUpByNumber)
    }
 }
 
+/*
+ * This test will catch us, when the everything table below hasn't been
+ * updated. Note that this test might take a while since there is no way to
+ * linearly walk the enums.
+ */
+TEST(EnumStrings, InverseLookUpByNumber)
+{
+   const char *mesa_enum, *dummy = "";
+   bool found;
+
+   /* XXX: The 0xFFFF limit looks hacky, but it'll do for now */
+   for (unsigned i = 0; i < 0xFFFF; i++) {
+      mesa_enum = _mesa_enum_to_string(i);
+      found = false;
+
+      if (memcmp(mesa_enum, "0x", 2) != 0) {
+         for (int j = 0; everything[j].name != NULL; j++) {
+            if (i == everything[j].value) {
+               found = true;
+               break;
+            }
+         }
+
+         if (!found)
+            EXPECT_STREQ(mesa_enum, dummy);
+      }
+   }
+}
+
+
 TEST(EnumStrings, LookUpUnknownNumber)
 {
    EXPECT_STRCASEEQ("0xEEEE", _mesa_enum_to_string(0xEEEE));
-- 
2.6.2



More information about the mesa-dev mailing list