[8fb2bea] | 1 | /* |
---|
| 2 | * Copyright (c) 2013 Zhongwei Yao. |
---|
| 3 | * |
---|
| 4 | * The license and distribution terms for this file may be |
---|
| 5 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 6 | * http://www.rtems.org/license/LICENSE. |
---|
[8fb2bea] | 7 | */ |
---|
| 8 | |
---|
| 9 | #ifdef HAVE_CONFIG_H |
---|
| 10 | #include "config.h" |
---|
| 11 | #endif |
---|
| 12 | |
---|
| 13 | #include <tmacros.h> |
---|
| 14 | #include <rtems/score/chainimpl.h> |
---|
| 15 | #include <rtems/score/freechain.h> |
---|
| 16 | |
---|
[6c0301d] | 17 | const char rtems_test_name[] = "SPFREECHAIN 1"; |
---|
| 18 | |
---|
[8fb2bea] | 19 | typedef struct { |
---|
[fdb45d6] | 20 | Chain_Node Node; |
---|
[8fb2bea] | 21 | int x; |
---|
| 22 | } test_node; |
---|
| 23 | |
---|
[fdb45d6] | 24 | static rtems_task Init(rtems_task_argument ignored) |
---|
[8fb2bea] | 25 | { |
---|
[fdb45d6] | 26 | Freechain_Control fc; |
---|
| 27 | test_node *node; |
---|
[21275b58] | 28 | test_node node2; |
---|
[8fb2bea] | 29 | |
---|
[fdb45d6] | 30 | TEST_BEGIN(); |
---|
[8fb2bea] | 31 | |
---|
[21275b58] | 32 | _Freechain_Initialize(&fc, &node2, 1, sizeof(node2)); |
---|
| 33 | rtems_test_assert(_Chain_Node_count_unprotected(&fc.Free) == 1); |
---|
| 34 | rtems_test_assert(_Chain_First(&fc.Free) == &node2.Node); |
---|
| 35 | rtems_test_assert(_Chain_Last(&fc.Free) == &node2.Node); |
---|
[8fb2bea] | 36 | |
---|
[21275b58] | 37 | _Freechain_Initialize(&fc, NULL, 0, sizeof(test_node)); |
---|
[fdb45d6] | 38 | rtems_test_assert(_Chain_Is_empty(&fc.Free)); |
---|
[8fb2bea] | 39 | |
---|
[fdb45d6] | 40 | rtems_test_assert(_Freechain_Get(&fc, NULL, 0, sizeof(test_node)) == NULL); |
---|
[8fb2bea] | 41 | |
---|
[fdb45d6] | 42 | rtems_test_assert(_Freechain_Get(&fc, malloc, 1, SIZE_MAX) == NULL); |
---|
[8fb2bea] | 43 | |
---|
| 44 | /* check whether freechain put and get works correctly*/ |
---|
| 45 | |
---|
[f59f2fe9] | 46 | _Freechain_Put(&fc, NULL); |
---|
| 47 | |
---|
[8fb2bea] | 48 | puts( "INIT - Get node from freechain - OK" ); |
---|
[fdb45d6] | 49 | node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node)); |
---|
| 50 | node->x = 1; |
---|
[8fb2bea] | 51 | |
---|
| 52 | puts( "INIT - Put node back to freechain - OK" ); |
---|
[fdb45d6] | 53 | _Freechain_Put(&fc, node); |
---|
[8fb2bea] | 54 | |
---|
| 55 | puts( "INIT - Verify freechain node put and get - OK" ); |
---|
[fdb45d6] | 56 | node = _Freechain_Get(&fc, NULL, 0, sizeof(test_node)); |
---|
| 57 | rtems_test_assert(node->x == 1); |
---|
[8fb2bea] | 58 | |
---|
[6c0301d] | 59 | TEST_END(); |
---|
[8fb2bea] | 60 | rtems_test_exit(0); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /* configuration information */ |
---|
| 64 | |
---|
[c4b8b147] | 65 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[8fb2bea] | 66 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
| 67 | |
---|
[6c0301d] | 68 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 69 | |
---|
[8fb2bea] | 70 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 71 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 72 | |
---|
| 73 | #define CONFIGURE_INIT |
---|
| 74 | #include <rtems/confdefs.h> |
---|
| 75 | |
---|
| 76 | /* global variables */ |
---|