tools/testing/selftests/alsa/utimer-test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/alsa/utimer-test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/alsa/utimer-test.c
Extension
.c
Size
4197 bytes
Lines
173
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 (parse_timer_output(buf)) {
		case TIMER_APP_STARTED:
			/* global-timer waits for timer to trigger, so start the ticking thread */
			pthread_create(&ticking_thread, NULL, ticking_func,
				       &self->utimer_info->fd);
			break;
		case TIMER_APP_RESULT:
			total_ticks = parse_timer_result(buf);
			break;
		case TIMER_NO_EVENT:
			break;
		}
	}
	pthread_join(ticking_thread, NULL);
	ASSERT_EQ(total_ticks, TICKS_COUNT);
	pclose(rfp);
	free(buf);
}

TEST(wrong_timers_test) {
	int timer_dev_fd;
	int utimer_fd;
	struct snd_timer_uinfo wrong_timer = {
		.resolution = 0,
		.id = UTIMER_DEFAULT_ID,
		.fd = UTIMER_DEFAULT_FD,
	};

	timer_dev_fd = open("/dev/snd/timer", O_RDONLY);
	ASSERT_GE(timer_dev_fd, 0);

	utimer_fd = ioctl(timer_dev_fd, SNDRV_TIMER_IOCTL_CREATE, &wrong_timer);
	ASSERT_LT(utimer_fd, 0);
	/* Check that id was not updated */
	ASSERT_EQ(wrong_timer.id, UTIMER_DEFAULT_ID);

	/* Test the NULL as an argument is processed correctly */
	ASSERT_LT(ioctl(timer_dev_fd, SNDRV_TIMER_IOCTL_CREATE, NULL), 0);

	close(timer_dev_fd);
}

TEST_HARNESS_MAIN

Annotation

Implementation Notes