~ubuntu-branches/ubuntu/raring/clamav/raring-updates

« back to all changes in this revision

Viewing changes to win32/3rdparty/pthreads/tests/inherit1.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-06-18 11:56:34 UTC
  • mfrom: (0.35.21 sid)
  • Revision ID: james.westby@ubuntu.com-20110618115634-u2lovivet0qx34d0
Tags: 0.97.1+dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * File: inherit1.c
3
 
 *
4
 
 *
5
 
 * --------------------------------------------------------------------------
6
 
 *
7
 
 *      Pthreads-win32 - POSIX Threads Library for Win32
8
 
 *      Copyright(C) 1998 John E. Bossom
9
 
 *      Copyright(C) 1999,2005 Pthreads-win32 contributors
10
 
 * 
11
 
 *      Contact Email: rpj@callisto.canberra.edu.au
12
 
 * 
13
 
 *      The current list of contributors is contained
14
 
 *      in the file CONTRIBUTORS included with the source
15
 
 *      code distribution. The list can also be seen at the
16
 
 *      following World Wide Web location:
17
 
 *      http://sources.redhat.com/pthreads-win32/contributors.html
18
 
 * 
19
 
 *      This library is free software; you can redistribute it and/or
20
 
 *      modify it under the terms of the GNU Lesser General Public
21
 
 *      License as published by the Free Software Foundation; either
22
 
 *      version 2 of the License, or (at your option) any later version.
23
 
 * 
24
 
 *      This library is distributed in the hope that it will be useful,
25
 
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
 
 *      Lesser General Public License for more details.
28
 
 * 
29
 
 *      You should have received a copy of the GNU Lesser General Public
30
 
 *      License along with this library in the file COPYING.LIB;
31
 
 *      if not, write to the Free Software Foundation, Inc.,
32
 
 *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
33
 
 *
34
 
 * --------------------------------------------------------------------------
35
 
 *
36
 
 * Test Synopsis:
37
 
 * - Test thread priority inheritance.
38
 
 *
39
 
 * Test Method (Validation or Falsification):
40
 
 * - 
41
 
 *
42
 
 * Requirements Tested:
43
 
 * -
44
 
 *
45
 
 * Features Tested:
46
 
 * -
47
 
 *
48
 
 * Cases Tested:
49
 
 * -
50
 
 *
51
 
 * Description:
52
 
 * -
53
 
 *
54
 
 * Environment:
55
 
 * -
56
 
 *
57
 
 * Input:
58
 
 * - None.
59
 
 *
60
 
 * Output:
61
 
 * - File name, Line number, and failed expression on failure.
62
 
 * - No output on success.
63
 
 *
64
 
 * Assumptions:
65
 
 * -
66
 
 *
67
 
 * Pass Criteria:
68
 
 * - Process returns zero exit status.
69
 
 *
70
 
 * Fail Criteria:
71
 
 * - Process returns non-zero exit status.
72
 
 */
73
 
 
74
 
#include "test.h"
75
 
 
76
 
enum {
77
 
  PTW32TEST_THREAD_INIT_PRIO = 0,
78
 
  PTW32TEST_MAXPRIORITIES = 512
79
 
};
80
 
 
81
 
int minPrio;
82
 
int maxPrio;
83
 
int validPriorities[PTW32TEST_MAXPRIORITIES];
84
 
 
85
 
 
86
 
void * func(void * arg)
87
 
{
88
 
  int policy;
89
 
  struct sched_param param;
90
 
 
91
 
  assert(pthread_getschedparam(pthread_self(), &policy, &param) == 0);
92
 
  return (void *) param.sched_priority;
93
 
}
94
 
 
95
 
 
96
 
void *
97
 
getValidPriorities(void * arg)
98
 
{
99
 
  int prioSet;
100
 
  pthread_t thread = pthread_self();
101
 
  HANDLE threadH = pthread_getw32threadhandle_np(thread);
102
 
  struct sched_param param;
103
 
 
104
 
  for (prioSet = minPrio;
105
 
       prioSet <= maxPrio;
106
 
       prioSet++)
107
 
    {
108
 
        /*
109
 
       * If prioSet is invalid then the threads priority is unchanged
110
 
       * from the previous value. Make the previous value a known
111
 
       * one so that we can check later.
112
 
       */
113
 
        param.sched_priority = prioSet;
114
 
        assert(pthread_setschedparam(thread, SCHED_OTHER, &param) == 0);
115
 
        validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH);
116
 
    }
117
 
 
118
 
  return (void *) 0;
119
 
}
120
 
 
121
 
 
122
 
int
123
 
main()
124
 
{
125
 
  pthread_t t;
126
 
  pthread_t mainThread = pthread_self();
127
 
  pthread_attr_t attr;
128
 
  void * result = NULL;
129
 
  struct sched_param param;
130
 
  struct sched_param mainParam;
131
 
  int prio;
132
 
  int policy;
133
 
  int inheritsched = -1;
134
 
  pthread_t threadID = pthread_self();
135
 
  HANDLE threadH = pthread_getw32threadhandle_np(threadID);
136
 
 
137
 
  assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
138
 
  assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
139
 
 
140
 
  assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
141
 
  assert(pthread_join(t, &result) == 0);
142
 
 
143
 
  assert(pthread_attr_init(&attr) == 0);
144
 
  assert(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED) == 0);
145
 
  assert(pthread_attr_getinheritsched(&attr, &inheritsched) == 0);
146
 
  assert(inheritsched == PTHREAD_INHERIT_SCHED);
147
 
 
148
 
  for (prio = minPrio; prio <= maxPrio; prio++)
149
 
    {
150
 
      mainParam.sched_priority = prio;
151
 
 
152
 
      /* Set the thread's priority to a known initial value. */
153
 
      SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
154
 
 
155
 
      /* Change the main thread priority */
156
 
      assert(pthread_setschedparam(mainThread, SCHED_OTHER, &mainParam) == 0);
157
 
      assert(pthread_getschedparam(mainThread, &policy, &mainParam) == 0);
158
 
      assert(policy == SCHED_OTHER);
159
 
      /* Priority returned below should be the level set by pthread_setschedparam(). */
160
 
      assert(mainParam.sched_priority == prio);
161
 
      assert(GetThreadPriority(threadH) ==
162
 
               validPriorities[prio+(PTW32TEST_MAXPRIORITIES/2)]);
163
 
 
164
 
      for (param.sched_priority = prio;
165
 
           param.sched_priority <= maxPrio;
166
 
           param.sched_priority++)
167
 
        {
168
 
          /* The new thread create should ignore this new priority */
169
 
          assert(pthread_attr_setschedparam(&attr, &param) == 0);
170
 
          assert(pthread_create(&t, &attr, func, NULL) == 0);
171
 
          pthread_join(t, &result);
172
 
          assert((int) result == mainParam.sched_priority);
173
 
        }
174
 
    }
175
 
 
176
 
  return 0;
177
 
}