source: rtems/testsuites/psxtests/psxmsgq03/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 2.5 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#define CONFIGURE_INIT
15#include "system.h"
16
17#include <fcntl.h>           /* For O_* constants */
18#include <sys/stat.h>        /* For mode constants */
19#include <mqueue.h>
20
21#include "test_support.h"
22
23const char rtems_test_name[] = "PSXMSGQ 3";
24
25/* forward declarations to avoid warnings */
26rtems_timer_service_routine mq_send_timer(rtems_id timer, void *arg);
27
28mqd_t Queue;
29volatile bool tsr_fired;
30volatile int  tsr_status;
31volatile int  tsr_errno;
32
33rtems_timer_service_routine mq_send_timer(
34  rtems_id  timer,
35  void     *arg
36)
37{
38  int msg = 4;
39
40  tsr_fired = true;
41
42  tsr_status = mq_send( Queue, (const char *)&msg, sizeof(int), 1 );
43  tsr_errno = errno;
44}
45
46void *POSIX_Init(
47  void *argument
48)
49{
50  struct mq_attr     attr;
51  int                status;
52  rtems_id           timer;
53  rtems_status_code  rc;
54
55  TEST_BEGIN();
56
57  attr.mq_maxmsg  = 1;
58  attr.mq_msgsize = sizeof(int);
59
60  puts( "Init - Open message queue" );
61  Queue = mq_open( "Qsend", O_CREAT | O_RDWR, 0x777, &attr );
62  if ( Queue == (-1) ) {
63    perror( "mq_open failed" );
64  }
65  rtems_test_assert( Queue != (-1) );
66
67  puts( "Init - send to message queue" );
68  status = mq_send( Queue, (const char *)&status, sizeof(int), 1 );
69  if ( status == (-1) ) {
70    perror( "mq_status failed" );
71  }
72  rtems_test_assert( status != (-1) );
73
74  /*
75   * Now create the timer we will send to a full queue from.
76   */
77  puts( "Init - Create Classic API Timer" );
78  rc = rtems_timer_create( 1, &timer );
79  directive_failed( rc, "rtems_timer_create" );
80
81  puts( "Init - Fire After Classic API Timer" );
82  tsr_fired = false;
83
84  rc = rtems_timer_fire_after(
85    timer,
86    rtems_clock_get_ticks_per_second(),
87    mq_send_timer,
88    NULL
89  );
90  directive_failed( rc, "rtems_timer_fire_after" );
91
92  sleep(2);
93
94  if ( tsr_fired == false ) {
95    puts( "ERROR -- TSR DID NOT FIRE" );
96    rtems_test_exit( 0 );
97  }
98  if ( (tsr_status != -1) || (tsr_errno != ENOMEM) ) {
99    puts( "ERROR -- TSR DID NOT RETURN CORRECT STATUS" );
100    printf(
101      "status=%d errno=%d --> %s\n",
102      tsr_status,
103      tsr_errno,
104      strerror(tsr_errno)
105    );
106    rtems_test_exit( 0 );
107  }
108
109  puts( "Init - mq_send from ISR returned correct status" );
110
111  TEST_END();
112  rtems_test_exit( 0 );
113
114  return NULL; /* just so the compiler thinks we returned something */
115}
Note: See TracBrowser for help on using the repository browser.