source: rtems/testsuites/sptests/spwkspace/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  Exercise Classic API Workspace Wrappers
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <tmacros.h>
17
18#include <string.h>
19
20#include <rtems/score/wkspace.h>
21
22const char rtems_test_name[] = "SPWKSPACE";
23
24/* forward declarations to avoid warnings */
25rtems_task Init(rtems_task_argument argument);
26
27static void test_workspace_string_duplicate(void)
28{
29  char a [] = "abcd";
30  char b [] = "abc";
31  char c [] = "ab";
32  char d [] = "a";
33  char e [] = "";
34  size_t maxlen = 3;
35  char *dup_a = _Workspace_String_duplicate( a, maxlen );
36  char *dup_b = _Workspace_String_duplicate( b, maxlen );
37  char *dup_c = _Workspace_String_duplicate( c, maxlen );
38  char *dup_d = _Workspace_String_duplicate( d, maxlen );
39  char *dup_e = _Workspace_String_duplicate( e, maxlen );
40
41  rtems_test_assert( dup_a != NULL );
42  rtems_test_assert( dup_b != NULL );
43  rtems_test_assert( dup_c != NULL );
44  rtems_test_assert( dup_d != NULL );
45  rtems_test_assert( dup_e != NULL );
46  rtems_test_assert( strcmp( dup_a, b ) == 0 );
47  rtems_test_assert( strcmp( dup_b, b ) == 0 );
48  rtems_test_assert( strcmp( dup_c, c ) == 0 );
49  rtems_test_assert( strcmp( dup_d, d ) == 0 );
50  rtems_test_assert( strcmp( dup_e, e ) == 0 );
51
52  _Workspace_Free( dup_a );
53  _Workspace_Free( dup_b );
54  _Workspace_Free( dup_c );
55  _Workspace_Free( dup_d );
56  _Workspace_Free( dup_e );
57}
58
59static void test_workspace_allocate_aligned(void)
60{
61  uintptr_t align = 512;
62  void *p = _Workspace_Allocate_aligned( 1, align );
63
64  rtems_test_assert( p != NULL );
65  rtems_test_assert( ((uintptr_t) p & (align - 1)) == 0 );
66
67  _Workspace_Free( p );
68}
69
70rtems_task Init(
71  rtems_task_argument argument
72)
73{
74  void                   *p1;
75  bool                    retbool;
76  Heap_Information_block  info;
77
78  TEST_BEGIN();
79
80  puts( "rtems_workspace_get_information - null pointer" );
81  retbool = rtems_workspace_get_information( NULL );
82  rtems_test_assert( retbool == false );
83
84  puts( "rtems_workspace_get_information - OK" );
85  retbool = rtems_workspace_get_information( &info );
86  rtems_test_assert( retbool == true );
87
88  puts( "rtems_workspace_allocate - null pointer" );
89  retbool = rtems_workspace_allocate( 42, NULL );
90  rtems_test_assert( retbool == false );
91
92  puts( "rtems_workspace_allocate - 0 bytes" );
93  retbool = rtems_workspace_allocate( 0, &p1 );
94  rtems_test_assert( retbool == false );
95
96  puts( "rtems_workspace_allocate - too many bytes" );
97  retbool = rtems_workspace_allocate( info.Free.largest * 2, &p1 );
98  rtems_test_assert( retbool == false );
99
100  puts( "rtems_workspace_allocate - 42 bytes" );
101  retbool = rtems_workspace_allocate( 42, &p1 );
102  rtems_test_assert( retbool == true );
103  rtems_test_assert( p1 != NULL );
104
105  puts( "rtems_workspace_free - NULL" );
106  retbool = rtems_workspace_free( NULL );
107  rtems_test_assert( retbool == true );
108
109  puts( "rtems_workspace_free - previous pointer to 42 bytes" );
110  retbool = rtems_workspace_free( p1 );
111  rtems_test_assert( retbool == true );
112
113  puts( "_Workspace_String_duplicate - samples" );
114  test_workspace_string_duplicate();
115
116  puts( "_Workspace_Allocate_aligned" );
117  test_workspace_allocate_aligned();
118
119  TEST_END();
120  rtems_test_exit( 0 );
121}
122
123/* configuration information */
124
125#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
126#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
127
128#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
129
130#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
131
132#define CONFIGURE_MAXIMUM_TASKS             1
133
134#define CONFIGURE_MEMORY_OVERHEAD 1
135
136#define CONFIGURE_INIT
137#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.