1 /* 2 * SPDX-License-Identifier: MIT 3 * 4 * Copyright © 2016 Intel Corporation 5 */ 6 7 #include "i915_selftest.h" 8 9 #include "huge_gem_object.h" 10 #include "selftests/igt_flush_test.h" 11 #include "selftests/mock_gem_device.h" 12 13 static int igt_gem_object(void *arg) 14 { 15 struct drm_i915_private *i915 = arg; 16 struct drm_i915_gem_object *obj; 17 int err; 18 19 /* Basic test to ensure we can create an object */ 20 21 obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); 22 if (IS_ERR(obj)) { 23 err = PTR_ERR(obj); 24 pr_err("i915_gem_object_create failed, err=%d\n", err); 25 goto out; 26 } 27 28 err = 0; 29 i915_gem_object_put(obj); 30 out: 31 return err; 32 } 33 34 static int igt_gem_huge(void *arg) 35 { 36 const unsigned int nreal = 509; /* just to be awkward */ 37 struct drm_i915_private *i915 = arg; 38 struct drm_i915_gem_object *obj; 39 unsigned int n; 40 int err; 41 42 /* Basic sanitycheck of our huge fake object allocation */ 43 44 obj = huge_gem_object(i915, 45 nreal * PAGE_SIZE, 46 to_gt(i915)->ggtt->vm.total + PAGE_SIZE); 47 if (IS_ERR(obj)) 48 return PTR_ERR(obj); 49 50 err = i915_gem_object_pin_pages_unlocked(obj); 51 if (err) { 52 pr_err("Failed to allocate %u pages (%lu total), err=%d\n", 53 nreal, obj->base.size / PAGE_SIZE, err); 54 goto out; 55 } 56 57 for (n = 0; n < obj->base.size / PAGE_SIZE; n++) { 58 if (i915_gem_object_get_page(obj, n) != 59 i915_gem_object_get_page(obj, n % nreal)) { 60 pr_err("Page lookup mismatch at index %u [%u]\n", 61 n, n % nreal); 62 err = -EINVAL; 63 goto out_unpin; 64 } 65 } 66 67 out_unpin: 68 i915_gem_object_unpin_pages(obj); 69 out: 70 i915_gem_object_put(obj); 71 return err; 72 } 73 74 int i915_gem_object_mock_selftests(void) 75 { 76 static const struct i915_subtest tests[] = { 77 SUBTEST(igt_gem_object), 78 }; 79 struct drm_i915_private *i915; 80 int err; 81 82 i915 = mock_gem_device(); 83 if (!i915) 84 return -ENOMEM; 85 86 err = i915_subtests(tests, i915); 87 88 mock_destroy_device(i915); 89 return err; 90 } 91 92 int i915_gem_object_live_selftests(struct drm_i915_private *i915) 93 { 94 static const struct i915_subtest tests[] = { 95 SUBTEST(igt_gem_huge), 96 }; 97 98 return i915_subtests(tests, i915); 99 } 100