source: rtems/testsuites/psxtmtests/psxtmthread05/init.c @ de549c3

4.11
Last change on this file since de549c3 was de549c3, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 3, 2014 at 3:16:43 PM

Misc psxtmtests: Use uint32_t not long for end_time to match printf() format expectations

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
3 *  On-Line Applications Research Corporation (OAR).
4 *  COPYRIGHT (c) 2013.
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.org/license/LICENSE.
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <timesys.h>
16#include <pthread.h>
17#include <sched.h>
18#include <rtems/timerdrv.h>
19#include "test_support.h"
20
21const char rtems_test_name[] = "PSXTMTHREAD 05";
22
23/* forward declarations to avoid warnings */
24void *POSIX_Init(void *argument);
25void benchmark_pthread_create(void);
26void benchmark_pthread_setschedparam(void);
27void *test_thread(void *argument);
28
29void benchmark_pthread_setschedparam(void)
30{
31  int status;
32  int policy;
33  struct sched_param param;
34  pthread_t thread_ID;
35
36  status = pthread_create(&thread_ID, NULL, test_thread, NULL);
37  rtems_test_assert( status == 0 );
38
39  /* make test_thread equal to POSIX_Init() */
40  pthread_getschedparam(pthread_self(), &policy, &param);
41 
42  pthread_setschedparam(thread_ID, policy, &param);
43  /* At this point, we've switched to test_thread */
44
45  /* Back from test_thread, switch to test_thread again */
46  param.sched_priority = sched_get_priority_min(policy);
47
48  benchmark_timer_initialize();
49  //lower own priority to minimun, scheduler forces an involuntary context switch
50  pthread_setschedparam(pthread_self(), policy, &param);
51}
52
53void *test_thread(
54  void *argument
55)
56{
57  uint32_t end_time;
58
59  sched_yield();
60
61  end_time = benchmark_timer_read();
62  put_time(
63    "pthread_setschedparam: lower own priority preempt",
64    end_time,
65    1,        /* Only executed once */
66    0,
67    0
68  );
69
70  TEST_END();
71  rtems_test_exit(0);
72  //Empty thread used in pthread_create().
73  return NULL;
74}
75
76void *POSIX_Init(
77  void *argument
78)
79{
80
81  TEST_BEGIN();
82  benchmark_pthread_setschedparam();
83
84  rtems_test_assert( 1 );
85  return NULL;
86}
87
88/* configuration information */
89
90#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
91#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
92
93#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
94#define CONFIGURE_POSIX_INIT_THREAD_TABLE
95
96#define CONFIGURE_INIT
97
98#include <rtems/confdefs.h>
99/* end of file */
Note: See TracBrowser for help on using the repository browser.