(root)/
strace-6.5/
tests-m32/
ioctl_lirc.c
       1  /*
       2   * Check LIRC_* ioctl decoding
       3   *
       4   * Copyright (C) 2022 Sean Young <sean@mess.org>
       5   */
       6  
       7  #include "tests.h"
       8  #include <stdio.h>
       9  #include <stdlib.h>
      10  #include <sys/ioctl.h>
      11  #include <linux/lirc.h>
      12  
      13  static const char *errstr;
      14  
      15  static long
      16  do_ioctl(kernel_ulong_t cmd, unsigned int *arg)
      17  {
      18  	long rc = ioctl(-1, cmd, arg);
      19  
      20  	errstr = sprintrc(rc);
      21  
      22  #ifdef INJECT_RETVAL
      23  	if (rc != INJECT_RETVAL)
      24  		error_msg_and_fail("Got a return value of %ld != %ld",
      25  				   rc, (long) INJECT_RETVAL);
      26  
      27  	static char inj_errstr[4096];
      28  
      29  	snprintf(inj_errstr, sizeof(inj_errstr), "%s (INJECTED)", errstr);
      30  	errstr = inj_errstr;
      31  #endif
      32  
      33  	return rc;
      34  }
      35  
      36  int
      37  main(int argc, char *argv[])
      38  {
      39  #ifdef INJECT_RETVAL
      40  	unsigned long num_skip;
      41  	bool locked = false;
      42  
      43  	if (argc < 2)
      44  		error_msg_and_fail("Usage: %s NUM_SKIP", argv[0]);
      45  
      46  	num_skip = strtoul(argv[1], NULL, 0);
      47  
      48  	for (size_t i = 0; i < num_skip; i++) {
      49  		long ret = ioctl(-1, LIRC_GET_FEATURES, 0);
      50  
      51  		printf("ioctl(-1, LIRC_GET_FEATURES, NULL) = %s%s\n",
      52  		       sprintrc(ret),
      53  		       ret == INJECT_RETVAL ? " (INJECTED)" : "");
      54  
      55  		if (ret != INJECT_RETVAL)
      56  			continue;
      57  
      58  		locked = true;
      59  		break;
      60  	}
      61  
      62  	if (!locked)
      63  		error_msg_and_fail("Hasn't locked on ioctl(-1"
      64  				   ", LIRC_GET_FEATURES, NULL) returning %d",
      65  				   INJECT_RETVAL);
      66  #endif
      67  
      68  	TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, value);
      69  
      70  	*value = 12000;
      71  	do_ioctl(LIRC_SET_REC_TIMEOUT, value);
      72  	printf("ioctl(-1, LIRC_SET_REC_TIMEOUT, [12000]) = %s\n", errstr);
      73  
      74  	*value = 1;
      75  	do_ioctl(LIRC_SET_WIDEBAND_RECEIVER, value);
      76  	printf("ioctl(-1, LIRC_SET_WIDEBAND_RECEIVER, [1]) = %s\n", errstr);
      77  
      78  	*value = 0;
      79  	do_ioctl(LIRC_SET_MEASURE_CARRIER_MODE, value);
      80  	printf("ioctl(-1, LIRC_SET_MEASURE_CARRIER_MODE, [0]) = %s\n", errstr);
      81  
      82  	*value = 4294967295;
      83  	do_ioctl(LIRC_SET_REC_TIMEOUT_REPORTS, value);
      84  	printf("ioctl(-1, LIRC_SET_REC_TIMEOUT_REPORTS, [4294967295]) = %s\n",
      85  	       errstr);
      86  
      87  	*value = 33;
      88  	do_ioctl(LIRC_SET_SEND_DUTY_CYCLE, value);
      89  	printf("ioctl(-1, LIRC_SET_SEND_DUTY_CYCLE, [33]) = %s\n", errstr);
      90  
      91  	*value = 38000;
      92  	do_ioctl(LIRC_SET_SEND_CARRIER, value);
      93  	printf("ioctl(-1, LIRC_SET_SEND_CARRIER, [38000]) = %s\n", errstr);
      94  
      95  	*value = 20000;
      96  	do_ioctl(LIRC_SET_REC_CARRIER, value);
      97  	printf("ioctl(-1, LIRC_SET_REC_CARRIER, [20000]) = %s\n", errstr);
      98  
      99  	*value = 40000;
     100  	do_ioctl(LIRC_SET_REC_CARRIER_RANGE, value);
     101  	printf("ioctl(-1, IPMICTL_SET_MAINTENANCE_MODE_CMD or "
     102  	       "LIRC_SET_REC_CARRIER_RANGE, [40000]) = %s\n",
     103  	       errstr);
     104  
     105  	*value = 2;
     106  	do_ioctl(LIRC_SET_SEND_MODE, value);
     107  	printf("ioctl(-1, LIRC_SET_SEND_MODE, [LIRC_MODE_PULSE]) = %s\n",
     108  	       errstr);
     109  
     110  	*value = 8;
     111  	do_ioctl(LIRC_SET_SEND_MODE, value);
     112  	printf("ioctl(-1, LIRC_SET_SEND_MODE, [LIRC_MODE_SCANCODE]) = %s\n",
     113  	       errstr);
     114  
     115  	*value = 4;
     116  	do_ioctl(LIRC_SET_REC_MODE, value);
     117  	printf("ioctl(-1, LIRC_SET_REC_MODE, [LIRC_MODE_MODE2]) = %s\n",
     118  	       errstr);
     119  
     120  	*value = 16;
     121  	do_ioctl(LIRC_SET_REC_MODE, value);
     122  	printf("ioctl(-1, LIRC_SET_REC_MODE, [LIRC_MODE_LIRCCODE]) = %s\n",
     123  	       errstr);
     124  
     125  	*value = 3;
     126  	do_ioctl(LIRC_SET_REC_MODE, value);
     127  	printf("ioctl(-1, LIRC_SET_REC_MODE, [0x3 /* LIRC_MODE_??? */]) = %s\n",
     128  	       errstr);
     129  
     130  	*value = 31;
     131  	do_ioctl(LIRC_SET_TRANSMITTER_MASK, value);
     132  	printf("ioctl(-1, LIRC_SET_TRANSMITTER_MASK, [0x1f]) = %s\n",
     133  	       errstr);
     134  
     135  	/* read ioctls */
     136  
     137  #ifdef INJECT_RETVAL
     138  
     139  	*value = LIRC_CAN_SEND_PULSE | LIRC_CAN_SET_SEND_DUTY_CYCLE |
     140  		LIRC_CAN_GET_REC_RESOLUTION | LIRC_CAN_USE_WIDEBAND_RECEIVER |
     141  		0x008000000;
     142  	do_ioctl(LIRC_GET_FEATURES, value);
     143  	printf("ioctl(-1, LIRC_GET_FEATURES, [LIRC_CAN_SEND_PULSE"
     144  	       "|LIRC_CAN_SET_SEND_DUTY_CYCLE|LIRC_CAN_USE_WIDEBAND_RECEIVER"
     145  	       "|LIRC_CAN_GET_REC_RESOLUTION|0x8000000]) = %s\n",
     146  	       errstr);
     147  
     148  	*value = 0;
     149  	do_ioctl(LIRC_GET_FEATURES, value);
     150  	printf("ioctl(-1, LIRC_GET_FEATURES, [0]) = %s\n",
     151  	       errstr);
     152  
     153  	*value = 1;
     154  	do_ioctl(LIRC_GET_REC_MODE, value);
     155  	printf("ioctl(-1, LIRC_GET_REC_MODE, [LIRC_MODE_RAW]) = %s\n",
     156  	       errstr);
     157  
     158  	*value = 2;
     159  	do_ioctl(LIRC_GET_SEND_MODE, value);
     160  	printf("ioctl(-1, LIRC_GET_SEND_MODE, [LIRC_MODE_PULSE]) = %s\n",
     161  	       errstr);
     162  
     163  	*value = 120;
     164  	do_ioctl(LIRC_GET_REC_RESOLUTION, value);
     165  	printf("ioctl(-1, LIRC_GET_REC_RESOLUTION, [120]) = %s\n",
     166  	       errstr);
     167  
     168  	*value = 120000;
     169  	do_ioctl(LIRC_GET_REC_TIMEOUT, value);
     170  	printf("ioctl(-1, LIRC_GET_REC_TIMEOUT, [120000]) = %s\n",
     171  	       errstr);
     172  
     173  	*value = 1100;
     174  	do_ioctl(LIRC_GET_MIN_TIMEOUT, value);
     175  	printf("ioctl(-1, I2OVALIDATE or LIRC_GET_MIN_TIMEOUT, [1100]) = %s\n",
     176  	       errstr);
     177  
     178  	*value = 10100;
     179  	do_ioctl(LIRC_GET_MAX_TIMEOUT, value);
     180  	printf("ioctl(-1, LIRC_GET_MAX_TIMEOUT, [10100]) = %s\n",
     181  	       errstr);
     182  
     183  	*value = 15;
     184  	do_ioctl(LIRC_GET_LENGTH, value);
     185  	printf("ioctl(-1, LIRC_GET_LENGTH, [15]) = %s\n",
     186  	       errstr);
     187  
     188  	do_ioctl(LIRC_GET_FEATURES, value + 1);
     189  	printf("ioctl(-1, LIRC_GET_FEATURES, %p) = %s\n",
     190  	       value + 1, errstr);
     191  
     192  #else
     193  
     194  	do_ioctl(LIRC_GET_FEATURES, value);
     195  	printf("ioctl(-1, LIRC_GET_FEATURES, %p) = %s\n",
     196  	       value, errstr);
     197  
     198  #endif
     199  
     200  	do_ioctl(_IO('i', 0xff), value);
     201  	printf("ioctl(-1, _IOC(_IOC_NONE, 0x69, 0xff, 0), %p) = %s\n",
     202  	       value, errstr);
     203  
     204  	puts("+++ exited with 0 +++");
     205  	return 0;
     206  }