source:
rtems/testsuites/psxtests/psxmsgq03/init.c
@
2317457
Last change on this file since 2317457 was 2317457, checked in by Joel Sherrill <joel.sherrill@…>, on 12/08/09 at 17:52:53 | |
---|---|
|
|
File size: 2.4 KB |
Line | |
---|---|
1 | /* |
2 | * COPYRIGHT (c) 1989-2009. |
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 | * $Id$ |
10 | */ |
11 | |
12 | #define CONFIGURE_INIT |
13 | #include "system.h" |
14 | |
15 | #include <fcntl.h> /* For O_* constants */ |
16 | #include <sys/stat.h> /* For mode constants */ |
17 | #include <mqueue.h> |
18 | |
19 | #include "test_support.h" |
20 | |
21 | mqd_t Queue; |
22 | volatile bool tsr_fired; |
23 | volatile int tsr_status; |
24 | volatile int tsr_errno; |
25 | |
26 | rtems_timer_service_routine mq_send_timer( |
27 | rtems_id timer, |
28 | void *arg |
29 | ) |
30 | { |
31 | int msg = 4; |
32 | |
33 | tsr_fired = true; |
34 | |
35 | tsr_status = mq_send( Queue, (const char *)&msg, sizeof(int), 1 ); |
36 | tsr_errno = errno; |
37 | } |
38 | |
39 | void *POSIX_Init( |
40 | void *argument |
41 | ) |
42 | { |
43 | struct mq_attr attr; |
44 | int status; |
45 | rtems_id timer; |
46 | rtems_status_code rc; |
47 | |
48 | puts( "\n\n*** POSIX MESSAGE QUEUE TEST 3 ***" ); |
49 | |
50 | attr.mq_maxmsg = 1; |
51 | attr.mq_msgsize = sizeof(int); |
52 | |
53 | puts( "Init - Open message queue" ); |
54 | Queue = mq_open( "Qsend", O_CREAT | O_RDWR, 0x777, &attr ); |
55 | if ( Queue == (-1) ) { |
56 | perror( "mq_open failed" ); |
57 | } |
58 | rtems_test_assert( Queue != (-1) ); |
59 | |
60 | puts( "Init - send to message queue" ); |
61 | status = mq_send( Queue, (const char *)&status, sizeof(int), 1 ); |
62 | if ( status == (-1) ) { |
63 | perror( "mq_status failed" ); |
64 | } |
65 | rtems_test_assert( status != (-1) ); |
66 | |
67 | /* |
68 | * Now create the timer we will send to a full queue from. |
69 | */ |
70 | puts( "Init - Create Classic API Timer" ); |
71 | rc = rtems_timer_create( 1, &timer ); |
72 | directive_failed( rc, "rtems_timer_create" ); |
73 | |
74 | puts( "Init - Fire After Classic API Timer" ); |
75 | tsr_fired = false; |
76 | |
77 | rc = rtems_timer_fire_after( |
78 | timer, |
79 | rtems_clock_get_ticks_per_second(), |
80 | mq_send_timer, |
81 | NULL |
82 | ); |
83 | directive_failed( rc, "rtems_timer_fire_after" ); |
84 | |
85 | sleep(2); |
86 | |
87 | if ( tsr_fired == false ) { |
88 | puts( "ERROR -- TSR DID NOT FIRE" ); |
89 | rtems_test_exit( 0 ); |
90 | } |
91 | if ( (tsr_status != -1) || (tsr_errno != ENOMEM) ) { |
92 | puts( "ERROR -- TSR DID NOT RETURN CORRECT STATUS" ); |
93 | printf( |
94 | "status=%d errno=%d --> %s\n", |
95 | tsr_status, |
96 | tsr_errno, |
97 | strerror(tsr_errno) |
98 | ); |
99 | rtems_test_exit( 0 ); |
100 | } |
101 | |
102 | puts( "Init - mq_send from ISR returned correct status" ); |
103 | |
104 | puts( "*** END OF POSIX MESSAGE QUEUE TEST 3 ***" ); |
105 | rtems_test_exit( 0 ); |
106 | |
107 | return NULL; /* just so the compiler thinks we returned something */ |
108 | } |
Note: See TracBrowser
for help on using the repository browser.