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 |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
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 | |
---|
17 | const char rtems_test_name[] = "SPFREECHAIN 1"; |
---|
18 | |
---|
19 | typedef struct { |
---|
20 | Chain_Node Node; |
---|
21 | int x; |
---|
22 | } test_node; |
---|
23 | |
---|
24 | static rtems_task Init(rtems_task_argument ignored) |
---|
25 | { |
---|
26 | Freechain_Control fc; |
---|
27 | test_node *node; |
---|
28 | test_node node2; |
---|
29 | |
---|
30 | TEST_BEGIN(); |
---|
31 | |
---|
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); |
---|
36 | |
---|
37 | _Freechain_Initialize(&fc, NULL, 0, sizeof(test_node)); |
---|
38 | rtems_test_assert(_Chain_Is_empty(&fc.Free)); |
---|
39 | |
---|
40 | rtems_test_assert(_Freechain_Get(&fc, NULL, 0, sizeof(test_node)) == NULL); |
---|
41 | |
---|
42 | rtems_test_assert(_Freechain_Get(&fc, malloc, 1, SIZE_MAX) == NULL); |
---|
43 | |
---|
44 | /* check whether freechain put and get works correctly*/ |
---|
45 | |
---|
46 | _Freechain_Put(&fc, NULL); |
---|
47 | |
---|
48 | puts( "INIT - Get node from freechain - OK" ); |
---|
49 | node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node)); |
---|
50 | node->x = 1; |
---|
51 | |
---|
52 | puts( "INIT - Put node back to freechain - OK" ); |
---|
53 | _Freechain_Put(&fc, node); |
---|
54 | |
---|
55 | puts( "INIT - Verify freechain node put and get - OK" ); |
---|
56 | node = _Freechain_Get(&fc, NULL, 0, sizeof(test_node)); |
---|
57 | rtems_test_assert(node->x == 1); |
---|
58 | |
---|
59 | TEST_END(); |
---|
60 | rtems_test_exit(0); |
---|
61 | } |
---|
62 | |
---|
63 | /* configuration information */ |
---|
64 | |
---|
65 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
66 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
67 | |
---|
68 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
69 | |
---|
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 */ |
---|