source: rtems/testsuites/smptests/smppsxmutex01/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#define TEST_INIT
20
21#include <errno.h>
22#include <pthread.h>
23
24#include <rtems.h>
25#include <rtems/libcsupport.h>
26
27#include "tmacros.h"
28
29const char rtems_test_name[] = "SMPPSXMUTEX 1";
30
31#define SCHED_A rtems_build_name(' ', ' ', ' ', 'A')
32
33#define SCHED_B rtems_build_name(' ', ' ', ' ', 'B')
34
35typedef struct {
36  pthread_t thread_b;
37  pthread_mutexattr_t mtx_attr;
38  pthread_mutex_t mtx_a;
39  pthread_mutex_t mtx_b;
40} test_context;
41
42static test_context test_instance;
43
44static void *thread_b(void *arg)
45{
46  test_context *ctx;
47  rtems_id scheduler_b_id;
48  rtems_status_code sc;
49  rtems_task_priority prio;
50  int prio_ceiling;
51  int eno;
52
53  ctx = arg;
54
55  rtems_test_assert(rtems_get_current_processor() == 0);
56
57  sc = rtems_scheduler_ident(SCHED_B, &scheduler_b_id);
58  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
59
60  sc = rtems_task_set_priority(pthread_self(), RTEMS_CURRENT_PRIORITY, &prio);
61  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
62
63  sc = rtems_task_set_scheduler(pthread_self(), scheduler_b_id, prio);
64  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
65
66  rtems_test_assert(rtems_get_current_processor() == 1);
67
68  eno = pthread_mutex_init(&ctx->mtx_b, &ctx->mtx_attr);
69  rtems_test_assert(eno == 0);
70
71  eno = pthread_mutex_getprioceiling(&ctx->mtx_b, &prio_ceiling);
72  rtems_test_assert(eno == 0);
73  rtems_test_assert(prio_ceiling == 254);
74
75  eno = pthread_mutex_lock(&ctx->mtx_b);
76  rtems_test_assert(eno == 0);
77
78  eno = pthread_mutex_unlock(&ctx->mtx_b);
79  rtems_test_assert(eno == 0);
80
81  eno = pthread_mutex_destroy(&ctx->mtx_b);
82  rtems_test_assert(eno == 0);
83
84  eno = pthread_mutex_getprioceiling(&ctx->mtx_a, &prio_ceiling);
85  rtems_test_assert(eno == 0);
86  rtems_test_assert(prio_ceiling == 126);
87
88  eno = pthread_mutex_lock(&ctx->mtx_a);
89  rtems_test_assert(eno == EINVAL);
90
91  return ctx;
92}
93
94static void test(test_context *ctx)
95{
96  uint32_t cpu_count;
97  int prio_ceiling;
98  int eno;
99
100  cpu_count = rtems_get_processor_count();
101
102  rtems_test_assert(rtems_get_current_processor() == 0);
103
104  eno = pthread_mutexattr_init(&ctx->mtx_attr);
105  rtems_test_assert(eno == 0);
106
107  eno = pthread_mutexattr_setprotocol(&ctx->mtx_attr, PTHREAD_PRIO_PROTECT);
108  rtems_test_assert(eno == 0);
109
110  eno = pthread_mutex_init(&ctx->mtx_a, &ctx->mtx_attr);
111  rtems_test_assert(eno == 0);
112
113  eno = pthread_mutex_getprioceiling(&ctx->mtx_a, &prio_ceiling);
114  rtems_test_assert(eno == 0);
115  rtems_test_assert(prio_ceiling == 126);
116
117  eno = pthread_mutex_lock(&ctx->mtx_a);
118  rtems_test_assert(eno == 0);
119
120  eno = pthread_mutex_unlock(&ctx->mtx_a);
121  rtems_test_assert(eno == 0);
122
123  if (cpu_count > 1) {
124    void *exit_code;
125
126    eno = pthread_create(&ctx->thread_b, NULL, thread_b, ctx);
127    rtems_test_assert(eno == 0);
128
129    exit_code = NULL;
130    eno = pthread_join(ctx->thread_b, &exit_code);
131    rtems_test_assert(eno == 0);
132    rtems_test_assert(exit_code == ctx);
133  }
134
135  eno = pthread_mutex_destroy(&ctx->mtx_a);
136  rtems_test_assert(eno == 0);
137
138  eno = pthread_mutexattr_destroy(&ctx->mtx_attr);
139  rtems_test_assert(eno == 0);
140}
141
142static void *POSIX_Init(void *arg)
143{
144  rtems_resource_snapshot snapshot;
145
146  TEST_BEGIN();
147
148  rtems_resource_snapshot_take(&snapshot);
149
150  test(&test_instance);
151
152  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
153
154  TEST_END();
155  rtems_test_exit(0);
156}
157
158#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
159#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
160
161#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
162
163#define CONFIGURE_MAXIMUM_PROCESSORS 2
164
165#define CONFIGURE_SCHEDULER_PRIORITY_SMP
166
167#include <rtems/scheduler.h>
168
169RTEMS_SCHEDULER_CONTEXT_PRIORITY_SMP(a, 128);
170
171RTEMS_SCHEDULER_CONTEXT_PRIORITY_SMP(b, 256);
172
173#define CONFIGURE_SCHEDULER_CONTROLS \
174  RTEMS_SCHEDULER_CONTROL_PRIORITY_SMP(a, SCHED_A), \
175  RTEMS_SCHEDULER_CONTROL_PRIORITY_SMP(b, SCHED_B)  \
176
177#define CONFIGURE_SMP_SCHEDULER_ASSIGNMENTS \
178  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \
179  RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL)
180
181#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
182
183#define CONFIGURE_POSIX_INIT_THREAD_TABLE
184
185#define CONFIGURE_INIT
186
187#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.