1/*
2 * This file is part of adjtimex strace test.
3 *
4 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "tests.h"
31#include <stdio.h>
32#include <stdint.h>
33#include <string.h>
34#include <sys/timex.h>
35
36#include "xlat.h"
37#include "xlat/adjtimex_state.h"
38#include "xlat/adjtimex_status.h"
39
40int
41main(void)
42{
43	int state = adjtimex(NULL);
44	printf("adjtimex(NULL) = %s\n", sprintrc(state));
45
46	TAIL_ALLOC_OBJECT_CONST_PTR(struct timex, tx);
47	memset(tx, 0, sizeof(*tx));
48
49	state = adjtimex(tx);
50	if (state < 0)
51		perror_msg_and_skip("adjtimex");
52
53	printf("adjtimex({modes=0, offset=%jd, freq=%jd, maxerror=%jd"
54	       ", esterror=%jd, status=",
55	       (intmax_t) tx->offset,
56	       (intmax_t) tx->freq,
57	       (intmax_t) tx->maxerror,
58	       (intmax_t) tx->esterror);
59	if (tx->status)
60		printflags(adjtimex_status, (unsigned int) tx->status, NULL);
61	else
62		putchar('0');
63	printf(", constant=%jd, precision=%jd"
64	       ", tolerance=%jd, time={tv_sec=%lld, tv_usec=%llu}, tick=%jd"
65	       ", ppsfreq=%jd, jitter=%jd, shift=%d, stabil=%jd, jitcnt=%jd"
66	       ", calcnt=%jd, errcnt=%jd, stbcnt=%jd"
67#ifdef HAVE_STRUCT_TIMEX_TAI
68	       ", tai=%d"
69#endif
70	       "}) = %d (",
71	       (intmax_t) tx->constant,
72	       (intmax_t) tx->precision,
73	       (intmax_t) tx->tolerance,
74	       (long long) tx->time.tv_sec,
75	       zero_extend_signed_to_ull(tx->time.tv_usec),
76	       (intmax_t) tx->tick,
77	       (intmax_t) tx->ppsfreq,
78	       (intmax_t) tx->jitter,
79	       tx->shift,
80	       (intmax_t) tx->stabil,
81	       (intmax_t) tx->jitcnt,
82	       (intmax_t) tx->calcnt,
83	       (intmax_t) tx->errcnt,
84	       (intmax_t) tx->stbcnt,
85#ifdef HAVE_STRUCT_TIMEX_TAI
86	       tx->tai,
87#endif
88	       state);
89	printxval(adjtimex_state, (unsigned int) state, NULL);
90	puts(")");
91
92	puts("+++ exited with 0 +++");
93	return 0;
94}
95