Revision 1236 branches/threaded2merge/tests/threads/msimple/tests_adthread_manager.cpp

tests_adthread_manager.cpp (revision 1236)
191 191
  delete ad_comm::pthread_manager;
192 192
  ad_comm::pthread_manager = 0;
193 193
}
194
void* test_cwrite_lock_buffer(void* ptr)
195
{
196
  new_thread_data* tptr = (new_thread_data*)ptr;
197
  int i = tptr->thread_no;
198
cout << "Thread: " << i << endl;
199
  ad_comm::pthread_manager->cwrite_lock_buffer(i);
200
cout << "UNThread: " << i << endl;
201
  lflag--;
202
  return ptr;
203
}
204
/*
205
TEST_F(tests_adthread_manager, cwrite_lock_buffer)
206
{
207
  const int nthread = 5;
208
  const int ngroups = 1;
209
  ivector ng(1, ngroups);
210
  // number of threads in group 1
211
  ng(1)=nthread;
212
  // create instance of pthread_manager class 
213
  // third argument is number of bytes in the transfer buffer
214
  ad_comm::pthread_manager = new adpthread_manager(ngroups, ng, 32005);
215
  if (ad_comm::pthread_manager == 0)
216
  {
217
    FAIL();
218
  }
219

  
220
  ad_comm::pthread_manager->attach_code(test_cwrite_lock_buffer);
221

  
222
  new_thread_data data[nthread + 1];
223
  for (int i = 0; i <= nthread; i++)
224
  {
225
    data[i].thread_no = i;
226
  }
227

  
228
  lflag = 0;
229
  for (int i = 1; i <= nthread; i++)
230
  {
231
    ad_comm::pthread_manager->cwrite_lock_buffer(i);
232
    lflag++;
233
    ad_comm::pthread_manager->cwrite_unlock_buffer(i);
234
  }
235
  ASSERT_EQ(5, lflag);
236

  
237
  //This starts thread after a unknown delay
238
  ad_comm::pthread_manager->create_all(&data);
239
  ASSERT_EQ(5, lflag);
240
  cout << __func__ << ':' << __LINE__ << endl;
241
  sleep(1);
242
  cout << __func__ << ':' << __LINE__ << endl;
243
  for (int i = 1; i <= nthread; i++)
244
  {
245
  cout << __func__ << ':' << __LINE__ << endl;
246
    ad_comm::pthread_manager->cwrite_unlock_buffer(i);
247
  cout << __func__ << ':' << __LINE__ << endl;
248
  }
249
  cout << __func__ << ':' << __LINE__ << endl;
250
  ad_comm::pthread_manager->pthread_join_all();
251
  cout << __func__ << ':' << __LINE__ << endl;
252
  //Need to join it
253
  ASSERT_EQ(0, lflag);
254

  
255
  delete ad_comm::pthread_manager;
256
  ad_comm::pthread_manager = 0;
257
}
258
*/
259
class tests_adthread_buffer: public ::testing::Test {};
260
TEST_F(tests_adthread_buffer, constructor)
261
{
262
  adthread_buffer b;
263
}
264
TEST_F(tests_adthread_buffer, copy_constructor)
265
{
266
  adthread_buffer a;
267
  adthread_buffer b(a);
268
}
269
int count = 0;
270
void* testlock(void* ptr)
271
{
272
  adthread_buffer* a = (adthread_buffer*)ptr;
273
  count++;
274
  a->lock();
275
  count++;
276
  return ptr;
277
}
278
void* testunlock(void* ptr)
279
{
280
  adthread_buffer* a = (adthread_buffer*)ptr;
281
  a->unlock();
282
  return ptr;
283
}
284
TEST_F(tests_adthread_buffer, read_lock_buffer)
285
{
286
  adthread_buffer a;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff