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

Unified Diff: chrome/test/nacl/nacl_browsertest.cc

Issue 10825462: Add browser_test to check that NaCl is logging UMA samples correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Edits Created 8 years, 4 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 | « chrome/test/nacl/DEPS ('k') | ppapi/native_client/src/trusted/plugin/plugin_error.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/nacl/nacl_browsertest.cc
diff --git a/chrome/test/nacl/nacl_browsertest.cc b/chrome/test/nacl/nacl_browsertest.cc
index caf7d06bf39d282377509b52f167eefa8b9cb43d..fe1a47ab14b6fbdcc407269b8637ede5de751670 100644
--- a/chrome/test/nacl/nacl_browsertest.cc
+++ b/chrome/test/nacl/nacl_browsertest.cc
@@ -5,6 +5,8 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/statistics_recorder.h"
#include "base/path_service.h"
#include "base/values.h"
#include "chrome/browser/ui/browser_tabstrip.h"
@@ -13,9 +15,12 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/javascript_test_observer.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/histogram_fetcher.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/web_contents.h"
+#include "native_client/src/trusted/service_runtime/nacl_error_code.h"
#include "net/base/net_util.h"
+#include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
#include "webkit/plugins/webplugininfo.h"
namespace {
@@ -226,6 +231,105 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, SimpleLoadTest) {
RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
}
+class HistogramHelper {
+ public:
+ HistogramHelper() {}
+
+ // Each child process may have its own histogram data, make sure this data
+ // gets accumulated into the browser process before we examine the histograms.
+ void Fetch() {
+ base::Closure callback = base::Bind(&HistogramHelper::FetchCallback,
+ base::Unretained(this));
+
+ content::FetchHistogramsAsynchronously(
+ MessageLoop::current(),
+ callback,
+ // Give up after 60 seconds, which is longer than the 45 second timeout
+ // for browser tests. If this call times out, it means that a child
+ // process is not responding which is something we should not ignore.
+ base::TimeDelta::FromMilliseconds(60000));
+ content::RunMessageLoop();
+ }
+
+ // We know the exact number of samples in a bucket, and that no other bucket
+ // should have samples.
+ void ExpectUniqueSample(const std::string& name, size_t bucket,
+ base::Histogram::Count expected_count) {
+ base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name);
+ ASSERT_NE(static_cast<base::Histogram*>(NULL), histogram) <<
+ "Histogram \"" << name << "\" does not exist.";
+
+ base::Histogram::SampleSet samples;
+ histogram->SnapshotSample(&samples);
+ CheckBucketCount(name, bucket, expected_count, samples);
+ CheckTotalCount(name, expected_count, samples);
+ }
+
+ // We don't know the values of the samples, but we know how many there are.
+ void ExpectTotalCount(const std::string& name, base::Histogram::Count count) {
+ base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name);
+ ASSERT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name <<
+ "\" does not exist.";
+
+ base::Histogram::SampleSet samples;
+ histogram->SnapshotSample(&samples);
+ CheckTotalCount(name, count, samples);
+ }
+
+ private:
+ void FetchCallback() {
+ MessageLoopForUI::current()->Quit();
+ }
+
+ void CheckBucketCount(const std::string& name, size_t bucket,
+ base::Histogram::Count expected_count,
+ base::Histogram::SampleSet& samples) {
+ EXPECT_EQ(expected_count, samples.counts(bucket)) << "Histogram \"" <<
+ name << "\" does not have the right number of samples (" <<
+ expected_count << ") in the expected bucket (" << bucket << ").";
+ }
+
+ void CheckTotalCount(const std::string& name,
+ base::Histogram::Count expected_count,
+ base::Histogram::SampleSet& samples) {
+ EXPECT_EQ(expected_count, samples.TotalCount()) << "Histogram \"" << name <<
+ "\" does not have the right total number of samples (" <<
+ expected_count << ").";
+ }
+};
+
+// TODO(ncbray) create multiple variants (newlib, glibc, pnacl) of the same test
+// via macros.
+IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, UMALoadTest) {
+ // Sanity check.
+ ASSERT_TRUE(base::StatisticsRecorder::IsActive());
+
+ // Load a NaCl module to generate UMA data.
+ RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
+
+ // Make sure histograms from child processes have been accumulated in the
+ // browser brocess.
+ HistogramHelper histograms;
+ histograms.Fetch();
+
+ // Did the plugin report success?
+ histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin",
+ plugin::ERROR_LOAD_SUCCESS, 1);
+
+ // Did the sel_ldr report success?
+ histograms.ExpectUniqueSample("NaCl.LoadStatus.SelLdr",
+ LOAD_OK, 1);
+
+ // Make sure we have other important histograms.
+ histograms.ExpectTotalCount("NaCl.Perf.StartupTime.LoadModule", 1);
+ histograms.ExpectTotalCount("NaCl.Perf.StartupTime.Total", 1);
+ histograms.ExpectTotalCount("NaCl.Perf.Size.Manifest", 1);
+ histograms.ExpectTotalCount("NaCl.Perf.Size.Nexe", 1);
+}
+
+// TODO(ncbray) convert the rest of nacl_uma.py and test validation failiures
Mark Seaborn 2012/08/24 19:30:42 Clarify that nacl_uma.py is from the native_client
Nick Bray (chromium) 2012/08/24 21:13:56 Done.
+// and crashes.
+
#endif // !(defined(ADDRESS_SANITIZER) && defined(OS_LINUX))
} // namespace anonymous
« no previous file with comments | « chrome/test/nacl/DEPS ('k') | ppapi/native_client/src/trusted/plugin/plugin_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698