(root)/
strace-6.5/
tests-m32/
timer_create.c
       1  /*
       2   * Check decoding of timer_create syscall.
       3   *
       4   * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2015-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #include <stdio.h>
      15  #include <signal.h>
      16  #include <time.h>
      17  #include <unistd.h>
      18  #include "sigevent.h"
      19  
      20  int
      21  main(void)
      22  {
      23  	syscall(__NR_timer_create, CLOCK_REALTIME, NULL, NULL);
      24  	printf("timer_create(CLOCK_REALTIME, NULL, NULL) = -1 %s (%m)\n",
      25  	       errno2name());
      26  
      27  	int tid[4] = {};
      28  	struct_sigevent sev = {
      29  		.sigev_notify = 0xdefaced,
      30  		.sigev_signo = 0xfacefeed,
      31  		.sigev_value.sival_ptr =
      32  			(void *) (unsigned long) 0xdeadbeefbadc0dedULL
      33  	};
      34  
      35  	syscall(__NR_timer_create, CLOCK_REALTIME, &sev, NULL);
      36  	printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
      37  	       "sival_ptr=%p}, sigev_signo=%u, "
      38  	       "sigev_notify=%#x /* SIGEV_??? */}, NULL) = -1 %s (%m)\n",
      39  	       sev.sigev_value.sival_int,
      40  	       sev.sigev_value.sival_ptr,
      41  	       sev.sigev_signo, sev.sigev_notify,
      42  	       errno2name());
      43  
      44  	sev.sigev_notify = SIGEV_NONE;
      45  	if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0]))
      46  		perror_msg_and_skip("timer_create CLOCK_REALTIME");
      47  	printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
      48  	       "sival_ptr=%p}, sigev_signo=%u, sigev_notify=SIGEV_NONE}, "
      49  	       "[%d]) = 0\n",
      50  	       sev.sigev_value.sival_int,
      51  	       sev.sigev_value.sival_ptr,
      52  	       sev.sigev_signo, tid[0]);
      53  
      54  	sev.sigev_notify = SIGEV_SIGNAL;
      55  	sev.sigev_signo = SIGALRM;
      56  	if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1]))
      57  		perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
      58  	printf("timer_create(CLOCK_MONOTONIC, {sigev_value={sival_int=%d, "
      59  	       "sival_ptr=%p}, sigev_signo=SIGALRM, "
      60  	       "sigev_notify=SIGEV_SIGNAL}, [%d]) = 0\n",
      61  	       sev.sigev_value.sival_int,
      62  	       sev.sigev_value.sival_ptr, tid[1]);
      63  
      64  	sev.sigev_notify = SIGEV_THREAD;
      65  	sev.sigev_un.sigev_thread.function =
      66  		(void *) (unsigned long) 0xdeadbeefbadc0dedULL;
      67  	sev.sigev_un.sigev_thread.attribute =
      68  		(void *) (unsigned long) 0xcafef00dfacefeedULL;
      69  	if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
      70  		perror_msg_and_skip("timer_create CLOCK_REALTIME");
      71  	printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
      72  	       "sival_ptr=%p}, sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
      73  	       ", sigev_notify_function=%p, sigev_notify_attributes=%p}"
      74  	       ", [%d]) = 0\n",
      75  	       sev.sigev_value.sival_int,
      76  	       sev.sigev_value.sival_ptr,
      77  	       sev.sigev_un.sigev_thread.function,
      78  	       sev.sigev_un.sigev_thread.attribute,
      79  	       tid[2]);
      80  
      81  #ifndef SIGEV_THREAD_ID
      82  # define SIGEV_THREAD_ID 4
      83  #endif
      84  	sev.sigev_notify = SIGEV_THREAD_ID;
      85  	sev.sigev_un.tid = getpid();
      86  	if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
      87  		perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
      88  	printf("timer_create(CLOCK_MONOTONIC, {sigev_value={sival_int=%d, "
      89  	       "sival_ptr=%p}, sigev_signo=SIGALRM, "
      90  	       "sigev_notify=SIGEV_THREAD_ID, sigev_notify_thread_id=%d}"
      91  	       ", [%d]) = 0\n",
      92  	       sev.sigev_value.sival_int,
      93  	       sev.sigev_value.sival_ptr,
      94  	       sev.sigev_un.tid,
      95  	       tid[3]);
      96  
      97  	puts("+++ exited with 0 +++");
      98  	return 0;
      99  }