Re: [PATCH i-g-t] tests/kms_properties: Add GET_PROPERTY ioctl sanity check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 12, 2017 at 05:21:49PM +0200, Daniel Vetter wrote:
> I've broken this accidentally. Let's make sure this doesn't happen
> anymore. Testcases suggested by Chris.
> 
> Acked-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
> Signed-off-by: Daniel Vetter <daniel.vetter@xxxxxxxxx>
> ---
>  tests/kms_properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/tests/kms_properties.c b/tests/kms_properties.c
> index 591e1a019190..c15026b89acd 100644
> --- a/tests/kms_properties.c
> +++ b/tests/kms_properties.c
> @@ -358,6 +358,63 @@ static void test_object_invalid_properties(igt_display_t *display,
>  		test_invalid_properties(display->drm_fd, id, type, output->id, DRM_MODE_OBJECT_CONNECTOR, atomic);
>  }
>  
> +static void get_prop_sanity(igt_display_t *display)
> +{
> +	int i, fd;
> +	uint64_t *values;
> +	struct drm_mode_property_enum *enums;
> +
> +	fd = display->drm_fd;
> +
> +	/*
> +	 * There's no way to enumerate all properties, we just have to
> +	 * brute-force the first few kms ids. 1000 should be enough.
> +	 */
> +	for (i = 0; i < 1000; i++) {
> +		struct drm_mode_get_property prop;
> +
> +		memset(&prop, 0, sizeof(prop));
> +		prop.prop_id = i;
> +
> +		if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
> +			continue;
> +
> +		if (prop.count_values) {
> +			values = calloc(prop.count_values, sizeof(uint64_t));
> +			igt_assert(values);
> +			memset(values, 0x5c, sizeof(uint64_t)*prop.count_values);
> +			prop.values_ptr = to_user_pointer(values);
> +		}
> +
> +		/* despite what libdrm makes you believe, we never supply
> +		 * additional information for BLOB properties, only for enums
> +		 * and bitmasks */
> +		igt_assert_eq(!!prop.count_enum_blobs,
> +			      !!(prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)));
> +		if (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK))
> +			igt_assert(prop.count_enum_blobs == prop.count_values);
> +
> +		if (prop.count_enum_blobs) {
> +			enums = calloc(prop.count_enum_blobs, sizeof(*enums));
> +			memset(enums, 0x5c, sizeof(*enums)*prop.count_enum_blobs);
> +			igt_assert(enums);
> +			prop.enum_blob_ptr = to_user_pointer(enums);
> +		}
> +
> +		do_ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop);
> +
> +		for (int j = 0; j < prop.count_values; j++) {
> +			igt_assert(values[j] != 0x5c5c5c5c5c5c5c5cULL);
> +
> +			if (!(prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)))
> +				continue;
> +			igt_assert(enums[j].value != 0x5c5c5c5c5c5c5c5cULL);
> +			igt_assert(enums[j].value == values[j]);
> +			igt_assert(enums[j].name[0] != '\0');
> +		}

Yikes, totally missed the callocs without free. A small leak today...
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux