Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gt / st_shmem_utils.c
blobb279fe88b70ee74f356db5cbfdd48aea4f8230bb
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2020 Intel Corporation
4 */
6 /* Just a quick and causal check of the shmem_utils API */
8 static int igt_shmem_basic(void *ignored)
10 u32 datum = 0xdeadbeef, result;
11 struct file *file;
12 u32 *map;
13 int err;
15 file = shmem_create_from_data("mock", &datum, sizeof(datum));
16 if (IS_ERR(file))
17 return PTR_ERR(file);
19 result = 0;
20 err = shmem_read(file, 0, &result, sizeof(result));
21 if (err)
22 goto out_file;
24 if (result != datum) {
25 pr_err("Incorrect read back from shmemfs: %x != %x\n",
26 result, datum);
27 err = -EINVAL;
28 goto out_file;
31 result = 0xc0ffee;
32 err = shmem_write(file, 0, &result, sizeof(result));
33 if (err)
34 goto out_file;
36 map = shmem_pin_map(file);
37 if (!map) {
38 err = -ENOMEM;
39 goto out_file;
42 if (*map != result) {
43 pr_err("Incorrect read back via mmap of last write: %x != %x\n",
44 *map, result);
45 err = -EINVAL;
46 goto out_map;
49 out_map:
50 shmem_unpin_map(file, map);
51 out_file:
52 fput(file);
53 return err;
56 int shmem_utils_mock_selftests(void)
58 static const struct i915_subtest tests[] = {
59 SUBTEST(igt_shmem_basic),
62 return i915_subtests(tests, NULL);