1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <timesys.h> |
---|
34 | #include <pthread.h> |
---|
35 | #include <sched.h> |
---|
36 | #include <rtems/btimer.h> |
---|
37 | #include "test_support.h" |
---|
38 | |
---|
39 | const char rtems_test_name[] = "PSXTMTHREAD 04"; |
---|
40 | |
---|
41 | /* forward declarations to avoid warnings */ |
---|
42 | void benchmark_pthread_setschedparam(void); |
---|
43 | void benchmark_pthread_getschedparam(void); |
---|
44 | void *POSIX_Init(void *argument); |
---|
45 | |
---|
46 | void benchmark_pthread_getschedparam(void) |
---|
47 | { |
---|
48 | uint32_t end_time; |
---|
49 | int status; |
---|
50 | int policy; |
---|
51 | struct sched_param param; |
---|
52 | |
---|
53 | benchmark_timer_initialize(); |
---|
54 | status = pthread_getschedparam( pthread_self(), &policy, ¶m ); |
---|
55 | end_time = benchmark_timer_read(); |
---|
56 | rtems_test_assert( status == 0 ); |
---|
57 | |
---|
58 | put_time( |
---|
59 | "pthread_getschedparam: only case", |
---|
60 | end_time, |
---|
61 | 1, /* Only executed once */ |
---|
62 | 0, |
---|
63 | 0 |
---|
64 | ); |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | void benchmark_pthread_setschedparam(void) |
---|
69 | { |
---|
70 | uint32_t end_time; |
---|
71 | int status; |
---|
72 | int policy; |
---|
73 | struct sched_param param; |
---|
74 | |
---|
75 | status = pthread_getschedparam( pthread_self(), &policy, ¶m ); |
---|
76 | rtems_test_assert( status == 0 ); |
---|
77 | |
---|
78 | /* Arbitrary priority, no other threads to preempt us so it doesn't matter. */ |
---|
79 | param.sched_priority = 5; |
---|
80 | benchmark_timer_initialize(); |
---|
81 | status = pthread_setschedparam( pthread_self(), policy, ¶m ); |
---|
82 | end_time = benchmark_timer_read(); |
---|
83 | rtems_test_assert( status == 0 ); |
---|
84 | |
---|
85 | put_time( |
---|
86 | "pthread_setschedparam: no thread switch", |
---|
87 | end_time, |
---|
88 | 1, /* Only executed once */ |
---|
89 | 0, |
---|
90 | 0 |
---|
91 | ); |
---|
92 | } |
---|
93 | |
---|
94 | void *POSIX_Init( |
---|
95 | void *argument |
---|
96 | ) |
---|
97 | { |
---|
98 | |
---|
99 | TEST_BEGIN(); |
---|
100 | |
---|
101 | benchmark_pthread_getschedparam(); |
---|
102 | benchmark_pthread_setschedparam(); |
---|
103 | |
---|
104 | TEST_END(); |
---|
105 | rtems_test_exit(0); |
---|
106 | } |
---|
107 | |
---|
108 | /* configuration information */ |
---|
109 | |
---|
110 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
111 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
112 | |
---|
113 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
114 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
115 | |
---|
116 | #define CONFIGURE_INIT |
---|
117 | |
---|
118 | #include <rtems/confdefs.h> |
---|
119 | /* end of file */ |
---|