diff options
author | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 12:37:58 +0000 |
---|---|---|
committer | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 12:37:58 +0000 |
commit | 0716cbab63d81f732a9779cb72842cd30c23633a (patch) | |
tree | c591430c960d81b9f58e34cde3a58e59cf7ae793 /base/tools_sanity_unittest.cc | |
parent | 6877743b0d10f2597554db43e2041e2b5a6f4d96 (diff) | |
download | chromium_src-0716cbab63d81f732a9779cb72842cd30c23633a.zip chromium_src-0716cbab63d81f732a9779cb72842cd30c23633a.tar.gz chromium_src-0716cbab63d81f732a9779cb72842cd30c23633a.tar.bz2 |
Added the ToolsSanityTest test case to base_unittests.
tools_sanity_test.cc contains positive tests for tools used on the buildbots.
ToolsSanityTest.MemoryLeak contains an memory leak reportable by Memcheck and
heap leak checker.
ToolsSanityTest.DataRace contains a data race reportable by ThreadSanitizer.
The corresponding suppressions are in
tools/valgrind/{memcheck,tsan}/suppressions.txt
The idea is to check the tools' reports for their presence when testing
base_unittests.
Review URL: http://codereview.chromium.org/491044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/tools_sanity_unittest.cc')
-rw-r--r-- | base/tools_sanity_unittest.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/base/tools_sanity_unittest.cc b/base/tools_sanity_unittest.cc new file mode 100644 index 0000000..91f56b4 --- /dev/null +++ b/base/tools_sanity_unittest.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop.h" +#include "base/thread.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +// We use caps here just to ensure that the method name doesn't interfere with +// the wildcarded suppressions. +class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate { + public: + explicit TOOLS_SANITY_TEST_CONCURRENT_THREAD(bool *value) : value_(value) {} + ~TOOLS_SANITY_TEST_CONCURRENT_THREAD() {} + void ThreadMain() { + *value_ = true; + } + private: + bool* value_; +}; + +} + +// A memory leak detector should report an error in this test. +TEST(ToolsSanityTest, MemoryLeak) { + int *leak = new int[256]; // Leak some memory intentionally. + leak[4] = 1; // Make sure the allocated memory is used. +} + +// A data race detector should report an error in this test. +TEST(ToolsSanityTest, DataRace) { + bool shared = false; + PlatformThreadHandle a; + PlatformThreadHandle b; + PlatformThread::Delegate *thread1 = + new TOOLS_SANITY_TEST_CONCURRENT_THREAD(&shared); + PlatformThread::Delegate *thread2 = + new TOOLS_SANITY_TEST_CONCURRENT_THREAD(&shared); + + PlatformThread::Create(0, thread1, &a); + PlatformThread::Create(0, thread2, &b); + PlatformThread::Join(a); + PlatformThread::Join(b); + EXPECT_TRUE(shared); + delete thread1; + delete thread2; +} + |