diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-04-22 10:40:14 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-04-22 10:40:14 +0000 |
commit | 5b31c423a0edfb947f26b666157f706589c8876e (patch) | |
tree | f71d6973530df1f3da9ba9ef7f58a66c63ac4742 /lldb/packages/Python/lldbsuite/test | |
parent | 8c4acddebc47b2d6dbd8d05fc39bf2e007046e16 (diff) | |
download | bcm5719-llvm-5b31c423a0edfb947f26b666157f706589c8876e.tar.gz bcm5719-llvm-5b31c423a0edfb947f26b666157f706589c8876e.zip |
Renumber ThreadSanitizer-provided thread IDs to match LLDB thread numbers.
llvm-svn: 267133
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
3 files changed, 131 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/Makefile new file mode 100644 index 00000000000..c930ae563fc --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS := -fsanitize=thread -g + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/TestTsanThreadNumbers.py b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/TestTsanThreadNumbers.py new file mode 100644 index 00000000000..18ebaa08f8a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/TestTsanThreadNumbers.py @@ -0,0 +1,67 @@ +""" +Tests that TSan and LLDB have correct thread numbers. +""" + +import os, time +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil +import json + +class TsanThreadNumbersTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(oslist=["linux"], bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)") + @skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default + @skipIfRemote + @skipUnlessCompilerRt + def test (self): + self.build () + self.tsan_tests () + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def tsan_tests (self): + exe = os.path.join (os.getcwd(), "a.out") + self.expect("file " + exe, patterns = [ "Current executable set to .*a.out" ]) + + self.runCmd("run") + + stop_reason = self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason() + if stop_reason == lldb.eStopReasonExec: + # On OS X 10.10 and older, we need to re-exec to enable interceptors. + self.runCmd("continue") + + # the stop reason of the thread should be breakpoint. + self.expect("thread list", "A data race should be detected", + substrs = ['stopped', 'stop reason = Data race detected']) + + self.assertEqual(self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(), lldb.eStopReasonInstrumentation) + + report_thread_id = self.dbg.GetSelectedTarget().process.GetSelectedThread().GetIndexID() + + self.expect("thread info -s", "The extended stop info should contain the TSan provided fields", + substrs = ["instrumentation_class", "description", "mops"]) + + output_lines = self.res.GetOutput().split('\n') + json_line = '\n'.join(output_lines[2:]) + data = json.loads(json_line) + self.assertEqual(data["instrumentation_class"], "ThreadSanitizer") + self.assertEqual(data["issue_type"], "data-race") + self.assertEqual(len(data["mops"]), 2) + + self.assertEqual(data["mops"][0]["thread_id"], report_thread_id) + + other_thread_id = data["mops"][1]["thread_id"] + self.assertTrue(other_thread_id != report_thread_id) + other_thread = self.dbg.GetSelectedTarget().process.GetThreadByIndexID(other_thread_id) + self.assertTrue(other_thread.IsValid()) + + self.runCmd("thread select %d" % other_thread_id) + + self.expect("thread backtrace", "The other thread should be stopped in f1 or f2", + substrs = ["a.out", "main.c"]) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/main.c new file mode 100644 index 00000000000..04ebb723c3b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/tsan/thread_numbers/main.c @@ -0,0 +1,58 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +char *pointer; + +void *nothing(void *p) { + return NULL; +} + +void *f1(void *p) { + pointer[0] = 'x'; + sleep(100); + return NULL; +} + +void *f2(void *p) { + pointer[0] = 'y'; + sleep(100); + return NULL; +} + +int main (int argc, char const *argv[]) +{ + pointer = (char *)malloc(10); + + for (int i = 0; i < 3; i++) { + pthread_t t; + pthread_create(&t, NULL, nothing, NULL); + pthread_join(t, NULL); + } + + pthread_t t1; + pthread_create(&t1, NULL, f1, NULL); + + for (int i = 0; i < 3; i++) { + pthread_t t; + pthread_create(&t, NULL, nothing, NULL); + pthread_join(t, NULL); + } + + pthread_t t2; + pthread_create(&t2, NULL, f2, NULL); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + + return 0; +} |