Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Generate an instrumented vDVS plugin binary #1633

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions client_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SCRIPTS := ../misc/scripts
PLUGNAME := docker-volume-vsphere
SHARED_PLUGNAME := vsphere-shared
GOPATH_PLUGNAME := $(PLUGNAME)/client_plugin
INSTRUMENTED_PLUGIN_BIN := vdvs-instrumented
GOPATH_ORG :=vmware
MAINTAINERS := cna-storage@vmware.com
REPO_URL := https://github.com/$(GOPATH_ORG)/$(PLUGNAME)
Expand Down Expand Up @@ -72,7 +73,11 @@ PLUGIN_BIN = $(BIN)/$(PLUGNAME)
SHARED_PLUGIN_BIN = $(BIN)/$(SHARED_PLUGNAME)

# all binaries for VMs - plugin and tests
VM_BINS = $(PLUGIN_BIN) $(BIN)/$(VMDKOPS_TEST_MODULE).test $(BIN)/$(PLUGNAME).test
# PLUGIN_BIN - vDVS plugin binary
# $(BIN)/$(VMDKOPS_TEST_MODULE).test - Running mock esx test
# $(BIN)/$(PLUGNAME).test - Running sanity test
# $(BIN)/$(INSTRUMENTED_PLUGIN_BIN) - Instrumented vDVS plugin binary for capturing code coverage
VM_BINS = $(PLUGIN_BIN) $(BIN)/$(VMDKOPS_TEST_MODULE).test $(BIN)/$(PLUGNAME).test $(BIN)/$(INSTRUMENTED_PLUGIN_BIN)
SHARED_VM_BINS = $(SHARED_PLUGIN_BIN)

VIBFILE := vmware-esx-vmdkops-$(PKG_VERSION).vib
Expand All @@ -84,7 +89,7 @@ PLUGIN := github.com/$(GOPATH_ORG)/$(GOPATH_PLUGNAME)
# test location, picking up E2E tests
E2E_Tests := github.com/$(GOPATH_ORG)/$(PLUGNAME)/tests/e2e

GO := GO15VENDOREXPERIMENT=1 go
GO := go
FPM := fpm

# make sure we rebuild of vmkdops or Dockerfile change (since we develop them together)
Expand All @@ -105,6 +110,8 @@ SHARED_PLUGIN_SRC = shared_plugin/main.go drivers/shared/shared_driver.go driver

TEST_SRC = ../tests/utils/inputparams/testparams.go

VMDK_PLUGIN_TEST_SRC = ./vmdk_plugin/*_test.go

# Canned recipe
define log_target
@echo
Expand Down Expand Up @@ -152,13 +159,17 @@ $(PLUGIN_BIN): $(COMMON_SRC) $(VMDK_PLUGIN_SRC) $(VMDKOPS_MODULE_SRC)
$(BIN)/$(VMDKOPS_TEST_MODULE).test: $(VMDKOPS_MODULE_SRC) $(TEST_SRC) $(VMDKOPS_MODULE)/*_test.go
$(GO) test -c -o $@ $(PLUGIN)/$(VMDKOPS_MODULE) -cover

$(BIN)/$(PLUGNAME).test: $(COMMON_SRC) $(VMDK_PLUGIN_SRC) $(TEST_SRC) ./vmdk_plugin/*_test.go
$(GO) test -c -o $@ $(PLUGIN)/vmdk_plugin -cover
$(BIN)/$(PLUGNAME).test: $(COMMON_SRC) $(VMDK_PLUGIN_SRC) $(TEST_SRC) $(VMDK_PLUGIN_TEST_SRC)
$(GO) test -c -o $@ $(PLUGIN)/vmdk_plugin -cover -tags sanity

$(SHARED_PLUGIN_BIN): $(COMMON_SRC) $(SHARED_PLUGIN_SRC)
@-mkdir -p $(BIN) && chmod a+w $(BIN)
$(GO) build --ldflags '-extldflags "-static"' -o $(SHARED_PLUGIN_BIN) $(PLUGIN)/shared_plugin

# vDVS binary to capture code coverage
$(BIN)/$(INSTRUMENTED_PLUGIN_BIN): $(COMMON_SRC) $(VMDKOPS_MODULE_SRC) $(VMDK_PLUGIN_TEST_SRC)
$(GO) test -coverprofile=/tmp/cover.out -coverpkg=$(PLUGIN)/... -c -o $@ $(PLUGIN)/vmdk_plugin -tags testmain -covermode count

.PHONY: clean
clean:
$(BUILD) clean-as-root
Expand Down
52 changes: 52 additions & 0 deletions client_plugin/utils/codecov/covdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
//
// 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.

// Util to flush out coverage profile from an instrumented binary.

package coverage

import (
"fmt"
"os"
"testing"
)

type dummyTestDeps func(pat, str string) (bool, error)

// Capture util dumps the collected data locally.
func Capture() {
fmt.Println("START: Collecting coverage profiling data")

// saving the state
oldstdout := os.Stdout
oldstderr := os.Stderr

os.Stdout, _ = os.Open(os.DevNull)
os.Stderr, _ = os.Open(os.DevNull)

tests := []testing.InternalTest{}
benchmarks := []testing.InternalBenchmark{}
examples := []testing.InternalExample{}
var f dummyTestDeps

dummyM := testing.MainStart(f, tests, benchmarks, examples)
dummyM.Run()

// back to normal state
// restore stdout/err
os.Stdout = oldstdout
os.Stderr = oldstderr

fmt.Println("END: Collecting coverage data...")
}
2 changes: 2 additions & 0 deletions client_plugin/utils/plugin_server/plugin_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"github.com/vmware/docker-volume-vsphere/client_plugin/utils/codecov"
)

// PluginServer responds to HTTP requests from Docker.
Expand All @@ -40,6 +41,7 @@ func StartServer(driverName string, driver *volume.Driver) {
go func() {
sig := <-sigChannel
log.WithFields(log.Fields{"signal": sig}).Warning("Received signal ")
coverage.Capture()
server.Destroy()
os.Exit(0)
}()
Expand Down
28 changes: 28 additions & 0 deletions client_plugin/vmdk_plugin/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2017 VMware, Inc. All Rights Reserved.
//
// 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.\

// A sample test to run vDVS in a test mode to collect coverage data from
// an instrumented binary.

// +build testmain

package main

import (
"testing"
)

func TestRunMain(t *testing.T) {
main()
}
2 changes: 2 additions & 0 deletions client_plugin/vmdk_plugin/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// VMDK Docker driver sanity tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some comments about what is the sanity test is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test was left out with the tags .. so adding a tag for the test to control during the build time.

//

// +build sanity

package main

import (
Expand Down