st_shmem_utils.c 1.1 KB

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