1 // SPDX-License-Identifier: GPL-2.0
4 * media_device_test.c - Media Controller Device ioctl loop Test
6 * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
7 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
12 * This file adds a test for Media Controller API.
13 * This test should be run as root and should not be
14 * included in the Kselftest run. This test should be
15 * run when hardware and driver that makes use Media
16 * Controller API are present in the system.
18 * This test opens user specified Media Device and calls
19 * MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10
23 * sudo ./media_device_test -d /dev/mediaX
25 * While test is running, remove the device and
26 * ensure there are no use after free errors and
27 * other Oops in the dmesg. Enable KaSan kernel
28 * config option for use-after-free error detection.
37 #include <sys/ioctl.h>
40 #include <linux/media.h>
42 #include "../kselftest.h"
44 int main(int argc
, char **argv
)
47 char media_device
[256];
49 struct media_device_info mdi
;
54 printf("Usage: %s [-d </dev/mediaX>]\n", argv
[0]);
58 /* Process arguments */
59 while ((opt
= getopt(argc
, argv
, "d:")) != -1) {
62 strncpy(media_device
, optarg
, sizeof(media_device
) - 1);
63 media_device
[sizeof(media_device
)-1] = '\0';
66 printf("Usage: %s [-d </dev/mediaX>]\n", argv
[0]);
72 ksft_exit_skip("Please run the test as root - Exiting.\n");
74 /* Generate random number of interations */
75 srand((unsigned int) time(NULL
));
78 /* Open Media device and keep it open */
79 fd
= open(media_device
, O_RDWR
);
81 printf("Media Device open errno %s\n", strerror(errno
));
86 "While test is running, remove the device and\n"
87 "ensure there are no use after free errors and\n"
88 "other Oops in the dmesg. Enable KaSan kernel\n"
89 "config option for use-after-free error detection.\n\n");
91 printf("Running test for %d iterations\n", count
);
94 ret
= ioctl(fd
, MEDIA_IOC_DEVICE_INFO
, &mdi
);
96 printf("Media Device Info errno %s\n", strerror(errno
));
98 printf("Media device model %s driver %s - count %d\n",
99 mdi
.model
, mdi
.driver
, count
);