tools/testing/selftests/vDSO/vdso_test_abi.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/vDSO/vdso_test_abi.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/vDSO/vdso_test_abi.c
Extension
.c
Size
8029 bytes
Lines
300
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

struct vdso_timespec64 {
	uint64_t tv_sec;
	uint64_t tv_nsec;
};

typedef long (*vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz);
typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
typedef long (*vdso_clock_gettime64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
typedef long (*vdso_clock_getres_time64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
typedef time_t (*vdso_time_t)(time_t *t);

static const char * const vdso_clock_name[] = {
	[CLOCK_REALTIME]		= "CLOCK_REALTIME",
	[CLOCK_MONOTONIC]		= "CLOCK_MONOTONIC",
	[CLOCK_PROCESS_CPUTIME_ID]	= "CLOCK_PROCESS_CPUTIME_ID",
	[CLOCK_THREAD_CPUTIME_ID]	= "CLOCK_THREAD_CPUTIME_ID",
	[CLOCK_MONOTONIC_RAW]		= "CLOCK_MONOTONIC_RAW",
	[CLOCK_REALTIME_COARSE]		= "CLOCK_REALTIME_COARSE",
	[CLOCK_MONOTONIC_COARSE]	= "CLOCK_MONOTONIC_COARSE",
	[CLOCK_BOOTTIME]		= "CLOCK_BOOTTIME",
	[CLOCK_REALTIME_ALARM]		= "CLOCK_REALTIME_ALARM",
	[CLOCK_BOOTTIME_ALARM]		= "CLOCK_BOOTTIME_ALARM",
	[10 /* CLOCK_SGI_CYCLE */]	= "CLOCK_SGI_CYCLE",
	[CLOCK_TAI]			= "CLOCK_TAI",
};

static void vdso_test_gettimeofday(void)
{
	/* Find gettimeofday. */
	vdso_gettimeofday_t vdso_gettimeofday =
		(vdso_gettimeofday_t)vdso_sym(version, name[0]);

	if (!vdso_gettimeofday) {
		ksft_print_msg("Couldn't find %s\n", name[0]);
		ksft_test_result_skip("%s\n", name[0]);
		return;
	}

	struct timeval tv;
	long ret = VDSO_CALL(vdso_gettimeofday, 2, &tv, 0);

	if (ret == 0) {
		ksft_print_msg("The time is %lld.%06lld\n",
			       (long long)tv.tv_sec, (long long)tv.tv_usec);
		ksft_test_result_pass("%s\n", name[0]);
	} else {
		ksft_test_result_fail("%s\n", name[0]);
	}
}

static void vdso_test_clock_gettime64(clockid_t clk_id)
{
	/* Find clock_gettime64. */
	vdso_clock_gettime64_t vdso_clock_gettime64 =
		(vdso_clock_gettime64_t)vdso_sym(version, name[5]);

	if (!vdso_clock_gettime64) {
		ksft_print_msg("Couldn't find %s\n", name[5]);
		ksft_test_result_skip("%s %s\n", name[5],
				      vdso_clock_name[clk_id]);
		return;
	}

	struct vdso_timespec64 ts;
	long ret = VDSO_CALL(vdso_clock_gettime64, 2, clk_id, &ts);

	if (ret == 0) {
		ksft_print_msg("The time is %lld.%06lld\n",
			       (long long)ts.tv_sec, (long long)ts.tv_nsec);
		ksft_test_result_pass("%s %s\n", name[5],
				      vdso_clock_name[clk_id]);
	} else {
		ksft_test_result_fail("%s %s\n", name[5],
				      vdso_clock_name[clk_id]);
	}
}

static void vdso_test_clock_gettime(clockid_t clk_id)
{
	/* Find clock_gettime. */
	vdso_clock_gettime_t vdso_clock_gettime =
		(vdso_clock_gettime_t)vdso_sym(version, name[1]);

	if (!vdso_clock_gettime) {
		ksft_print_msg("Couldn't find %s\n", name[1]);
		ksft_test_result_skip("%s %s\n", name[1],
				      vdso_clock_name[clk_id]);
		return;
	}

Annotation

Implementation Notes