summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/context
diff options
context:
space:
mode:
authorJamie Liu <jamieliu@google.com>2019-06-20 13:33:43 -0700
committergVisor bot <gvisor-bot@google.com>2019-06-20 13:36:14 -0700
commit7db8685100bc5f69ec42e5498781301ee835667c (patch)
tree730c096c47216fa30544a717f7e077ac413b68c9 /pkg/sentry/context
parent292f70cbf7b4d2da9f2fc5d1049ba49e6846e805 (diff)
Preallocate auth.NewAnonymousCredentials() in contexttest.TestContext.
Otherwise every call to, say, fs.ContextCanAccessFile() in a benchmark using contexttest allocates new auth.Credentials, a new auth.UserNamespace, ... PiperOrigin-RevId: 254261051
Diffstat (limited to 'pkg/sentry/context')
-rw-r--r--pkg/sentry/context/contexttest/contexttest.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkg/sentry/context/contexttest/contexttest.go b/pkg/sentry/context/contexttest/contexttest.go
index 6d0120518..15cf086a9 100644
--- a/pkg/sentry/context/contexttest/contexttest.go
+++ b/pkg/sentry/context/contexttest/contexttest.go
@@ -59,6 +59,7 @@ func Context(tb testing.TB) context.Context {
l: limits.NewLimitSet(),
mf: mf,
platform: p,
+ creds: auth.NewAnonymousCredentials(),
otherValues: make(map[interface{}]interface{}),
}
}
@@ -70,6 +71,7 @@ type TestContext struct {
l *limits.LimitSet
mf *pgalloc.MemoryFile
platform platform.Platform
+ creds *auth.Credentials
otherValues map[interface{}]interface{}
}
@@ -108,6 +110,8 @@ func (t *TestContext) RegisterValue(key, value interface{}) {
// Value implements context.Context.
func (t *TestContext) Value(key interface{}) interface{} {
switch key {
+ case auth.CtxCredentials:
+ return t.creds
case limits.CtxLimits:
return t.l
case pgalloc.CtxMemoryFile: