~ubuntu-branches/ubuntu/natty/clamav/natty-security

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2011-11-08 10:28:26 UTC
  • mfrom: (105.2.3 natty-proposed)
  • Revision ID: package-import@ubuntu.com-20111108102826-aj6ukrmm6t9kyh56
Tags: 0.97.3+dfsg-1ubuntu0.11.04.1
* SECURITY UPDATE: no change rebuild for security pocket
  - CVE-2011-3627

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * File: cancel1.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: Test setting cancel state and cancel type.
37
 
 * - 
38
 
 *
39
 
 * Test Method (Validation or Falsification):
40
 
 * - 
41
 
 *
42
 
 * Requirements Tested:
43
 
 * - pthread_setcancelstate function
44
 
 * - pthread_setcanceltype function
45
 
 *
46
 
 * Features Tested:
47
 
 * - 
48
 
 *
49
 
 * Cases Tested:
50
 
 * - 
51
 
 *
52
 
 * Description:
53
 
 * - 
54
 
 *
55
 
 * Environment:
56
 
 * - 
57
 
 *
58
 
 * Input:
59
 
 * - None.
60
 
 *
61
 
 * Output:
62
 
 * - File name, Line number, and failed expression on failure.
63
 
 * - No output on success.
64
 
 *
65
 
 * Assumptions:
66
 
 * - pthread_create, pthread_self work.
67
 
 *
68
 
 * Pass Criteria:
69
 
 * - Process returns zero exit status.
70
 
 *
71
 
 * Fail Criteria:
72
 
 * - Process returns non-zero exit status.
73
 
 */
74
 
 
75
 
#include "test.h"
76
 
 
77
 
/*
78
 
 * Create NUMTHREADS threads in addition to the Main thread.
79
 
 */
80
 
enum {
81
 
  NUMTHREADS = 2
82
 
};
83
 
 
84
 
typedef struct bag_t_ bag_t;
85
 
struct bag_t_ {
86
 
  int threadnum;
87
 
  int started;
88
 
  /* Add more per-thread state variables here */
89
 
};
90
 
 
91
 
static bag_t threadbag[NUMTHREADS + 1];
92
 
 
93
 
void *
94
 
mythread(void * arg)
95
 
{
96
 
  bag_t * bag = (bag_t *) arg;
97
 
 
98
 
  assert(bag == &threadbag[bag->threadnum]);
99
 
  assert(bag->started == 0);
100
 
  bag->started = 1;
101
 
 
102
 
  /* ... */
103
 
  {
104
 
    int oldstate;
105
 
    int oldtype;
106
 
 
107
 
    assert(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) == 0);
108
 
    assert(oldstate == PTHREAD_CANCEL_ENABLE); /* Check default */
109
 
    assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
110
 
    assert(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) == 0);
111
 
    assert(pthread_setcancelstate(oldstate, &oldstate) == 0);
112
 
    assert(oldstate == PTHREAD_CANCEL_DISABLE); /* Check setting */
113
 
 
114
 
    assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype) == 0);
115
 
    assert(oldtype == PTHREAD_CANCEL_DEFERRED); /* Check default */
116
 
    assert(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) == 0);
117
 
    assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
118
 
    assert(pthread_setcanceltype(oldtype, &oldtype) == 0);
119
 
    assert(oldtype == PTHREAD_CANCEL_ASYNCHRONOUS); /* Check setting */
120
 
  }
121
 
 
122
 
  return 0;
123
 
}
124
 
 
125
 
int
126
 
main()
127
 
{
128
 
  int failed = 0;
129
 
  int i;
130
 
  pthread_t t[NUMTHREADS + 1];
131
 
 
132
 
  assert((t[0] = pthread_self()).p != NULL);
133
 
 
134
 
  for (i = 1; i <= NUMTHREADS; i++)
135
 
    {
136
 
      threadbag[i].started = 0;
137
 
      threadbag[i].threadnum = i;
138
 
      assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
139
 
    }
140
 
 
141
 
  /*
142
 
   * Code to control or munipulate child threads should probably go here.
143
 
   */
144
 
 
145
 
  /*
146
 
   * Give threads time to run.
147
 
   */
148
 
  Sleep(NUMTHREADS * 1000);
149
 
 
150
 
  /*
151
 
   * Standard check that all threads started.
152
 
   */
153
 
  for (i = 1; i <= NUMTHREADS; i++)
154
 
    { 
155
 
      failed = !threadbag[i].started;
156
 
 
157
 
      if (failed)
158
 
        {
159
 
          fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
160
 
        }
161
 
    }
162
 
 
163
 
  assert(!failed);
164
 
 
165
 
  /*
166
 
   * Check any results here. Set "failed" and only print ouput on failure.
167
 
   */
168
 
  for (i = 1; i <= NUMTHREADS; i++)
169
 
    { 
170
 
      /* ... */
171
 
    }
172
 
 
173
 
  assert(!failed);
174
 
 
175
 
  /*
176
 
   * Success.
177
 
   */
178
 
  return 0;
179
 
}