Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:47

0001 /*
0002  * Copyright (c) 2013 Zhongwei Yao.
0003  *
0004  *  The license and distribution terms for this file may be
0005  *  found in the file LICENSE in this distribution or at
0006  *  http://www.rtems.org/license/LICENSE.
0007  */
0008 
0009 #ifdef HAVE_CONFIG_H
0010 #include "config.h"
0011 #endif
0012 
0013 #include <tmacros.h>
0014 #include <rtems/score/chainimpl.h>
0015 #include <rtems/score/freechainimpl.h>
0016 
0017 const char rtems_test_name[] = "SPFREECHAIN 1";
0018 
0019 typedef struct {
0020   Chain_Node Node;
0021   int x;
0022 } test_node;
0023 
0024 static rtems_task Init(rtems_task_argument ignored)
0025 {
0026     Freechain_Control fc;
0027     test_node *node;
0028     test_node node2;
0029 
0030     TEST_BEGIN();
0031 
0032     _Freechain_Initialize(&fc, &node2, 1, sizeof(node2));
0033     rtems_test_assert(!_Freechain_Is_empty(&fc));
0034     rtems_test_assert(_Chain_Node_count_unprotected(&fc.Free) == 1);
0035     rtems_test_assert(_Chain_First(&fc.Free) == &node2.Node);
0036     rtems_test_assert(_Chain_Last(&fc.Free) == &node2.Node);
0037 
0038     node = _Freechain_Pop(&fc);
0039     rtems_test_assert(_Freechain_Is_empty(&fc));
0040     rtems_test_assert(node == &node2);
0041 
0042     _Freechain_Initialize(&fc, NULL, 0, sizeof(test_node));
0043     rtems_test_assert(_Freechain_Is_empty(&fc));
0044 
0045     rtems_test_assert(_Freechain_Get(&fc, NULL, 0, sizeof(test_node)) == NULL);
0046 
0047     rtems_test_assert(_Freechain_Get(&fc, malloc, 1, SIZE_MAX) == NULL);
0048 
0049     /* check whether freechain put and get works correctly*/
0050 
0051     _Freechain_Put(&fc, NULL);
0052 
0053     puts( "INIT - Get node from freechain - OK" );
0054     node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node));
0055     node->x = 1;
0056 
0057     puts( "INIT - Put node back to freechain - OK" );
0058     _Freechain_Put(&fc, node);
0059 
0060     puts( "INIT - Verify freechain node put and get - OK" );
0061     node = _Freechain_Get(&fc, NULL, 0, sizeof(test_node));
0062     rtems_test_assert(node->x == 1);
0063 
0064     TEST_END();
0065     rtems_test_exit(0);
0066 }
0067 
0068 /* configuration information */
0069 
0070 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0071 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0072 
0073 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0074 
0075 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0076 #define CONFIGURE_MAXIMUM_TASKS 1
0077 
0078 #define CONFIGURE_INIT
0079 #include <rtems/confdefs.h>
0080 
0081 /* global variables */