core: Remove remaining uses of veyron2/rt package and delete it.

This is part of the RuntimeX migration.
This CL depends on (includes) https://vanadium-review.googlesource.com/#/c/2005/

Change-Id: I909b47c35b9bb90d02dab17333f3d1a2e6779ca1
diff --git a/profiles/chrome/chrome.go b/profiles/chrome/chrome.go
index e16556d..ef9235e 100644
--- a/profiles/chrome/chrome.go
+++ b/profiles/chrome/chrome.go
@@ -7,7 +7,6 @@
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/options"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/profiles/internal/platform"
 	_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
@@ -19,10 +18,6 @@
 
 type chrome struct{}
 
-func init() {
-	rt.RegisterProfile(New())
-}
-
 // New returns a new instance of a Profile for use within chrome, in particular
 // chrome extensions etc should use.
 func New() veyron2.Profile {
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
index d25d7f6..2882a08 100644
--- a/profiles/gce/init.go
+++ b/profiles/gce/init.go
@@ -11,7 +11,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/netstate"
@@ -29,10 +28,6 @@
 	ListenSpec ipc.ListenSpec
 )
 
-func init() {
-	rt.RegisterProfile(&profile{})
-}
-
 type profile struct {
 	ac *appcycle.AppCycle
 }
diff --git a/profiles/generic.go b/profiles/generic.go
index 9b5ff05..20af927 100644
--- a/profiles/generic.go
+++ b/profiles/generic.go
@@ -4,7 +4,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/profiles/internal"
@@ -25,10 +24,6 @@
 
 var _ veyron2.Profile = (*generic)(nil)
 
-func init() {
-	rt.RegisterProfile(New())
-}
-
 // New returns a new instance of a very generic Profile. It can be used
 // as a default by Runtime implementations, in unit tests etc.
 func New() veyron2.Profile {
diff --git a/profiles/roaming/roaming.go b/profiles/roaming/roaming.go
index 6f04215..b4acfb5 100644
--- a/profiles/roaming/roaming.go
+++ b/profiles/roaming/roaming.go
@@ -14,7 +14,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/netconfig"
@@ -37,10 +36,6 @@
 	ListenSpec ipc.ListenSpec
 )
 
-func init() {
-	rt.RegisterProfile(New())
-}
-
 type profile struct {
 	gce                  string
 	ac                   *appcycle.AppCycle
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index 3d5bfe0..e09d5f0 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -22,6 +22,7 @@
 	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/appcycle"
+	"v.io/core/veyron/lib/exec"
 	"v.io/core/veyron/lib/flags"
 	"v.io/core/veyron/lib/netconfig"
 	"v.io/core/veyron/lib/netstate"
@@ -53,14 +54,29 @@
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
 	log := vlog.Log
-	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
 
-	commonFlags.Parse(os.Args[1:], nil)
+	handle, err := exec.GetChildHandle()
+	switch err {
+	case exec.ErrNoVersion:
+		// The process has not been started through the veyron exec
+		// library. No further action is needed.
+	case nil:
+		// The process has been started through the veyron exec
+		// library.
+	default:
+		return nil, nil, nil, err
+	}
+	var execConfig map[string]string
+	if handle != nil {
+		execConfig = handle.Config.Dump()
+	}
+	commonFlags.Parse(os.Args[1:], execConfig)
 	lf := commonFlags.ListenFlags()
 	listenSpec := ipc.ListenSpec{
 		Addrs: ipc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
+	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/profiles/static/static.go b/profiles/static/static.go
index 683ebae..4ed8d39 100644
--- a/profiles/static/static.go
+++ b/profiles/static/static.go
@@ -7,7 +7,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/netstate"
@@ -29,10 +28,6 @@
 	ListenSpec ipc.ListenSpec
 )
 
-func init() {
-	rt.RegisterProfile(New())
-}
-
 type static struct {
 	gce string
 	ac  *appcycle.AppCycle
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index 57b7f2c..7536850 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -11,6 +11,7 @@
 	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/appcycle"
+	"v.io/core/veyron/lib/exec"
 	"v.io/core/veyron/lib/flags"
 	"v.io/core/veyron/lib/netstate"
 	"v.io/core/veyron/lib/websocket"
@@ -38,14 +39,28 @@
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
 	log := vlog.Log
 
-	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
-
-	commonFlags.Parse(os.Args[1:], nil)
+	handle, err := exec.GetChildHandle()
+	switch err {
+	case exec.ErrNoVersion:
+		// The process has not been started through the veyron exec
+		// library. No further action is needed.
+	case nil:
+		// The process has been started through the veyron exec
+		// library.
+	default:
+		return nil, nil, nil, err
+	}
+	var execConfig map[string]string
+	if handle != nil {
+		execConfig = handle.Config.Dump()
+	}
+	commonFlags.Parse(os.Args[1:], execConfig)
 	lf := commonFlags.ListenFlags()
 	listenSpec := ipc.ListenSpec{
 		Addrs: ipc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
+	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/runtimes/google/ipc/benchmark/benchmark_test.go b/runtimes/google/ipc/benchmark/benchmark_test.go
index f16eea1..f0a00bc 100644
--- a/runtimes/google/ipc/benchmark/benchmark_test.go
+++ b/runtimes/google/ipc/benchmark/benchmark_test.go
@@ -112,7 +112,8 @@
 		panic(err)
 	}
 
-	serverAddr, serverStop := StartServer(ctx, veyron2.GetListenSpec(ctx))
+	var serverStop func()
+	serverAddr, serverStop = StartServer(ctx, veyron2.GetListenSpec(ctx))
 
 	// Create a VC to exclude the VC setup time from the benchmark.
 	CallEcho(&testing.B{}, ctx, serverAddr, 1, 0, benchmark.NewStats(1))
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index c7bcafa..0e94bcf 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -13,7 +13,6 @@
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/ipc/stream"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/rt"
 
 	"v.io/core/veyron/lib/exec"
 	"v.io/core/veyron/lib/flags"
@@ -54,10 +53,6 @@
 
 var _ veyron2.Runtime = (*vrt)(nil)
 
-func init() {
-	rt.RegisterRuntime(veyron2.GoogleRuntimeName, New)
-}
-
 // Implements veyron2/rt.New
 func New(opts ...veyron2.ROpt) (veyron2.Runtime, error) {
 	handle, err := exec.GetChildHandle()
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index 618ddf7..6686a6b 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -223,6 +223,10 @@
 	// TODO(suharshs,mattr): Go through the rt.Cleanup function and make sure everything
 	// gets cleaned up.
 
+	if handle != nil {
+		handle.SetReady()
+	}
+
 	return r, ctx, r.cancel, nil
 }
 
diff --git a/services/mgmt/application/impl/acl_test.go b/services/mgmt/application/impl/acl_test.go
index 34c71c7..f8b9ded 100644
--- a/services/mgmt/application/impl/acl_test.go
+++ b/services/mgmt/application/impl/acl_test.go
@@ -87,8 +87,10 @@
 	storedir, cleanup := mgmttest.SetupRootDir(t, "application")
 	defer cleanup()
 
-	otherCtx, otherCancel := mgmttest.NewRuntime(t, ctx)
-	defer otherCancel()
+	otherCtx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal())
+	if err != nil {
+		panic(err)
+	}
 
 	idp := tsecurity.NewIDProvider("root")
 
@@ -220,8 +222,11 @@
 	storedir, cleanup := mgmttest.SetupRootDir(t, "application")
 	defer cleanup()
 
-	otherCtx, otherCancel := mgmttest.NewRuntime(t, ctx)
-	defer otherCancel()
+	otherCtx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal())
+	if err != nil {
+		panic(err)
+	}
+
 	idp := tsecurity.NewIDProvider("root")
 
 	// By default, globalRT and otherRT will have blessings generated based on the
diff --git a/services/mgmt/binary/binaryd/main.go b/services/mgmt/binary/binaryd/main.go
index 4a22834..a5ff9eb 100644
--- a/services/mgmt/binary/binaryd/main.go
+++ b/services/mgmt/binary/binaryd/main.go
@@ -7,12 +7,12 @@
 	"os"
 
 	"v.io/core/veyron2"
-	"v.io/core/veyron2/rt"
+	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/netstate"
 	"v.io/core/veyron/lib/signals"
-	"v.io/core/veyron/profiles/roaming"
+	_ "v.io/core/veyron/profiles/roaming"
 	"v.io/core/veyron/services/mgmt/binary/impl"
 )
 
@@ -26,7 +26,7 @@
 
 // toIPPort tries to swap in the 'best' accessible IP for the host part of the
 // address, if the provided address has an unspecified IP.
-func toIPPort(addr string) string {
+func toIPPort(ctx *context.T, addr string) string {
 	host, port, err := net.SplitHostPort(addr)
 	if err != nil {
 		vlog.Errorf("SplitHostPort(%v) failed: %v", addr, err)
@@ -37,7 +37,8 @@
 		host = "127.0.0.1"
 		ips, err := netstate.GetAccessibleIPs()
 		if err == nil {
-			if a, err := roaming.ListenSpec.AddressChooser("tcp", ips); err == nil && len(a) > 0 {
+			ls := veyron2.GetListenSpec(ctx)
+			if a, err := ls.AddressChooser("tcp", ips); err == nil && len(a) > 0 {
 				host = a[0].Address().String()
 			}
 		}
@@ -46,13 +47,8 @@
 }
 
 func main() {
-	runtime, err := rt.New()
-	if err != nil {
-		vlog.Fatalf("Could not initialize runtime: %v", err)
-	}
-	defer runtime.Cleanup()
-
-	ctx := runtime.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
 
 	rootDir, err := impl.SetupRootDir(*rootDirFlag)
 	if err != nil {
@@ -66,7 +62,7 @@
 		vlog.Errorf("Listen(%s) failed: %v", *httpAddr, err)
 		os.Exit(1)
 	}
-	rootURL := toIPPort(listener.Addr().String())
+	rootURL := toIPPort(ctx, listener.Addr().String())
 	state, err := impl.NewState(rootDir, rootURL, defaultDepth)
 	if err != nil {
 		vlog.Errorf("NewState(%v, %v, %v) failed: %v", rootDir, rootURL, defaultDepth, err)
@@ -85,9 +81,10 @@
 		return
 	}
 	defer server.Stop()
-	endpoints, err := server.Listen(roaming.ListenSpec)
+	ls := veyron2.GetListenSpec(ctx)
+	endpoints, err := server.Listen(ls)
 	if err != nil {
-		vlog.Errorf("Listen(%s) failed: %v", roaming.ListenSpec, err)
+		vlog.Errorf("Listen(%s) failed: %v", ls, err)
 		return
 	}
 
diff --git a/services/mgmt/binary/impl/acl_test.go b/services/mgmt/binary/impl/acl_test.go
index 14006c7..8962d52 100644
--- a/services/mgmt/binary/impl/acl_test.go
+++ b/services/mgmt/binary/impl/acl_test.go
@@ -10,7 +10,6 @@
 
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/security"
 	"v.io/core/veyron2/services/mgmt/repository"
 	"v.io/core/veyron2/services/security/access"
@@ -33,14 +32,6 @@
 func init() {
 	modules.RegisterChild(binaryCmd, "", binaryd)
 	testutil.Init()
-
-	globalRT, err := rt.New()
-	if err != nil {
-		panic(err)
-	}
-	gctx = globalRT.NewContext()
-	globalCancel = globalRT.Cleanup
-	veyron2.GetNamespace(gctx).CacheCtl(naming.DisableCache(true))
 }
 
 // TestHelperProcess is the entrypoint for the modules commands in
@@ -57,12 +48,13 @@
 	publishName := args[0]
 	storedir := args[1]
 
+	ctx, shutdown := veyron2.Init()
+
 	defer fmt.Fprintf(stdout, "%v terminating\n", publishName)
 	defer vlog.VI(1).Infof("%v terminating", publishName)
-	defer globalCancel()
-	server, endpoint := mgmttest.NewServer(gctx)
-	defer server.Stop()
+	defer shutdown()
 
+	server, endpoint := mgmttest.NewServer(ctx)
 	name := naming.JoinAddressName(endpoint, "")
 	vlog.VI(1).Infof("binaryd name: %v", name)
 
@@ -71,7 +63,7 @@
 	if err != nil {
 		vlog.Fatalf("NewState(%v, %v, %v) failed: %v", storedir, "", depth, err)
 	}
-	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(gctx), state)
+	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(ctx), state)
 	if err != nil {
 		vlog.Fatalf("Failed to create binaryd dispatcher: %v", err)
 	}
@@ -80,14 +72,18 @@
 	}
 
 	fmt.Fprintf(stdout, "ready:%d\n", os.Getpid())
-	<-signals.ShutdownOnSignals(gctx)
+	<-signals.ShutdownOnSignals(ctx)
 
 	return nil
 }
 
 func TestBinaryRootACL(t *testing.T) {
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	selfPrincipal := tsecurity.NewPrincipal("self")
-	selfCtx, err := veyron2.SetPrincipal(gctx, selfPrincipal)
+	selfCtx, err := veyron2.SetPrincipal(ctx, selfPrincipal)
 	if err != nil {
 		t.Fatalf("SetPrincipal failed: %v", err)
 	}
diff --git a/services/mgmt/binary/impl/http_test.go b/services/mgmt/binary/impl/http_test.go
index db4b0a5..6eb0142 100644
--- a/services/mgmt/binary/impl/http_test.go
+++ b/services/mgmt/binary/impl/http_test.go
@@ -8,6 +8,8 @@
 	"net/http"
 	"testing"
 
+	"v.io/core/veyron2"
+	"v.io/core/veyron2/naming"
 	"v.io/core/veyron2/services/mgmt/repository"
 
 	"v.io/core/veyron/lib/testutil"
@@ -16,10 +18,14 @@
 
 // TestHTTP checks that HTTP download works.
 func TestHTTP(t *testing.T) {
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	// TODO(caprita): This is based on TestMultiPart (impl_test.go).  Share
 	// the code where possible.
 	for length := 2; length < 5; length++ {
-		binary, _, url, cleanup := startServer(t, 2)
+		binary, _, url, cleanup := startServer(t, ctx, 2)
 		defer cleanup()
 		// Create <length> chunks of up to 4MB of random bytes.
 		data := make([][]byte, length)
@@ -29,15 +35,15 @@
 			data[i] = testutil.RandomBytes(size)
 		}
 		mediaInfo := repository.MediaInfo{Type: "application/octet-stream"}
-		if err := binary.Create(gctx, int32(length), mediaInfo); err != nil {
+		if err := binary.Create(ctx, int32(length), mediaInfo); err != nil {
 			t.Fatalf("Create() failed: %v", err)
 		}
 		for i := 0; i < length; i++ {
-			if streamErr, err := invokeUpload(t, gctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
+			if streamErr, err := invokeUpload(t, ctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
 				t.FailNow()
 			}
 		}
-		parts, _, err := binary.Stat(gctx)
+		parts, _, err := binary.Stat(ctx)
 		if err != nil {
 			t.Fatalf("Stat() failed: %v", err)
 		}
@@ -70,7 +76,7 @@
 				t.Fatalf("Unexpected size: expected %v, got %v", expected, got)
 			}
 		}
-		if err := binary.Delete(gctx); err != nil {
+		if err := binary.Delete(ctx); err != nil {
 			t.Fatalf("Delete() failed: %v", err)
 		}
 	}
diff --git a/services/mgmt/binary/impl/impl_test.go b/services/mgmt/binary/impl/impl_test.go
index 97ac906..3fcad12 100644
--- a/services/mgmt/binary/impl/impl_test.go
+++ b/services/mgmt/binary/impl/impl_test.go
@@ -27,17 +27,14 @@
 	veyronPrefix = "veyron_binary_repository"
 )
 
-var gctx *context.T
-var globalCancel context.CancelFunc
-
 // startServer starts the binary repository server.
-func startServer(t *testing.T, depth int) (repository.BinaryClientMethods, string, string, func()) {
+func startServer(t *testing.T, ctx *context.T, depth int) (repository.BinaryClientMethods, string, string, func()) {
 	// Setup the root of the binary repository.
 	rootDir, cleanup := mgmttest.SetupRootDir(t, "bindir")
 	prepDirectory(t, rootDir)
 
 	// Setup and start the binary repository server.
-	server, endpoint := mgmttest.NewServer(gctx)
+	server, endpoint := mgmttest.NewServer(ctx)
 
 	listener, err := net.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
@@ -52,7 +49,7 @@
 			vlog.Fatalf("Serve() failed: %v", err)
 		}
 	}()
-	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(gctx), state)
+	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(ctx), state)
 	if err != nil {
 		t.Fatalf("NewDispatcher failed: %v", err)
 	}
@@ -75,19 +72,23 @@
 // all possible valid values of the depth used for the directory
 // hierarchy that stores binary objects in the local file system.
 func TestHierarchy(t *testing.T) {
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	for i := 0; i < md5.Size; i++ {
-		binary, ep, _, cleanup := startServer(t, i)
+		binary, ep, _, cleanup := startServer(t, ctx, i)
 		defer cleanup()
 		data := testData()
 
 		// Test the binary repository interface.
-		if err := binary.Create(gctx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+		if err := binary.Create(ctx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
 			t.Fatalf("Create() failed: %v", err)
 		}
-		if streamErr, err := invokeUpload(t, gctx, binary, data, 0); streamErr != nil || err != nil {
+		if streamErr, err := invokeUpload(t, ctx, binary, data, 0); streamErr != nil || err != nil {
 			t.FailNow()
 		}
-		parts, _, err := binary.Stat(gctx)
+		parts, _, err := binary.Stat(ctx)
 		if err != nil {
 			t.Fatalf("Stat() failed: %v", err)
 		}
@@ -100,21 +101,21 @@
 		if expected, got := len(data), int(parts[0].Size); expected != got {
 			t.Fatalf("Unexpected size: expected %v, got %v", expected, got)
 		}
-		output, streamErr, err := invokeDownload(t, gctx, binary, 0)
+		output, streamErr, err := invokeDownload(t, ctx, binary, 0)
 		if streamErr != nil || err != nil {
 			t.FailNow()
 		}
 		if bytes.Compare(output, data) != 0 {
 			t.Fatalf("Unexpected output: expected %v, got %v", data, output)
 		}
-		results, err := testutil.GlobName(gctx, naming.JoinAddressName(ep, ""), "...")
+		results, err := testutil.GlobName(ctx, naming.JoinAddressName(ep, ""), "...")
 		if err != nil {
 			t.Fatalf("GlobName failed: %v", err)
 		}
 		if expected := []string{"", "test"}; !reflect.DeepEqual(results, expected) {
 			t.Errorf("Unexpected results: expected %q, got %q", expected, results)
 		}
-		if err := binary.Delete(gctx); err != nil {
+		if err := binary.Delete(ctx); err != nil {
 			t.Fatalf("Delete() failed: %v", err)
 		}
 	}
@@ -124,8 +125,12 @@
 // uploads and downloads ranging the number of parts the test binary
 // consists of.
 func TestMultiPart(t *testing.T) {
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	for length := 2; length < 5; length++ {
-		binary, _, _, cleanup := startServer(t, 2)
+		binary, _, _, cleanup := startServer(t, ctx, 2)
 		defer cleanup()
 		// Create <length> chunks of up to 4MB of random bytes.
 		data := make([][]byte, length)
@@ -133,21 +138,21 @@
 			data[i] = testData()
 		}
 		// Test the binary repository interface.
-		if err := binary.Create(gctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+		if err := binary.Create(ctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
 			t.Fatalf("Create() failed: %v", err)
 		}
 		for i := 0; i < length; i++ {
-			if streamErr, err := invokeUpload(t, gctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
+			if streamErr, err := invokeUpload(t, ctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
 				t.FailNow()
 			}
 		}
-		parts, _, err := binary.Stat(gctx)
+		parts, _, err := binary.Stat(ctx)
 		if err != nil {
 			t.Fatalf("Stat() failed: %v", err)
 		}
 		for i := 0; i < length; i++ {
 			hpart := md5.New()
-			output, streamErr, err := invokeDownload(t, gctx, binary, int32(i))
+			output, streamErr, err := invokeDownload(t, ctx, binary, int32(i))
 			if streamErr != nil || err != nil {
 				t.FailNow()
 			}
@@ -163,7 +168,7 @@
 				t.Fatalf("Unexpected size: expected %v, got %v", expected, got)
 			}
 		}
-		if err := binary.Delete(gctx); err != nil {
+		if err := binary.Delete(ctx); err != nil {
 			t.Fatalf("Delete() failed: %v", err)
 		}
 	}
@@ -173,21 +178,25 @@
 // resumption ranging the number of parts the uploaded binary consists
 // of.
 func TestResumption(t *testing.T) {
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	for length := 2; length < 5; length++ {
-		binary, _, _, cleanup := startServer(t, 2)
+		binary, _, _, cleanup := startServer(t, ctx, 2)
 		defer cleanup()
 		// Create <length> chunks of up to 4MB of random bytes.
 		data := make([][]byte, length)
 		for i := 0; i < length; i++ {
 			data[i] = testData()
 		}
-		if err := binary.Create(gctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+		if err := binary.Create(ctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
 			t.Fatalf("Create() failed: %v", err)
 		}
 		// Simulate a flaky upload client that keeps uploading parts until
 		// finished.
 		for {
-			parts, _, err := binary.Stat(gctx)
+			parts, _, err := binary.Stat(ctx)
 			if err != nil {
 				t.Fatalf("Stat() failed: %v", err)
 			}
@@ -201,13 +210,13 @@
 			for i := 0; i < length; i++ {
 				fail := testutil.Rand.Intn(2)
 				if parts[i] == impl.MissingPart && fail != 0 {
-					if streamErr, err := invokeUpload(t, gctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
+					if streamErr, err := invokeUpload(t, ctx, binary, data[i], int32(i)); streamErr != nil || err != nil {
 						t.FailNow()
 					}
 				}
 			}
 		}
-		if err := binary.Delete(gctx); err != nil {
+		if err := binary.Delete(ctx); err != nil {
 			t.Fatalf("Delete() failed: %v", err)
 		}
 	}
@@ -215,7 +224,11 @@
 
 // TestErrors checks that the binary interface correctly reports errors.
 func TestErrors(t *testing.T) {
-	binary, _, _, cleanup := startServer(t, 2)
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+	binary, _, _, cleanup := startServer(t, ctx, 2)
 	defer cleanup()
 	const length = 2
 	data := make([][]byte, length)
@@ -225,51 +238,51 @@
 			data[i][j] = byte(testutil.Rand.Int())
 		}
 	}
-	if err := binary.Create(gctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+	if err := binary.Create(ctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
 		t.Fatalf("Create() failed: %v", err)
 	}
-	if err := binary.Create(gctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err == nil {
+	if err := binary.Create(ctx, int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err == nil {
 		t.Fatalf("Create() did not fail when it should have")
 	} else if want := verror.Exist.ID; !verror.Is(err, want) {
 		t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
 	}
-	if streamErr, err := invokeUpload(t, gctx, binary, data[0], 0); streamErr != nil || err != nil {
+	if streamErr, err := invokeUpload(t, ctx, binary, data[0], 0); streamErr != nil || err != nil {
 		t.Fatalf("Upload() failed: %v", err)
 	}
-	if _, err := invokeUpload(t, gctx, binary, data[0], 0); err == nil {
+	if _, err := invokeUpload(t, ctx, binary, data[0], 0); err == nil {
 		t.Fatalf("Upload() did not fail when it should have")
 	} else if want := verror.Exist.ID; !verror.Is(err, want) {
 		t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
 	}
-	if _, _, err := invokeDownload(t, gctx, binary, 1); err == nil {
+	if _, _, err := invokeDownload(t, ctx, binary, 1); err == nil {
 		t.Fatalf("Download() did not fail when it should have")
 	} else if want := verror.NoExist.ID; !verror.Is(err, want) {
 		t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
 	}
-	if streamErr, err := invokeUpload(t, gctx, binary, data[1], 1); streamErr != nil || err != nil {
+	if streamErr, err := invokeUpload(t, ctx, binary, data[1], 1); streamErr != nil || err != nil {
 		t.Fatalf("Upload() failed: %v", err)
 	}
-	if _, streamErr, err := invokeDownload(t, gctx, binary, 0); streamErr != nil || err != nil {
+	if _, streamErr, err := invokeDownload(t, ctx, binary, 0); streamErr != nil || err != nil {
 		t.Fatalf("Download() failed: %v", err)
 	}
 	// Upload/Download on a part number that's outside the range set forth in
 	// Create should fail.
 	for _, part := range []int32{-1, length} {
-		if _, err := invokeUpload(t, gctx, binary, []byte("dummy"), part); err == nil {
+		if _, err := invokeUpload(t, ctx, binary, []byte("dummy"), part); err == nil {
 			t.Fatalf("Upload() did not fail when it should have")
 		} else if want := impl.ErrInvalidPart.ID; !verror.Is(err, want) {
 			t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
 		}
-		if _, _, err := invokeDownload(t, gctx, binary, part); err == nil {
+		if _, _, err := invokeDownload(t, ctx, binary, part); err == nil {
 			t.Fatalf("Download() did not fail when it should have")
 		} else if want := impl.ErrInvalidPart.ID; !verror.Is(err, want) {
 			t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
 		}
 	}
-	if err := binary.Delete(gctx); err != nil {
+	if err := binary.Delete(ctx); err != nil {
 		t.Fatalf("Delete() failed: %v", err)
 	}
-	if err := binary.Delete(gctx); err == nil {
+	if err := binary.Delete(ctx); err == nil {
 		t.Fatalf("Delete() did not fail when it should have")
 	} else if want := verror.NoExist.ID; !verror.Is(err, want) {
 		t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
@@ -277,7 +290,11 @@
 }
 
 func TestGlob(t *testing.T) {
-	_, ep, _, cleanup := startServer(t, 2)
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+	_, ep, _, cleanup := startServer(t, ctx, 2)
 	defer cleanup()
 	data := testData()
 
@@ -286,14 +303,14 @@
 		name := naming.JoinAddressName(ep, obj)
 		binary := repository.BinaryClient(name)
 
-		if err := binary.Create(gctx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+		if err := binary.Create(ctx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
 			t.Fatalf("Create() failed: %v", err)
 		}
-		if streamErr, err := invokeUpload(t, gctx, binary, data, 0); streamErr != nil || err != nil {
+		if streamErr, err := invokeUpload(t, ctx, binary, data, 0); streamErr != nil || err != nil {
 			t.FailNow()
 		}
 	}
-	results, err := testutil.GlobName(gctx, naming.JoinAddressName(ep, ""), "...")
+	results, err := testutil.GlobName(ctx, naming.JoinAddressName(ep, ""), "...")
 	if err != nil {
 		t.Fatalf("GlobName failed: %v", err)
 	}
diff --git a/services/mgmt/device/impl/proxy_invoker_test.go b/services/mgmt/device/impl/proxy_invoker_test.go
index 2009a8c..2668160 100644
--- a/services/mgmt/device/impl/proxy_invoker_test.go
+++ b/services/mgmt/device/impl/proxy_invoker_test.go
@@ -7,7 +7,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/security"
 	"v.io/core/veyron2/services/mgmt/stats"
 	"v.io/core/veyron2/services/security/access"
@@ -19,12 +18,9 @@
 // TODO(toddw): Add tests of Signature and MethodSignature.
 
 func TestProxyInvoker(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %v", err)
-	}
-	defer runtime.Cleanup()
-	ctx := runtime.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
 
 	// server1 is a normal server
 	server1, err := veyron2.NewServer(ctx)
@@ -51,7 +47,6 @@
 		t.Fatalf("Listen: %v", err)
 	}
 	disp := &proxyDispatcher{
-		runtime,
 		naming.JoinAddressName(eps1[0].String(), "__debug/stats"),
 		stats.StatsServer(nil).Describe__(),
 	}
@@ -85,9 +80,8 @@
 func (*dummy) Method(_ ipc.ServerContext) error { return nil }
 
 type proxyDispatcher struct {
-	runtime veyron2.Runtime
-	remote  string
-	desc    []ipc.InterfaceDesc
+	remote string
+	desc   []ipc.InterfaceDesc
 }
 
 func (d *proxyDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
diff --git a/services/mgmt/lib/binary/impl_test.go b/services/mgmt/lib/binary/impl_test.go
index 4a4deb4..42db6a4 100644
--- a/services/mgmt/lib/binary/impl_test.go
+++ b/services/mgmt/lib/binary/impl_test.go
@@ -11,7 +11,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/services/mgmt/repository"
 	"v.io/core/veyron2/vlog"
 
@@ -24,19 +23,11 @@
 	veyronPrefix = "veyron_binary_repository"
 )
 
-var gctx *context.T
-
 func init() {
 	testutil.Init()
-
-	runtime, err := rt.New()
-	if err != nil {
-		panic(err)
-	}
-	gctx = runtime.NewContext()
 }
 
-func setupRepository(t *testing.T) (string, func()) {
+func setupRepository(t *testing.T, ctx *context.T) (string, func()) {
 	// Setup the root of the binary repository.
 	rootDir, err := ioutil.TempDir("", veyronPrefix)
 	if err != nil {
@@ -47,7 +38,7 @@
 		vlog.Fatalf("WriteFile(%v, %v, %v) failed: %v", path, impl.Version, perm, err)
 	}
 	// Setup and start the binary repository server.
-	server, err := veyron2.NewServer(gctx)
+	server, err := veyron2.NewServer(ctx)
 	if err != nil {
 		t.Fatalf("NewServer() failed: %v", err)
 	}
@@ -57,7 +48,7 @@
 		t.Fatalf("NewState(%v, %v) failed: %v", rootDir, depth, err)
 	}
 
-	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(gctx), state)
+	dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(ctx), state)
 	if err != nil {
 		t.Fatalf("NewDispatcher() failed: %v\n", err)
 	}
@@ -89,24 +80,28 @@
 // TestBufferAPI tests the binary repository client-side library
 // interface using buffers.
 func TestBufferAPI(t *testing.T) {
-	von, cleanup := setupRepository(t)
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+	von, cleanup := setupRepository(t, ctx)
 	defer cleanup()
 	data := testutil.RandomBytes(testutil.Rand.Intn(10 << 20))
 	mediaInfo := repository.MediaInfo{Type: "application/octet-stream"}
-	if err := Upload(gctx, von, data, mediaInfo); err != nil {
+	if err := Upload(ctx, von, data, mediaInfo); err != nil {
 		t.Fatalf("Upload(%v) failed: %v", von, err)
 	}
-	output, outInfo, err := Download(gctx, von)
+	output, outInfo, err := Download(ctx, von)
 	if err != nil {
 		t.Fatalf("Download(%v) failed: %v", von, err)
 	}
 	if bytes.Compare(data, output) != 0 {
 		t.Errorf("Data mismatch:\nexpected %v %v\ngot %v %v", len(data), data[:100], len(output), output[:100])
 	}
-	if err := Delete(gctx, von); err != nil {
+	if err := Delete(ctx, von); err != nil {
 		t.Errorf("Delete(%v) failed: %v", von, err)
 	}
-	if _, _, err := Download(gctx, von); err == nil {
+	if _, _, err := Download(ctx, von); err == nil {
 		t.Errorf("Download(%v) did not fail", von)
 	}
 	if !reflect.DeepEqual(mediaInfo, outInfo) {
@@ -117,7 +112,11 @@
 // TestFileAPI tests the binary repository client-side library
 // interface using files.
 func TestFileAPI(t *testing.T) {
-	von, cleanup := setupRepository(t)
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+	von, cleanup := setupRepository(t, ctx)
 	defer cleanup()
 	// Create up to 10MB of random bytes.
 	data := testutil.RandomBytes(testutil.Rand.Intn(10 << 20))
@@ -141,10 +140,10 @@
 	if _, err := src.Write(data); err != nil {
 		t.Fatalf("Write() failed: %v", err)
 	}
-	if err := UploadFromFile(gctx, von, src.Name()); err != nil {
+	if err := UploadFromFile(ctx, von, src.Name()); err != nil {
 		t.Fatalf("UploadFromFile(%v, %v) failed: %v", von, src.Name(), err)
 	}
-	if err := DownloadToFile(gctx, von, dst.Name()); err != nil {
+	if err := DownloadToFile(ctx, von, dst.Name()); err != nil {
 		t.Fatalf("DownloadToFile(%v, %v) failed: %v", von, dst.Name(), err)
 	}
 	output, err := ioutil.ReadFile(dst.Name())
@@ -161,7 +160,7 @@
 	if expected := `{"Type":"application/octet-stream","Encoding":""}`; string(jMediaInfo) != expected {
 		t.Errorf("unexpected media info: expected %q, got %q", expected, string(jMediaInfo))
 	}
-	if err := Delete(gctx, von); err != nil {
+	if err := Delete(ctx, von); err != nil {
 		t.Errorf("Delete(%v) failed: %v", von, err)
 	}
 }
@@ -169,9 +168,13 @@
 // TestDownloadURL tests the binary repository client-side library
 // DownloadURL method.
 func TestDownloadURL(t *testing.T) {
-	von, cleanup := setupRepository(t)
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+	von, cleanup := setupRepository(t, ctx)
 	defer cleanup()
-	url, _, err := DownloadURL(gctx, von)
+	url, _, err := DownloadURL(ctx, von)
 	if err != nil {
 		t.Fatalf("DownloadURL(%v) failed: %v", von, err)
 	}
diff --git a/services/mgmt/lib/testutil/modules.go b/services/mgmt/lib/testutil/modules.go
index b98460d..23aa53e 100644
--- a/services/mgmt/lib/testutil/modules.go
+++ b/services/mgmt/lib/testutil/modules.go
@@ -10,7 +10,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/security"
 	"v.io/core/veyron2/vlog"
 
@@ -127,17 +126,6 @@
 	return server, endpoints[0].String()
 }
 
-// NewRuntime makes an instance of the runtime.
-func NewRuntime(t *testing.T, octx *context.T, opts ...veyron2.ROpt) (*context.T, context.CancelFunc) {
-	runtime, err := rt.New(opts...)
-	if err != nil {
-		t.Fatalf("rt.New() failed: %v", err)
-	}
-	ctx := runtime.NewContext()
-	veyron2.GetNamespace(ctx).SetRoots(veyron2.GetNamespace(octx).Roots()[0])
-	return ctx, runtime.Cleanup
-}
-
 // ReadPID waits for the "ready:<PID>" line from the child and parses out the
 // PID of the child.
 func ReadPID(t *testing.T, s *expect.Session) int {