source: rtems/testsuites/smptests/smppsxaffinity01/init.c @ b422aa3f

5
Last change on this file since b422aa3f was b422aa3f, checked in by Sebastian Huber <sebastian.huber@…>, on 04/26/18 at 14:05:45

tests: Remove configure feature checks

Update #3409.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[f3e6b18]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
[c499856]7 *  http://www.rtems.org/license/LICENSE.
[f3e6b18]8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define  _GNU_SOURCE
15
16#include <tmacros.h>
17#include <errno.h>
18#include <pthread.h>
19#include <sched.h>
20
[ad48ebb]21const char rtems_test_name[] = "SMPPSXAFFINITY 1";
22
[f3e6b18]23#define CPU_COUNT 4
24
25pthread_t           Init_id;
26
27/* forward declarations to avoid warnings */
28void *POSIX_Init(void *argument);
29void Validate_attrgetaffinity_errors(void);
30void Validate_attrsetaffinity_errors(void);
31void Validate_attr(void);
32
[5c332349]33void Validate_attrgetaffinity_errors(void)
[f3e6b18]34{
35  int                 sc;
36  cpu_set_t           cpuset;
37  pthread_attr_t      attr;
38
[af9115f3]39  sc = pthread_attr_init( &attr );
40  rtems_test_assert( sc == 0 );
41
[f3e6b18]42  /* Verify pthread_attr_getaffinity_np validates attr  */
[af9115f3]43  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
44  sc = pthread_attr_getaffinity_np( NULL, sizeof( cpuset ), &cpuset );
45  rtems_test_assert( sc == EINVAL );
[f3e6b18]46
47  /* Verify pthread_attr_getaffinity_np validates cpuset */
[af9115f3]48  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
49  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), NULL );
50  rtems_test_assert( sc == EINVAL );
[f3e6b18]51
52  /* Verify pthread_attr_getaffinity_np validates cpusetsize */
53  puts( "Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL" );
[af9115f3]54  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
[f3e6b18]55  rtems_test_assert( sc == EINVAL );
56
[af9115f3]57  sc = pthread_attr_destroy( &attr );
58  rtems_test_assert( sc == 0 );
59
60  puts( "Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL" );
61  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), &cpuset );
62  rtems_test_assert( sc == EINVAL );
[f3e6b18]63}
64
[5c332349]65void Validate_attrsetaffinity_errors(void)
[f3e6b18]66{
67  int                 sc;
68  cpu_set_t           cpuset;
69  pthread_attr_t      attr;
70
[af9115f3]71  sc = pthread_attr_init( &attr );
72  rtems_test_assert( sc == 0 );
73
[f3e6b18]74  /* Verify pthread_attr_setaffinity_np validates attr.  */
[af9115f3]75  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
76  sc = pthread_attr_setaffinity_np( NULL, sizeof( cpuset ), &cpuset );
77  rtems_test_assert( sc == EINVAL );
[f3e6b18]78
79  /* Verify pthread_attr_setaffinity_np validates cpuset    */
[af9115f3]80  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
81  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), NULL );
82  rtems_test_assert( sc == EINVAL );
[f3e6b18]83
84  /* Verify pthread_attr_setaffinity_np validates cpusetsize */
85  puts( "Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL" );
[af9115f3]86  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
[f3e6b18]87  rtems_test_assert( sc == EINVAL );
88
[af9115f3]89  sc = pthread_attr_destroy( &attr );
90  rtems_test_assert( sc == 0 );
[f3e6b18]91
[af9115f3]92  puts( "Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL" );
93  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), &cpuset  );
[f3e6b18]94  rtems_test_assert( sc == EINVAL );
95}
96
97void Validate_attr(void )
98{
99  int                 sc;
100  pthread_attr_t      attr;
101  uint32_t            cpus;
102  cpu_set_t           cpuset1;
103  cpu_set_t           cpuset2;
104  int                 i;
105  int                 priority;
106
107  sc = pthread_getattr_np( Init_id, &attr );
108  rtems_test_assert( sc == 0 );
109
110  priority = sched_get_priority_min( SCHED_FIFO );
111  rtems_test_assert( priority != -1 );
112
113
[4bc8d2e]114  cpus = rtems_get_processor_count();
[5c332349]115  puts(
[f3e6b18]116    "Init - Validate pthread_attr_setaffinity_np and "
117    "pthread_attr_getaffinity_np"
118  );
[5c332349]119
[f3e6b18]120  /* Set each cpu seperately in the affinity set */
121  for ( i=0; i<cpus; i++ ){
122    CPU_ZERO(&cpuset1);
123    CPU_SET(i, &cpuset1);
124
125    sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), &cpuset1 );
126    rtems_test_assert( sc == 0 );
127
128    sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t), &cpuset2 );
129    rtems_test_assert( sc == 0 );
[5c332349]130
[f3e6b18]131    rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
132  }
133}
134
135void *POSIX_Init(
136  void *ignored
137)
138{
[ad48ebb]139  TEST_BEGIN();
[f3e6b18]140
[5c332349]141  /* Initialize thread id */
[f3e6b18]142  Init_id = pthread_self();
143
144  Validate_attrsetaffinity_errors();
145  Validate_attrgetaffinity_errors();
146  Validate_attr();
[5c332349]147
[ad48ebb]148  TEST_END();
[f3e6b18]149  rtems_test_exit(0);
150}
151
152/* configuration information */
153
[c4b8b147]154#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
[f3e6b18]155#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
156
[54835ae]157#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
[f3e6b18]158
[d4e1ead]159#define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
[f3e6b18]160
161#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
162
[ad48ebb]163#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
164
[f3e6b18]165#define CONFIGURE_POSIX_INIT_THREAD_TABLE
166
167#define CONFIGURE_INIT
168#include <rtems/confdefs.h>
169
170/* global variables */
Note: See TracBrowser for help on using the repository browser.