1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
/*
* Copyright © 2014-2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Damien Lespiau <damien.lespiau@intel.com>
* Daniel Stone <daniels@collabora.com>
*/
/**
* TEST: kms prop blob
* Category: Display
* Description: Tests behaviour of mass-data 'blob' properties.
* Driver requirement: i915, xe
* Mega feature: General Display Features
*/
#include "igt.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
/**
* SUBTEST: blob-multiple
* Description: Test validates destroying multiple properties explicitly works as needed.
*
* SUBTEST: blob-prop-%s
* Description: Tests validates the %arg[1] of the properties created.
*
* arg[1]:
*
* @core: validity
* @lifetime: lifetime
* @validate: blob size
*/
/**
* SUBTEST: basic
* Description: Test to ensure property support exists
*
* SUBTEST: invalid-%s-%s
* Description: Tests error handling when invalid properties are %ar[1] with %arg[2].
*
* arg[1]:
*
* @get: fetched
* @set: set
*
* arg[2]:
*
* @prop: blob object type
* @prop-any: object of any type
*/
IGT_TEST_DESCRIPTION("Tests behaviour of mass-data 'blob' properties.");
static const struct drm_mode_modeinfo test_mode_valid = {
.clock = 1234,
.hdisplay = 640,
.hsync_start = 641,
.hsync_end = 642,
.htotal = 643,
.hskew = 0,
.vdisplay = 480,
.vsync_start = 481,
.vsync_end = 482,
.vtotal = 483,
.vscan = 0,
.vrefresh = 60000,
.flags = 0,
.type = 0,
.name = "FROMUSER",
};
#define ioctl_or_ret_errno(fd, ioc, ioc_data) { \
if (drmIoctl(fd, ioc, ioc_data) != 0) \
return errno; \
}
static void igt_require_propblob(int fd)
{
struct drm_mode_create_blob c;
struct drm_mode_destroy_blob d;
uint32_t blob_data;
c.data = (uintptr_t) &blob_data;
c.length = sizeof(blob_data);
igt_require(drmIoctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &c) == 0);
d.blob_id = c.blob_id;
igt_require(drmIoctl(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &d) == 0);
}
static int
validate_prop(int fd, uint32_t prop_id)
{
struct drm_mode_get_blob get;
struct drm_mode_modeinfo ret_mode;
get.blob_id = prop_id;
get.length = 0;
get.data = (uintptr_t) 0;
ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
if (get.length != sizeof(test_mode_valid))
return ENOMEM;
get.data = (uintptr_t) &ret_mode;
ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
if (memcmp(&ret_mode, &test_mode_valid, sizeof(test_mode_valid)) != 0)
return EINVAL;
return 0;
}
static uint32_t
create_prop(int fd)
{
struct drm_mode_create_blob create;
create.length = sizeof(test_mode_valid);
create.data = (uintptr_t) &test_mode_valid;
do_ioctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
igt_assert_neq_u32(create.blob_id, 0);
return create.blob_id;
}
static int
destroy_prop(int fd, uint32_t prop_id)
{
struct drm_mode_destroy_blob destroy;
destroy.blob_id = prop_id;
ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
return 0;
}
static void
test_validate(int fd)
{
struct drm_mode_create_blob create;
struct drm_mode_get_blob get;
char too_small[32];
uint32_t prop_id;
memset(too_small, 0, sizeof(too_small));
/* Outlandish size. */
create.length = 0x10000;
create.data = (uintptr_t) &too_small;
do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
/* Outlandish address. */
create.length = sizeof(test_mode_valid);
create.data = (uintptr_t) 0xdeadbeee;
do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
/* When we pass an incorrect size, the kernel should correct us. */
prop_id = create_prop(fd);
get.blob_id = prop_id;
get.length = sizeof(too_small);
get.data = (uintptr_t) too_small;
do_ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
igt_assert_eq_u32(get.length, sizeof(test_mode_valid));
get.blob_id = prop_id;
get.data = (uintptr_t) 0xdeadbeee;
do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
}
static void
test_lifetime(int fd)
{
int fd2;
uint32_t prop_id, prop_id2;
fd2 = drm_open_driver(DRIVER_ANY);
igt_assert_fd(fd2);
/* Ensure clients can see properties created by other clients. */
prop_id = create_prop(fd);
igt_assert_eq(validate_prop(fd, prop_id), 0);
igt_assert_eq(validate_prop(fd2, prop_id), 0);
/* ... but can't destroy them. */
igt_assert_eq(destroy_prop(fd2, prop_id), EPERM);
/* Make sure properties can't be accessed once explicitly destroyed. */
prop_id2 = create_prop(fd2);
igt_assert_eq(validate_prop(fd2, prop_id2), 0);
igt_assert_eq(destroy_prop(fd2, prop_id2), 0);
igt_assert_eq(validate_prop(fd2, prop_id2), ENOENT);
igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
/* Make sure properties are cleaned up on client exit. */
prop_id2 = create_prop(fd2);
igt_assert_eq(validate_prop(fd, prop_id2), 0);
igt_assert_eq(drm_close_driver(fd2), 0);
igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
igt_assert_eq(validate_prop(fd, prop_id), 0);
igt_assert_eq(destroy_prop(fd, prop_id), 0);
igt_assert_eq(validate_prop(fd, prop_id), ENOENT);
}
static void
test_multiple(int fd)
{
uint32_t prop_ids[5];
int fd2;
int i;
fd2 = drm_open_driver(DRIVER_ANY);
igt_assert_fd(fd2);
/* Ensure destroying multiple properties explicitly works as needed. */
for (i = 0; i < ARRAY_SIZE(prop_ids); i++) {
prop_ids[i] = create_prop(fd2);
igt_assert_eq(validate_prop(fd, prop_ids[i]), 0);
igt_assert_eq(validate_prop(fd2, prop_ids[i]), 0);
}
for (i = 0; i < ARRAY_SIZE(prop_ids); i++) {
igt_assert_eq(destroy_prop(fd2, prop_ids[i]), 0);
igt_assert_eq(validate_prop(fd2, prop_ids[i]), ENOENT);
}
igt_assert_eq(drm_close_driver(fd2), 0);
fd2 = drm_open_driver(DRIVER_ANY);
igt_assert_fd(fd2);
/* Ensure that multiple properties get cleaned up on fd close. */
for (i = 0; i < ARRAY_SIZE(prop_ids); i++) {
prop_ids[i] = create_prop(fd2);
igt_assert_eq(validate_prop(fd, prop_ids[i]), 0);
igt_assert_eq(validate_prop(fd2, prop_ids[i]), 0);
}
igt_assert_eq(drm_close_driver(fd2), 0);
for (i = 0; i < ARRAY_SIZE(prop_ids); i++)
igt_assert_eq(validate_prop(fd, prop_ids[i]), ENOENT);
}
static void
test_core(int fd)
{
uint32_t prop_id;
/* The first hurdle. */
prop_id = create_prop(fd);
igt_assert_eq(validate_prop(fd, prop_id), 0);
igt_assert_eq(destroy_prop(fd, prop_id), 0);
/* Look up some invalid property IDs. They should fail. */
igt_assert_eq(validate_prop(fd, 0xffffffff), ENOENT);
igt_assert_eq(validate_prop(fd, 0), ENOENT);
}
static void
test_basic(int fd)
{
uint32_t prop_id;
/* A very simple gating test to ensure property support exists. */
prop_id = create_prop(fd);
igt_assert_eq(destroy_prop(fd, prop_id), 0);
}
static void prop_tests(int fd)
{
struct drm_mode_obj_get_properties get_props = {};
struct drm_mode_obj_set_property set_prop = {};
uint64_t prop, prop_val, blob_id;
igt_fixture
blob_id = create_prop(fd);
get_props.props_ptr = (uintptr_t) ∝
get_props.prop_values_ptr = (uintptr_t) &prop_val;
get_props.count_props = 1;
get_props.obj_id = blob_id;
igt_describe("Tests error handling when invalid properties are fetched with "
"object of any type.");
igt_subtest("invalid-get-prop-any") {
get_props.obj_type = 0; /* DRM_MODE_OBJECT_ANY */
igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES,
&get_props) == -1 && errno == EINVAL);
}
igt_describe("Tests error handling when invalid properties are fetched with blob "
"object type.");
igt_subtest("invalid-get-prop") {
get_props.obj_type = DRM_MODE_OBJECT_BLOB;
igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES,
&get_props) == -1 && errno == EINVAL);
}
set_prop.value = 0;
set_prop.prop_id = 1;
set_prop.obj_id = blob_id;
igt_describe("Tests error handling when invalid properties are set with object "
"of any type.");
igt_subtest("invalid-set-prop-any") {
set_prop.obj_type = 0; /* DRM_MODE_OBJECT_ANY */
igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY,
&set_prop) == -1 && errno == EINVAL);
}
igt_describe("Tests error handling when invalid properties are set with blob object type.");
igt_subtest("invalid-set-prop") {
set_prop.obj_type = DRM_MODE_OBJECT_BLOB;
igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY,
&set_prop) == -1 && errno == EINVAL);
}
igt_fixture
destroy_prop(fd, blob_id);
}
igt_main
{
int fd;
igt_fixture {
fd = drm_open_driver(DRIVER_ANY);
igt_require(fd >= 0);
igt_require_propblob(fd);
}
igt_describe("Test to ensure property support exists.");
igt_subtest("basic")
test_basic(fd);
igt_describe("Tests error handling when invalid property IDs are passed.");
igt_subtest("blob-prop-core")
test_core(fd);
igt_describe("Tests error handling when incorrect blob size is passed.");
igt_subtest("blob-prop-validate")
test_validate(fd);
igt_describe("Tests validates the lifetime of the properties created.");
igt_subtest("blob-prop-lifetime")
test_lifetime(fd);
igt_describe("Test validates destroying multiple properties explicitly works as needed.");
igt_subtest("blob-multiple")
test_multiple(fd);
prop_tests(fd);
igt_fixture
drm_close_driver(fd);
}
|