forked from Imagelibrary/rtems
165 lines
4.7 KiB
C
165 lines
4.7 KiB
C
/*
|
|
* COPYRIGHT (c) 1989-2009.
|
|
* On-Line Applications Research Corporation (OAR).
|
|
*
|
|
* The license and distribution terms for this file may be
|
|
* found in the file LICENSE in this distribution or at
|
|
* http://www.rtems.com/license/LICENSE.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#include <tmacros.h>
|
|
#include <rtems/chain.h>
|
|
|
|
#define EVENT RTEMS_EVENT_13
|
|
#define TIMEOUT 1
|
|
|
|
typedef struct {
|
|
rtems_chain_node Node;
|
|
int id;
|
|
} test_node;
|
|
|
|
static void test_chain_get_with_wait(void)
|
|
{
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
rtems_chain_control chain;
|
|
rtems_chain_node *p = (rtems_chain_node *) 1;
|
|
|
|
puts( "INIT - Verify rtems_chain_get_with_wait" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
|
|
rtems_test_assert( sc == RTEMS_TIMEOUT );
|
|
rtems_test_assert( p == NULL );
|
|
}
|
|
|
|
static void test_chain_with_notification(void)
|
|
{
|
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
|
rtems_chain_control chain;
|
|
rtems_chain_node a;
|
|
rtems_chain_node *p = (rtems_chain_node *) 1;
|
|
rtems_event_set out = 0;
|
|
|
|
puts( "INIT - Verify rtems_chain_append_with_notification" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
sc = rtems_chain_append_with_notification( &chain, &a, rtems_task_self(), EVENT );
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
rtems_test_assert( p == &a );
|
|
|
|
puts( "INIT - Verify rtems_chain_prepend_with_notification" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
sc = rtems_chain_prepend_with_notification( &chain, &a, rtems_task_self(), EVENT );
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
rtems_test_assert( p == &a );
|
|
|
|
puts( "INIT - Verify rtems_chain_get_with_notification" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
rtems_chain_append( &chain, &a );
|
|
sc = rtems_chain_get_with_notification( &chain, rtems_task_self(), EVENT, &p );
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
rtems_test_assert( p == &a );
|
|
sc = rtems_event_receive(
|
|
EVENT,
|
|
RTEMS_EVENT_ALL | RTEMS_WAIT,
|
|
TIMEOUT,
|
|
&out
|
|
);
|
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
|
rtems_test_assert( out == EVENT );
|
|
}
|
|
|
|
static void test_chain_with_empty_check(void)
|
|
{
|
|
rtems_chain_control chain;
|
|
rtems_chain_node a;
|
|
rtems_chain_node b;
|
|
rtems_chain_node *p;
|
|
bool empty;
|
|
|
|
puts( "INIT - Verify rtems_chain_append_with_empty_check" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
empty = rtems_chain_append_with_empty_check( &chain, &a );
|
|
rtems_test_assert( empty );
|
|
empty = rtems_chain_append_with_empty_check( &chain, &a );
|
|
rtems_test_assert( !empty );
|
|
|
|
puts( "INIT - Verify rtems_chain_prepend_with_empty_check" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
empty = rtems_chain_prepend_with_empty_check( &chain, &a );
|
|
rtems_test_assert( empty );
|
|
empty = rtems_chain_prepend_with_empty_check( &chain, &a );
|
|
rtems_test_assert( !empty );
|
|
|
|
puts( "INIT - Verify rtems_chain_get_with_empty_check" );
|
|
rtems_chain_initialize_empty( &chain );
|
|
rtems_chain_append( &chain, &a );
|
|
rtems_chain_append( &chain, &b );
|
|
empty = rtems_chain_get_with_empty_check( &chain, &p );
|
|
rtems_test_assert( !empty );
|
|
rtems_test_assert( p == &a );
|
|
empty = rtems_chain_get_with_empty_check( &chain, &p );
|
|
rtems_test_assert( empty );
|
|
rtems_test_assert( p == &b );
|
|
}
|
|
|
|
rtems_task Init(
|
|
rtems_task_argument ignored
|
|
)
|
|
{
|
|
rtems_chain_control chain1;
|
|
rtems_chain_node *p;
|
|
test_node node1, node2;
|
|
int id;
|
|
|
|
puts( "\n\n*** TEST OF RTEMS CHAIN API ***" );
|
|
|
|
puts( "Init - Initialize chain empty" );
|
|
rtems_chain_initialize_empty( &chain1 );
|
|
|
|
/* verify that the chain append and insert work */
|
|
puts( "INIT - Verify rtems_chain_insert" );
|
|
node1.id = 1;
|
|
node2.id = 2;
|
|
rtems_chain_append( &chain1, &node1.Node );
|
|
rtems_chain_insert( &node1.Node, &node2.Node );
|
|
|
|
for ( p = chain1.first, id = 1 ;
|
|
!rtems_chain_is_tail(&chain1, p) ;
|
|
p = p->next , id++ ) {
|
|
test_node *t = (test_node *)p;
|
|
if ( id > 2 ) {
|
|
puts( "INIT - TOO MANY NODES ON CHAIN" );
|
|
rtems_test_exit(0);
|
|
}
|
|
if ( t->id != id ) {
|
|
puts( "INIT - ERROR ON CHAIN ID MISMATCH" );
|
|
rtems_test_exit(0);
|
|
}
|
|
}
|
|
|
|
test_chain_with_empty_check();
|
|
test_chain_with_notification();
|
|
test_chain_get_with_wait();
|
|
|
|
puts( "*** END OF RTEMS CHAIN API TEST ***" );
|
|
rtems_test_exit(0);
|
|
}
|
|
|
|
/* configuration information */
|
|
|
|
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
|
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
|
|
|
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
|
#define CONFIGURE_MAXIMUM_TASKS 1
|
|
|
|
#define CONFIGURE_INIT
|
|
#include <rtems/confdefs.h>
|
|
|
|
/* global variables */
|