source: rtems/testsuites/psxtmtests/psxtmthread02/init.c @ fd46711

4.115
Last change on this file since fd46711 was fd46711, checked in by bjorn larsson <bjornlarsson@…>, on 03/21/14 at 20:35:26

psxtmtests: Add test.h support

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
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
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <timesys.h>
15#include <pthread.h>
16#include <sched.h>
17#include <rtems/timerdrv.h>
18#include "test_support.h"
19
20const char rtems_test_name[] = "PSXTMTHREAD 02";
21
22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void benchmark_pthread_create(void);
25void *thread(void *argument);
26
27void benchmark_pthread_create(void)
28{
29  int  status;
30  pthread_t thread_ID;
31  pthread_attr_t attr;
32  struct sched_param param;
33
34  status = pthread_attr_init(&attr);
35  rtems_test_assert( status == 0 );
36
37  status = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
38  rtems_test_assert( status == 0 );
39
40  status = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
41  rtems_test_assert( status == 0 );
42
43  param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
44  status = pthread_attr_setschedparam(&attr, &param);
45  rtems_test_assert( status == 0 );
46
47  /* create second thread with max priority and get preempted on creation */
48  benchmark_timer_initialize();
49  status = pthread_create(&thread_ID, &attr, thread, NULL);
50}
51
52void *thread(
53  void *argument
54)
55{
56  long end_time;
57
58  end_time = benchmark_timer_read();
59  put_time(
60    "pthread_create: preempt",
61    end_time,
62    1,        /* Only executed once */
63    0,
64    0
65  );
66  return NULL;
67}
68
69void *POSIX_Init(
70  void *argument
71)
72{
73
74  TEST_BEGIN();
75
76  benchmark_pthread_create();
77
78  TEST_END();
79  rtems_test_exit(0);
80}
81
82/* configuration information */
83
84#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
85#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
86
87#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
88#define CONFIGURE_POSIX_INIT_THREAD_TABLE
89
90#define CONFIGURE_INIT
91
92#include <rtems/confdefs.h>
93/* end of file */
Note: See TracBrowser for help on using the repository browser.