tools/testing/selftests/media_tests/media_device_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/media_tests/media_device_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/media_tests/media_device_test.c
Extension
.c
Size
2564 bytes
Lines
104
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (opt) {
		case 'd':
			strncpy(media_device, optarg, sizeof(media_device) - 1);
			media_device[sizeof(media_device)-1] = '\0';
			break;
		default:
			printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
			exit(-1);
		}
	}

	if (getuid() != 0)
		ksft_exit_skip("Please run the test as root - Exiting.\n");

	/* Generate random number of interations */
	srand((unsigned int) time(NULL));
	count = rand();

	/* Open Media device and keep it open */
	fd = open(media_device, O_RDWR);
	if (fd == -1) {
		printf("Media Device open errno %s\n", strerror(errno));
		exit(-1);
	}

	printf("\nNote:\n"
	       "While test is running, remove the device and\n"
	       "ensure there are no use after free errors and\n"
	       "other Oops in the dmesg. Enable KaSan kernel\n"
	       "config option for use-after-free error detection.\n\n");

	printf("Running test for %d iterations\n", count);

	while (count > 0) {
		ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
		if (ret < 0)
			printf("Media Device Info errno %s\n", strerror(errno));
		else
			printf("Media device model %s driver %s - count %d\n",
				mdi.model, mdi.driver, count);
		sleep(10);
		count--;
	}
}

Annotation

Implementation Notes