summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-30 14:14:01 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-30 14:14:01 +0000
commit7ba0e1a08c29d56302158767dc6526ce798ce762 (patch)
tree57cec7099a45e6b78b38ab94715d32eb02451a04 /chrome/test
parent2173eb2590da6eea89bc1118b019c1cf4dbc257a (diff)
downloadchromium_src-7ba0e1a08c29d56302158767dc6526ce798ce762.zip
chromium_src-7ba0e1a08c29d56302158767dc6526ce798ce762.tar.gz
chromium_src-7ba0e1a08c29d56302158767dc6526ce798ce762.tar.bz2
[Linux/Mac] clean up the shared memory file on disk used by stats in tests.
BUG=none TEST=files shouldn't be left around. Review URL: http://codereview.chromium.org/518019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/unit/chrome_test_suite.h40
1 files changed, 33 insertions, 7 deletions
diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h
index bd05e0d..7a77a94 100644
--- a/chrome/test/unit/chrome_test_suite.h
+++ b/chrome/test/unit/chrome_test_suite.h
@@ -13,9 +13,6 @@
#include "app/resource_bundle.h"
#include "base/stats_table.h"
#include "base/file_util.h"
-#if defined(OS_MACOSX)
-#include "base/mac_util.h"
-#endif
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "base/scoped_nsautorelease_pool.h"
@@ -29,6 +26,28 @@
#include "net/base/mock_host_resolver.h"
#include "net/base/net_util.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
+
+#if defined(OS_POSIX)
+#include "base/shared_memory.h"
+#endif
+
+namespace {
+
+void RemoveSharedMemoryFile(std::string& filename) {
+ // Stats uses SharedMemory under the hood. On posix, this results in a file
+ // on disk.
+#if defined(OS_POSIX)
+ base::SharedMemory memory;
+ memory.Delete(UTF8ToWide(filename));
+#endif
+}
+
+} // namespace
+
+
// In many cases it may be not obvious that a test makes a real DNS lookup.
// We generally don't want to rely on external DNS servers for our tests,
// so this host resolver procedure catches external queries.
@@ -109,11 +128,13 @@ class ChromeTestSuite : public TestSuite {
// output, it'll pass regardless of the system language.
ResourceBundle::InitSharedInstance(L"en-US");
- // initialize the global StatsTable for unit_tests
- std::string statsfile = "unit_tests";
+ // initialize the global StatsTable for unit_tests (make sure the file
+ // doesn't exist before opening it so the test gets a clean slate)
+ stats_filename_ = "unit_tests";
std::string pid_string = StringPrintf("-%d", base::GetCurrentProcId());
- statsfile += pid_string;
- stats_table_ = new StatsTable(statsfile, 20, 200);
+ stats_filename_ += pid_string;
+ RemoveSharedMemoryFile(stats_filename_);
+ stats_table_ = new StatsTable(stats_filename_, 20, 200);
StatsTable::set_current(stats_table_);
}
@@ -130,6 +151,7 @@ class ChromeTestSuite : public TestSuite {
// Tear down shared StatsTable; prevents unit_tests from leaking it.
StatsTable::set_current(NULL);
delete stats_table_;
+ RemoveSharedMemoryFile(stats_filename_);
// Delete the test_user_data dir recursively
FilePath user_data_dir;
@@ -142,6 +164,10 @@ class ChromeTestSuite : public TestSuite {
}
StatsTable* stats_table_;
+ // The name used for the stats file so it can be cleaned up on posix during
+ // test shutdown.
+ std::string stats_filename_;
+
ScopedOleInitializer ole_initializer_;
scoped_refptr<WarningHostResolverProc> host_resolver_proc_;
net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;