Ticket #1428: mw_uid-788.patch

File mw_uid-788.patch, 10.6 KB (added by Daniel Ramirez, on Dec 19, 2013 at 12:29:37 AM)

patch to fix short timeouts, add test to confirm fix

  • cpukit/libmisc/fb/mw_uid.c

    From eca94ebec082e8ced9f1d3e4c09ef52a5b8c1d0f Mon Sep 17 00:00:00 2001
    From: Allen Hessenflow <allanh@kallisti.com>
    Date: Wed, 18 Dec 2013 18:54:53 -0600
    Subject: [PATCH 1/2] mw_uid: corrects uid_read_message short timeouts
    
    ---
     cpukit/libmisc/fb/mw_uid.c | 13 +++++++++++--
     1 file changed, 11 insertions(+), 2 deletions(-)
    
    diff --git a/cpukit/libmisc/fb/mw_uid.c b/cpukit/libmisc/fb/mw_uid.c
    index cb138dc..a911e09 100644
    a b int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout ) 
    9090{
    9191  rtems_status_code status;
    9292  size_t            size = 0;
    93   unsigned long     micro_secs = timeout*1000;
    9493  int               wait = (timeout != 0);
     94  int ticks = RTEMS_MICROSECONDS_TO_TICKS(timeout * 1000);
     95
     96  if (timeout == (unsigned long) -1) {
     97    ticks = RTEMS_NO_TIMEOUT;
     98  } else if (timeout && ticks == 0) {
     99    /* if timeout greater than 0 and smaller than a tick, round up to avoid
     100     * unintentionally RTEMS_NO_TIMEOUT
     101     */
     102    ticks = 1;
     103  }
    95104
    96105  status = rtems_message_queue_receive(
    97106   queue_id,
    98107   (void*)m,
    99108   &size,
    100109   wait ? RTEMS_WAIT : RTEMS_NO_WAIT,
    101    RTEMS_MICROSECONDS_TO_TICKS(micro_secs)
     110   ticks
    102111  );
    103112
    104113  if( status == RTEMS_SUCCESSFUL ) {
  • testsuites/libtests/Makefile.am

    -- 
    1.8.3.1
    
    
    From f72ab9f448756a062602224446043463a1947270 Mon Sep 17 00:00:00 2001
    From: Daniel Ramirez <javamonn@gmail.com>
    Date: Wed, 18 Dec 2013 19:05:14 -0600
    Subject: [PATCH 2/2] libtests: added test to confirm bugfix
    
    ---
     testsuites/libtests/Makefile.am                 |   2 +-
     testsuites/libtests/configure.ac                |   1 +
     testsuites/libtests/uid01/Makefile.am           |  23 ++++
     testsuites/libtests/uid01/init.c                | 154 ++++++++++++++++++++++++
     testsuites/libtests/uid01/msmouse.c             |  37 ++++++
     testsuites/libtests/uid01/serial_mouse_config.c |  33 +++++
     testsuites/libtests/uid01/uid01.doc             |  19 +++
     7 files changed, 268 insertions(+), 1 deletion(-)
     create mode 100644 testsuites/libtests/uid01/Makefile.am
     create mode 100644 testsuites/libtests/uid01/init.c
     create mode 100644 testsuites/libtests/uid01/msmouse.c
     create mode 100644 testsuites/libtests/uid01/serial_mouse_config.c
     create mode 100644 testsuites/libtests/uid01/uid01.doc
    
    diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
    index f05f12b..6659b2a 100644
    a b SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \ 
    2424    block08 block09 block10 block11 block12 stringto01 \
    2525    tar01 tar02 tar03 \
    2626    math mathf mathl complex \
    27     mouse01
     27    mouse01 uid01
    2828
    2929if NETTESTS
    3030if HAS_POSIX
  • testsuites/libtests/configure.ac

    diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
    index ebe8a0a..c945f44 100644
    a b malloc05/Makefile 
    8989monitor/Makefile
    9090monitor02/Makefile
    9191mouse01/Makefile
     92uid01/Makefile
    9293putenvtest/Makefile
    9394rtems++/Makefile
    9495rtmonuse/Makefile
  • new file testsuites/libtests/uid01/Makefile.am

    diff --git a/testsuites/libtests/uid01/Makefile.am b/testsuites/libtests/uid01/Makefile.am
    new file mode 100644
    index 0000000..929825a
    - +  
     1
     2rtems_tests_PROGRAMS = uid01
     3uid01_SOURCES = init.c serial_mouse_config.c msmouse.c\
     4    ../termios04/termios_testdriver_intr.c
     5
     6dist_rtems_tests_DATA = uid01.scn
     7dist_rtems_tests_DATA += uid01.doc
     8
     9include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
     10include $(top_srcdir)/../automake/compile.am
     11include $(top_srcdir)/../automake/leaf.am
     12
     13AM_CPPFLAGS += -I$(top_srcdir)/../support/include
     14AM_CPPFLAGS += -I$(top_srcdir)/termios04
     15
     16LINK_OBJS = $(uid01_OBJECTS)
     17LINK_LIBS = $(uid01_LDLIBS)
     18
     19uid01$(EXEEXT): $(uid01_OBJECTS) $(uid01_DEPENDENCIES)
     20        @rm -f uid01$(EXEEXT)
     21        $(make-exe)
     22
     23include $(top_srcdir)/../automake/local.am
  • new file testsuites/libtests/uid01/init.c

    diff --git a/testsuites/libtests/uid01/init.c b/testsuites/libtests/uid01/init.c
    new file mode 100644
    index 0000000..50dd2f8
    - +  
     1/*
     2 *  COPYRIGHT (c) 2013.
     3 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  The license and distribution terms for this file may be
     6 *  found in the file LICENSE in this distribution or at
     7 *  http://www.rtems.com/license/LICENSE.
     8 */
     9
     10#ifdef HAVE_CONFIG_H
     11#include "config.h"
     12#endif
     13
     14#include <bsp.h>
     15
     16#include <stdlib.h>
     17#include <stdio.h>
     18
     19#include <sys/types.h>
     20#include <sys/stat.h>
     21#include <fcntl.h>
     22#include <sys/ioctl.h>
     23#include <unistd.h>
     24#include <rtems/mw_uid.h>
     25#include "termios_testdriver_intr.h"
     26#include "tmacros.h"
     27
     28#define UID_MESSAGE_COUNT 10
     29
     30/* forward declarations to avoid warnings */
     31rtems_task Init(rtems_task_argument argument);
     32void open_it(void);
     33void register_it(void);
     34void printf_uid_message(struct MW_UID_MESSAGE *uid);
     35void receive_uid_message(void);
     36void close_it(void);
     37
     38extern const char *Mouse_Type_Long;
     39extern const char *Mouse_Type_Short;
     40extern const unsigned char Mouse_Actions[];
     41extern const size_t Mouse_Actions_Size;
     42extern const size_t Mouse_Actions_Per_Iteration;
     43
     44int Mouse_Index = 0;
     45
     46int Test_fd;
     47
     48void open_it(void)
     49{
     50  /* open the file */
     51  Test_fd = open( "/dev/mouse", O_RDONLY );
     52  rtems_test_assert( Test_fd != -1 );
     53}
     54
     55void register_it(void)
     56  int                rc;
     57  char               name[5] = "mous";
     58
     59  rc = uid_open_queue( name, 0, UID_MESSAGE_COUNT );
     60  rtems_test_assert( rc == 0 );
     61
     62  rc = uid_register_device( Test_fd, name );
     63  rtems_test_assert( rc == 0 );
     64}
     65
     66void printf_uid_message(
     67  struct MW_UID_MESSAGE *uid
     68)
     69{
     70  uid_print_message_with_plugin(
     71    stdout,
     72    (rtems_printk_plugin_t)fprintf,
     73    uid
     74  );
     75}
     76
     77void receive_uid_message(void)
     78{
     79  int                    rc;
     80  struct MW_UID_MESSAGE  uid;
     81
     82  rc = uid_read_message( &uid, 0.5L );
     83  if ( rc != sizeof(struct MW_UID_MESSAGE) )
     84    return;
     85  printf_uid_message( &uid );
     86}
     87
     88void close_it(void)
     89{
     90  int rc;
     91
     92  rc = uid_unregister_device( Test_fd );
     93  rtems_test_assert( rc == 0 );
     94
     95  rc = close( Test_fd );
     96  rtems_test_assert( rc == 0 );
     97}
     98
     99rtems_task Init(
     100  rtems_task_argument ignored
     101)
     102{
     103
     104  printf( "\n\n*** UID01 TEST ***\n" );
     105
     106  open_it();
     107  register_it();
     108
     109  /* No message should ever be recieved. With a timeout val of 0, this
     110   * call will never return. We use this to check if patch was correct
     111   * by passing a number of ticks greater than 0 and less than 1. If
     112   * patch was correct, this call will timeout instead of waiting
     113   * indefinitely.
     114   */
     115  receive_uid_message();
     116
     117  close_it();
     118  printf( "*** END OF UID01 TEST ***\n" );
     119  rtems_test_exit( 0 );
     120}
     121
     122/* configuration information */
     123
     124#include <rtems/serial_mouse.h>
     125#include "termios_testdriver_intr.h"
     126
     127/* NOTICE: the clock driver is explicitly disabled */
     128#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     129#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
     130#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
     131    TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
     132    SERIAL_MOUSE_DRIVER_TABLE_ENTRY
     133
     134/* one for the console and one for the test port */
     135#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2
     136
     137/* we need to be able to open the test device and mouse */
     138#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
     139#define CONFIGURE_MAXIMUM_TASKS  1
     140#define CONFIGURE_MAXIMUM_TIMERS 2
     141#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
     142
     143#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
     144  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( \
     145    UID_MESSAGE_COUNT, \
     146    sizeof(struct MW_UID_MESSAGE) \
     147  )
     148
     149#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     150#define CONFIGURE_INIT
     151
     152#include <rtems/confdefs.h>
     153
     154/* end of file */
  • new file testsuites/libtests/uid01/msmouse.c

    diff --git a/testsuites/libtests/uid01/msmouse.c b/testsuites/libtests/uid01/msmouse.c
    new file mode 100644
    index 0000000..1957d32
    - +  
     1/*
     2 *  COPYRIGHT (c) 1989-2011.
     3 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  The license and distribution terms for this file may be
     6 *  found in the file LICENSE in this distribution or at
     7 *  http://www.rtems.com/license/LICENSE.
     8 */
     9
     10#ifdef HAVE_CONFIG_H
     11#include "config.h"
     12#endif
     13
     14#include <sys/types.h>
     15
     16const char *Mouse_Type_Long = "Microsoft Mouse";
     17const char *Mouse_Type_Short = "ms";
     18
     19#define PRESSED     1
     20#define NOT_PRESSED 0
     21
     22#define MS_MOUSE_BYTES( _lb, _rb, _x, _y ) \
     23  (0x40 | ((_lb) ? 0x20 : 0x00) | ((_rb) ? 0x10 : 0x00) | \
     24     ((_y & 0xC) >> 4) | (_x >> 6)), \
     25  (_x & 0x3F), \
     26  (_y & 0x3F)
     27
     28const unsigned char Mouse_Actions[] = {
     29  MS_MOUSE_BYTES(     PRESSED, NOT_PRESSED,    1,    2),
     30  MS_MOUSE_BYTES( NOT_PRESSED, PRESSED,        1,    2),
     31  MS_MOUSE_BYTES( NOT_PRESSED, NOT_PRESSED, 0xff,    2),
     32  MS_MOUSE_BYTES( NOT_PRESSED, NOT_PRESSED,    1, 0xff)
     33};
     34
     35const size_t Mouse_Actions_Size = sizeof(Mouse_Actions);
     36const size_t Mouse_Actions_Per_Iteration = 3;
     37
  • new file testsuites/libtests/uid01/serial_mouse_config.c

    diff --git a/testsuites/libtests/uid01/serial_mouse_config.c b/testsuites/libtests/uid01/serial_mouse_config.c
    new file mode 100644
    index 0000000..09e420a
    - +  
     1/*
     2 *
     3 * MODULE DESCRIPTION:
     4 * This module implements the RTEMS drivers for the PC serial ports
     5 * as /dev/ttyS1 for COM1 and /dev/ttyS2 as COM2. If one of the ports
     6 * is used as the console, this driver would fail to initialize.
     7 *
     8 * This code was based on the console driver. It is based on the
     9 * current termios framework. This is just a shell around the
     10 * termios support.
     11 *
     12 */
     13
     14#ifdef HAVE_CONFIG_H
     15#include "config.h"
     16#endif
     17
     18#include "tmacros.h"
     19#include <rtems/serial_mouse.h>
     20#include "termios_testdriver_intr.h"
     21
     22extern const char *Mouse_Type_Short;
     23
     24bool bsp_get_serial_mouse_device(
     25  const char **name,
     26  const char **type
     27)
     28{
     29  *name = TERMIOS_TEST_DRIVER_DEVICE_NAME;
     30  *type = Mouse_Type_Short;
     31
     32  return true;
     33}
  • new file testsuites/libtests/uid01/uid01.doc

    diff --git a/testsuites/libtests/uid01/uid01.doc b/testsuites/libtests/uid01/uid01.doc
    new file mode 100644
    index 0000000..4a7481e
    - +  
     1#  COPYRIGHT (c) 2013.
     2#  On-Line Applications Research Corporation (OAR).
     3#
     4#  The license and distribution terms for this file may be
     5#  found in the file LICENSE in this distribution or at
     6#  http://www.rtems.com/license/LICENSE.
     7#
     8
     9This file describes the directives and concepts tested by this test set.
     10
     11test set name: uid01
     12
     13directives:
     14  + uid_read_message
     15
     16concepts:
     17  + Tests that uid_read_message when called with a timeout greater than 0
     18    ticks but less than 1 tick will correctly round this up to a 1 tick
     19    timeout.