media_device_open.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * media_device_open.c - Media Controller Device Open Test
  4. *
  5. * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
  6. * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  7. *
  8. */
  9. /*
  10. * This file adds a test for Media Controller API.
  11. * This test should be run as root and should not be
  12. * included in the Kselftest run. This test should be
  13. * run when hardware and driver that makes use Media
  14. * Controller API are present in the system.
  15. *
  16. * This test opens user specified Media Device and calls
  17. * MEDIA_IOC_DEVICE_INFO ioctl, closes the file, and exits.
  18. *
  19. * Usage:
  20. * sudo ./media_device_open -d /dev/mediaX
  21. *
  22. * Run this test is a loop and run bind/unbind on the driver.
  23. */
  24. #include <stdio.h>
  25. #include <unistd.h>
  26. #include <stdlib.h>
  27. #include <errno.h>
  28. #include <string.h>
  29. #include <fcntl.h>
  30. #include <sys/ioctl.h>
  31. #include <sys/stat.h>
  32. #include <linux/media.h>
  33. #include "../kselftest.h"
  34. int main(int argc, char **argv)
  35. {
  36. int opt;
  37. char media_device[256];
  38. int count = 0;
  39. struct media_device_info mdi;
  40. int ret;
  41. int fd;
  42. if (argc < 2) {
  43. printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
  44. exit(-1);
  45. }
  46. /* Process arguments */
  47. while ((opt = getopt(argc, argv, "d:")) != -1) {
  48. switch (opt) {
  49. case 'd':
  50. strncpy(media_device, optarg, sizeof(media_device) - 1);
  51. media_device[sizeof(media_device)-1] = '\0';
  52. break;
  53. default:
  54. printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
  55. exit(-1);
  56. }
  57. }
  58. if (getuid() != 0)
  59. ksft_exit_skip("Please run the test as root - Exiting.\n");
  60. /* Open Media device and keep it open */
  61. fd = open(media_device, O_RDWR);
  62. if (fd == -1) {
  63. printf("Media Device open errno %s\n", strerror(errno));
  64. exit(-1);
  65. }
  66. ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
  67. if (ret < 0)
  68. printf("Media Device Info errno %s\n", strerror(errno));
  69. else
  70. printf("Media device model %s driver %s\n",
  71. mdi.model, mdi.driver);
  72. }