valgrind: r10932 - trunk/drd/tests

View: New views
1 Messages — Rating Filter:   Alert me  

valgrind: r10932 - trunk/drd/tests

by svn-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Author: bart
Date: 2009-11-09 15:44:53 +0000 (Mon, 09 Nov 2009)
New Revision: 10932

Log:
Added a regression test.

Added:
   trunk/drd/tests/qt4_atomic.cpp
Modified:
   trunk/drd/tests/
   trunk/drd/tests/Makefile.am



Property changes on: trunk/drd/tests
___________________________________________________________________
Name: svn:ignore
   - *.dSYM
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
annotate_ignore_rw
annotate_ignore_write
annotate_publish_hg
annotate_rwlock
atomic_var
bar_bad
bar_trivial
boost_thread
circular_buffer
custom_alloc
drd_bitmap_test
fp_race
hg01_all_ok
hg02_deadlock
hg03_inherit
hg04_race
hg05_race2
hg06_readshared
hold_lock
linuxthreads_det
Makefile
Makefile.in
matinv
memory_allocation
monitor_example
new_delete
omp_matinv
omp_prime
omp_printf
pth_barrier
pth_barrier_race
pth_barrier_reinit
pth_broadcast
pth_cancel_locked
pth_cleanup_handler
pth_cond_race
pth_create_chain
pth_create_glibc_2_0
pth_detached
pth_detached_sem
pth_inconsistent_cond_wait
pth_mutex_reinit
pth_process_shared_mutex
pth_spinlock
qt4_mutex
qt4_rwlock
qt4_semaphore
recursive_mutex
rwlock_race
rwlock_test
rwlock_type_checking
sem_as_mutex
sem_open
sigalrm
tc01_simple_race
tc02_simple_tls
tc03_re_excl
tc04_free_lock
tc05_simple_race
tc06_two_races
tc07_hbl1
tc08_hbl2
tc09_bad_unlock
tc10_rec_lock
tc11_XCHG
tc12_rwl_trivial
tc13_laog1
tc15_laog_lockdel
tc16_byterace
tc17_sembar
tc18_semabuse
tc19_shadowmem
tc20_verifywrap
tc21_pthonce
tc22_exit_w_lock
tc23_bogus_condwait
tc24_nonzero_sem
thread_name
trylock
tsan_unittest
unit_bitmap
unit_vc
vg_regtest.tmp*

   + *.dSYM
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
annotate_ignore_rw
annotate_ignore_write
annotate_publish_hg
annotate_rwlock
atomic_var
bar_bad
bar_trivial
boost_thread
circular_buffer
custom_alloc
drd_bitmap_test
fp_race
hg01_all_ok
hg02_deadlock
hg03_inherit
hg04_race
hg05_race2
hg06_readshared
hold_lock
linuxthreads_det
Makefile
Makefile.in
matinv
memory_allocation
monitor_example
new_delete
omp_matinv
omp_prime
omp_printf
pth_barrier
pth_barrier_race
pth_barrier_reinit
pth_broadcast
pth_cancel_locked
pth_cleanup_handler
pth_cond_race
pth_create_chain
pth_create_glibc_2_0
pth_detached
pth_detached_sem
pth_inconsistent_cond_wait
pth_mutex_reinit
pth_process_shared_mutex
pth_spinlock
qt4_atomic
qt4_mutex
qt4_rwlock
qt4_semaphore
recursive_mutex
rwlock_race
rwlock_test
rwlock_type_checking
sem_as_mutex
sem_open
sigalrm
tc01_simple_race
tc02_simple_tls
tc03_re_excl
tc04_free_lock
tc05_simple_race
tc06_two_races
tc07_hbl1
tc08_hbl2
tc09_bad_unlock
tc10_rec_lock
tc11_XCHG
tc12_rwl_trivial
tc13_laog1
tc15_laog_lockdel
tc16_byterace
tc17_sembar
tc18_semabuse
tc19_shadowmem
tc20_verifywrap
tc21_pthonce
tc22_exit_w_lock
tc23_bogus_condwait
tc24_nonzero_sem
thread_name
trylock
tsan_unittest
unit_bitmap
unit_vc
vg_regtest.tmp*


Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2009-11-06 08:59:34 UTC (rev 10931)
+++ trunk/drd/tests/Makefile.am 2009-11-09 15:44:53 UTC (rev 10932)
@@ -147,6 +147,8 @@
  pth_process_shared_mutex.vgtest             \
  pth_spinlock.stderr.exp                     \
  pth_spinlock.vgtest                         \
+ qt4_atomic.stderr.exp                       \
+ qt4_atomic.vgtest                           \
  qt4_mutex.stderr.exp                        \
  qt4_mutex.vgtest                            \
  qt4_rwlock.stderr.exp                       \
@@ -300,7 +302,7 @@
 endif
 
 if HAVE_QTCORE
-check_PROGRAMS += qt4_mutex qt4_rwlock qt4_semaphore
+check_PROGRAMS += qt4_atomic qt4_mutex qt4_rwlock qt4_semaphore
 endif
 
 
@@ -352,6 +354,10 @@
 endif
 
 if HAVE_QTCORE
+qt4_atomic_SOURCES          = qt4_atomic.cpp
+qt4_atomic_CXXFLAGS         = $(AM_CXXFLAGS) $(QTCORE_CFLAGS)
+qt4_atomic_LDADD            = $(LDADD) $(QTCORE_LIBS)
+
 qt4_mutex_SOURCES           = qt4_mutex.cpp
 qt4_mutex_CXXFLAGS          = $(AM_CXXFLAGS) $(QTCORE_CFLAGS)
 qt4_mutex_LDADD             = $(LDADD) $(QTCORE_LIBS)

Added: trunk/drd/tests/qt4_atomic.cpp
===================================================================
--- trunk/drd/tests/qt4_atomic.cpp                        (rev 0)
+++ trunk/drd/tests/qt4_atomic.cpp 2009-11-09 15:44:53 UTC (rev 10932)
@@ -0,0 +1,66 @@
+/// Test program that uses the QAtomicInt class.
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include "config.h"
+#include <QMutex>         // class QMutex
+#include <QAtomicInt>     // class QAtomicInt
+#include <cassert>
+#include <cstdio>         // fprintf()
+#include <cstdlib>        // atoi()
+#include <new>
+#include <pthread.h>      // pthread_barrier_t
+#include <vector>
+
+
+static pthread_barrier_t s_barrier;
+static QAtomicInt* s_pAtomicInt;
+
+
+void* thread_func(void* pArg)
+{
+  const int iArg = *reinterpret_cast<int*>(pArg);
+
+  pthread_barrier_wait(&s_barrier);
+
+  while (! s_pAtomicInt->testAndSetOrdered(iArg, iArg + 1))
+    ;
+
+  return NULL;
+}
+
+int main(int argc, char** argv)
+{
+  int i;
+  const int n_threads = 10;
+  std::vector<int>       thread_arg(n_threads);
+  std::vector<pthread_t> tid(n_threads);
+
+  fprintf(stderr, "Start of test.\n");
+
+  pthread_barrier_init(&s_barrier, 0, n_threads);
+  s_pAtomicInt = new QAtomicInt();
+  for (i = 0; i < n_threads; i++)
+  {
+    thread_arg[i] = i;
+    pthread_create(&tid[i], 0, thread_func, &thread_arg[i]);
+  }
+  for (i = 0; i < n_threads; i++)
+  {
+    pthread_join(tid[i], NULL);
+  }
+  pthread_barrier_destroy(&s_barrier);
+
+  if (*s_pAtomicInt == n_threads)
+    fprintf(stderr, "Test successful.\n");
+  else
+    fprintf(stderr, "Test failed: counter = %d, should be %d\n",
+            static_cast<int>(*s_pAtomicInt), n_threads);
+
+  delete s_pAtomicInt;
+  s_pAtomicInt = 0;
+
+  return 0;
+}


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@...
https://lists.sourceforge.net/lists/listinfo/valgrind-developers