Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: MIT
0002 /*
0003  * Copyright © 2020 Intel Corporation
0004  */
0005 
0006 /* Just a quick and causal check of the shmem_utils API */
0007 
0008 static int igt_shmem_basic(void *ignored)
0009 {
0010     u32 datum = 0xdeadbeef, result;
0011     struct file *file;
0012     u32 *map;
0013     int err;
0014 
0015     file = shmem_create_from_data("mock", &datum, sizeof(datum));
0016     if (IS_ERR(file))
0017         return PTR_ERR(file);
0018 
0019     result = 0;
0020     err = shmem_read(file, 0, &result, sizeof(result));
0021     if (err)
0022         goto out_file;
0023 
0024     if (result != datum) {
0025         pr_err("Incorrect read back from shmemfs: %x != %x\n",
0026                result, datum);
0027         err = -EINVAL;
0028         goto out_file;
0029     }
0030 
0031     result = 0xc0ffee;
0032     err = shmem_write(file, 0, &result, sizeof(result));
0033     if (err)
0034         goto out_file;
0035 
0036     map = shmem_pin_map(file);
0037     if (!map) {
0038         err = -ENOMEM;
0039         goto out_file;
0040     }
0041 
0042     if (*map != result) {
0043         pr_err("Incorrect read back via mmap of last write: %x != %x\n",
0044                *map, result);
0045         err = -EINVAL;
0046         goto out_map;
0047     }
0048 
0049 out_map:
0050     shmem_unpin_map(file, map);
0051 out_file:
0052     fput(file);
0053     return err;
0054 }
0055 
0056 int shmem_utils_mock_selftests(void)
0057 {
0058     static const struct i915_subtest tests[] = {
0059         SUBTEST(igt_shmem_basic),
0060     };
0061 
0062     return i915_subtests(tests, NULL);
0063 }