Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2562)

Unified Diff: base/stats_table_unittest.cc

Issue 19724: Properly honor base::SharedMemory semantics for name="" to mean... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/shared_memory_win.cc ('k') | chrome/renderer/render_process.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/stats_table_unittest.cc
===================================================================
--- base/stats_table_unittest.cc (revision 8817)
+++ base/stats_table_unittest.cc (working copy)
@@ -5,6 +5,7 @@
#include "base/multiprocess_test.h"
#include "base/platform_thread.h"
#include "base/simple_thread.h"
+#include "base/shared_memory.h"
#include "base/stats_table.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
@@ -19,6 +20,11 @@
namespace base {
class StatsTableTest : public MultiProcessTest {
+ public:
+ void DeleteShmem(std::string name) {
+ base::SharedMemory mem;
+ mem.Delete(UTF8ToWide(name));
+ }
};
// Open a StatsTable and verify that we can write to each of the
@@ -27,6 +33,7 @@
const std::string kTableName = "VerifySlotsStatTable";
const int kMaxThreads = 1;
const int kMaxCounter = 5;
+ DeleteShmem(kTableName);
StatsTable table(kTableName, kMaxThreads, kMaxCounter);
// Register a single thread.
@@ -50,6 +57,8 @@
// Try to allocate an additional counter. Verify it fails.
int counter_id = table.FindCounter(counter_base_name);
EXPECT_EQ(counter_id, 0);
+
+ DeleteShmem(kTableName);
}
// CounterZero will continually be set to 0.
@@ -104,6 +113,7 @@
const std::string kTableName = "MultipleThreadStatTable";
const int kMaxThreads = 20;
const int kMaxCounter = 5;
+ DeleteShmem(kTableName);
StatsTable table(kTableName, kMaxThreads, kMaxCounter);
StatsTable::set_current(&table);
@@ -149,16 +159,18 @@
EXPECT_EQ((kMaxThreads % 2) * kThreadLoops,
table.GetCounterValue(name));
EXPECT_EQ(0, table.CountThreadsRegistered());
+
+ DeleteShmem(kTableName);
}
-const std::string kTableName = "MultipleProcessStatTable";
+const std::string kMPTableName = "MultipleProcessStatTable";
MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) {
// Each process will open the shared memory and set counters
// concurrently in a loop. We'll use some pauses to
// mixup the scheduling.
- StatsTable table(kTableName, 0, 0);
+ StatsTable table(kMPTableName, 0, 0);
StatsTable::set_current(&table);
StatsCounter zero_counter(kCounterZero);
StatsCounter lucky13_counter(kCounter1313);
@@ -177,12 +189,11 @@
// Create a few processes and have them poke on their counters.
TEST_F(StatsTableTest, MultipleProcesses) {
// Create a stats table.
- const std::string kTableName = "MultipleProcessStatTable";
const int kMaxProcs = 20;
const int kMaxCounter = 5;
- StatsTable table(kTableName, kMaxProcs, kMaxCounter);
+ DeleteShmem(kMPTableName);
+ StatsTable table(kMPTableName, kMaxProcs, kMaxCounter);
StatsTable::set_current(&table);
-
EXPECT_EQ(0, table.CountThreadsRegistered());
// Spin up a set of processes to go bang on the various counters.
@@ -220,6 +231,8 @@
EXPECT_EQ(-kMaxProcs * kThreadLoops,
table.GetCounterValue(name));
EXPECT_EQ(0, table.CountThreadsRegistered());
+
+ DeleteShmem(kMPTableName);
}
class MockStatsCounter : public StatsCounter {
@@ -235,6 +248,7 @@
const std::string kTableName = "StatTable";
const int kMaxThreads = 20;
const int kMaxCounter = 5;
+ DeleteShmem(kTableName);
StatsTable table(kTableName, kMaxThreads, kMaxCounter);
StatsTable::set_current(&table);
@@ -271,6 +285,8 @@
EXPECT_EQ(-1, table.GetCounterValue("c:foo"));
foo.Decrement(-1);
EXPECT_EQ(0, table.GetCounterValue("c:foo"));
+
+ DeleteShmem(kTableName);
}
class MockStatsCounterTimer : public StatsCounterTimer {
@@ -348,6 +364,7 @@
const std::string kTableName = "StatTable";
const int kMaxThreads = 20;
const int kMaxCounter = 5;
+ DeleteShmem(kTableName);
StatsTable table(kTableName, kMaxThreads, kMaxCounter);
StatsTable::set_current(&table);
@@ -378,6 +395,8 @@
EXPECT_LE(1000, table.GetCounterValue("t:foo"));
EXPECT_LE(1000, table.GetCounterValue("t:bar"));
EXPECT_EQ(2, table.GetCounterValue("c:bar"));
+
+ DeleteShmem(kTableName);
}
} // namespace base
« no previous file with comments | « base/shared_memory_win.cc ('k') | chrome/renderer/render_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698