source: rtems/testsuites/psxtests/psxkey02/init.c @ 698c2e50

4.115
Last change on this file since 698c2e50 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2014.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <pthread.h>
15#include <errno.h>
16#include <rtems/libcsupport.h>
17#include "tmacros.h"
18#include "pmacros.h"
19
20const char rtems_test_name[] = "PSXKEY 2";
21
22/* forward declarations to avoid warnings */
23rtems_task Init(rtems_task_argument ignored);
24
25rtems_task Init(rtems_task_argument ignored)
26{
27  pthread_key_t           key;
28  int                     eno;
29  bool                    ok;
30  uintptr_t               to_alloc;
31  void                   *alloced;
32  rtems_resource_snapshot snapshot;
33  void                   *greedy;
34
35  TEST_BEGIN();
36
37  greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc );
38  rtems_resource_snapshot_take( &snapshot );
39
40  puts( "Init - pthread_key_create - ENOMEM" );
41  while ( to_alloc > 8 ) {
42    ok = rtems_workspace_allocate( to_alloc, &alloced );
43    rtems_test_assert( ok );
44
45    eno = pthread_key_create( &key, NULL );
46
47    rtems_workspace_free( alloced );
48
49    if ( eno == 0 )
50      break;
51
52    rtems_test_assert( eno == ENOMEM );
53
54    /*
55     * Verify heap is still in same shape if we couldn't allocate a task
56     */
57    ok = rtems_resource_snapshot_check( &snapshot );
58    rtems_test_assert( ok );
59
60    to_alloc -= 8;
61  }
62
63  rtems_test_assert( eno == 0 );
64
65  /*
66   * Verify heap is still in same shape after we free the task
67   */
68  puts( "Init - pthread_key_delete - OK" );
69  eno = pthread_key_delete( key );
70  rtems_test_assert( eno == 0 );
71
72  puts( "Init - verify workspace has same memory" );
73  ok = rtems_resource_snapshot_check( &snapshot );
74  rtems_test_assert( ok );
75
76  rtems_workspace_greedy_free( greedy );
77
78  TEST_END();
79  rtems_test_exit(0);
80}
81
82/* configuration information */
83
84#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
85#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
86
87#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
88
89#define CONFIGURE_MAXIMUM_TASKS          1
90#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
91
92#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
93
94#define CONFIGURE_INIT
95#include <rtems/confdefs.h>
96
97/* global variables */
Note: See TracBrowser for help on using the repository browser.