modetest: add an add_property_optional variant that does not print errors
authorIlia Mirkin <imirkin@alum.mit.edu>
Sun, 2 Jun 2019 18:33:26 +0000 (14:33 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sat, 22 Jun 2019 17:34:25 +0000 (13:34 -0400)
As new features are added and others are declared to be legacy, it's
nice to be able to implement fallbacks. As such, create a
property-setting variant that does not generate errors which can very
well be entirely expected.

Will be used for gamma control in a future change.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
tests/modetest/modetest.c

index a1c81f6..71ddc86 100644 (file)
@@ -948,9 +948,10 @@ struct property_arg {
        char name[DRM_PROP_NAME_LEN+1];
        uint32_t prop_id;
        uint64_t value;
+       bool optional;
 };
 
-static void set_property(struct device *dev, struct property_arg *p)
+static bool set_property(struct device *dev, struct property_arg *p)
 {
        drmModeObjectProperties *props = NULL;
        drmModePropertyRes **props_info = NULL;
@@ -982,13 +983,13 @@ static void set_property(struct device *dev, struct property_arg *p)
        if (p->obj_type == 0) {
                fprintf(stderr, "Object %i not found, can't set property\n",
                        p->obj_id);
-                       return;
+               return false;
        }
 
        if (!props) {
                fprintf(stderr, "%s %i has no properties\n",
                        obj_type, p->obj_id);
-               return;
+               return false;
        }
 
        for (i = 0; i < (int)props->count_props; ++i) {
@@ -999,9 +1000,10 @@ static void set_property(struct device *dev, struct property_arg *p)
        }
 
        if (i == (int)props->count_props) {
-               fprintf(stderr, "%s %i has no %s property\n",
-                       obj_type, p->obj_id, p->name);
-               return;
+               if (!p->optional)
+                       fprintf(stderr, "%s %i has no %s property\n",
+                               obj_type, p->obj_id, p->name);
+               return false;
        }
 
        p->prop_id = props->props[i];
@@ -1015,6 +1017,8 @@ static void set_property(struct device *dev, struct property_arg *p)
        if (ret < 0)
                fprintf(stderr, "failed to set %s %i property %s to %" PRIu64 ": %s\n",
                        obj_type, p->obj_id, p->name, p->value, strerror(errno));
+
+       return true;
 }
 
 /* -------------------------------------------------------------------------- */
@@ -1072,6 +1076,19 @@ static void add_property(struct device *dev, uint32_t obj_id,
        set_property(dev, &p);
 }
 
+static bool add_property_optional(struct device *dev, uint32_t obj_id,
+                                 const char *name, uint64_t value)
+{
+       struct property_arg p;
+
+       p.obj_id = obj_id;
+       strcpy(p.name, name);
+       p.value = value;
+       p.optional = true;
+
+       return set_property(dev, &p);
+}
+
 static int atomic_set_plane(struct device *dev, struct plane_arg *p,
                                                        int pattern, bool update)
 {