-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shahriyar Jalayeri <[email protected]>
- Loading branch information
Showing
7 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
DEBUG ?= "debug" | ||
|
||
# HOSTARCH is the host architecture | ||
# ARCH is the target architecture | ||
# we need to keep track of them separately | ||
HOSTARCH ?= $(shell uname -m) | ||
HOSTOS ?= $(shell uname -s | tr A-Z a-z) | ||
|
||
# canonicalized names for host architecture | ||
override HOSTARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(HOSTARCH))) | ||
|
||
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling | ||
# and for my OS | ||
ARCH ?= $(HOSTARCH) | ||
OS ?= $(HOSTOS) | ||
|
||
# canonicalized names for target architecture | ||
override ARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(ARCH))) | ||
|
||
WORKDIR ?= $(CURDIR)/../../dist | ||
TESTDIR := tests/$(shell basename $(CURDIR)) | ||
BINDIR := $(WORKDIR)/bin | ||
DATADIR := $(WORKDIR)/$(TESTDIR)/ | ||
BIN := eden | ||
LOCALBIN := $(BINDIR)/$(BIN)-$(OS)-$(ARCH) | ||
TESTNAME := eden.vcom | ||
TESTBIN := $(TESTNAME).test | ||
TESTSCN := $(TESTNAME).tests.txt | ||
LOCALTESTBIN := $(TESTBIN)-$(OS)-$(ARCH) | ||
LINKDIR := ../../tests/vcom | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
clean: | ||
rm -rf $(LOCALTESTBIN) $(BINDIR)/$(TESTBIN) $(WORKDIR)/$(TESTSCN) $(CURDIR)/$(TESTBIN) $(BINDIR)/$(TESTBIN) | ||
|
||
$(BINDIR): | ||
mkdir -p $@ | ||
$(DATADIR): | ||
mkdir -p $@ | ||
|
||
test: | ||
$(LOCALBIN) test $(CURDIR) -v $(DEBUG) | ||
|
||
build: setup | ||
|
||
testbin: $(TESTBIN) | ||
$(LOCALTESTBIN): $(BINDIR) *.go | ||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go test -c -ldflags "-s -w" -o $@ *.go | ||
|
||
$(TESTBIN): $(LOCALTESTBIN) | ||
ln -sf $(LOCALTESTBIN) $(CURDIR)/$(TESTBIN) | ||
|
||
setup: testbin $(BINDIR) $(DATADIR) | ||
cp -a $(LOCALTESTBIN) $(CURDIR)/$(TESTBIN) $(BINDIR) | ||
cp -a *.yml $(TESTSCN) $(DATADIR) | ||
|
||
debug: | ||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go test -c -gcflags "all=-N -l" -o $@ *.go | ||
dlv dap --listen=:12345 --headless=true --api-version=2 exec ./debug -- -test.v | ||
|
||
.PHONY: test build setup clean all testbin debug | ||
|
||
help: | ||
@echo "EDEN is the harness for testing EVE and ADAM" | ||
@echo | ||
@echo "This Makefile automates commons tasks of EDEN testing" | ||
@echo | ||
@echo "Commonly used maintenance and development targets:" | ||
@echo " build build test-binary (OS and ARCH options supported, for ex. OS=linux ARCH=arm64)" | ||
@echo " setup setup of test environment" | ||
@echo " test run tests" | ||
@echo " clean cleanup of test harness" | ||
@echo | ||
@echo "You need install requirements for EVE (look at https://github.com/lf-edge/eve#install-dependencies)." | ||
@echo "You need access to docker socket and installed qemu packages." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
eden: | ||
# test binary | ||
test-bin: "eden.vcom.test" | ||
|
||
# test scenario | ||
test-scenario: "eden.vcom.tests.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eden.vcom.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
import socket | ||
|
||
CID = socket.VMADDR_CID_HOST | ||
PORT = 2000 | ||
s = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM) | ||
s.connect((CID, PORT)) | ||
s.sendall(b"{\"channel\":2,\"request\":1}") | ||
response = s.recv(1024) | ||
print(response.decode('utf-8')) | ||
s.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package vcom | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
tk "github.com/lf-edge/eden/pkg/evetestkit" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var eveNode *tk.EveNode | ||
|
||
const ( | ||
sshPort = "8027" | ||
appLink = "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" | ||
projectName = "vcomlink" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
log.Println("VCOM Test started") | ||
defer log.Println("VCOM Test finished") | ||
|
||
node, err := tk.InitilizeTest(projectName, tk.WithControllerVerbosity("debug")) | ||
if err != nil { | ||
log.Fatalf("Failed to initialize test: %v", err) | ||
} | ||
|
||
eveNode = node | ||
res := m.Run() | ||
os.Exit(res) | ||
} | ||
|
||
func TestVcomLink(t *testing.T) { | ||
log.Println("TestVcomLink started") | ||
defer log.Println("TestVcomLink finished") | ||
|
||
if !eveNode.EveIsTpmEnabled() { | ||
t.Skip("TPM is not enabled, skipping test") | ||
} | ||
|
||
t.Log("Checking if vcomlink is running on EVE") | ||
stat, err := eveNode.EveRunCommand("eve exec pillar ss -l --vsock") | ||
if err != nil { | ||
t.Fatalf("Failed to check if vcomlink is running: %v", err) | ||
} | ||
// vcomlink listens on port 2000 and host cid is 2. | ||
// this is hacky way to check it is running, but it works ¯\_(ツ)_/¯ | ||
if !strings.Contains(string(stat), "2:2000") { | ||
t.Fatalf("vcomlink is not running, ss output :\n%s", stat) | ||
} | ||
|
||
appName := tk.GetRandomAppName(projectName) | ||
pubPorts := []string{sshPort + ":22"} | ||
pc := tk.GetDefaultVMConfig(appName, tk.AppDefaultCloudConfig, pubPorts) | ||
err = eveNode.EveDeployApp(appLink, pc, tk.WithSSH(tk.AppDefaultSSHUser, tk.AppDefaultSSHPass, sshPort)) | ||
if err != nil { | ||
t.Fatalf("Failed to deploy app: %v", err) | ||
} | ||
defer func() { | ||
err = eveNode.AppStopAndRemove(appName) | ||
if err != nil { | ||
log.Errorf("Failed to stop and remove app: %v", err) | ||
} | ||
}() | ||
|
||
// wait for the app to show up in the list | ||
time.Sleep(10 * time.Second) | ||
|
||
// wait 5 minutes for the app to start | ||
t.Logf("Waiting for app %s to start...", appName) | ||
err = eveNode.AppWaitForRunningState(appName, 60*5) | ||
if err != nil { | ||
t.Fatalf("Failed to wait for app to start: %v", err) | ||
} | ||
|
||
t.Logf("Waiting for ssh to be ready...") | ||
err = eveNode.AppWaitForSSH(appName, 60*5) | ||
if err != nil { | ||
t.Fatalf("Failed to wait for ssh: %v", err) | ||
} | ||
t.Logf("SSH connection established") | ||
|
||
t.Log("Installing socat on the vm") | ||
_, err = eveNode.AppSSHExec(appName, "sudo apt-get -y install socat") | ||
if err != nil { | ||
t.Fatalf("Failed install socat on the vm: %v", err) | ||
} | ||
|
||
err = eveNode.AppSCPCopy(appName, "scripts/testvsock.py", "testvsock.py") | ||
if err != nil { | ||
t.Fatalf("Failed to copy testvsock.py to the vm: %v", err) | ||
} | ||
|
||
out, err := eveNode.AppSSHExec(appName, "python3 testvsock.py") | ||
if err != nil { | ||
t.Fatalf("Failed to communicate with host via vsock: %v", err) | ||
} | ||
|
||
// XXX : fix this by importing vcom from eve and unmrashal the output | ||
// to TpmResponseEk | ||
if strings.Contains(string(out), "error") { | ||
t.Fatalf("Failed to communicate with host via vsock: %v", out) | ||
} | ||
t.Log("Successfully communicated from VM to vcomlink (host) via vsock") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test eden.vcom.test |