tools/testing/selftests/proc/proc-uptime-001.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-uptime-001.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/proc/proc-uptime-001.c
Extension
.c
Size
1638 bytes
Lines
59
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

// Test that boottime value in /proc/uptime and CLOCK_BOOTTIME increment
// monotonically. We don't test idle time monotonicity due to broken iowait
// task counting, cf: comment above get_cpu_idle_time_us()
#undef NDEBUG
#include <assert.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "proc-uptime.h"

int main(void)
{
	uint64_t start, u0, u1, c0, c1;
	int fd;

	fd = open("/proc/uptime", O_RDONLY);
	assert(fd >= 0);

	u0 = proc_uptime(fd);
	start = u0;
	c0 = clock_boottime();

	do {
		u1 = proc_uptime(fd);
		c1 = clock_boottime();

		/* Is /proc/uptime monotonic ? */
		assert(u1 >= u0);

		/* Is CLOCK_BOOTTIME monotonic ? */
		assert(c1 >= c0);

		/* Is CLOCK_BOOTTIME VS /proc/uptime monotonic ? */
		assert(c0 >= u0);

		u0 = u1;
		c0 = c1;
	} while (u1 - start < 100);

	return 0;
}

Annotation

Implementation Notes