tools/testing/selftests/timers/valid-adjtimex.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/valid-adjtimex.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/valid-adjtimex.c- Extension
.c- Size
- 6916 bytes
- Lines
- 328
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.htime.hsys/time.hsys/timex.hstring.hsignal.hunistd.hinclude/vdso/time64.hkselftest.hsys/syscall.h
Detected Declarations
function clock_adjtimefunction clear_time_statefunction validate_freqfunction set_offsetfunction set_bad_offsetfunction validate_set_offsetfunction main
Annotated Snippet
if (ret < 0) {
printf("[FAIL]\n");
printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
valid_freq[i], valid_freq[i]>>16);
pass = -1;
goto out;
}
tx.modes = 0;
ret = adjtimex(&tx);
if (tx.freq != valid_freq[i]) {
printf("Warning: freq value %ld not what we set it (%ld)!\n",
tx.freq, valid_freq[i]);
}
}
for (i = 0; i < NUM_FREQ_OUTOFRANGE; i++) {
tx.modes = ADJ_FREQUENCY;
tx.freq = outofrange_freq[i];
ret = adjtimex(&tx);
if (ret < 0) {
printf("[FAIL]\n");
printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
outofrange_freq[i], outofrange_freq[i]>>16);
pass = -1;
goto out;
}
tx.modes = 0;
ret = adjtimex(&tx);
if (tx.freq == outofrange_freq[i]) {
printf("[FAIL]\n");
printf("ERROR: out of range value %ld actually set!\n",
tx.freq);
pass = -1;
goto out;
}
}
if (sizeof(long) == 8) { /* this case only applies to 64bit systems */
for (i = 0; i < NUM_FREQ_INVALID; i++) {
tx.modes = ADJ_FREQUENCY;
tx.freq = invalid_freq[i];
ret = adjtimex(&tx);
if (ret >= 0) {
printf("[FAIL]\n");
printf("Error: No failure on invalid ADJ_FREQUENCY %ld\n",
invalid_freq[i]);
pass = -1;
goto out;
}
}
}
printf("[OK]\n");
out:
/* reset freq to zero */
tx.modes = ADJ_FREQUENCY;
tx.freq = 0;
ret = adjtimex(&tx);
return pass;
}
int set_offset(long long offset, int use_nano)
{
struct timex tmx = {};
int ret;
tmx.modes = ADJ_SETOFFSET;
if (use_nano) {
tmx.modes |= ADJ_NANO;
tmx.time.tv_sec = offset / NSEC_PER_SEC;
tmx.time.tv_usec = offset % NSEC_PER_SEC;
if (offset < 0 && tmx.time.tv_usec) {
tmx.time.tv_sec -= 1;
tmx.time.tv_usec += NSEC_PER_SEC;
}
} else {
tmx.time.tv_sec = offset / USEC_PER_SEC;
tmx.time.tv_usec = offset % USEC_PER_SEC;
if (offset < 0 && tmx.time.tv_usec) {
tmx.time.tv_sec -= 1;
tmx.time.tv_usec += USEC_PER_SEC;
}
}
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `time.h`, `sys/time.h`, `sys/timex.h`, `string.h`, `signal.h`, `unistd.h`.
- Detected declarations: `function clock_adjtime`, `function clear_time_state`, `function validate_freq`, `function set_offset`, `function set_bad_offset`, `function validate_set_offset`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.