veyron/runtimes/google/rt: Make tests use veyron2.Init.

Change-Id: Ibd50614be6f5de2734bbcca8226ef4cda035bf96
diff --git a/profiles/chrome/chromeinit.go b/profiles/chrome/chromeinit.go
index b18108d..6ec957d 100644
--- a/profiles/chrome/chromeinit.go
+++ b/profiles/chrome/chromeinit.go
@@ -15,7 +15,7 @@
 }
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
-	runtime, ctx, shutdown, err := grt.Init(ctx, nil)
+	runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, nil, nil)
 	if err != nil {
 		return nil, nil, shutdown, err
 	}
diff --git a/profiles/gce/initx.go b/profiles/gce/initx.go
index 4aa63c8..45d9b23 100644
--- a/profiles/gce/initx.go
+++ b/profiles/gce/initx.go
@@ -8,10 +8,12 @@
 	"flag"
 	"fmt"
 	"net"
+	"os"
 
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
+	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/flags"
@@ -33,16 +35,14 @@
 }
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
+	vlog.Log.VI(1).Infof("Initializing GCE profile.")
 	if !gce.RunningOnGCE() {
 		return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
 	}
 
-	runtime, ctx, shutdown, err := grt.Init(ctx, nil)
-	if err != nil {
-		return nil, nil, shutdown, err
-	}
-	runtime.GetLogger(ctx).VI(1).Infof("Initializing GCE profile.")
+	ac := appcycle.New()
 
+	commonFlags.Parse(os.Args[1:], nil)
 	lf := commonFlags.ListenFlags()
 	listenSpec := ipc.ListenSpec{
 		Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -50,20 +50,21 @@
 	}
 
 	if ip, err := gce.ExternalIPAddress(); err != nil {
-		return nil, nil, shutdown, err
+		return nil, nil, nil, err
 	} else {
 		listenSpec.AddressChooser = func(network string, addrs []ipc.Address) ([]ipc.Address, error) {
 			return []ipc.Address{&netstate.AddrIfc{&net.IPAddr{IP: ip}, "gce-nat", nil}}, nil
 		}
 	}
-	ctx = runtime.SetListenSpec(ctx, listenSpec)
 
-	ac := appcycle.New()
-	ctx = runtime.SetAppCycle(ctx, ac)
+	runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, nil)
+	if err != nil {
+		return nil, nil, shutdown, err
+	}
 
 	profileShutdown := func() {
-		shutdown()
 		ac.Shutdown()
+		shutdown()
 	}
 
 	return runtime, ctx, profileShutdown, nil
diff --git a/profiles/genericinit.go b/profiles/genericinit.go
index cbd7312..257974a 100644
--- a/profiles/genericinit.go
+++ b/profiles/genericinit.go
@@ -3,8 +3,10 @@
 import (
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
+	"v.io/core/veyron2/ipc"
 
 	"v.io/core/veyron/lib/appcycle"
+	"v.io/core/veyron/profiles/internal"
 	_ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
 	_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
 	_ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
@@ -16,18 +18,24 @@
 }
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
-	runtime, ctx, shutdown, err := grt.Init(ctx, nil)
+	ac := appcycle.New()
+
+	runtime, ctx, shutdown, err := grt.Init(ctx,
+		ac,
+		nil,
+		&ipc.ListenSpec{
+			Addrs:          ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
+			AddressChooser: internal.IPAddressChooser,
+		},
+		nil)
 	if err != nil {
 		return nil, nil, nil, err
 	}
 	runtime.GetLogger(ctx).VI(1).Infof("Initializing generic profile.")
 
-	ac := appcycle.New()
-	ctx = runtime.SetAppCycle(ctx, ac)
-
 	profileShutdown := func() {
-		shutdown()
 		ac.Shutdown()
+		shutdown()
 	}
 	return runtime, ctx, profileShutdown, nil
 }
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index 533cabb..8dbe076 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -12,11 +12,13 @@
 
 import (
 	"flag"
+	"os"
 
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
+	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/flags"
@@ -47,14 +49,10 @@
 }
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
-	runtime, ctx, shutdown, err := grt.Init(ctx, nil)
-	if err != nil {
-		return nil, nil, shutdown, err
-	}
-	log := runtime.GetLogger(ctx)
+	log := vlog.Log
+	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
 
-	ctx = runtime.SetReservedNameDispatcher(ctx, debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
-
+	commonFlags.Parse(os.Args[1:], nil)
 	lf := commonFlags.ListenFlags()
 	listenSpec := ipc.ListenSpec{
 		Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -62,7 +60,6 @@
 	}
 
 	ac := appcycle.New()
-	ctx = runtime.SetAppCycle(ctx, ac)
 
 	// Our address is private, so we test for running on GCE and for its
 	// 1:1 NAT configuration.
@@ -71,36 +68,40 @@
 			listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
 				return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
 			}
-			ctx = runtime.SetListenSpec(ctx, listenSpec)
-			return runtime, ctx, shutdown, nil
+			runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+			if err != nil {
+				return nil, nil, shutdown, err
+			}
+			profileShutdown := func() {
+				ac.Shutdown()
+				shutdown()
+			}
+			return runtime, ctx, profileShutdown, nil
 		}
 	}
 
-	publisher := runtime.GetPublisher(ctx)
+	publisher := config.NewPublisher()
 
 	// Create stream in Init function to avoid a race between any
 	// goroutines started here and consumers started after Init returns.
 	ch := make(chan config.Setting)
 	stop, err := publisher.CreateStream(SettingsStreamName, SettingsStreamName, ch)
 	if err != nil {
-		log.Errorf("failed to create publisher: %s", err)
 		ac.Shutdown()
-		return nil, nil, shutdown, err
+		return nil, nil, nil, err
 	}
 
 	prev, err := netstate.GetAccessibleIPs()
 	if err != nil {
-		log.VI(2).Infof("failed to determine network state")
 		ac.Shutdown()
-		return nil, nil, shutdown, err
+		return nil, nil, nil, err
 	}
 
 	// Start the dhcp watcher.
 	watcher, err := netconfig.NewNetConfigWatcher()
 	if err != nil {
-		log.VI(2).Infof("Failed to get new config watcher: %s", err)
 		ac.Shutdown()
-		return nil, nil, shutdown, err
+		return nil, nil, nil, err
 	}
 
 	cleanupCh := make(chan struct{})
@@ -110,13 +111,16 @@
 	listenSpec.StreamName = SettingsStreamName
 	listenSpec.AddressChooser = internal.IPAddressChooser
 
-	ctx = runtime.SetListenSpec(ctx, listenSpec)
+	runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+	if err != nil {
+		return nil, nil, shutdown, err
+	}
 
 	go monitorNetworkSettingsX(runtime, ctx, watcher, prev, stop, cleanupCh, watcherCh, ch)
 	profileShutdown := func() {
 		close(cleanupCh)
-		shutdown()
 		ac.Shutdown()
+		shutdown()
 		<-watcherCh
 	}
 	return runtime, ctx, profileShutdown, nil
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index 4def643..4f84141 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -2,10 +2,12 @@
 
 import (
 	"flag"
+	"os"
 
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
+	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/flags"
@@ -31,14 +33,11 @@
 }
 
 func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
-	runtime, ctx, shutdown, err := grt.Init(ctx, nil)
-	if err != nil {
-		return nil, nil, nil, err
-	}
-	log := runtime.GetLogger(ctx)
+	log := vlog.Log
 
-	ctx = runtime.SetReservedNameDispatcher(ctx, debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
+	reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
 
+	commonFlags.Parse(os.Args[1:], nil)
 	lf := commonFlags.ListenFlags()
 	listenSpec := ipc.ListenSpec{
 		Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -46,7 +45,6 @@
 	}
 
 	ac := appcycle.New()
-	ctx = runtime.SetAppCycle(ctx, ac)
 
 	// Our address is private, so we test for running on GCE and for its 1:1 NAT
 	// configuration. GCEPublicAddress returns a non-nil addr if we are running on GCE.
@@ -55,15 +53,23 @@
 			listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
 				return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
 			}
+			runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+			if err != nil {
+				return nil, nil, nil, err
+			}
 			return runtime, ctx, shutdown, nil
 		}
 	}
 	listenSpec.AddressChooser = internal.IPAddressChooser
-	ctx = runtime.SetListenSpec(ctx, listenSpec)
+
+	runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+	if err != nil {
+		return nil, nil, shutdown, err
+	}
 
 	profileShutdown := func() {
-		shutdown()
 		ac.Shutdown()
+		shutdown()
 	}
 	return runtime, ctx, profileShutdown, nil
 }
diff --git a/runtimes/google/rt/ipc_test.go b/runtimes/google/rt/ipc_test.go
index 70dd0d2..f62178a 100644
--- a/runtimes/google/rt/ipc_test.go
+++ b/runtimes/google/rt/ipc_test.go
@@ -10,7 +10,6 @@
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/security"
 
 	"v.io/core/veyron/lib/testutil"
@@ -41,12 +40,12 @@
 	return ctx.LocalPrincipal().MintDischarge(c, security.UnconstrainedUse())
 }
 
-func newRT() *context.T {
-	r, err := rt.New()
+func newCtx(rootCtx *context.T) *context.T {
+	ctx, err := veyron2.SetPrincipal(rootCtx, tsecurity.NewPrincipal("defaultBlessings"))
 	if err != nil {
 		panic(err)
 	}
-	return r.NewContext()
+	return ctx
 }
 
 func union(blessings ...security.Blessings) security.Blessings {
@@ -75,6 +74,13 @@
 	return cav
 }
 
+func mkBlessings(blessings security.Blessings, err error) security.Blessings {
+	if err != nil {
+		panic(err)
+	}
+	return blessings
+}
+
 func mkThirdPartyCaveat(discharger security.PublicKey, location string, caveats ...security.Caveat) security.Caveat {
 	if len(caveats) == 0 {
 		caveats = []security.Caveat{security.UnconstrainedUse()}
@@ -103,26 +109,23 @@
 }
 
 func TestClientServerBlessings(t *testing.T) {
-	b := func(blessings security.Blessings, err error) security.Blessings {
-		if err != nil {
-			t.Fatal(err)
-		}
-		return blessings
-	}
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	var (
 		rootAlpha, rootBeta, rootUnrecognized = tsecurity.NewIDProvider("alpha"), tsecurity.NewIDProvider("beta"), tsecurity.NewIDProvider("unrecognized")
-		clientCtx, serverCtx                  = newRT(), newRT()
+		clientCtx, serverCtx                  = newCtx(ctx), newCtx(ctx)
 		pclient                               = veyron2.GetPrincipal(clientCtx)
 		pserver                               = veyron2.GetPrincipal(serverCtx)
 
 		// A bunch of blessings
-		alphaClient        = b(rootAlpha.NewBlessings(pclient, "client"))
-		betaClient         = b(rootBeta.NewBlessings(pclient, "client"))
-		unrecognizedClient = b(rootUnrecognized.NewBlessings(pclient, "client"))
+		alphaClient        = mkBlessings(rootAlpha.NewBlessings(pclient, "client"))
+		betaClient         = mkBlessings(rootBeta.NewBlessings(pclient, "client"))
+		unrecognizedClient = mkBlessings(rootUnrecognized.NewBlessings(pclient, "client"))
 
-		alphaServer        = b(rootAlpha.NewBlessings(pserver, "server"))
-		betaServer         = b(rootBeta.NewBlessings(pserver, "server"))
-		unrecognizedServer = b(rootUnrecognized.NewBlessings(pserver, "server"))
+		alphaServer        = mkBlessings(rootAlpha.NewBlessings(pserver, "server"))
+		betaServer         = mkBlessings(rootBeta.NewBlessings(pserver, "server"))
+		unrecognizedServer = mkBlessings(rootUnrecognized.NewBlessings(pserver, "server"))
 	)
 	// Setup the client's blessing store
 	pclient.BlessingStore().Set(alphaClient, "alpha/server")
@@ -196,14 +199,11 @@
 }
 
 func TestServerDischarges(t *testing.T) {
-	b := func(blessings security.Blessings, err error) security.Blessings {
-		if err != nil {
-			t.Fatal(err)
-		}
-		return blessings
-	}
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	var (
-		dischargerCtx, clientCtx, serverCtx = newRT(), newRT(), newRT()
+		dischargerCtx, clientCtx, serverCtx = newCtx(ctx), newCtx(ctx), newCtx(ctx)
 		pdischarger                         = veyron2.GetPrincipal(dischargerCtx)
 		pclient                             = veyron2.GetPrincipal(clientCtx)
 		pserver                             = veyron2.GetPrincipal(serverCtx)
@@ -231,7 +231,7 @@
 	}
 
 	// Setup up the client's blessing store so that it can talk to the server.
-	rootClient := b(root.NewBlessings(pclient, "client"))
+	rootClient := mkBlessings(root.NewBlessings(pclient, "client"))
 	if _, err := pclient.BlessingStore().Set(nil, security.AllPrincipals); err != nil {
 		t.Fatal(err)
 	}
@@ -270,7 +270,7 @@
 		t.Fatal(err)
 	}
 
-	rootServerInvalidTPCaveat := b(root.NewBlessings(pserver, "server", mkThirdPartyCaveat(pdischarger.PublicKey(), dischargeServerName, mkCaveat(security.ExpiryCaveat(time.Now().Add(-1*time.Second))))))
+	rootServerInvalidTPCaveat := mkBlessings(root.NewBlessings(pserver, "server", mkThirdPartyCaveat(pdischarger.PublicKey(), dischargeServerName, mkCaveat(security.ExpiryCaveat(time.Now().Add(-1*time.Second))))))
 	if err := pserver.BlessingStore().SetDefault(rootServerInvalidTPCaveat); err != nil {
 		t.Fatal(err)
 	}
diff --git a/runtimes/google/rt/mgmt_test.go b/runtimes/google/rt/mgmt_test.go
index 6062899..220a562 100644
--- a/runtimes/google/rt/mgmt_test.go
+++ b/runtimes/google/rt/mgmt_test.go
@@ -14,20 +14,16 @@
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/mgmt"
 	"v.io/core/veyron2/naming"
-	"v.io/core/veyron2/options"
 	"v.io/core/veyron2/services/mgmt/appcycle"
 
 	"v.io/core/veyron/lib/expect"
 	"v.io/core/veyron/lib/modules"
 	"v.io/core/veyron/lib/testutil"
 	"v.io/core/veyron/profiles"
-	"v.io/core/veyron/runtimes/google/rt"
 	vflag "v.io/core/veyron/security/flag"
 	"v.io/core/veyron/services/mgmt/device"
 )
 
-var profileOpt = options.Profile{profiles.New()}
-
 const (
 	noWaitersCmd = "noWaiters"
 	forceStopCmd = "forceStop"
@@ -44,8 +40,9 @@
 // TestBasic verifies that the basic plumbing works: LocalStop calls result in
 // stop messages being sent on the channel passed to WaitForStop.
 func TestBasic(t *testing.T) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
 	ch := make(chan string, 1)
 	m.WaitForStop(ch)
@@ -65,8 +62,9 @@
 // TestMultipleWaiters verifies that the plumbing works with more than one
 // registered wait channel.
 func TestMultipleWaiters(t *testing.T) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
 	ch1 := make(chan string, 1)
 	m.WaitForStop(ch1)
@@ -87,8 +85,9 @@
 // channel is not being drained: once the channel's buffer fills up, future
 // Stops become no-ops.
 func TestMultipleStops(t *testing.T) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
 	ch := make(chan string, 1)
 	m.WaitForStop(ch)
@@ -106,8 +105,9 @@
 }
 
 func noWaiters(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
 	fmt.Fprintf(stdout, "ready\n")
 	modules.WaitForEOF(stdin)
@@ -136,8 +136,9 @@
 }
 
 func forceStop(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
 	fmt.Fprintf(stdout, "ready\n")
 	modules.WaitForEOF(stdin)
@@ -185,8 +186,8 @@
 // TestProgress verifies that the ticker update/track logic works for a single
 // tracker.
 func TestProgress(t *testing.T) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+
 	m := veyron2.GetAppCycle(ctx)
 	m.AdvanceGoal(50)
 	ch := make(chan veyron2.Task, 1)
@@ -207,7 +208,7 @@
 	checkNoProgress(t, ch)
 	m.AdvanceGoal(0)
 	checkNoProgress(t, ch)
-	r.Cleanup()
+	shutdown()
 	if _, ok := <-ch; ok {
 		t.Errorf("Expected channel to be closed")
 	}
@@ -217,8 +218,8 @@
 // works for more than one tracker.  It also ensures that the runtime doesn't
 // block when the tracker channels are full.
 func TestProgressMultipleTrackers(t *testing.T) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+
 	m := veyron2.GetAppCycle(ctx)
 	// ch1 is 1-buffered, ch2 is 2-buffered.
 	ch1, ch2 := make(chan veyron2.Task, 1), make(chan veyron2.Task, 2)
@@ -242,7 +243,7 @@
 	m.AdvanceGoal(4)
 	checkProgress(t, ch1, 11, 4)
 	checkProgress(t, ch2, 11, 4)
-	r.Cleanup()
+	shutdown()
 	if _, ok := <-ch1; ok {
 		t.Errorf("Expected channel to be closed")
 	}
@@ -252,13 +253,10 @@
 }
 
 func app(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
-	r, err := rt.New(profileOpt)
-	if err != nil {
-		return err
-	}
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
+
 	m := veyron2.GetAppCycle(ctx)
-	defer r.Cleanup()
 	ch := make(chan string, 1)
 	m.WaitForStop(ch)
 	fmt.Fprintf(stdout, "Got %s\n", <-ch)
@@ -300,8 +298,7 @@
 }
 
 func setupRemoteAppCycleMgr(t *testing.T) (*context.T, modules.Handle, appcycle.AppCycleClientMethods, func()) {
-	r, _ := rt.New(profileOpt)
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
 
 	configServer, configServiceName, ch := createConfigServer(t, ctx)
 	sh, err := modules.NewShell(ctx, veyron2.GetPrincipal(ctx))
@@ -325,8 +322,7 @@
 	return ctx, h, appCycle, func() {
 		configServer.Stop()
 		sh.Cleanup(os.Stderr, os.Stderr)
-		// Don't do r.Cleanup() since the runtime needs to be used by
-		// more than one test case.
+		shutdown()
 	}
 }
 
diff --git a/runtimes/google/rt/mgmtx.go b/runtimes/google/rt/mgmtx.go
index cef0cb7..8795bc2 100644
--- a/runtimes/google/rt/mgmtx.go
+++ b/runtimes/google/rt/mgmtx.go
@@ -14,7 +14,7 @@
 	"v.io/core/veyron/lib/exec"
 )
 
-func initMgmt(ctx *context.T, appCycle veyron2.AppCycle, handle *exec.ChildHandle) error {
+func (rt *RuntimeX) initMgmt(ctx *context.T, appCycle veyron2.AppCycle, handle *exec.ChildHandle) error {
 	// Do not initialize the mgmt runtime if the process has not
 	// been started through the veyron exec library by a device
 	// manager.
@@ -34,10 +34,10 @@
 	if err == nil && parentPeerPattern != "" {
 		// Grab the blessing from our blessing store that the parent
 		// told us to use so they can talk to us.
-		serverBlessing := veyron2.GetPrincipal(ctx).BlessingStore().ForPeer(parentPeerPattern)
+		serverBlessing := rt.GetPrincipal(ctx).BlessingStore().ForPeer(parentPeerPattern)
 		serverOpts = append(serverOpts, options.ServerBlessings{serverBlessing})
 	}
-	server, err := veyron2.NewServer(ctx, serverOpts...)
+	server, err := rt.NewServer(ctx, serverOpts...)
 	if err != nil {
 		return err
 	}
@@ -49,19 +49,12 @@
 		server.Stop()
 		return err
 	}
-	err = callbackToParent(ctx, parentName, naming.JoinAddressName(eps[0].String(), ""))
+	err = rt.callbackToParent(ctx, parentName, naming.JoinAddressName(eps[0].String(), ""))
 	if err != nil {
 		server.Stop()
 		return err
 	}
 
-	if done := ctx.Done(); done != nil {
-		go func() {
-			<-done
-			server.Stop()
-		}()
-	}
-
 	return nil
 }
 
@@ -84,9 +77,10 @@
 	return &ipc.ListenSpec{Addrs: ipc.ListenAddrs{{protocol, address}}}, nil
 }
 
-func callbackToParent(ctx *context.T, parentName, myName string) error {
-	ctx, _ = context.WithTimeout(ctx, 10*time.Second)
-	call, err := veyron2.GetClient(ctx).StartCall(ctx, parentName, "Set", []interface{}{mgmt.AppCycleManagerConfigKey, myName})
+func (rt *RuntimeX) callbackToParent(ctx *context.T, parentName, myName string) error {
+	ctx, _ = context.WithTimeout(ctx, time.Minute)
+	call, err := rt.GetClient(ctx).StartCall(ctx, parentName, "Set", []interface{}{mgmt.AppCycleManagerConfigKey, myName}, options.NoResolve{})
+
 	if err != nil {
 		return err
 	}
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index ff35b2d..1e9bd5a 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -12,7 +12,6 @@
 	"time"
 
 	"v.io/core/veyron2"
-	"v.io/core/veyron2/config"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/i18n"
 	"v.io/core/veyron2/ipc"
@@ -48,7 +47,6 @@
 	appCycleKey
 	listenSpecKey
 	protocolsKey
-	publisherKey
 	backgroundKey
 )
 
@@ -79,7 +77,6 @@
 	ctx = context.WithValue(ctx, namespaceKey, rt.ns)
 	ctx = context.WithValue(ctx, loggerKey, vlog.Log)
 	ctx = context.WithValue(ctx, principalKey, rt.principal)
-	ctx = context.WithValue(ctx, publisherKey, rt.publisher)
 	ctx = context.WithValue(ctx, profileKey, rt.profile)
 	ctx = context.WithValue(ctx, appCycleKey, rt.ac)
 	return ctx
@@ -95,7 +92,13 @@
 	wait     *sync.Cond
 }
 
-func Init(ctx *context.T, protocols []string) (*RuntimeX, *context.T, veyron2.Shutdown, error) {
+type reservedNameDispatcher struct {
+	dispatcher ipc.Dispatcher
+	opts       []ipc.ServerOpt
+}
+
+// TODO(mattr,suharshs): Decide if ROpts would be better than this.
+func Init(ctx *context.T, appCycle veyron2.AppCycle, protocols []string, listenSpec *ipc.ListenSpec, reservedDispatcher ipc.Dispatcher, dispatcherOpts ...ipc.ServerOpt) (*RuntimeX, *context.T, veyron2.Shutdown, error) {
 	r := &RuntimeX{}
 	r.wait = sync.NewCond(&r.mu)
 
@@ -124,11 +127,22 @@
 	r.initLogging(ctx)
 	ctx = context.WithValue(ctx, loggerKey, vlog.Log)
 
-	// Set the preferred protocols.
+	if reservedDispatcher != nil {
+		ctx = context.WithValue(ctx, reservedNameKey, &reservedNameDispatcher{reservedDispatcher, dispatcherOpts})
+	}
+
+	if appCycle != nil {
+		ctx = context.WithValue(ctx, appCycleKey, appCycle)
+	}
+
 	if len(protocols) > 0 {
 		ctx = context.WithValue(ctx, protocolsKey, protocols)
 	}
 
+	if listenSpec != nil {
+		ctx = context.WithValue(ctx, listenSpecKey, listenSpec)
+	}
+
 	// Setup i18n.
 	ctx = i18n.ContextWithLangID(ctx, i18n.LangIDFromEnv())
 	if len(flags.I18nCatalogue) != 0 {
@@ -168,7 +182,7 @@
 
 	// The client we create here is incomplete (has a nil principal) and only works
 	// because the agent uses anonymous unix sockets and VCSecurityNone.
-	// After security is initialized we will attach a real client.
+	// After security is initialized we attach a real client.
 	_, client, err := r.SetNewClient(ctx)
 	if err != nil {
 		return nil, nil, nil, err
@@ -188,13 +202,10 @@
 	}
 
 	// Initialize management.
-	if err := initMgmt(ctx, r.GetAppCycle(ctx), handle); err != nil {
+	if err := r.initMgmt(ctx, r.GetAppCycle(ctx), handle); err != nil {
 		return nil, nil, nil, err
 	}
 
-	// Initialize the config publisher.
-	ctx = context.WithValue(ctx, publisherKey, config.NewPublisher())
-
 	ctx = r.SetBackgroundContext(ctx)
 
 	// TODO(suharshs,mattr): Go through the rt.Cleanup function and make sure everything
@@ -286,7 +297,7 @@
 
 func (r *RuntimeX) NewServer(ctx *context.T, opts ...ipc.ServerOpt) (ipc.Server, error) {
 	// Create a new RoutingID (and StreamManager) for each server.
-	_, sm, err := r.SetNewStreamManager(ctx)
+	sm, err := newStreamManager()
 	if err != nil {
 		return nil, fmt.Errorf("failed to create ipc/stream/Manager: %v", err)
 	}
@@ -311,6 +322,7 @@
 		if err := server.Stop(); err != nil {
 			vlog.Errorf("A server could not be stopped: %v", err)
 		}
+		sm.Shutdown()
 	}
 	if err = r.addChild(ctx, stop); err != nil {
 		return nil, err
@@ -318,17 +330,22 @@
 	return server, nil
 }
 
-func (r *RuntimeX) setNewStreamManager(ctx *context.T, opts ...stream.ManagerOpt) (*context.T, stream.Manager, error) {
+func newStreamManager(opts ...stream.ManagerOpt) (stream.Manager, error) {
 	rid, err := naming.NewRoutingID()
 	if err != nil {
-		return ctx, nil, err
+		return nil, err
 	}
 	sm := imanager.InternalNew(rid)
+	return sm, nil
+}
+
+func (r *RuntimeX) setNewStreamManager(ctx *context.T, opts ...stream.ManagerOpt) (*context.T, stream.Manager, error) {
+	sm, err := newStreamManager(opts...)
 	newctx := context.WithValue(ctx, streamManagerKey, sm)
 	if err = r.addChild(ctx, sm.Shutdown); err != nil {
 		return ctx, nil, err
 	}
-	return newctx, sm, nil
+	return newctx, sm, err
 }
 
 func (r *RuntimeX) SetNewStreamManager(ctx *context.T, opts ...stream.ManagerOpt) (*context.T, stream.Manager, error) {
@@ -459,17 +476,6 @@
 	return logger
 }
 
-type reservedNameDispatcher struct {
-	dispatcher ipc.Dispatcher
-	opts       []ipc.ServerOpt
-}
-
-// TODO(mattr): Get this from the profile instead, then remove this
-// method from the interface.
-func (*RuntimeX) SetReservedNameDispatcher(ctx *context.T, server ipc.Dispatcher, opts ...ipc.ServerOpt) *context.T {
-	return context.WithValue(ctx, reservedNameKey, &reservedNameDispatcher{server, opts})
-}
-
 // SetProfile sets the profile used to create this runtime.
 // TODO(suharshs, mattr): Determine if this is needed by functions after the new
 // profile init function is in use. This will probably be easy to do because:
@@ -487,30 +493,14 @@
 	return profile
 }
 
-// SetAppCycle attaches an appCycle to the context.
-func (r *RuntimeX) SetAppCycle(ctx *context.T, appCycle veyron2.AppCycle) *context.T {
-	return context.WithValue(ctx, appCycleKey, appCycle)
-}
-
 func (*RuntimeX) GetAppCycle(ctx *context.T) veyron2.AppCycle {
 	appCycle, _ := ctx.Value(appCycleKey).(veyron2.AppCycle)
 	return appCycle
 }
 
-func (*RuntimeX) SetListenSpec(ctx *context.T, listenSpec ipc.ListenSpec) *context.T {
-	return context.WithValue(ctx, listenSpecKey, listenSpec)
-}
-
 func (*RuntimeX) GetListenSpec(ctx *context.T) ipc.ListenSpec {
-	listenSpec, _ := ctx.Value(listenSpecKey).(ipc.ListenSpec)
-	return listenSpec
-}
-
-// GetPublisher returns a configuration Publisher that can be used to access
-// configuration information.
-func (*RuntimeX) GetPublisher(ctx *context.T) *config.Publisher {
-	publisher, _ := ctx.Value(publisherKey).(*config.Publisher)
-	return publisher
+	listenSpec, _ := ctx.Value(listenSpecKey).(*ipc.ListenSpec)
+	return *listenSpec
 }
 
 func (*RuntimeX) SetBackgroundContext(ctx *context.T) *context.T {
diff --git a/runtimes/google/rt/runtimex_test.go b/runtimes/google/rt/runtimex_test.go
index ab1eba5..bd10057 100644
--- a/runtimes/google/rt/runtimex_test.go
+++ b/runtimes/google/rt/runtimex_test.go
@@ -13,7 +13,7 @@
 // InitForTest creates a context for use in a test.
 func InitForTest(t *testing.T) (*rt.RuntimeX, *context.T, veyron2.Shutdown) {
 	ctx, cancel := context.WithCancel(nil)
-	r, ctx, shutdown, err := rt.Init(ctx, nil)
+	r, ctx, shutdown, err := rt.Init(ctx, nil, nil, nil, nil)
 	if err != nil {
 		t.Fatal(err)
 	}
diff --git a/runtimes/google/rt/shutdown_servers_test.go b/runtimes/google/rt/shutdown_servers_test.go
index 5e32689..db4ab6b 100644
--- a/runtimes/google/rt/shutdown_servers_test.go
+++ b/runtimes/google/rt/shutdown_servers_test.go
@@ -12,7 +12,6 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/ipc"
-	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/modules"
@@ -72,12 +71,10 @@
 // For a more typical server, see simpleServerProgram.
 func complexServerProgram(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
 	// Initialize the runtime.  This is boilerplate.
-	r, err := rt.New()
-	if err != nil {
-		vlog.Fatalf("Could not initialize runtime: %s", err)
-	}
-
-	ctx := r.NewContext()
+	ctx, shutdown := veyron2.Init()
+	// shutdown is optional, but it's a good idea to clean up, especially
+	// since it takes care of flushing the logs before exiting.
+	defer shutdown()
 
 	// This is part of the test setup -- we need a way to accept
 	// commands from the parent process to simulate Stop and
@@ -85,10 +82,6 @@
 	// application code.
 	defer remoteCmdLoop(ctx, stdin)()
 
-	// r.Cleanup is optional, but it's a good idea to clean up, especially
-	// since it takes care of flushing the logs before exiting.
-	defer r.Cleanup()
-
 	// Create a couple servers, and start serving.
 	server1 := makeServer(ctx)
 	server2 := makeServer(ctx)
@@ -220,19 +213,15 @@
 // complexServerProgram.
 func simpleServerProgram(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
 	// Initialize the runtime.  This is boilerplate.
-	r, err := rt.New()
-	if err != nil {
-		vlog.Fatalf("Could not initialize runtime: %s", err)
-	}
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
 	// r.Cleanup is optional, but it's a good idea to clean up, especially
 	// since it takes care of flushing the logs before exiting.
 	//
 	// We use defer to ensure this is the last thing in the program (to
 	// avoid shutting down the runtime while it may still be in use), and to
 	// allow it to execute even if a panic occurs down the road.
-	defer r.Cleanup()
-
-	ctx := r.NewContext()
+	defer shutdown()
 
 	// This is part of the test setup -- we need a way to accept
 	// commands from the parent process to simulate Stop and
diff --git a/runtimes/google/rt/signal_test.go b/runtimes/google/rt/signal_test.go
index d9b296d..9cf77af 100644
--- a/runtimes/google/rt/signal_test.go
+++ b/runtimes/google/rt/signal_test.go
@@ -10,13 +10,10 @@
 	"time"
 
 	"v.io/core/veyron2"
-	"v.io/core/veyron2/config"
-	"v.io/core/veyron2/options"
-	"v.io/core/veyron2/rt"
 
-	"v.io/core/veyron/lib/appcycle"
 	"v.io/core/veyron/lib/expect"
 	"v.io/core/veyron/lib/modules"
+	_ "v.io/core/veyron/profiles"
 )
 
 func init() {
@@ -24,31 +21,6 @@
 	modules.RegisterChild("withoutRuntime", "", withoutRuntime)
 }
 
-// A fack profile to explicitly request the Google runtime.
-type myprofile struct{}
-
-func (mp *myprofile) Name() string {
-	return "test"
-}
-
-func (mp *myprofile) Runtime() (string, []veyron2.ROpt) {
-	return "google", nil
-}
-
-func (mp *myprofile) Platform() *veyron2.Platform {
-	return &veyron2.Platform{"google", nil, "v1", "any", "rel1", ".2", "who knows", "this host"}
-}
-
-func (mp *myprofile) String() string {
-	return "myprofile on " + mp.Platform().String()
-}
-
-func (mp *myprofile) Init(veyron2.Runtime, *config.Publisher) (veyron2.AppCycle, error) {
-	return appcycle.New(), nil
-}
-
-func (mp *myprofile) Cleanup() {}
-
 func simpleEchoProgram(stdin io.Reader, stdout io.Writer) {
 	fmt.Fprintf(stdout, "ready\n")
 	scanner := bufio.NewScanner(stdin)
@@ -59,14 +31,9 @@
 }
 
 func withRuntime(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
-	// Make sure that we use "google" runtime implementation in this
-	// package even though we have to use the public API which supports
-	// arbitrary runtime implementations.
-	r, err := rt.New(options.Profile{&myprofile{}})
-	if err != nil {
-		return err
-	}
-	defer r.Cleanup()
+	_, shutdown := veyron2.Init()
+	defer shutdown()
+
 	simpleEchoProgram(stdin, stdout)
 	return nil
 }