Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LCOW functional tests and benchmarks for uVMs and containers. #1351

Merged
merged 4 commits into from Aug 23, 2022

Conversation

helsaawy
Copy link
Contributor

@helsaawy helsaawy commented Apr 13, 2022

This PR is broken into two commits: the first has the core changes, and the second is vendoring and switching other tests to use the new testing utilities.

Added functional tests and benchmarks for LCOW uVMs and containers and updated other LCOW tests to work.
Non-working tests are skipped.

Split out test utilities from test/functional to an internal package, and updated it o use containerd instead of docker.
Updated cri-containerd and runhcs tests to use moved code in test\internal.

Updated k8s.io/cri-api to v0.22 to useWindowsPodSandboxConfig struct

Relies on PRs:

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

helsaawy added a commit to helsaawy/hcsshim that referenced this pull request Apr 19, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

The tests themselves are broken out here:
microsoft#1352
microsoft#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
helsaawy added a commit to helsaawy/hcsshim that referenced this pull request Apr 19, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

The tests themselves are broken out here:
microsoft#1352
microsoft#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
helsaawy added a commit to helsaawy/hcsshim that referenced this pull request Apr 19, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

Added doc.go files to guest packages to prevent linter/compiler errors
under windows.

The tests themselves are broken out here:
microsoft#1352
microsoft#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
helsaawy added a commit to helsaawy/hcsshim that referenced this pull request Apr 25, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

Added doc.go files to guest packages to prevent linter/compiler errors
under windows.

The tests themselves are broken out here:
microsoft#1352
microsoft#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
helsaawy added a commit to helsaawy/hcsshim that referenced this pull request May 3, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

Added doc.go files to guest packages to prevent linter/compiler errors
under windows.

The tests themselves are broken out here:
microsoft#1352
microsoft#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
helsaawy added a commit that referenced this pull request May 3, 2022
Exposed data and functionality for testing GCS:
* `internal\guest\runtime\hcsv2.Container.InitProcess()`
* `internal\guest\runtime\hcsv2.GetOrAddNetworkNamespace()`
* `internal\guest\runtime\hcsv2.RemoveNetworkNamespace()`
* `internal\guest\runtime\hcsv2.Host.SecurityPolicyEnforcer()`
* `internal\guest\runtime\hcsv2.Host.Transport()`

Fixed bug where `host.RemoveContainer` did not remove the network
namespace for standalone and pod containers.

Updated go-winio version to include bugfixes for closing hvsockets,
specifically to close a socket for writing (needed by internal\cmd
to signal that the stdin stream has finished).

Added doc.go files to guest packages to prevent linter/compiler errors
under windows.

The tests themselves are broken out here:
#1352
#1351

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy mentioned this pull request May 4, 2022
3 tasks
@helsaawy helsaawy force-pushed the he/lcowfunc branch 3 times, most recently from b358cef to 5bc615a Compare May 4, 2022 21:21
@helsaawy helsaawy marked this pull request as ready for review May 4, 2022 21:21
@helsaawy helsaawy requested a review from a team as a code owner May 4, 2022 21:21
@helsaawy helsaawy force-pushed the he/lcowfunc branch 3 times, most recently from 40400b1 to f621e11 Compare May 5, 2022 00:26
@helsaawy helsaawy force-pushed the he/lcowfunc branch 2 times, most recently from bf77250 to 531d89d Compare May 10, 2022 15:52
@helsaawy
Copy link
Contributor Author

rebased and fixed test-vendor CI issue

@helsaawy helsaawy force-pushed the he/lcowfunc branch 3 times, most recently from 24b1ac0 to 7381576 Compare May 11, 2022 15:14
@helsaawy helsaawy force-pushed the he/lcowfunc branch 3 times, most recently from 2f110e9 to 6831726 Compare June 14, 2022 16:56
@helsaawy
Copy link
Contributor Author

rebased to fix merge conflicts, removed branch .\test\vendor

@helsaawy
Copy link
Contributor Author

rebased, updated tests

Copy link
Contributor

@ambarve ambarve left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this Hamza! This is a ton of great work!

test/internal/timeout/timeout.go Outdated Show resolved Hide resolved
test/functional/lcow_container_test.go Show resolved Hide resolved
test/cri-containerd/runpodsandbox_test.go Show resolved Hide resolved
test/functional/lcow_container_bench_test.go Show resolved Hide resolved
scripts/Test-Functional.ps1 Show resolved Hide resolved
test/internal/constants/constants.go Outdated Show resolved Hide resolved
test/internal/containerd/containerd.go Outdated Show resolved Hide resolved
test/internal/layers/layerfolders.go Show resolved Hide resolved
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
opts := defaultLCOWOptions(b, b.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

Does each iteration count as a "subtest" for the benchmark? If no, wouldn't b.Name() not be unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So its a little weird, but this is based on how the docs tell you to do it, a benchmark run of BenchmarkLCOW_UVM_Create will include as many iterations (b.N) the target -benchtime criteria is met (either a set number, eg. -benchtime 1000x or duration, eg. -benchtime 3s)
All those iterations are accumulated under one timer, which can then be repeated via -count

So if we with
'-test.count=2' '-test.run=^#' '-test.benchmem' '-test.bench=.' '-test.benchtime=2x'
The output would look something like (I dont know why go append the 12 here):

BenchmarkLCOW_UVM_Create-12                      	       2	  84758700 ns/op	   47800 B/op	     363 allocs/op
BenchmarkLCOW_UVM_Create-12                      	       2	  81733600 ns/op	   42584 B/op	     348 allocs/op
BenchmarkLCOW_UVM_Create-12                       	       2	  83118950 ns/op	   43904 B/op	     385 allocs/op

benchstat then aggregates benchmarks with the same name, so we want the non-uniqueness:

LCOW_UVM_Create-12               83.2ms ± 2%

Copy link
Contributor

Choose a reason for hiding this comment

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

how does creating a new LCOW work if the names are the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the cleanup() call on line 33 deletes the uvm, so the name can be reused

vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))

b.StartTimer()
if err := vm.Start(ctx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why aren't we using the same 'uvm.Start' function here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it has a bunch of test-related overhead I dont want to profile

f := func() {
if err := vm.Close(); err != nil {
t.Logf("could not close vm %q: %v", vm.ID(), err)
}
}
if err != nil {
t.Helper()
t.Fatalf("could not start UVM: %v", err)
}
return f

Copy link
Contributor

Choose a reason for hiding this comment

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

That's pretty negligible code though, I wouldn't expect any of it to cause a marked slowdown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats true, I can change it back if you think it distracts unnecessarily?

}

func Wait(_ context.Context, t testing.TB, c *cmd.Cmd) int {
// todo, wait on context.Done
Copy link
Contributor

Choose a reason for hiding this comment

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

why did we not do this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didnt need it yet, and I didnt want to include a whole new batch of tests to see if canceling contexts work as expected
It was more of a note for when we expand the functional tests

// been waited on (usually via a WaitForProcess request) and had its exit code read
// (hcsv2/process.go:(*containerProcess).Wait).
//
// So ... to test container kill and wait times, we need to first start and wait on the init process
Copy link
Contributor

Choose a reason for hiding this comment

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

So this just tests the time for the kill and wait command to return when the container init is already exited? I would think the thing we really care about is how long it takes to stop a simple program that's running.

Comment on lines +97 to +101
id := strings.ReplaceAll(t.Name(), "/", "")
scratch, _ := layers.ScratchSpace(ctx, t, vm, "", "", cache)
spec := oci.CreateLinuxSpec(ctx, t, id,
oci.DefaultLinuxSpecOpts(id,
ctrdoci.WithProcessArgs(tt.args...),
oci.WithWindowsLayerFolders(append(ls, scratch)))...)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably all be refactored out as well

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

Rebase and then lgtm

Split out utility functions from `test/functional` into an internal package,
separate from functional tests.
Updated code to use containerd instead of docker.

Added new functional tests and benchmarks for LCOW uVM containers, and
updated other LCOW tests as well. Not all (LCOW) functional tests were
updated, and most others are now explicitly skipped.

Updated `k8s.io/cri-api` to v0.22 to include `WindowsPodSandboxConfig`
struct

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Added deprecated warning to `layers.LayerFolders`, which relies on
docker.
Added doc comment to functional tests to clarify overlap with other
tests.
Removed unnecessary parameter in `WaitForError`.
Updated snapshotter logic

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy merged commit feaf10a into microsoft:main Aug 23, 2022
@helsaawy helsaawy deleted the he/lcowfunc branch August 23, 2022 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants