Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:35

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2013 Daniel Ramirez <javamonn@gmail.com>
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <bsp.h>
0033 
0034 #include <stdlib.h>
0035 #include <stdio.h>
0036 
0037 #include <sys/types.h>
0038 #include <sys/stat.h>
0039 #include <fcntl.h>
0040 #include <sys/ioctl.h>
0041 #include <unistd.h>
0042 #include <rtems/mw_uid.h>
0043 #include "../termios04/termios_testdriver_intr.h"
0044 #include "tmacros.h"
0045 
0046 const char rtems_test_name[] = "UID 1";
0047 
0048 #define UID_MESSAGE_COUNT 10
0049 
0050 /* forward declarations to avoid warnings */
0051 rtems_task Init(rtems_task_argument argument);
0052 void open_it(void);
0053 void register_it(void);
0054 void printf_uid_message(struct MW_UID_MESSAGE *uid);
0055 void receive_uid_message(void);
0056 void close_it(void);
0057 
0058 extern const char *Mouse_Type_Long;
0059 extern const char *Mouse_Type_Short;
0060 extern const unsigned char Mouse_Actions[];
0061 extern const size_t Mouse_Actions_Size;
0062 extern const size_t Mouse_Actions_Per_Iteration;
0063 
0064 int Mouse_Index = 0;
0065 
0066 int Test_fd;
0067 
0068 void open_it(void)
0069 {
0070   /* open the file */
0071   Test_fd = open( "/dev/mouse", O_RDONLY );
0072   rtems_test_assert( Test_fd != -1 );
0073 }
0074 
0075 void register_it(void)
0076 {
0077   int                rc;
0078   char               name[5] = "mous";
0079 
0080   rc = uid_open_queue( name, 0, UID_MESSAGE_COUNT );
0081   rtems_test_assert( rc == 0 );
0082 
0083   rc = uid_register_device( Test_fd, name );
0084   rtems_test_assert( rc == 0 );
0085 }
0086 
0087 void printf_uid_message(
0088   struct MW_UID_MESSAGE *uid
0089 )
0090 {
0091   uid_print_message_with_plugin(
0092     &rtems_test_printer,
0093     uid
0094   );
0095 }
0096 
0097 void receive_uid_message(void)
0098 {
0099   int                    rc;
0100   struct MW_UID_MESSAGE  uid;
0101 
0102   rc = uid_read_message( &uid, 0.5L );
0103   if ( rc != sizeof(struct MW_UID_MESSAGE) )
0104     return;
0105   printf_uid_message( &uid );
0106 }
0107 
0108 void close_it(void)
0109 {
0110   int rc;
0111 
0112   rc = uid_unregister_device( Test_fd );
0113   rtems_test_assert( rc == 0 );
0114 
0115   rc = close( Test_fd );
0116   rtems_test_assert( rc == 0 );
0117 }
0118 
0119 rtems_task Init(
0120   rtems_task_argument ignored
0121 )
0122 {
0123 
0124   TEST_BEGIN();
0125 
0126   open_it();
0127   register_it();
0128 
0129   /* No message should ever be recieved. With a timeout val of 0, this
0130    * call will never return. We use this to check if patch was correct
0131    * by passing a number of ticks greater than 0 and less than 1. If
0132    * patch was correct, this call will timeout instead of waiting
0133    * indefinitely.
0134    */
0135   receive_uid_message();
0136 
0137   close_it();
0138   TEST_END();
0139   rtems_test_exit( 0 );
0140 }
0141 
0142 /* configuration information */
0143 
0144 #include <rtems/serial_mouse.h>
0145 
0146 /* NOTICE: the clock driver is explicitly disabled */
0147 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0148 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0149 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0150     TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
0151     SERIAL_MOUSE_DRIVER_TABLE_ENTRY
0152 
0153 /* we need to be able to open the test device and mouse */
0154 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 5
0155 #define CONFIGURE_MAXIMUM_TASKS  1
0156 #define CONFIGURE_MAXIMUM_TIMERS 2
0157 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
0158 
0159 #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
0160   CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( \
0161     UID_MESSAGE_COUNT, \
0162     sizeof(struct MW_UID_MESSAGE) \
0163   )
0164 
0165 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0166 
0167 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0168 
0169 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0170 
0171 #define CONFIGURE_INIT
0172 
0173 #include <rtems/confdefs.h>
0174 
0175 /* end of file */