(root)/
strace-6.5/
tests-mx32/
adjtimex.c
       1  /*
       2   * This file is part of adjtimex strace test.
       3   *
       4   * Copyright (c) 2015-2021 Dmitry V. Levin <ldv@strace.io>
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  
      13  #ifdef __NR_adjtimex
      14  
      15  # include <stddef.h>
      16  # include <stdio.h>
      17  # include <stdint.h>
      18  # include <string.h>
      19  # include <sys/timex.h>
      20  # include <unistd.h>
      21  
      22  # include "kernel_old_timex.h"
      23  
      24  # include "xlat.h"
      25  # include "xlat/adjtimex_state.h"
      26  # include "xlat/adjtimex_status.h"
      27  
      28  static const char *errstr;
      29  
      30  static long
      31  k_adjtimex(void *const buf)
      32  {
      33  	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
      34  	const kernel_ulong_t arg1 = (uintptr_t) buf;
      35  	const long rc = syscall(__NR_adjtimex, arg1, bad, bad, bad, bad, bad);
      36  	errstr = sprintrc(rc);
      37  	return rc;
      38  }
      39  
      40  int
      41  main(void)
      42  {
      43  	int state = k_adjtimex(NULL);
      44  	printf("adjtimex(NULL) = %s\n", errstr);
      45  
      46  	TAIL_ALLOC_OBJECT_CONST_PTR(kernel_old_timex_t, tx);
      47  	memset(tx, 0, sizeof(*tx));
      48  
      49  	state = k_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, tai=%d"
      67  	       "}) = %d (",
      68  	       (intmax_t) tx->constant,
      69  	       (intmax_t) tx->precision,
      70  	       (intmax_t) tx->tolerance,
      71  	       (long long) tx->time.tv_sec,
      72  	       zero_extend_signed_to_ull(tx->time.tv_usec),
      73  	       (intmax_t) tx->tick,
      74  	       (intmax_t) tx->ppsfreq,
      75  	       (intmax_t) tx->jitter,
      76  	       tx->shift,
      77  	       (intmax_t) tx->stabil,
      78  	       (intmax_t) tx->jitcnt,
      79  	       (intmax_t) tx->calcnt,
      80  	       (intmax_t) tx->errcnt,
      81  	       (intmax_t) tx->stbcnt,
      82  	       tx->tai,
      83  	       state);
      84  	printxval(adjtimex_state, (unsigned int) state, NULL);
      85  	puts(")");
      86  
      87  	puts("+++ exited with 0 +++");
      88  	return 0;
      89  }
      90  
      91  #else
      92  
      93  SKIP_MAIN_UNDEFINED("__NR_adjtimex")
      94  
      95  #endif