xref: /linux/drivers/gpu/drm/i915/gt/st_shmem_utils.c (revision 95298d63c67673c654c08952672d016212b26054)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 /* Just a quick and causal check of the shmem_utils API */
7 
8 static int igt_shmem_basic(void *ignored)
9 {
10 	u32 datum = 0xdeadbeef, result;
11 	struct file *file;
12 	u32 *map;
13 	int err;
14 
15 	file = shmem_create_from_data("mock", &datum, sizeof(datum));
16 	if (IS_ERR(file))
17 		return PTR_ERR(file);
18 
19 	result = 0;
20 	err = shmem_read(file, 0, &result, sizeof(result));
21 	if (err)
22 		goto out_file;
23 
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;
29 	}
30 
31 	result = 0xc0ffee;
32 	err = shmem_write(file, 0, &result, sizeof(result));
33 	if (err)
34 		goto out_file;
35 
36 	map = shmem_pin_map(file);
37 	if (!map) {
38 		err = -ENOMEM;
39 		goto out_file;
40 	}
41 
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;
47 	}
48 
49 out_map:
50 	shmem_unpin_map(file, map);
51 out_file:
52 	fput(file);
53 	return err;
54 }
55 
56 int shmem_utils_mock_selftests(void)
57 {
58 	static const struct i915_subtest tests[] = {
59 		SUBTEST(igt_shmem_basic),
60 	};
61 
62 	return i915_subtests(tests, NULL);
63 }
64