]> granicus.if.org Git - strace/blob - tests/adjtimex.c
Update copyright headers
[strace] / tests / adjtimex.c
1 /*
2  * This file is part of adjtimex strace test.
3  *
4  * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <string.h>
14 #include <sys/timex.h>
15
16 #include "xlat.h"
17 #include "xlat/adjtimex_state.h"
18 #include "xlat/adjtimex_status.h"
19
20 int
21 main(void)
22 {
23         int state = adjtimex(NULL);
24         printf("adjtimex(NULL) = %s\n", sprintrc(state));
25
26         TAIL_ALLOC_OBJECT_CONST_PTR(struct timex, tx);
27         memset(tx, 0, sizeof(*tx));
28
29         state = adjtimex(tx);
30         if (state < 0)
31                 perror_msg_and_skip("adjtimex");
32
33         printf("adjtimex({modes=0, offset=%jd, freq=%jd, maxerror=%jd"
34                ", esterror=%jd, status=",
35                (intmax_t) tx->offset,
36                (intmax_t) tx->freq,
37                (intmax_t) tx->maxerror,
38                (intmax_t) tx->esterror);
39         if (tx->status)
40                 printflags(adjtimex_status, (unsigned int) tx->status, NULL);
41         else
42                 putchar('0');
43         printf(", constant=%jd, precision=%jd"
44                ", tolerance=%jd, time={tv_sec=%lld, tv_usec=%llu}, tick=%jd"
45                ", ppsfreq=%jd, jitter=%jd, shift=%d, stabil=%jd, jitcnt=%jd"
46                ", calcnt=%jd, errcnt=%jd, stbcnt=%jd"
47 #ifdef HAVE_STRUCT_TIMEX_TAI
48                ", tai=%d"
49 #endif
50                "}) = %d (",
51                (intmax_t) tx->constant,
52                (intmax_t) tx->precision,
53                (intmax_t) tx->tolerance,
54                (long long) tx->time.tv_sec,
55                zero_extend_signed_to_ull(tx->time.tv_usec),
56                (intmax_t) tx->tick,
57                (intmax_t) tx->ppsfreq,
58                (intmax_t) tx->jitter,
59                tx->shift,
60                (intmax_t) tx->stabil,
61                (intmax_t) tx->jitcnt,
62                (intmax_t) tx->calcnt,
63                (intmax_t) tx->errcnt,
64                (intmax_t) tx->stbcnt,
65 #ifdef HAVE_STRUCT_TIMEX_TAI
66                tx->tai,
67 #endif
68                state);
69         printxval(adjtimex_state, (unsigned int) state, NULL);
70         puts(")");
71
72         puts("+++ exited with 0 +++");
73         return 0;
74 }