ref: devtools: Move many libraries from v.io/x/ref/lib to v.io/x/ref/profiles/internal.

We are attempting to minimize our API surface area prior to release.  I also
move a few libraries from v.io/x/ref/lib into v.io/x/ref/testlib to make their
intent more clear.

MultiPart: 3/4

Change-Id: I9288720927ffcaf36d5b0efea2e1146070d3cb23
diff --git a/cmd/naming/simulator/driver.go b/cmd/naming/simulator/driver.go
index 6c6b33b..f562216 100644
--- a/cmd/naming/simulator/driver.go
+++ b/cmd/naming/simulator/driver.go
@@ -19,9 +19,9 @@
 	"v.io/v23"
 	"v.io/v23/context"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	_ "v.io/x/ref/lib/modules/core"
+	"v.io/x/ref/lib/testutil/expect"
 	_ "v.io/x/ref/profiles"
 )
 
diff --git a/cmd/servicerunner/main.go b/cmd/servicerunner/main.go
index 815d74e..21ac2f2 100644
--- a/cmd/servicerunner/main.go
+++ b/cmd/servicerunner/main.go
@@ -11,11 +11,11 @@
 
 	"v.io/v23"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/signals"
+	"v.io/x/ref/lib/testutil/expect"
 	"v.io/x/ref/profiles"
 )
 
diff --git a/examples/rps/rpsbot/impl_test.go b/examples/rps/rpsbot/impl_test.go
index 98579ea..cb97524 100644
--- a/examples/rps/rpsbot/impl_test.go
+++ b/examples/rps/rpsbot/impl_test.go
@@ -17,10 +17,10 @@
 	"v.io/v23/context"
 	"v.io/v23/ipc"
 	"v.io/x/ref/examples/rps"
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 )
 
 //go:generate v23 test generate
diff --git a/lib/filelocker/locker_test.go b/lib/filelocker/locker_test.go
index ca4763e..b0ea46e 100644
--- a/lib/filelocker/locker_test.go
+++ b/lib/filelocker/locker_test.go
@@ -10,8 +10,8 @@
 	"testing"
 	"time"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
+	"v.io/x/ref/lib/testutil/expect"
 )
 
 //go:generate v23 test generate
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index 3f521cc..0112757 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -12,11 +12,11 @@
 
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	_ "v.io/x/ref/profiles"
 )
 
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index 9e99bf8..b04b54f 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -19,9 +19,9 @@
 	"v.io/v23/services/mgmt/appcycle"
 	"v.io/v23/vtrace"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	_ "v.io/x/ref/profiles"
 	vflag "v.io/x/ref/security/flag"
 	"v.io/x/ref/services/mgmt/device"
diff --git a/lib/expect/expect.go b/lib/testutil/expect/expect.go
similarity index 100%
rename from lib/expect/expect.go
rename to lib/testutil/expect/expect.go
diff --git a/lib/expect/expect_test.go b/lib/testutil/expect/expect_test.go
similarity index 99%
rename from lib/expect/expect_test.go
rename to lib/testutil/expect/expect_test.go
index 9dfcf03..46f6223 100644
--- a/lib/expect/expect_test.go
+++ b/lib/testutil/expect/expect_test.go
@@ -9,7 +9,7 @@
 	"testing"
 	"time"
 
-	"v.io/x/ref/lib/expect"
+	"v.io/x/ref/lib/testutil/expect"
 )
 
 func TestSimple(t *testing.T) {
diff --git a/lib/testutil/v23tests/v23tests.go b/lib/testutil/v23tests/v23tests.go
index e9c0682..292eb60 100644
--- a/lib/testutil/v23tests/v23tests.go
+++ b/lib/testutil/v23tests/v23tests.go
@@ -91,9 +91,9 @@
 	"v.io/v23/security"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	"v.io/x/ref/security/agent"
 )
diff --git a/lib/testutil/v23tests/v23tests_test.go b/lib/testutil/v23tests/v23tests_test.go
index 64ceb99..d64ed11 100644
--- a/lib/testutil/v23tests/v23tests_test.go
+++ b/lib/testutil/v23tests/v23tests_test.go
@@ -15,9 +15,9 @@
 	"v.io/v23/naming"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	"v.io/x/ref/lib/testutil/v23tests"
 	_ "v.io/x/ref/profiles"
 )
diff --git a/profiles/chrome/chromeinit.go b/profiles/chrome/chromeinit.go
index 776e74d..51c87a5 100644
--- a/profiles/chrome/chromeinit.go
+++ b/profiles/chrome/chromeinit.go
@@ -11,10 +11,10 @@
 	"v.io/x/lib/vlog"
 
 	"v.io/x/ref/lib/flags"
-	"v.io/x/ref/lib/websocket"
 	"v.io/x/ref/profiles/internal"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/wsh_nacl"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	grt "v.io/x/ref/profiles/internal/rt"
 )
 
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
index ac9d9f1..e92b472 100644
--- a/profiles/gce/init.go
+++ b/profiles/gce/init.go
@@ -14,15 +14,15 @@
 	"v.io/v23/ipc"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/appcycle"
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/lib/netstate"
-	"v.io/x/ref/lib/websocket"
 	"v.io/x/ref/profiles/internal"
 	"v.io/x/ref/profiles/internal/gce"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/wsh"
+	"v.io/x/ref/profiles/internal/lib/appcycle"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	grt "v.io/x/ref/profiles/internal/rt"
 )
 
diff --git a/profiles/genericinit.go b/profiles/genericinit.go
index f401981..d6398f6 100644
--- a/profiles/genericinit.go
+++ b/profiles/genericinit.go
@@ -8,13 +8,13 @@
 	"v.io/v23/ipc"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/appcycle"
 	"v.io/x/ref/lib/flags"
-	"v.io/x/ref/lib/websocket"
 	"v.io/x/ref/profiles/internal"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/wsh"
+	"v.io/x/ref/profiles/internal/lib/appcycle"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	grt "v.io/x/ref/profiles/internal/rt"
 )
 
diff --git a/profiles/internal/ipc/client_test.go b/profiles/internal/ipc/client_test.go
index 49455d1..b16c1d9 100644
--- a/profiles/internal/ipc/client_test.go
+++ b/profiles/internal/ipc/client_test.go
@@ -18,11 +18,11 @@
 	"v.io/v23/verror"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	_ "v.io/x/ref/profiles"
 	inaming "v.io/x/ref/profiles/internal/naming"
diff --git a/profiles/internal/ipc/full_test.go b/profiles/internal/ipc/full_test.go
index bb39bdb..2063629 100644
--- a/profiles/internal/ipc/full_test.go
+++ b/profiles/internal/ipc/full_test.go
@@ -31,13 +31,13 @@
 
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/lib/netstate"
-	"v.io/x/ref/lib/publisher"
 	"v.io/x/ref/lib/stats"
 	"v.io/x/ref/lib/testutil"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	imanager "v.io/x/ref/profiles/internal/ipc/stream/manager"
 	"v.io/x/ref/profiles/internal/ipc/stream/vc"
+	"v.io/x/ref/profiles/internal/lib/publisher"
 	inaming "v.io/x/ref/profiles/internal/naming"
 	tnaming "v.io/x/ref/profiles/internal/testing/mocks/naming"
 	ivtrace "v.io/x/ref/profiles/internal/vtrace"
diff --git a/profiles/internal/ipc/protocols/tcp/init.go b/profiles/internal/ipc/protocols/tcp/init.go
index 92fb5b9..70348f3 100644
--- a/profiles/internal/ipc/protocols/tcp/init.go
+++ b/profiles/internal/ipc/protocols/tcp/init.go
@@ -4,7 +4,7 @@
 	"net"
 	"time"
 
-	"v.io/x/ref/lib/tcputil"
+	"v.io/x/ref/profiles/internal/lib/tcputil"
 
 	"v.io/v23/ipc"
 	"v.io/x/lib/vlog"
diff --git a/profiles/internal/ipc/protocols/ws/init.go b/profiles/internal/ipc/protocols/ws/init.go
index fc01478..5b72412 100644
--- a/profiles/internal/ipc/protocols/ws/init.go
+++ b/profiles/internal/ipc/protocols/ws/init.go
@@ -3,7 +3,7 @@
 import (
 	"v.io/v23/ipc"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 func init() {
diff --git a/profiles/internal/ipc/protocols/wsh/init.go b/profiles/internal/ipc/protocols/wsh/init.go
index b7eb9b5..dcbc57f 100644
--- a/profiles/internal/ipc/protocols/wsh/init.go
+++ b/profiles/internal/ipc/protocols/wsh/init.go
@@ -5,7 +5,7 @@
 import (
 	"v.io/v23/ipc"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 func init() {
diff --git a/profiles/internal/ipc/protocols/wsh_nacl/init.go b/profiles/internal/ipc/protocols/wsh_nacl/init.go
index 82cfd48..1ebe44f 100644
--- a/profiles/internal/ipc/protocols/wsh_nacl/init.go
+++ b/profiles/internal/ipc/protocols/wsh_nacl/init.go
@@ -5,7 +5,7 @@
 import (
 	"v.io/v23/ipc"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 func init() {
diff --git a/profiles/internal/ipc/proxy_test.go b/profiles/internal/ipc/proxy_test.go
index 26e243d..93d4792 100644
--- a/profiles/internal/ipc/proxy_test.go
+++ b/profiles/internal/ipc/proxy_test.go
@@ -20,16 +20,16 @@
 	"v.io/v23/verror"
 	"v.io/v23/vtrace"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/lib/modules"
-	"v.io/x/ref/lib/publisher"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	_ "v.io/x/ref/profiles"
 	iipc "v.io/x/ref/profiles/internal/ipc"
 	imanager "v.io/x/ref/profiles/internal/ipc/stream/manager"
 	"v.io/x/ref/profiles/internal/ipc/stream/proxy"
 	"v.io/x/ref/profiles/internal/ipc/stream/vc"
+	"v.io/x/ref/profiles/internal/lib/publisher"
 	inaming "v.io/x/ref/profiles/internal/naming"
 	tnaming "v.io/x/ref/profiles/internal/testing/mocks/naming"
 	ivtrace "v.io/x/ref/profiles/internal/vtrace"
diff --git a/profiles/internal/ipc/resolve_test.go b/profiles/internal/ipc/resolve_test.go
index 9c3dd8a..91a1331 100644
--- a/profiles/internal/ipc/resolve_test.go
+++ b/profiles/internal/ipc/resolve_test.go
@@ -8,10 +8,10 @@
 	"v.io/v23"
 	"v.io/v23/naming"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	iipc "v.io/x/ref/profiles/internal/ipc"
 	inaming "v.io/x/ref/profiles/internal/naming"
 )
diff --git a/profiles/internal/ipc/server.go b/profiles/internal/ipc/server.go
index 7dddf07..3359261 100644
--- a/profiles/internal/ipc/server.go
+++ b/profiles/internal/ipc/server.go
@@ -26,9 +26,9 @@
 	"v.io/x/ref/profiles/internal/ipc/stream"
 
 	"v.io/x/ref/lib/netstate"
-	"v.io/x/ref/lib/publisher"
 	"v.io/x/ref/lib/stats"
 	"v.io/x/ref/profiles/internal/ipc/stream/vc"
+	"v.io/x/ref/profiles/internal/lib/publisher"
 	inaming "v.io/x/ref/profiles/internal/naming"
 	ivtrace "v.io/x/ref/profiles/internal/vtrace"
 
diff --git a/profiles/internal/ipc/stream/benchmark/throughput_ws.go b/profiles/internal/ipc/stream/benchmark/throughput_ws.go
index 551a0fb..961a93e 100644
--- a/profiles/internal/ipc/stream/benchmark/throughput_ws.go
+++ b/profiles/internal/ipc/stream/benchmark/throughput_ws.go
@@ -5,7 +5,7 @@
 	"net"
 	"testing"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 // benchmarkWS sets up nConns WS connections and measures throughput.
diff --git a/profiles/internal/ipc/stream/benchmark/throughput_wsh.go b/profiles/internal/ipc/stream/benchmark/throughput_wsh.go
index a7fd748..f5881a5 100644
--- a/profiles/internal/ipc/stream/benchmark/throughput_wsh.go
+++ b/profiles/internal/ipc/stream/benchmark/throughput_wsh.go
@@ -5,7 +5,7 @@
 	"net"
 	"testing"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 // benchmarkWS sets up nConns WS connections and measures throughput.
diff --git a/profiles/internal/ipc/stream/manager/listener.go b/profiles/internal/ipc/stream/manager/listener.go
index f1a3f60..9800e5d 100644
--- a/profiles/internal/ipc/stream/manager/listener.go
+++ b/profiles/internal/ipc/stream/manager/listener.go
@@ -7,9 +7,9 @@
 	"strings"
 	"sync"
 
-	"v.io/x/ref/lib/upcqueue"
 	"v.io/x/ref/profiles/internal/ipc/stream/proxy"
 	"v.io/x/ref/profiles/internal/ipc/stream/vif"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 	inaming "v.io/x/ref/profiles/internal/naming"
 
 	"v.io/v23/naming"
diff --git a/profiles/internal/ipc/stream/manager/manager_test.go b/profiles/internal/ipc/stream/manager/manager_test.go
index 222387f..62bf6dc 100644
--- a/profiles/internal/ipc/stream/manager/manager_test.go
+++ b/profiles/internal/ipc/stream/manager/manager_test.go
@@ -18,9 +18,9 @@
 	"v.io/x/lib/vlog"
 	"v.io/x/ref/profiles/internal/ipc/stream"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
diff --git a/profiles/internal/ipc/stream/proxy/proxy.go b/profiles/internal/ipc/stream/proxy/proxy.go
index aed07ca..50d23a3 100644
--- a/profiles/internal/ipc/stream/proxy/proxy.go
+++ b/profiles/internal/ipc/stream/proxy/proxy.go
@@ -16,8 +16,6 @@
 	"v.io/v23/vom"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/publisher"
-	"v.io/x/ref/lib/upcqueue"
 	"v.io/x/ref/profiles/internal/ipc/stream/crypto"
 	"v.io/x/ref/profiles/internal/ipc/stream/id"
 	"v.io/x/ref/profiles/internal/ipc/stream/message"
@@ -27,6 +25,8 @@
 	"v.io/x/ref/profiles/internal/lib/bqueue"
 	"v.io/x/ref/profiles/internal/lib/bqueue/drrqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	"v.io/x/ref/profiles/internal/lib/publisher"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 
 	"v.io/x/ref/lib/stats"
 )
diff --git a/profiles/internal/ipc/stream/vc/listener.go b/profiles/internal/ipc/stream/vc/listener.go
index 42946b5..df18355 100644
--- a/profiles/internal/ipc/stream/vc/listener.go
+++ b/profiles/internal/ipc/stream/vc/listener.go
@@ -3,8 +3,8 @@
 import (
 	"errors"
 
-	"v.io/x/ref/lib/upcqueue"
 	"v.io/x/ref/profiles/internal/ipc/stream"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 )
 
 var errListenerClosed = errors.New("Listener has been closed")
diff --git a/profiles/internal/ipc/stream/vc/reader.go b/profiles/internal/ipc/stream/vc/reader.go
index b24cd5a..051d222 100644
--- a/profiles/internal/ipc/stream/vc/reader.go
+++ b/profiles/internal/ipc/stream/vc/reader.go
@@ -6,9 +6,9 @@
 	"sync"
 	"sync/atomic"
 
-	vsync "v.io/x/ref/lib/sync"
-	"v.io/x/ref/lib/upcqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 )
 
 // readHandler is the interface used by the reader to notify other components
diff --git a/profiles/internal/ipc/stream/vc/vc.go b/profiles/internal/ipc/stream/vc/vc.go
index 0860870..6a4d3c5 100644
--- a/profiles/internal/ipc/stream/vc/vc.go
+++ b/profiles/internal/ipc/stream/vc/vc.go
@@ -13,11 +13,11 @@
 	"sync"
 	"time"
 
-	vsync "v.io/x/ref/lib/sync"
 	"v.io/x/ref/profiles/internal/ipc/stream/crypto"
 	"v.io/x/ref/profiles/internal/ipc/stream/id"
 	"v.io/x/ref/profiles/internal/lib/bqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
 
 	"v.io/v23/context"
 	"v.io/v23/ipc/version"
diff --git a/profiles/internal/ipc/stream/vc/writer.go b/profiles/internal/ipc/stream/vc/writer.go
index d2a59e3..a065f7c 100644
--- a/profiles/internal/ipc/stream/vc/writer.go
+++ b/profiles/internal/ipc/stream/vc/writer.go
@@ -7,9 +7,9 @@
 	"sync"
 	"sync/atomic"
 
-	vsync "v.io/x/ref/lib/sync"
 	"v.io/x/ref/profiles/internal/lib/bqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
 )
 
 var errWriterClosed = errors.New("attempt to call Write on Flow that has been Closed")
diff --git a/profiles/internal/ipc/stream/vc/writer_test.go b/profiles/internal/ipc/stream/vc/writer_test.go
index 345fcd4..50e4029 100644
--- a/profiles/internal/ipc/stream/vc/writer_test.go
+++ b/profiles/internal/ipc/stream/vc/writer_test.go
@@ -7,10 +7,10 @@
 	"reflect"
 	"testing"
 
-	"v.io/x/ref/lib/sync"
 	"v.io/x/ref/profiles/internal/lib/bqueue"
 	"v.io/x/ref/profiles/internal/lib/bqueue/drrqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	"v.io/x/ref/profiles/internal/lib/sync"
 )
 
 // TestWrite is a very basic, easy to follow, but not very thorough test of the
diff --git a/profiles/internal/ipc/stream/vif/vif.go b/profiles/internal/ipc/stream/vif/vif.go
index 19d051c..596864b 100644
--- a/profiles/internal/ipc/stream/vif/vif.go
+++ b/profiles/internal/ipc/stream/vif/vif.go
@@ -21,8 +21,6 @@
 	"v.io/v23/verror"
 	"v.io/v23/vtrace"
 	"v.io/x/lib/vlog"
-	vsync "v.io/x/ref/lib/sync"
-	"v.io/x/ref/lib/upcqueue"
 	"v.io/x/ref/profiles/internal/ipc/stream"
 	"v.io/x/ref/profiles/internal/ipc/stream/crypto"
 	"v.io/x/ref/profiles/internal/ipc/stream/id"
@@ -33,6 +31,8 @@
 	"v.io/x/ref/profiles/internal/lib/bqueue/drrqueue"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
 	"v.io/x/ref/profiles/internal/lib/pcqueue"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 )
 
 const pkgPath = "v.io/x/ref/profiles/internal/ipc/stream/vif"
diff --git a/lib/appcycle/appcycle.go b/profiles/internal/lib/appcycle/appcycle.go
similarity index 100%
rename from lib/appcycle/appcycle.go
rename to profiles/internal/lib/appcycle/appcycle.go
diff --git a/profiles/internal/lib/bqueue/drrqueue/drrqueue.go b/profiles/internal/lib/bqueue/drrqueue/drrqueue.go
index cf3b82f..8902a0d 100644
--- a/profiles/internal/lib/bqueue/drrqueue/drrqueue.go
+++ b/profiles/internal/lib/bqueue/drrqueue/drrqueue.go
@@ -23,10 +23,10 @@
 	"io"
 	"sync"
 
-	"v.io/x/ref/lib/deque"
-	vsync "v.io/x/ref/lib/sync"
 	"v.io/x/ref/profiles/internal/lib/bqueue"
+	"v.io/x/ref/profiles/internal/lib/deque"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
 )
 
 // T defines the type of round-robin buffer queues.  The queue has multiple
diff --git a/lib/deque/deque.go b/profiles/internal/lib/deque/deque.go
similarity index 100%
rename from lib/deque/deque.go
rename to profiles/internal/lib/deque/deque.go
diff --git a/lib/deque/deque_test.go b/profiles/internal/lib/deque/deque_test.go
similarity index 100%
rename from lib/deque/deque_test.go
rename to profiles/internal/lib/deque/deque_test.go
diff --git a/lib/deque/v23_internal_test.go b/profiles/internal/lib/deque/v23_internal_test.go
similarity index 100%
rename from lib/deque/v23_internal_test.go
rename to profiles/internal/lib/deque/v23_internal_test.go
diff --git a/lib/publisher/publisher.go b/profiles/internal/lib/publisher/publisher.go
similarity index 100%
rename from lib/publisher/publisher.go
rename to profiles/internal/lib/publisher/publisher.go
diff --git a/lib/publisher/publisher_test.go b/profiles/internal/lib/publisher/publisher_test.go
similarity index 98%
rename from lib/publisher/publisher_test.go
rename to profiles/internal/lib/publisher/publisher_test.go
index 5dc1fbc..58ed04b 100644
--- a/lib/publisher/publisher_test.go
+++ b/profiles/internal/lib/publisher/publisher_test.go
@@ -12,7 +12,7 @@
 	"v.io/v23/vtrace"
 
 	"v.io/x/ref/lib/flags"
-	"v.io/x/ref/lib/publisher"
+	"v.io/x/ref/profiles/internal/lib/publisher"
 	tnaming "v.io/x/ref/profiles/internal/testing/mocks/naming"
 	ivtrace "v.io/x/ref/profiles/internal/vtrace"
 )
diff --git a/lib/publisher/v23_internal_test.go b/profiles/internal/lib/publisher/v23_internal_test.go
similarity index 100%
rename from lib/publisher/v23_internal_test.go
rename to profiles/internal/lib/publisher/v23_internal_test.go
diff --git a/lib/sync/doc.go b/profiles/internal/lib/sync/doc.go
similarity index 100%
rename from lib/sync/doc.go
rename to profiles/internal/lib/sync/doc.go
diff --git a/lib/sync/lock.go b/profiles/internal/lib/sync/lock.go
similarity index 100%
rename from lib/sync/lock.go
rename to profiles/internal/lib/sync/lock.go
diff --git a/lib/sync/semaphore.go b/profiles/internal/lib/sync/semaphore.go
similarity index 100%
rename from lib/sync/semaphore.go
rename to profiles/internal/lib/sync/semaphore.go
diff --git a/lib/sync/semaphore_test.go b/profiles/internal/lib/sync/semaphore_test.go
similarity index 100%
rename from lib/sync/semaphore_test.go
rename to profiles/internal/lib/sync/semaphore_test.go
diff --git a/lib/sync/v23_internal_test.go b/profiles/internal/lib/sync/v23_internal_test.go
similarity index 100%
rename from lib/sync/v23_internal_test.go
rename to profiles/internal/lib/sync/v23_internal_test.go
diff --git a/lib/sync/wait_group.go b/profiles/internal/lib/sync/wait_group.go
similarity index 100%
rename from lib/sync/wait_group.go
rename to profiles/internal/lib/sync/wait_group.go
diff --git a/lib/sync/wait_group_test.go b/profiles/internal/lib/sync/wait_group_test.go
similarity index 100%
rename from lib/sync/wait_group_test.go
rename to profiles/internal/lib/sync/wait_group_test.go
diff --git a/lib/tcputil/tcputil.go b/profiles/internal/lib/tcputil/tcputil.go
similarity index 100%
rename from lib/tcputil/tcputil.go
rename to profiles/internal/lib/tcputil/tcputil.go
diff --git a/lib/upcqueue/upcqueue.go b/profiles/internal/lib/upcqueue/upcqueue.go
similarity index 97%
rename from lib/upcqueue/upcqueue.go
rename to profiles/internal/lib/upcqueue/upcqueue.go
index 8d8ba94..e7562d9 100644
--- a/lib/upcqueue/upcqueue.go
+++ b/profiles/internal/lib/upcqueue/upcqueue.go
@@ -15,8 +15,8 @@
 	"errors"
 	"sync"
 
-	"v.io/x/ref/lib/deque"
-	vsync "v.io/x/ref/lib/sync"
+	"v.io/x/ref/profiles/internal/lib/deque"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
 )
 
 var (
diff --git a/lib/upcqueue/upcqueue_test.go b/profiles/internal/lib/upcqueue/upcqueue_test.go
similarity index 98%
rename from lib/upcqueue/upcqueue_test.go
rename to profiles/internal/lib/upcqueue/upcqueue_test.go
index c164730..42b5bca 100644
--- a/lib/upcqueue/upcqueue_test.go
+++ b/profiles/internal/lib/upcqueue/upcqueue_test.go
@@ -7,7 +7,7 @@
 	"time"
 
 	"v.io/x/lib/vlog"
-	vsync "v.io/x/ref/lib/sync"
+	vsync "v.io/x/ref/profiles/internal/lib/sync"
 )
 
 //go:generate v23 test generate
diff --git a/lib/upcqueue/v23_internal_test.go b/profiles/internal/lib/upcqueue/v23_internal_test.go
similarity index 100%
rename from lib/upcqueue/v23_internal_test.go
rename to profiles/internal/lib/upcqueue/v23_internal_test.go
diff --git a/lib/websocket/conn.go b/profiles/internal/lib/websocket/conn.go
similarity index 100%
rename from lib/websocket/conn.go
rename to profiles/internal/lib/websocket/conn.go
diff --git a/lib/websocket/conn_nacl.go b/profiles/internal/lib/websocket/conn_nacl.go
similarity index 100%
rename from lib/websocket/conn_nacl.go
rename to profiles/internal/lib/websocket/conn_nacl.go
diff --git a/lib/websocket/conn_test.go b/profiles/internal/lib/websocket/conn_test.go
similarity index 100%
rename from lib/websocket/conn_test.go
rename to profiles/internal/lib/websocket/conn_test.go
diff --git a/lib/websocket/dialer.go b/profiles/internal/lib/websocket/dialer.go
similarity index 94%
rename from lib/websocket/dialer.go
rename to profiles/internal/lib/websocket/dialer.go
index 02ea6c6..d8169c0 100644
--- a/lib/websocket/dialer.go
+++ b/profiles/internal/lib/websocket/dialer.go
@@ -10,7 +10,7 @@
 
 	"github.com/gorilla/websocket"
 
-	"v.io/x/ref/lib/tcputil"
+	"v.io/x/ref/profiles/internal/lib/tcputil"
 )
 
 func Dial(protocol, address string, timeout time.Duration) (net.Conn, error) {
diff --git a/lib/websocket/hybrid.go b/profiles/internal/lib/websocket/hybrid.go
similarity index 96%
rename from lib/websocket/hybrid.go
rename to profiles/internal/lib/websocket/hybrid.go
index 9928e30..74748e1 100644
--- a/lib/websocket/hybrid.go
+++ b/profiles/internal/lib/websocket/hybrid.go
@@ -4,7 +4,7 @@
 	"net"
 	"time"
 
-	"v.io/x/ref/lib/tcputil"
+	"v.io/x/ref/profiles/internal/lib/tcputil"
 )
 
 // TODO(jhahn): Figure out a way for this mapping to be shared.
diff --git a/lib/websocket/listener.go b/profiles/internal/lib/websocket/listener.go
similarity index 98%
rename from lib/websocket/listener.go
rename to profiles/internal/lib/websocket/listener.go
index 83ab442..81e2ef3 100644
--- a/lib/websocket/listener.go
+++ b/profiles/internal/lib/websocket/listener.go
@@ -14,8 +14,8 @@
 
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/tcputil"
-	"v.io/x/ref/lib/upcqueue"
+	"v.io/x/ref/profiles/internal/lib/tcputil"
+	"v.io/x/ref/profiles/internal/lib/upcqueue"
 )
 
 var errListenerIsClosed = errors.New("Listener has been Closed")
diff --git a/lib/websocket/listener_nacl.go b/profiles/internal/lib/websocket/listener_nacl.go
similarity index 100%
rename from lib/websocket/listener_nacl.go
rename to profiles/internal/lib/websocket/listener_nacl.go
diff --git a/lib/websocket/util_test.go b/profiles/internal/lib/websocket/util_test.go
similarity index 100%
rename from lib/websocket/util_test.go
rename to profiles/internal/lib/websocket/util_test.go
diff --git a/lib/websocket/v23_internal_test.go b/profiles/internal/lib/websocket/v23_internal_test.go
similarity index 100%
rename from lib/websocket/v23_internal_test.go
rename to profiles/internal/lib/websocket/v23_internal_test.go
diff --git a/lib/websocket/ws_test.go b/profiles/internal/lib/websocket/ws_test.go
similarity index 97%
rename from lib/websocket/ws_test.go
rename to profiles/internal/lib/websocket/ws_test.go
index 97d59da..f592d10 100644
--- a/lib/websocket/ws_test.go
+++ b/profiles/internal/lib/websocket/ws_test.go
@@ -7,7 +7,7 @@
 
 	"v.io/v23/ipc"
 
-	"v.io/x/ref/lib/websocket"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 )
 
 func packetTester(t *testing.T, dialer ipc.DialerFunc, listener ipc.ListenerFunc, txProtocol, rxProtocol string) {
diff --git a/profiles/internal/rt/mgmt_test.go b/profiles/internal/rt/mgmt_test.go
index 168dbaf..fe6a77f 100644
--- a/profiles/internal/rt/mgmt_test.go
+++ b/profiles/internal/rt/mgmt_test.go
@@ -16,9 +16,9 @@
 	"v.io/v23/naming"
 	"v.io/v23/services/mgmt/appcycle"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	_ "v.io/x/ref/profiles"
 	vflag "v.io/x/ref/security/flag"
 	"v.io/x/ref/services/mgmt/device"
diff --git a/profiles/internal/rt/rt_test.go b/profiles/internal/rt/rt_test.go
index d564369..89217db 100644
--- a/profiles/internal/rt/rt_test.go
+++ b/profiles/internal/rt/rt_test.go
@@ -13,10 +13,10 @@
 	"v.io/v23/security"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	vsecurity "v.io/x/ref/security"
 )
 
diff --git a/profiles/internal/rt/shutdown_test.go b/profiles/internal/rt/shutdown_test.go
index 120b0f5..0bf368b 100644
--- a/profiles/internal/rt/shutdown_test.go
+++ b/profiles/internal/rt/shutdown_test.go
@@ -10,9 +10,9 @@
 
 	"v.io/v23"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/signals"
+	"v.io/x/ref/lib/testutil/expect"
 )
 
 //go:generate v23 test generate
diff --git a/profiles/internal/rt/signal_test.go b/profiles/internal/rt/signal_test.go
index 291977d..5ebceba 100644
--- a/profiles/internal/rt/signal_test.go
+++ b/profiles/internal/rt/signal_test.go
@@ -9,9 +9,9 @@
 	"testing"
 	"time"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	_ "v.io/x/ref/profiles"
 )
 
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index e982740..adbe94b 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -19,15 +19,15 @@
 	"v.io/v23/ipc"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/appcycle"
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/lib/netconfig"
 	"v.io/x/ref/lib/netstate"
-	"v.io/x/ref/lib/websocket"
 	"v.io/x/ref/profiles/internal"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/wsh"
+	"v.io/x/ref/profiles/internal/lib/appcycle"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	grt "v.io/x/ref/profiles/internal/rt"
 	"v.io/x/ref/services/mgmt/debug"
 
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index d330b28..f837434 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -8,14 +8,14 @@
 	"v.io/v23/ipc"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/appcycle"
 	"v.io/x/ref/lib/flags"
 	"v.io/x/ref/lib/netstate"
-	"v.io/x/ref/lib/websocket"
 	"v.io/x/ref/profiles/internal"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/tcp"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/ws"
 	_ "v.io/x/ref/profiles/internal/ipc/protocols/wsh"
+	"v.io/x/ref/profiles/internal/lib/appcycle"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	grt "v.io/x/ref/profiles/internal/rt"
 	"v.io/x/ref/services/mgmt/debug"
 
diff --git a/security/agent/agent_test.go b/security/agent/agent_test.go
index 327b7a3..b47c080 100644
--- a/security/agent/agent_test.go
+++ b/security/agent/agent_test.go
@@ -10,9 +10,9 @@
 	"testing"
 	"time"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	_ "v.io/x/ref/profiles"
 	"v.io/x/ref/security/agent"
diff --git a/services/mgmt/device/impl/impl_test.go b/services/mgmt/device/impl/impl_test.go
index b25a398..403337f 100644
--- a/services/mgmt/device/impl/impl_test.go
+++ b/services/mgmt/device/impl/impl_test.go
@@ -43,11 +43,11 @@
 	"v.io/v23/verror"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/signals"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 	binaryimpl "v.io/x/ref/services/mgmt/binary/impl"
 	"v.io/x/ref/services/mgmt/device/config"
diff --git a/services/mgmt/lib/testutil/modules.go b/services/mgmt/lib/testutil/modules.go
index a7ee0eb..b03dcb9 100644
--- a/services/mgmt/lib/testutil/modules.go
+++ b/services/mgmt/lib/testutil/modules.go
@@ -13,11 +13,11 @@
 	"v.io/v23/security"
 	"v.io/x/lib/vlog"
 
-	"v.io/x/ref/lib/expect"
 	"v.io/x/ref/lib/flags/consts"
 	"v.io/x/ref/lib/modules"
 	"v.io/x/ref/lib/modules/core"
 	"v.io/x/ref/lib/testutil"
+	"v.io/x/ref/lib/testutil/expect"
 	tsecurity "v.io/x/ref/lib/testutil/security"
 )
 
diff --git a/services/mgmt/suidhelper/impl/flag/flag.go b/services/mgmt/suidhelper/impl/flag/flag.go
index d677e73..bf892ce 100644
--- a/services/mgmt/suidhelper/impl/flag/flag.go
+++ b/services/mgmt/suidhelper/impl/flag/flag.go
@@ -1,7 +1,7 @@
 // Package flag provides flag definitions for the suidhelper package.
 //
 // It does NOT depend on any packages outside the Go standard library.
-// This allows v.io/x/ref/lib/testutil to depend on this
+// This allows v.io/x/ref/lib/test to depend on this
 // package, thereby ensuring that the suidhelper flags are defined
 // before the flag.Parse call in testutil.init is made.
 //
diff --git a/services/wsprd/browspr/main/main_nacl.go b/services/wsprd/browspr/main/main_nacl.go
index b75b5f4..439c2f8 100644
--- a/services/wsprd/browspr/main/main_nacl.go
+++ b/services/wsprd/browspr/main/main_nacl.go
@@ -12,8 +12,8 @@
 	"v.io/v23/security"
 	"v.io/v23/vdl"
 	"v.io/x/lib/vlog"
-	"v.io/x/ref/lib/websocket"
 	_ "v.io/x/ref/profiles/chrome"
+	"v.io/x/ref/profiles/internal/lib/websocket"
 	vsecurity "v.io/x/ref/security"
 	"v.io/x/ref/services/wsprd/browspr"
 	"v.io/x/ref/services/wsprd/channel/channel_nacl"
diff --git a/services/wsprd/lib/signature_manager_test.go b/services/wsprd/lib/signature_manager_test.go
index 3c0ed5f..27e624e 100644
--- a/services/wsprd/lib/signature_manager_test.go
+++ b/services/wsprd/lib/signature_manager_test.go
@@ -9,7 +9,6 @@
 	"v.io/v23/context"
 	"v.io/v23/vdl"
 	"v.io/v23/vdlroot/signature"
-	"v.io/x/ref/lib/mocks"
 	"v.io/x/ref/lib/testutil"
 	"v.io/x/ref/profiles/fake"
 )
@@ -18,7 +17,7 @@
 	name = "/veyron/name"
 )
 
-func initContext(t *testing.T) (*context.T, mocks.ClientWithTimesCalled, v23.Shutdown) {
+func initContext(t *testing.T) (*context.T, clientWithTimesCalled, v23.Shutdown) {
 	ctx, shutdown := testutil.InitForTest()
 	initialSig := []signature.Interface{
 		{
@@ -30,7 +29,7 @@
 			},
 		},
 	}
-	client := mocks.NewSimpleClient(
+	client := newSimpleClient(
 		map[string][]interface{}{
 			"__Signature": []interface{}{initialSig},
 		},
diff --git a/lib/mocks/simple_client.go b/services/wsprd/lib/simple_client.go
similarity index 96%
rename from lib/mocks/simple_client.go
rename to services/wsprd/lib/simple_client.go
index d93d52e..931fba1 100644
--- a/lib/mocks/simple_client.go
+++ b/services/wsprd/lib/simple_client.go
@@ -1,4 +1,4 @@
-package mocks
+package lib
 
 import (
 	"errors"
@@ -13,7 +13,7 @@
 	"v.io/x/lib/vlog"
 )
 
-type ClientWithTimesCalled interface {
+type clientWithTimesCalled interface {
 	ipc.Client
 	TimesCalled(method string) int
 }
@@ -21,7 +21,7 @@
 // NewSimpleClient creates a new mocked ipc client where the given map of method name
 // to outputs is used for evaluating the method calls.
 // It also adds some testing features such as counters for number of times a method is called
-func NewSimpleClient(methodsResults map[string][]interface{}) ClientWithTimesCalled {
+func newSimpleClient(methodsResults map[string][]interface{}) clientWithTimesCalled {
 	return &simpleMockClient{
 		results:     methodsResults,
 		timesCalled: make(map[string]int),
diff --git a/lib/mocks/simple_client_test.go b/services/wsprd/lib/simple_client_test.go
similarity index 92%
rename from lib/mocks/simple_client_test.go
rename to services/wsprd/lib/simple_client_test.go
index 90d8633..c2fa717 100644
--- a/lib/mocks/simple_client_test.go
+++ b/services/wsprd/lib/simple_client_test.go
@@ -1,4 +1,4 @@
-package mocks
+package lib
 
 import (
 	"testing"
@@ -17,7 +17,7 @@
 	method2ExpectedResult := []interface{}{"one"}
 	method3ExpectedResult := []interface{}{nil}
 
-	client := NewSimpleClient(map[string][]interface{}{
+	client := newSimpleClient(map[string][]interface{}{
 		"method1": method1ExpectedResult,
 		"method2": method2ExpectedResult,
 		"method3": method3ExpectedResult,
@@ -74,7 +74,7 @@
 }
 
 func TestStructResult(t *testing.T) {
-	client := NewSimpleClient(map[string][]interface{}{
+	client := newSimpleClient(map[string][]interface{}{
 		"foo": []interface{}{
 			sampleStruct{Name: "bar"},
 		},
@@ -90,7 +90,7 @@
 }
 
 func TestErrorCall(t *testing.T) {
-	client := NewSimpleClient(map[string][]interface{}{
+	client := newSimpleClient(map[string][]interface{}{
 		"bar": []interface{}{},
 	})
 	ctx := testContext()
@@ -102,7 +102,7 @@
 }
 
 func TestNumberOfCalls(t *testing.T) {
-	client := NewSimpleClient(map[string][]interface{}{
+	client := newSimpleClient(map[string][]interface{}{
 		"method1": []interface{}{},
 		"method2": []interface{}{},
 	})