-
Notifications
You must be signed in to change notification settings - Fork 62
Enabled windows ProcessorAffinity support #629
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b52b578
Init Commit
e38b7c3
Update tests
0d2e6b1
Merge branch 'main' into cpuAffinity
RakeshwarK 3204568
Merge branch 'microsoft:main' into cpuAffinity
RakeshwarK cc25f56
Update tests
55cd743
Merge branch 'main' into cpuAffinity
RakeshwarK f54ea20
commit changes
d0d07e8
Merge branch 'cpuAffinity' of https://github.com/RakeshwarK/VirtualCl…
d95fe15
Merge branch 'microsoft:main' into cpuAffinity
RakeshwarK 0d259aa
Merge branch 'microsoft:main' into cpuAffinity
RakeshwarK ff91e6f
Windows Changes
1042592
Merge branch 'cpuAffinity' of https://github.com/RakeshwarK/VirtualCl…
7e027fe
Added Doccu
8a33af1
Format Doc
09e1508
Update profile
6d41a33
Merge branch 'main' into cpuAffinity
RakeshwarK b5a7820
commit changes
f7fa194
Merge branch 'main' into cpuAffinity
RakeshwarK 5782273
Merge branch 'main' into cpuAffinity
RakeshwarK 1c057d2
Merge branch 'main' into cpuAffinity
RakeshwarK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
...alClient/VirtualClient.Actions.FunctionalTests/ExampleWorkloadWithAffinityProfileTests.cs
This file contains hidden or 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,178 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace VirtualClient.Actions | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using NUnit.Framework; | ||
| using VirtualClient.Common; | ||
| using VirtualClient.Contracts; | ||
|
|
||
| [TestFixture] | ||
| [Category("Functional")] | ||
| public class ExampleWorkloadWithAffinityProfileTests | ||
| { | ||
| private DependencyFixture mockFixture; | ||
|
|
||
| [OneTimeSetUp] | ||
| public void SetupFixture() | ||
| { | ||
| this.mockFixture = new DependencyFixture(); | ||
| ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Unix, Architecture.X64)] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Unix, Architecture.Arm64)] | ||
| public void ExampleWorkloadProfileParametersAreInlinedCorrectly_Linux(string profile, PlatformID platform, Architecture architecture) | ||
| { | ||
| this.mockFixture.Setup(platform, architecture); | ||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) | ||
| { | ||
| WorkloadAssert.ParameterReferencesInlined(executor.Profile); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [Platform(Exclude = "Unix,Linux,MacOsX")] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Win32NT, Architecture.X64)] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Win32NT, Architecture.Arm64)] | ||
| public void ExampleWorkloadProfileParametersAreInlinedCorrectly_Windows(string profile, PlatformID platform, Architecture architecture) | ||
| { | ||
| this.mockFixture.Setup(platform, architecture); | ||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) | ||
| { | ||
| WorkloadAssert.ParameterReferencesInlined(executor.Profile); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Unix)] | ||
| public async Task ExampleWorkloadProfileInstallsTheExpectedDependenciesOnLinuxPlatform(string profile, PlatformID platform) | ||
| { | ||
| this.mockFixture.Setup(platform); | ||
|
|
||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true)) | ||
| { | ||
| await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false); | ||
|
|
||
| // Workload dependency package should be installed | ||
| WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "exampleworkload"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [Platform(Exclude = "Unix,Linux,MacOsX")] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Win32NT)] | ||
| public async Task ExampleWorkloadProfileInstallsTheExpectedDependenciesOnWindowsPlatform(string profile, PlatformID platform) | ||
| { | ||
| this.mockFixture.Setup(platform); | ||
|
|
||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true)) | ||
| { | ||
| await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false); | ||
|
|
||
| // Workload dependency package should be installed | ||
| WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "exampleworkload"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Unix)] | ||
| public async Task ExampleWorkloadProfileExecutesTheExpectedWorkloadWithAffinityOnLinux(string profile, PlatformID platform) | ||
| { | ||
| this.mockFixture.Setup(platform); | ||
| this.mockFixture.SetupPackage("exampleworkload", expectedFiles: "linux-x64/ExampleWorkload"); | ||
|
|
||
| this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) => | ||
| { | ||
| IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir); | ||
| if (command.Contains("bash") && arguments.Contains("numactl")) | ||
| { | ||
| // Verify numactl wrapper is used for CPU affinity on Linux | ||
| process.StandardOutput.Append("{ \"metric1\": 100, \"metric2\": 200 }"); | ||
| } | ||
|
|
||
| return process; | ||
| }; | ||
|
|
||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) | ||
| { | ||
| await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false); | ||
|
|
||
| // Verify numactl was used for CPU affinity | ||
| WorkloadAssert.CommandsExecuted(this.mockFixture, "\"numactl -C"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [Platform(Exclude = "Unix,Linux,MacOsX")] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json", PlatformID.Win32NT)] | ||
| public async Task ExampleWorkloadProfileExecutesTheExpectedWorkloadWithAffinityOnWindows(string profile, PlatformID platform) | ||
| { | ||
| this.mockFixture.Setup(platform); | ||
| this.mockFixture.SetupPackage("exampleworkload", expectedFiles: "win-x64/ExampleWorkload.exe"); | ||
|
|
||
| this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) => | ||
| { | ||
| InMemoryProcess process = this.mockFixture.CreateProcess(command, arguments, workingDir); | ||
| if (command.Contains("ExampleWorkload")) | ||
| { | ||
| // Set HasExited to false initially, true after "wait" | ||
| bool hasExited = false; | ||
| process.OnHasExited = () => hasExited; | ||
| process.OnStart = () => | ||
| { | ||
| hasExited = false; | ||
| return true; | ||
| }; | ||
|
|
||
| process.OnApplyAffinity = (mask) => | ||
| { | ||
| // Verify affinity mask is set while process is running | ||
| Assert.IsFalse(hasExited, "Affinity should be applied while process is running"); | ||
| Assert.Greater(mask.ToInt64(), 0); | ||
| }; | ||
|
|
||
| // Simulate process completion when WaitForExitAsync is called | ||
| process.WaitForExitAsync(CancellationToken.None); | ||
| process.StandardOutput.Append("{ \"metric1\": 100, \"metric2\": 200 }"); | ||
| hasExited = true; | ||
RakeshwarK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return process; | ||
| }; | ||
|
|
||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) | ||
| { | ||
| await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false); | ||
|
|
||
| // Verify the process was executed | ||
| WorkloadAssert.CommandsExecuted(this.mockFixture, "ExampleWorkload"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("PERF-CPU-EXAMPLE-AFFINITY.json")] | ||
| public void ExampleWorkloadProfileActionsWillNotBeExecutedIfTheWorkloadPackageDoesNotExist(string profile) | ||
| { | ||
| this.mockFixture.Setup(PlatformID.Unix); | ||
|
|
||
| // Ensure the workload package does not exist | ||
| this.mockFixture.PackageManager.Clear(); | ||
|
|
||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) | ||
| { | ||
| executor.ExecuteDependencies = false; | ||
|
|
||
| DependencyException error = Assert.ThrowsAsync<DependencyException>(() => executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None)); | ||
| Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, error.Reason); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.