Ticket #1428: mw_uid-1428.patch

File mw_uid-1428.patch, 10.5 KB (added by Daniel Ramirez, on Dec 19, 2013 at 4:04:57 AM)

reformat patch, implement new test to confirm fix

  • cpukit/libmisc/fb/mw_uid.c

    From eca94ebec082e8ced9f1d3e4c09ef52a5b8c1d0f Mon Sep 17 00:00:00 2001
    From: Allan 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 0489d7fd111a697ddcf7ee87973f73dceb0aaa33 Mon Sep 17 00:00:00 2001
    From: Daniel Ramirez <javamonn@gmail.com>
    Date: Wed, 18 Dec 2013 22:58:53 -0600
    Subject: [PATCH 2/2] libtests: added test to confirm patch fixes bug
    
    ---
     testsuites/libtests/Makefile.am                 |   2 +-
     testsuites/libtests/configure.ac                |   1 +
     testsuites/libtests/uid01/Makefile.am           |  22 ++++
     testsuites/libtests/uid01/init.c                | 155 ++++++++++++++++++++++++
     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..b7b68d9
    - +  
     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.doc
     7
     8include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
     9include $(top_srcdir)/../automake/compile.am
     10include $(top_srcdir)/../automake/leaf.am
     11
     12AM_CPPFLAGS += -I$(top_srcdir)/../support/include
     13AM_CPPFLAGS += -I$(top_srcdir)/termios04
     14
     15LINK_OBJS = $(uid01_OBJECTS)
     16LINK_LIBS = $(uid01_LDLIBS)
     17
     18uid01$(EXEEXT): $(uid01_OBJECTS) $(uid01_DEPENDENCIES)
     19        @rm -f uid01$(EXEEXT)
     20        $(make-exe)
     21
     22include $(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..0335347
    - +  
     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{
     57  int                rc;
     58  char               name[5] = "mous";
     59
     60  rc = uid_open_queue( name, 0, UID_MESSAGE_COUNT );
     61  rtems_test_assert( rc == 0 );
     62
     63  rc = uid_register_device( Test_fd, name );
     64  rtems_test_assert( rc == 0 );
     65}
     66
     67void printf_uid_message(
     68  struct MW_UID_MESSAGE *uid
     69)
     70{
     71  uid_print_message_with_plugin(
     72    stdout,
     73    (rtems_printk_plugin_t)fprintf,
     74    uid
     75  );
     76}
     77
     78void receive_uid_message(void)
     79{
     80  int                    rc;
     81  struct MW_UID_MESSAGE  uid;
     82
     83  rc = uid_read_message( &uid, 0.5L );
     84  if ( rc != sizeof(struct MW_UID_MESSAGE) )
     85    return;
     86  printf_uid_message( &uid );
     87}
     88
     89void close_it(void)
     90{
     91  int rc;
     92
     93  rc = uid_unregister_device( Test_fd );
     94  rtems_test_assert( rc == 0 );
     95
     96  rc = close( Test_fd );
     97  rtems_test_assert( rc == 0 );
     98}
     99
     100rtems_task Init(
     101  rtems_task_argument ignored
     102)
     103{
     104
     105  printf( "\n\n*** UID01 TEST ***\n" );
     106
     107  open_it();
     108  register_it();
     109
     110  /* No message should ever be recieved. With a timeout val of 0, this
     111   * call will never return. We use this to check if patch was correct
     112   * by passing a number of ticks greater than 0 and less than 1. If
     113   * patch was correct, this call will timeout instead of waiting
     114   * indefinitely.
     115   */
     116  receive_uid_message();
     117
     118  close_it();
     119  printf( "*** END OF UID01 TEST ***\n" );
     120  rtems_test_exit( 0 );
     121}
     122
     123/* configuration information */
     124
     125#include <rtems/serial_mouse.h>
     126#include "termios_testdriver_intr.h"
     127
     128/* NOTICE: the clock driver is explicitly disabled */
     129#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     130#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
     131#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
     132    TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
     133    SERIAL_MOUSE_DRIVER_TABLE_ENTRY
     134
     135/* one for the console and one for the test port */
     136#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2
     137
     138/* we need to be able to open the test device and mouse */
     139#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
     140#define CONFIGURE_MAXIMUM_TASKS  1
     141#define CONFIGURE_MAXIMUM_TIMERS 2
     142#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
     143
     144#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
     145  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( \
     146    UID_MESSAGE_COUNT, \
     147    sizeof(struct MW_UID_MESSAGE) \
     148  )
     149
     150#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     151#define CONFIGURE_INIT
     152
     153#include <rtems/confdefs.h>
     154
     155/* 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.