Chromium Code Reviews| Index: base/allocator/type_profiler_map_unittests.cc |
| diff --git a/base/allocator/type_profiler_map_unittests.cc b/base/allocator/type_profiler_map_unittests.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2720c662e54e717f7f904c3659951d19cd60174 |
| --- /dev/null |
| +++ b/base/allocator/type_profiler_map_unittests.cc |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2012 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. |
| + |
| +// This is a unittest set for TypeProfilerMap in third_party/tcmalloc. It is |
| +// independent from other tests and executed manually like allocator_unittests |
| +// since TypeProfilerMap is a singleton (like tcmalloc's heap-profiler), and |
| +// it requires RTTI and different compiling/linking options from others. |
| + |
| +#include <cstddef> |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/tcmalloc/chromium/src/gperftools/type_profiler_map.h" |
| + |
| +#if defined(PROFILING_TYPE) |
|
jar (doing other things)
2012/08/30 16:02:10
Please change this macro to:
TYPE_PROFILING
As cu
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
Done.
|
| +static const void* const g_const_null = static_cast<const void*>(NULL); |
|
jar (doing other things)
2012/08/30 16:02:10
Is this cast needed?
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
Required.
Using NULL directly, clang++ says:
../.
|
| + |
| +TEST(TypeProfilerMapTest, NormalOperation) { |
| + const std::type_info* type; |
| + |
| + // Allocate an object just to get a valid address. |
| + // This 'new' is not profiled by type_profiler. |
| + int* dummy = new int(48); |
| + |
| + type = TypeProfilerLookupType(dummy); |
| + EXPECT_EQ(type, g_const_null); |
| + |
| + TypeProfilerInsertType(dummy, 12, typeid(int)); |
| + type = TypeProfilerLookupType(dummy); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(int).name()); |
| + |
| + TypeProfilerEraseType(dummy); |
| + type = TypeProfilerLookupType(dummy); |
| + EXPECT_EQ(type, g_const_null); |
| + |
| + delete dummy; |
| +} |
| + |
| +TEST(TypeProfilerMapTest, EraseWithoutInsert) { |
| + const std::type_info* type; |
| + |
| + int* dummy = new int(48); |
|
jar (doing other things)
2012/08/30 16:02:10
use a scoped ref ptr, so you don't have to worry a
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
scoped_ptr? Done.
|
| + |
| + for (int i = 0; i < 10; ++i) { |
| + TypeProfilerEraseType(dummy); |
| + type = TypeProfilerLookupType(dummy); |
| + EXPECT_EQ(type, g_const_null); |
| + } |
| + |
| + delete dummy; |
| +} |
| + |
| +TEST(TypeProfilerMapTest, InsertThenMultipleErase) { |
|
jar (doing other things)
2012/08/30 16:02:10
Please also test multiple inserts of a single addr
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
Done for TypeProfilerMapTest for Insert/EraseType.
jar (doing other things)
2012/09/02 01:37:11
Good answer: (re: this CL has changed so that now
Dai Mikurube (NOT FULLTIME)
2012/09/03 08:16:30
What I'd like to say was: we accept this kind of w
|
| + const std::type_info* type; |
| + |
| + int* dummy = new int(48); |
| + |
| + TypeProfilerInsertType(dummy, 12, typeid(int)); |
| + type = TypeProfilerLookupType(dummy); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(int).name()); |
| + |
| + for (int i = 0; i < 10; ++i) { |
| + TypeProfilerEraseType(dummy); |
| + type = TypeProfilerLookupType(dummy); |
| + EXPECT_EQ(type, g_const_null); |
| + } |
| + |
| + delete dummy; |
| +} |
| +#endif // defined(PROFILING_TYPE) |
| + |
| +int main(int argc, char** argv) { |
| + testing::InitGoogleTest(&argc, argv); |
| + return RUN_ALL_TESTS(); |
| +} |