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

4.115
Last change on this file since db08c38 was db08c38, checked in by Chirayu Desai <cdesai@…>, on 11/24/13 at 07:04:13

psxtmtests: Add psxtmthread05 for pthread_setschedparam

New test psxtmthread 05 uses two tasks and times lowering
the priority of one task plus the preemption and context switch
to the other task.

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