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