Skip to content

Commit 66b2dbd

Browse files
committed
containerized-testing-tool: Add README and modify the docker file to accept ENABLED_TESTS environment variable
Signed-off-by: Ankita Pareek <ankitapareek@microsoft.com>
1 parent 8e9a8e7 commit 66b2dbd

File tree

4 files changed

+160
-8
lines changed

4 files changed

+160
-8
lines changed

tests/kata-containerized-test-tool/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ RUN tdnf update -y && tdnf install -y \
1212

1313
RUN mkdir -p /results
1414

15+
# Default environment variables
16+
ENV ENABLED_TESTS=""
17+
1518
ENTRYPOINT ["/app/kata-containerized-test-tool"]
1619
CMD ["--output", "/results"]
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Kata Containerized Testing Tool
2+
3+
A containerized testing framework for measuring system metrics in both Host VM and User VM (UVM) environments of Kata Confidential Containers.
4+
5+
## Overview
6+
This tool provides a flexible framework for running tests in both standard container environments (Host VM) and Kata Confidential Containers (UVM) environments. It supports configurable test execution with expected value validation.
7+
8+
## Building the Testing Tool
9+
10+
### Prerequisites
11+
12+
- Go 1.21 or higher
13+
- Docker
14+
- Access to Azure Container Registry (ACR)
15+
16+
### Build Steps
17+
18+
1. Clone the repository
19+
20+
```
21+
git clone https://github.com/kata-containers/kata-containers.git
22+
cd kata-containers/testing-tool
23+
```
24+
25+
2. Build the binary and the container
26+
27+
- Using Makefile
28+
```
29+
# Build both binary and container
30+
make all
31+
32+
# Or build individually
33+
make build # Just the binary
34+
make docker # Just the container
35+
```
36+
- Alternatively, build manually using
37+
38+
```
39+
# Build binary
40+
go build -o kata-containerized-test-tool cmd/katatest/main.go
41+
42+
# Build container
43+
docker build -t kata-test-container .
44+
```
45+
46+
## Uploading to Azure Container Registry
47+
1. Login to your Azure Container Registry
48+
49+
```
50+
docker login yourregistry.azurecr.io
51+
```
52+
53+
2. Tag the container image
54+
55+
```
56+
docker tag kata-test-container yourregistry.azurecr.io/kata-test-container:v1
57+
```
58+
59+
3. Push the image to ACR
60+
61+
```
62+
docker push yourregistry.azurecr.io/kata-test-container:v1
63+
```
64+
## Running Tests
65+
66+
### Pull Container Images
67+
First, pull the container image to your test environment:
68+
```
69+
# Pull using containerd
70+
sudo ctr images pull --user '<username>:<password>' yourregistry.azurecr.io/kata-test-container:v1
71+
72+
# Or pull using crictl
73+
sudo crictl pull yourregistry.azurecr.io/kata-test-container:v1
74+
```
75+
### Run manually
76+
77+
#### Host VM
78+
```
79+
sudo ctr run \
80+
--runtime io.containerd.runc.v2 \
81+
-t --rm \
82+
--env ENABLED_TESTS=cpu,memory \
83+
--env TEST_CPU_EXPECTED_VCPU_COUNT=4 \
84+
--env TEST_MEMORY_EXPECTED_MEMORY_MB=8192 \
85+
yourregistry.azurecr.io/kata-test-container:v1 host-test
86+
```
87+
88+
#### UVM
89+
```
90+
sudo ctr run \
91+
--cni \
92+
--runtime io.containerd.run.kata-cc.v2 \
93+
--runtime-config-path /opt/confidential-containers/share/defaults/kata-containers/configuration-clh-snp.toml \
94+
--snapshotter tardev \
95+
-t --rm \
96+
--env ENABLED_TESTS=cpu,memory \
97+
--env TEST_CPU_EXPECTED_VCPU_COUNT=2 \
98+
--env TEST_MEMORY_EXPECTED_MEMORY_MB=4096 \
99+
yourregistry.azurecr.io/kata-test-container:v1 uvm-test
100+
```
101+
102+
### Run Using Pod Manifests
103+
104+
#### Test Configuration
105+
- Selecting Tests
106+
Use the ENABLED_TESTS environment variable with a comma-separated list of test names:
107+
`ENABLED_TESTS=cpu,memory`
108+
- Setting Expected Values:
109+
Use environment variables in the format `TEST_<TESTNAME>_<PARAMETER>`
110+
```
111+
TEST_CPU_EXPECTED_VCPU_COUNT=4
112+
TEST_MEMORY_EXPECTED_MEMORY_MB=8192
113+
```
114+
You can create pod manifests with the test configurations to run the tests.
115+
116+
For e.g. the following pod manifest runs the test for CPU and memory with relevant expected values.
117+
118+
```
119+
apiVersion: v1
120+
kind: Pod
121+
metadata:
122+
name: kata-uvm-test
123+
annotations:
124+
io.kubernetes.cri.untrusted-workload: "true"
125+
spec:
126+
runtimeClassName: kata-cc
127+
containers:
128+
- name: uvm-test
129+
image: yourregistry.azurecr.io/kata-test-container:v1
130+
imagePullPolicy: IfNotPresent
131+
env:
132+
- name: ENABLED_TESTS
133+
value: "cpu,memory"
134+
- name: TEST_CPU_EXPECTED_VCPU_COUNT
135+
value: "2"
136+
- name: TEST_MEMORY_EXPECTED_MEMORY_MB
137+
value: "4096"
138+
```
139+
140+
## Adding a New Test
141+
142+
To add a new test to the framework, follow these general steps:
143+
144+
1. Create a test file: Add a new test file in the internal/tests directory structure. The file should implement the Test interface with Name() and Run() methods.
145+
2. Register your test: Update the main.go file to register your new test with the framework.
146+
3. Document parameters: Add documentation for your test's expected parameters in the README.md file.
147+
4. Build and deploy: Rebuild the container after adding your test, then push the updated container to your container registry.
148+
149+
Your new test will then be available and can be enabled through the configuration by including it in the ENABLED_TESTS list.
150+

tests/kata-containerized-test-tool/internal/core/framework.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ type Framework struct {
1515
outputDir string
1616
}
1717

18-
// NewFramework creates a new testing framework
18+
// Create a new testing framework
1919
func NewFramework(outputDir string) *Framework {
2020
return &Framework{
2121
tests: make(map[string]Test),
2222
outputDir: outputDir,
2323
}
2424
}
2525

26-
// RegisterTest adds a test to the framework
26+
// Add a test to the framework
2727
func (f *Framework) RegisterTest(test Test) {
2828
f.tests[test.Name()] = test
2929
}
3030

31-
// GetAvailableTests returns all registered tests
31+
// Return all registered tests
3232
func (f *Framework) GetAvailableTests() map[string]Test {
3333
return f.tests
3434
}
3535

36-
// ValidateConfiguration checks if the provided test configurations are valid
36+
// Check if the provided test configurations are valid
3737
func (f *Framework) ValidateConfiguration(testsToRun []Test,
3838
getExpectedValuesFunc func(string) map[string]interface{}) []string {
3939

@@ -84,12 +84,12 @@ func (f *Framework) ValidateConfiguration(testsToRun []Test,
8484
return warnings
8585
}
8686

87-
// RunTest executes a single test with the given expected values
87+
// Execute a single test with the given expected values
8888
func (f *Framework) RunTest(ctx context.Context, test Test, expectedValues map[string]interface{}) TestResult {
8989
return test.Run(ctx, expectedValues)
9090
}
9191

92-
// RunTests executes the given tests with their expected values
92+
// Execute the given tests with their expected values
9393
func (f *Framework) RunTests(ctx context.Context, testsToRun []Test,
9494
getExpectedValuesFunc func(string) map[string]interface{}) ([]TestResult, error) {
9595

@@ -112,7 +112,7 @@ func (f *Framework) RunTests(ctx context.Context, testsToRun []Test,
112112
return results, nil
113113
}
114114

115-
// SaveResults writes test results to a JSON file
115+
// Write test results to a JSON file
116116
func (f *Framework) saveResults(results []TestResult) error {
117117
filename := fmt.Sprintf("%s/results_%s.json",
118118
f.outputDir,

tests/kata-containerized-test-tool/internal/core/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// internal/core/types.go
21
package core
32

43
import (

0 commit comments

Comments
 (0)