source: rtems/testsuites/libtests/mouse01/init.c @ 24d0ee57

5
Last change on this file since 24d0ee57 was 24d0ee57, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 08:39:50

cpukit, testsuite: Add rtems_printf and rtems_printer support.

This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.

Printk and related functions are made to return a valid number of
characters formatted and output.

The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.

The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/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
28const char rtems_test_name[] = "MOUSE 1";
29
30#define UID_MESSAGE_COUNT 10
31
32/* forward declarations to avoid warnings */
33rtems_task Init(rtems_task_argument argument);
34bool enqueue_next_action(
35  const unsigned char *actions,
36  size_t               max,
37  size_t               to_enqueue
38);
39void open_it(void);
40void register_it(void);
41void printf_uid_message(struct MW_UID_MESSAGE *uid);
42void receive_uid_message(void);
43void close_it(void);
44
45extern const char *Mouse_Type_Long;
46extern const char *Mouse_Type_Short;
47extern const unsigned char Mouse_Actions[];
48extern const size_t Mouse_Actions_Size;
49extern const size_t Mouse_Actions_Per_Iteration;
50
51int Mouse_Index = 0;
52
53bool enqueue_next_action(
54  const unsigned char *actions,
55  size_t               max,
56  size_t               to_enqueue
57)
58{
59  if ( (Mouse_Index + to_enqueue) > max )
60    return false;
61
62  termios_test_driver_set_rx_enqueue_now( true );
63
64  termios_test_driver_set_rx( &actions[Mouse_Index], to_enqueue );
65  Mouse_Index += to_enqueue;
66
67  return true;
68}
69
70int Test_fd;
71
72void open_it(void)
73{
74  /* open the file */
75  puts( "open(/dev/mouse) - OK " );
76  Test_fd = open( "/dev/mouse", O_RDONLY );
77  rtems_test_assert( Test_fd != -1 );
78}
79
80void register_it(void)
81{
82  int                rc;
83  char               name[5] = "mous";
84
85  printf( "uid_open_queue() - mouse queue\n" );
86  rc = uid_open_queue( name, 0, UID_MESSAGE_COUNT );
87  rtems_test_assert( rc == 0 );
88
89  printf( "uid_register_device() - OK\n");
90  rc = uid_register_device( Test_fd, name );
91  rtems_test_assert( rc == 0 );
92}
93
94void printf_uid_message(
95  struct MW_UID_MESSAGE *uid
96)
97{
98  rtems_printer printer;
99  rtems_print_printer_printf( &printer );
100  uid_print_message_with_plugin(
101    &printer,
102    uid
103  );
104}
105
106void receive_uid_message(void)
107{
108  int                    rc;
109  struct MW_UID_MESSAGE  uid;
110
111  rc = uid_read_message( &uid, 0 );
112  if ( rc != sizeof(struct MW_UID_MESSAGE) )
113    return;
114  printf_uid_message( &uid );
115}
116
117void close_it(void)
118{
119  int rc;
120
121  printf( "uid_unregister_device() - OK\n" );
122  rc = uid_unregister_device( Test_fd );
123  rtems_test_assert( rc == 0 );
124
125  puts( "close(/dev/mouse) - OK " );
126  rc = close( Test_fd );
127  rtems_test_assert( rc == 0 );
128}
129
130rtems_task Init(
131  rtems_task_argument ignored
132)
133{
134  bool more_data;
135
136  TEST_BEGIN();
137
138  open_it();
139  register_it();
140  do {
141    more_data = enqueue_next_action(
142      Mouse_Actions,
143      Mouse_Actions_Size,
144      Mouse_Actions_Per_Iteration
145    );
146    receive_uid_message();
147  } while (more_data);
148  close_it();
149  TEST_END();
150  rtems_test_exit( 0 );
151}
152
153/* configuration information */
154
155#include <rtems/serial_mouse.h>
156#include "termios_testdriver_intr.h"
157
158/* NOTICE: the clock driver is explicitly disabled */
159#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
160#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
161#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
162    TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
163    SERIAL_MOUSE_DRIVER_TABLE_ENTRY
164
165/* one for the console and one for the test port */
166#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2
167
168/* we need to be able to open the test device and mouse */
169#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
170#define CONFIGURE_MAXIMUM_TASKS  1
171#define CONFIGURE_MAXIMUM_TIMERS 2
172#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
173
174#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
175  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( \
176    UID_MESSAGE_COUNT, \
177    sizeof(struct MW_UID_MESSAGE) \
178  )
179
180#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
181
182#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
183#define CONFIGURE_INIT
184
185#include <rtems/confdefs.h>
186
187/* end of file */
Note: See TracBrowser for help on using the repository browser.