This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New tsan tests.


On Wed, Dec 11, 2013 at 02:12:35PM +0400, Maxim Ostapenko wrote:
> I've added new  tests for tsan from LLVM.
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tsan/aligned_vs_unaligned_race.C
> @@ -0,0 +1,31 @@
> +/* { dg-do run } */
> +
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <stdint.h>
> +
> +uint64_t Global[2];
> +
> +void *Thread1(void *x) {
> +  Global[1]++;
> +  return NULL;
> +}
> +
> +void *Thread2(void *x) {
> +  char *p1 = reinterpret_cast<char *>(&Global[0]);
> +  uint64_t *p4 = reinterpret_cast<uint64_t *>(p1 + 1);

This test would fail on strict alignment targets.  Right now tsan
is supported only on x86_64-linux, so this isn't fatal right now, but
something to consider for the future.  Why is the test C++ only though?
Just replace the reinterpret_cast stuff with normal C cast?

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tsan/benign_race.C
> @@ -0,0 +1,40 @@
> +/* { dg-do run } */
> +
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +int Global;
> +int WTFGlobal;

Again, why C++ only?  Just guard the extern "C" { and } with #ifdef __cplusplus.

> +
> +extern "C" {
> +void AnnotateBenignRaceSized(const char *f, int l,
> +                             void *mem, unsigned int size, const char *desc);
> +void WTFAnnotateBenignRaceSized(const char *f, int l,
> +                                void *mem, unsigned int size,
> +                                const char *desc);
> +}

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tsan/default_options.C
> @@ -0,0 +1,34 @@
> +/* { dg-do run } */
> +/* { dg-shouldfail "tsan" } */
> +
> +#include <pthread.h>
> +#include <stdio.h>
> +
> +extern "C" const char *__tsan_default_options() {
> +  return "report_bugs=0";

Similarly.

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tsan/fd_close_norace.C
> @@ -0,0 +1,32 @@
> +/* { dg-do run } */
> +
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +void *Thread1(void *x) {
> +  int f = open("/dev/random", O_RDONLY);
> +  close(f);
> +  return NULL;
> +}
> +
> +void *Thread2(void *x) {
> +  sleep(1);
> +  int f = open("/dev/random", O_RDONLY);
> +  close(f);
> +  return NULL;
> +}
> +
> +int main() {
> +  pthread_t t[2];
> +  pthread_create(&t[0], NULL, Thread1, NULL);
> +  pthread_create(&t[1], NULL, Thread2, NULL);
> +  pthread_join(t[0], NULL);
> +  pthread_join(t[1], NULL);
> +  printf("OK\n");
> +}

Ditto.  Is the only non-C thing here the missing return 0; from main?

> +
> +/* { dg-prune-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */
> diff --git a/gcc/testsuite/g++.dg/tsan/fd_close_norace2.C b/gcc/testsuite/g++.dg/tsan/fd_close_norace2.C
> new file mode 100644
> index 0000000..f2d394c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tsan/fd_close_norace2.C

Likewise.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]