1*be1cb55aSChris Wilson // SPDX-License-Identifier: MIT
2*be1cb55aSChris Wilson /*
3*be1cb55aSChris Wilson * Copyright © 2020 Intel Corporation
4*be1cb55aSChris Wilson */
5*be1cb55aSChris Wilson
6*be1cb55aSChris Wilson /* Just a quick and causal check of the shmem_utils API */
7*be1cb55aSChris Wilson
igt_shmem_basic(void * ignored)8*be1cb55aSChris Wilson static int igt_shmem_basic(void *ignored)
9*be1cb55aSChris Wilson {
10*be1cb55aSChris Wilson u32 datum = 0xdeadbeef, result;
11*be1cb55aSChris Wilson struct file *file;
12*be1cb55aSChris Wilson u32 *map;
13*be1cb55aSChris Wilson int err;
14*be1cb55aSChris Wilson
15*be1cb55aSChris Wilson file = shmem_create_from_data("mock", &datum, sizeof(datum));
16*be1cb55aSChris Wilson if (IS_ERR(file))
17*be1cb55aSChris Wilson return PTR_ERR(file);
18*be1cb55aSChris Wilson
19*be1cb55aSChris Wilson result = 0;
20*be1cb55aSChris Wilson err = shmem_read(file, 0, &result, sizeof(result));
21*be1cb55aSChris Wilson if (err)
22*be1cb55aSChris Wilson goto out_file;
23*be1cb55aSChris Wilson
24*be1cb55aSChris Wilson if (result != datum) {
25*be1cb55aSChris Wilson pr_err("Incorrect read back from shmemfs: %x != %x\n",
26*be1cb55aSChris Wilson result, datum);
27*be1cb55aSChris Wilson err = -EINVAL;
28*be1cb55aSChris Wilson goto out_file;
29*be1cb55aSChris Wilson }
30*be1cb55aSChris Wilson
31*be1cb55aSChris Wilson result = 0xc0ffee;
32*be1cb55aSChris Wilson err = shmem_write(file, 0, &result, sizeof(result));
33*be1cb55aSChris Wilson if (err)
34*be1cb55aSChris Wilson goto out_file;
35*be1cb55aSChris Wilson
36*be1cb55aSChris Wilson map = shmem_pin_map(file);
37*be1cb55aSChris Wilson if (!map) {
38*be1cb55aSChris Wilson err = -ENOMEM;
39*be1cb55aSChris Wilson goto out_file;
40*be1cb55aSChris Wilson }
41*be1cb55aSChris Wilson
42*be1cb55aSChris Wilson if (*map != result) {
43*be1cb55aSChris Wilson pr_err("Incorrect read back via mmap of last write: %x != %x\n",
44*be1cb55aSChris Wilson *map, result);
45*be1cb55aSChris Wilson err = -EINVAL;
46*be1cb55aSChris Wilson goto out_map;
47*be1cb55aSChris Wilson }
48*be1cb55aSChris Wilson
49*be1cb55aSChris Wilson out_map:
50*be1cb55aSChris Wilson shmem_unpin_map(file, map);
51*be1cb55aSChris Wilson out_file:
52*be1cb55aSChris Wilson fput(file);
53*be1cb55aSChris Wilson return err;
54*be1cb55aSChris Wilson }
55*be1cb55aSChris Wilson
shmem_utils_mock_selftests(void)56*be1cb55aSChris Wilson int shmem_utils_mock_selftests(void)
57*be1cb55aSChris Wilson {
58*be1cb55aSChris Wilson static const struct i915_subtest tests[] = {
59*be1cb55aSChris Wilson SUBTEST(igt_shmem_basic),
60*be1cb55aSChris Wilson };
61*be1cb55aSChris Wilson
62*be1cb55aSChris Wilson return i915_subtests(tests, NULL);
63*be1cb55aSChris Wilson }
64