1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/test/histogram_tester.h"
6 #include "chrome/test/nacl/nacl_browsertest_util.h"
7 #include "components/nacl/browser/nacl_browser.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
10 #include "ppapi/c/private/ppb_nacl_private.h"
14 NACL_BROWSER_TEST_F(NaClBrowserTest
, SuccessfulLoadUMA
, {
15 base::HistogramTester histograms
;
16 // Load a NaCl module to generate UMA data.
17 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
19 // Make sure histograms from child processes have been accumulated in the
21 content::FetchHistogramsFromChildProcesses();
23 // Did the plugin report success?
24 histograms
.ExpectUniqueSample("NaCl.LoadStatus.Plugin",
25 PP_NACL_ERROR_LOAD_SUCCESS
, 1);
27 // Did the sel_ldr report success?
28 histograms
.ExpectUniqueSample("NaCl.LoadStatus.SelLdr",
31 // Check validation cache usage:
33 // Should have received 4 validation queries:
34 // - Two for the IRT: the app and one of the translator nexes use the IRT.
35 // - Two for the two PNaCl translator nexes.
36 // The PNaCl app nexe comes from a delete-on-close temp file, so it
37 // doesn't have a stable identity for validation caching. Overall, there
38 // are 3 eligible nexes. The first 3 queries for these eligible nexes
39 // are misses, and one of the IRT queries is a hit.
40 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
41 nacl::NaClBrowser::CACHE_MISS
, 3);
42 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
43 nacl::NaClBrowser::CACHE_HIT
, 1);
44 // Should have received a cache setting afterwards (IRT set only once).
45 histograms
.ExpectUniqueSample("NaCl.ValidationCache.Set",
46 nacl::NaClBrowser::CACHE_HIT
, 3);
48 // For the open-web, only the IRT is considered a "safe" and
49 // identity-cachable file. The nexes and .so files are not.
50 // Should have one cache query for the IRT.
51 histograms
.ExpectUniqueSample("NaCl.ValidationCache.Query",
52 nacl::NaClBrowser::CACHE_MISS
, 1);
53 // Should have received a cache setting afterwards for IRT and translators.
54 histograms
.ExpectUniqueSample("NaCl.ValidationCache.Set",
55 nacl::NaClBrowser::CACHE_HIT
, 1);
58 // Make sure we have other important histograms.
59 if (!IsAPnaclTest()) {
60 histograms
.ExpectTotalCount("NaCl.Perf.StartupTime.LoadModule", 1);
61 histograms
.ExpectTotalCount("NaCl.Perf.StartupTime.Total", 1);
62 histograms
.ExpectTotalCount("NaCl.Perf.Size.Manifest", 1);
63 histograms
.ExpectTotalCount("NaCl.Perf.Size.Nexe", 1);
65 histograms
.ExpectTotalCount("NaCl.Options.PNaCl.OptLevel", 1);
66 histograms
.ExpectTotalCount("NaCl.Perf.Size.Manifest", 1);
67 histograms
.ExpectTotalCount("NaCl.Perf.Size.Pexe", 1);
68 histograms
.ExpectTotalCount("NaCl.Perf.Size.PNaClTranslatedNexe", 1);
69 histograms
.ExpectTotalCount("NaCl.Perf.Size.PexeNexeSizePct", 1);
70 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.LoadCompiler", 1);
71 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.LoadLinker", 1);
72 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.CompileTime", 1);
73 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.CompileKBPerSec", 1);
74 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.LinkTime", 1);
75 histograms
.ExpectTotalCount(
76 "NaCl.Perf.PNaClLoadTime.PctCompiledWhenFullyDownloaded", 1);
77 histograms
.ExpectTotalCount("NaCl.Perf.PNaClLoadTime.TotalUncachedTime", 1);
78 histograms
.ExpectTotalCount(
79 "NaCl.Perf.PNaClLoadTime.TotalUncachedKBPerSec", 1);
80 histograms
.ExpectTotalCount("NaCl.Perf.PNaClCache.IsHit", 1);
84 class NaClBrowserTestNewlibVcacheExtension
:
85 public NaClBrowserTestNewlibExtension
{
87 base::FilePath::StringType
Variant() override
{
88 return FILE_PATH_LITERAL("extension_vcache_test/newlib");
92 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibVcacheExtension
,
93 ValidationCacheOfMainNexe
) {
94 base::HistogramTester histograms
;
95 // Hardcoded extension AppID that corresponds to the hardcoded
96 // public key in the manifest.json file. We need to load the extension
97 // nexe from the same origin, so we can't just try to load the extension
98 // nexe as a mime-type handler from a non-extension URL.
99 base::FilePath::StringType full_url
=
100 FILE_PATH_LITERAL("chrome-extension://cbcdidchbppangcjoddlpdjlenngjldk/")
101 FILE_PATH_LITERAL("extension_validation_cache.html");
102 RunNaClIntegrationTest(full_url
, true);
104 // Make sure histograms from child processes have been accumulated in the
106 content::FetchHistogramsFromChildProcesses();
107 // Should have received 2 validation queries (one for IRT and one for NEXE),
108 // and responded with a miss.
109 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
110 nacl::NaClBrowser::CACHE_MISS
, 2);
111 // TOTAL should then be 2 queries so far.
112 histograms
.ExpectTotalCount("NaCl.ValidationCache.Query", 2);
113 // Should have received a cache setting afterwards for IRT and nexe.
114 histograms
.ExpectBucketCount("NaCl.ValidationCache.Set",
115 nacl::NaClBrowser::CACHE_HIT
, 2);
117 // Load it again to hit the cache.
118 RunNaClIntegrationTest(full_url
, true);
119 content::FetchHistogramsFromChildProcesses();
120 // Should have received 2 more validation queries later (IRT and NEXE),
121 // and responded with a hit.
122 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
123 nacl::NaClBrowser::CACHE_HIT
, 2);
124 // TOTAL should then be 4 queries now.
125 histograms
.ExpectTotalCount("NaCl.ValidationCache.Query", 4);
126 // Still only 2 settings.
127 histograms
.ExpectTotalCount("NaCl.ValidationCache.Set", 2);
130 class NaClBrowserTestGLibcVcacheExtension
:
131 public NaClBrowserTestGLibcExtension
{
133 base::FilePath::StringType
Variant() override
{
134 return FILE_PATH_LITERAL("extension_vcache_test/glibc");
138 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension
,
139 MAYBE_GLIBC(ValidationCacheOfMainNexe
)) {
140 // Make sure histograms from child processes have been accumulated in the
142 base::HistogramTester histograms
;
143 // Hardcoded extension AppID that corresponds to the hardcoded
144 // public key in the manifest.json file. We need to load the extension
145 // nexe from the same origin, so we can't just try to load the extension
146 // nexe as a mime-type handler from a non-extension URL.
147 base::FilePath::StringType full_url
=
148 FILE_PATH_LITERAL("chrome-extension://cbcdidchbppangcjoddlpdjlenngjldk/")
149 FILE_PATH_LITERAL("extension_validation_cache.html");
150 RunNaClIntegrationTest(full_url
, true);
152 // Should have received 9 validation queries, which respond with misses:
154 // - ld.so (the initial nexe)
157 // - libpthread.so.9b15f6a6
160 // - libc.so.9b15f6a6
161 // - libm.so.9b15f6a6
162 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
163 nacl::NaClBrowser::CACHE_MISS
, 9);
164 // TOTAL should then be 9 queries so far.
165 histograms
.ExpectTotalCount("NaCl.ValidationCache.Query", 9);
166 // Should have received a cache setting afterwards for IRT and nexe.
167 histograms
.ExpectBucketCount("NaCl.ValidationCache.Set",
168 nacl::NaClBrowser::CACHE_HIT
, 9);
170 // Load it again to hit the cache.
171 RunNaClIntegrationTest(full_url
, true);
172 // Should have received 9 more validation queries and responded with hits.
173 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
174 nacl::NaClBrowser::CACHE_HIT
, 9);
175 histograms
.ExpectTotalCount("NaCl.ValidationCache.Query", 18);
176 histograms
.ExpectTotalCount("NaCl.ValidationCache.Set", 9);
179 // Test that validation for the 2 PNaCl translator nexes can be cached.
180 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
181 ValidationCacheOfTranslatorNexes
) {
182 base::HistogramTester histograms
;
183 // Run a load test w/ one pexe cache identity.
184 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
186 content::FetchHistogramsFromChildProcesses();
187 // Should have received 4 validation queries:
188 // - Two for the IRT: the app and one of the translator nexes use the IRT.
189 // - Two for the two PNaCl translator nexes.
190 // The PNaCl app nexe comes from a delete-on-close temp file, so it
191 // doesn't have a stable identity for validation caching. Overall, there
192 // are 3 eligible nexes. The first 3 queries for these eligible nexes
193 // are misses, and one of the IRT queries is a hit.
194 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
195 nacl::NaClBrowser::CACHE_MISS
, 3);
196 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
197 nacl::NaClBrowser::CACHE_HIT
, 1);
198 // Should have received a cache setting afterwards.
199 histograms
.ExpectUniqueSample("NaCl.ValidationCache.Set",
200 nacl::NaClBrowser::CACHE_HIT
, 3);
202 // Load the same pexe, but with a different cache identity.
203 // This means that translation will actually be redone,
204 // forcing the translators to be loaded a second time (but now with
206 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
208 // Should now have 4 more queries on top of the previous ones.
209 histograms
.ExpectTotalCount("NaCl.ValidationCache.Query", 8);
210 // With the extra queries being cache hits.
211 histograms
.ExpectBucketCount("NaCl.ValidationCache.Query",
212 nacl::NaClBrowser::CACHE_HIT
, 5);
213 // No extra cache settings.
214 histograms
.ExpectUniqueSample("NaCl.ValidationCache.Set",
215 nacl::NaClBrowser::CACHE_HIT
, 3);
219 // TODO(ncbray) convert the rest of nacl_uma.py (currently in the NaCl repo.)
220 // Test validation failures and crashes.