Skip to content

Commit

Permalink
Track paths and provide a rename hook.
Browse files Browse the repository at this point in the history
This change also adds extensive testing to the p9 package via mocks. The sanity
checks and type checks are moved from the gofer into the core package, where
they can be more easily validated.

PiperOrigin-RevId: 218296768
Change-Id: I4fc3c326e7bf1e0e140a454cbacbcc6fd617ab55
  • Loading branch information
amscanne authored and shentubot committed Oct 23, 2018
1 parent c2c0f9c commit 75cd70e
Show file tree
Hide file tree
Showing 128 changed files with 3,834 additions and 2,147 deletions.
20 changes: 13 additions & 7 deletions WORKSPACE
Expand Up @@ -15,7 +15,7 @@ go_register_toolchains(go_version="1.11.1")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()

# Add dependencies on external repositories.
# External repositories, in sorted order.
go_repository(
name = "com_github_cenkalti_backoff",
importpath = "github.com/cenkalti/backoff",
Expand All @@ -28,6 +28,12 @@ go_repository(
commit = "886344bea0798d02ff3fae16a922be5f6b26cee0"
)

go_repository(
name = "com_github_golang_mock",
importpath = "github.com/golang/mock",
commit = "600781dde9cca80734169b9e969d9054ccc57937",
)

go_repository(
name = "com_github_google_go-cmp",
importpath = "github.com/google/go-cmp",
Expand Down Expand Up @@ -58,6 +64,12 @@ go_repository(
commit = "b2d941ef6a780da2d9982c1fb28d77ad97f54fc7",
)

go_repository(
name = "com_github_syndtr_gocapability",
importpath = "github.com/syndtr/gocapability",
commit = "d98352740cb2c55f81556b63d4a1ec64c5a319c2",
)

go_repository(
name = "com_github_vishvananda_netlink",
importpath = "github.com/vishvananda/netlink",
Expand All @@ -81,9 +93,3 @@ go_repository(
importpath = "golang.org/x/sys",
commit = "0dd5e194bbf5eb84a39666eb4c98a4d007e4203a",
)

go_repository(
name = "com_github_syndtr_gocapability",
importpath = "github.com/syndtr/gocapability",
commit = "d98352740cb2c55f81556b63d4a1ec64c5a319c2",
)
4 changes: 2 additions & 2 deletions pkg/amutex/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "amutex",
srcs = ["amutex.go"],
Expand Down
4 changes: 2 additions & 2 deletions pkg/atomicbitops/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "atomicbitops",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/binary/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "binary",
srcs = ["binary.go"],
Expand Down
3 changes: 2 additions & 1 deletion pkg/bits/BUILD
@@ -1,6 +1,7 @@
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
load("//tools/go_generics:defs.bzl", "go_template", "go_template_instance")

go_library(
Expand Down
4 changes: 2 additions & 2 deletions pkg/compressio/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "compressio",
srcs = ["compressio.go"],
Expand Down
4 changes: 2 additions & 2 deletions pkg/control/client/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "client",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/control/server/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "server",
srcs = ["server.go"],
Expand Down
4 changes: 2 additions & 2 deletions pkg/dhcp/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "dhcp",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/eventchannel/BUILD
@@ -1,8 +1,8 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "eventchannel",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/fd/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "fd",
srcs = ["fd.go"],
Expand Down
4 changes: 2 additions & 2 deletions pkg/gate/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "gate",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/ilist/BUILD
@@ -1,8 +1,8 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_generics:defs.bzl", "go_template", "go_template_instance")
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "ilist",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/linewriter/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "linewriter",
srcs = ["linewriter.go"],
Expand Down
4 changes: 2 additions & 2 deletions pkg/log/BUILD
@@ -1,7 +1,7 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "log",
srcs = [
Expand Down
4 changes: 2 additions & 2 deletions pkg/metric/BUILD
@@ -1,8 +1,8 @@
package(licenses = ["notice"]) # Apache 2.0

load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

package(licenses = ["notice"]) # Apache 2.0

go_library(
name = "metric",
srcs = ["metric.go"],
Expand Down
2 changes: 2 additions & 0 deletions pkg/p9/BUILD
Expand Up @@ -15,6 +15,7 @@ go_library(
"handlers.go",
"messages.go",
"p9.go",
"path_tree.go",
"pool.go",
"server.go",
"transport.go",
Expand All @@ -32,6 +33,7 @@ go_test(
name = "p9_test",
size = "small",
srcs = [
"buffer_test.go",
"client_test.go",
"messages_test.go",
"p9_test.go",
Expand Down
31 changes: 31 additions & 0 deletions pkg/p9/buffer_test.go
@@ -0,0 +1,31 @@
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package p9

import (
"testing"
)

func TestBufferOverrun(t *testing.T) {
buf := &buffer{
// This header indicates that a large string should follow, but
// it is only two bytes. Reading a string should cause an
// overrun.
data: []byte{0x0, 0x16},
}
if s := buf.ReadString(); s != "" {
t.Errorf("overrun read got %s, want empty", s)
}
}
6 changes: 6 additions & 0 deletions pkg/p9/client.go
Expand Up @@ -116,6 +116,7 @@ func NewClient(socket *unet.Socket, messageSize uint32, version string) (*Client
msize: largestFixedSize,
}
}

// Compute a payload size and round to 512 (normal block size)
// if it's larger than a single block.
payloadSize := messageSize - largestFixedSize
Expand Down Expand Up @@ -299,3 +300,8 @@ func (c *Client) sendRecv(t message, r message) error {
func (c *Client) Version() uint32 {
return c.version
}

// Close closes the underlying socket.
func (c *Client) Close() error {
return c.socket.Close()
}
4 changes: 3 additions & 1 deletion pkg/p9/client_file.go
Expand Up @@ -172,6 +172,9 @@ func (c *clientFile) SetAttr(valid SetAttrMask, attr SetAttr) error {
}

// Remove implements File.Remove.
//
// N.B. This method is no longer part of the file interface and should be
// considered deprecated.
func (c *clientFile) Remove() error {
// Avoid double close.
if !atomic.CompareAndSwapUint32(&c.closed, 0, 1) {
Expand All @@ -181,7 +184,6 @@ func (c *clientFile) Remove() error {

// Send the remove message.
if err := c.client.sendRecv(&Tremove{FID: c.fid}, &Rremove{}); err != nil {
log.Warningf("Tremove failed, losing FID %v: %v", c.fid, err)
return err
}

Expand Down

0 comments on commit 75cd70e

Please sign in to comment.