9a4baba19a
* feat: back up persistent rules and resolve rule precedence deterministically
- Configuration export now includes persistent process rules (schema 3.0),
stays compatible with 2.0 bundles, validates before writing, previews
what an import replaces and rolls back on failure.
- Matching rules apply broad-to-specific (name, wildcard path, exact path,
then most recently edited), shared by the engine and the process summary,
which now lists the apply order and flags conflicting values.
- Localized the new strings in all seven languages.
* feat: clearer process and rule editors
- Process details: CPU, memory and I/O priority pickers with an explicit
Apply, undo of the last manual priority change (guarded against reused
PIDs), adaptive side/bottom details panel.
- Manual process control stays available while automation is paused, with
a persistent notice instead of an overlay.
- Saved-rule editor stages all edits (including the core mask) and saves
them together, showing pending changes.
- Localized the new strings in all seven languages.
* fix: one save path for a saved rule's cores
The rules editor's core mask went through a new update path that reported
success without saving when no affinity payload was built, and kept a
legacy mask next to a CPU selection. Merge it with the old single-purpose
method (now unused), keep its checks, and localize the undo message.
* feat: per-process efficiency mode (EcoQoS) for live processes and rules
Closes #66.
- Native: SetProcessInformation/GetProcessInformation with
ProcessPowerThrottling (EXECUTION_SPEED), three states: Windows decides,
On (EcoQoS), Off (never throttle / HighQoS).
- Process tab: context menu entries, a picker with Apply in the details
panel, current state in the summary, undo of the last change, included
when saving current settings as a rule (only if explicitly set).
- Rules: EfficiencyMode + ApplyEfficiencyModeOnStart, applied by the rules
engine, editable in the saved-rule editor, validated on import and part
of conflict detection.
- The summary flags when the global Power Throttling tweak voids it. CPU
priority is left alone, unlike Task Manager's efficiency mode.
- Localized in all seven languages.
* chore: keep CRLF line endings in SelectedProcessSummaryViewModel
* feat: clearer navigation, process page and rules editor
- Navigation pane open with short labels instead of seven bare icons.
- Processes: one toolbar row (search with placeholder, Filters and
Columns menus, sort, refresh); details split into Process, Priority,
CPU cores and Rule cards; pickers start from the process's current
values and stay empty when a value cannot be read; help paragraphs
moved into tooltips; core picker always visible.
- Rules: process rules first, clearer tab names, localized choices in the
saved-rule editor instead of internal enum names.
- Shorter page titles and subtitles in all seven languages; removed the
strings this made unused.
No data format changes.
* feat: settings and tweaks as Windows 11 rows, localized rule list
- Settings: one column of rows (what it is on the left, its switch on the
right), most used sections first, Save as the primary action.
- Tweaks: one tweak per row with its status dot and switch.
- Rule list: 'Applies' and 'Mode' columns use the same localized labels as
the editor and refresh on language change.
- Removed 76 strings no code referenced, from all seven languages.
* fix: issues found testing the beta in a clean Windows 11 VM
- Process counter could show more visible processes than the total
('157 / 151'): the batch total was a snapshot from the first load.
- Narrow windows (or 150% scaling): toolbar buttons move under the search
box instead of squeezing it to a few letters.
- Rules list keeps the 'Applies' column readable when narrow.
- Settings status message gets its own line instead of being cut.
Tested in a Hyper-V Windows 11 VM: clean install, upgrade, uninstall,
light and dark theme, 100% and 150% scaling.
* feat: remember layout choices; Windows 11 toggles in Tweaks
- The navigation pane, window size/position/maximized state, and the
process list filters, sort and columns now survive a restart. They live
in ui-state.json, apart from settings.json, so they never mark the
Settings page as unsaved or travel in exported configurations. A corrupt
file falls back to defaults; tests write to a temp file.
- Fixes the pane re-opening on every start (it was hard-coded open).
- Tweaks use a native-looking Windows 11 switch (40x20 track, sliding
thumb) with On/Off written beside it.
- New test: every on/off setting survives save and reload.
* docs: handoff for the 1.7.7 PR stack and beta test
* fix: P/E cores from the highest EfficiencyClass, AMD CCDs from real L3 groups
The legacy topology treated the lowest EfficiencyClass as the performance
core, swapping P- and E-cores on hybrid Intel CPUs. AMD CCDs were guessed
as 8 cores each, which split 6+6 parts (7900X3D, 9900X3D) into 8+4; they now
come from the L3 groups Windows reports, with the guess kept only as a
fallback. The topology snapshot also keeps each L3 group's size.
* feat: Game Boost, CPU Sets for the game and selected background apps
While a detected game runs, Game Boost sets process default CPU Sets from
the CPU topology: on AMD X3D with one larger L3 the game goes to the V-Cache
CCD, on Intel hybrid CPUs to the P-cores, and selected background apps
(browsers, sync clients, updaters, launchers) to the other cores. On dual-CCD
parts with equal L3 only the background moves, unless Isolation mode also
keeps the game on CCD0. Single-L3 and unreadable topologies are left to
Windows. Above Normal priority for the game is optional; never High.
Each change is written to a journal before it is made and undone when the
game exits, Game Boost is turned off or ThreadPilot closes, and on the next
start after a crash. Only values still exactly as Game Boost set them are
restored, never one a user rule or a manual change has taken over since.
Persistent rules and Game Boost share one apply gate, and a rule always
wins over Game Boost for the setting it covers.
The switch, mode and lists are on the Tweaks page, off by default, and take
effect without a restart.
* fix: Game Boost background entries with a full path never matched
The background list compared full-path entries against an empty path, so
only bare process names worked. Found by a new integration test that runs
the real services on two copies of PING.EXE: CPU Sets and priority are set
and read back through Windows, removed when Game Boost is turned off, and
undone from the journal after a simulated crash. The topology is simulated
from this machine's CPU Set IDs, so the test also runs on CPUs where Game
Boost would not act; it skips itself below 8 cores.
* feat: report Game Boost sessions and restore results in Activity
* test: diagnose EcoQoS read failures on Windows Server
* chore: prepare 1.7.7-beta.2 and keep prereleases out of stable channels
* test: use native full-query access mask in EcoQoS diagnostic
* docs: update beta handoff and prerelease publication policy
* ci: run native EcoQoS tests on a Windows 11-era kernel
Windows Server 2022 build 20348 rejects GetProcessInformation(ProcessPowerThrottling) with ERROR_INVALID_PARAMETER (87), with both limited and full query handles. Windows 11 local tests pass. Use Server 2025 for CI/release tests and smoke testing; keep the real round-trip assertions, remove temporary probes.
* test: lock beta publication and native runner contracts
* chore: separate stable 1.7.7 from experimental Game Boost
Stable retains the validated EcoQoS/rules/UI stack. Preserve the complete local Game Boost implementation at ef2ec24 for the separate 1.7.8-beta.1 prerelease; no experimental Game Boost/topology changes ship in stable. Keep channel-aware publication and Windows 11-era native CI tests.
364 lines
16 KiB
C#
364 lines
16 KiB
C#
namespace ThreadPilot.Core.Tests
|
|
{
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using Moq;
|
|
using ThreadPilot.Models;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
public sealed class SelectedProcessSummaryViewModelTests
|
|
{
|
|
[Fact]
|
|
public async Task UpdateAsync_WithNoSelectedProcess_ClearsSummary()
|
|
{
|
|
var viewModel = new SelectedProcessSummaryViewModel();
|
|
|
|
await viewModel.UpdateAsync(null);
|
|
|
|
Assert.False(viewModel.HasSelection);
|
|
Assert.Equal("No process selected", viewModel.CurrentProcessStatusText);
|
|
Assert.Equal("Memory priority unavailable", viewModel.MemoryPriorityText);
|
|
Assert.Equal("No saved rule", viewModel.RuleStatusText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WithSelectedProcess_PopulatesCheapProcessFields()
|
|
{
|
|
var viewModel = new SelectedProcessSummaryViewModel();
|
|
|
|
await viewModel.UpdateAsync(CreateProcess("Game.exe", 1234, ProcessPriorityClass.High, 0x3, 512 * 1024 * 1024));
|
|
|
|
Assert.True(viewModel.HasSelection);
|
|
Assert.Equal(1234, viewModel.ProcessId);
|
|
Assert.Equal("Game.exe", viewModel.ProcessName);
|
|
Assert.Equal(@"C:\Games\Game.exe", viewModel.ExecutablePath);
|
|
Assert.Equal("Selected process: Game.exe (PID 1234)", viewModel.ProcessTitle);
|
|
Assert.Equal("CPU priority: High", viewModel.CpuPriorityText);
|
|
Assert.Equal("Memory: 512 MB", viewModel.MemoryUsageText);
|
|
Assert.Equal("Affinity: legacy mask 0x3", viewModel.AffinityText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenSelectionChanges_ReplacesSummary()
|
|
{
|
|
var viewModel = new SelectedProcessSummaryViewModel();
|
|
|
|
await viewModel.UpdateAsync(CreateProcess("First.exe", 1, ProcessPriorityClass.Normal, 0x1, 1));
|
|
await viewModel.UpdateAsync(CreateProcess("Second.exe", 2, ProcessPriorityClass.BelowNormal, 0x2, 2));
|
|
|
|
Assert.Equal(2, viewModel.ProcessId);
|
|
Assert.Equal("Second.exe", viewModel.ProcessName);
|
|
Assert.Equal("CPU priority: BelowNormal", viewModel.CpuPriorityText);
|
|
Assert.Equal("Affinity: legacy mask 0x2", viewModel.AffinityText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenMemoryPriorityReadSucceeds_PopulatesMemoryPriority()
|
|
{
|
|
var memoryPriority = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriority
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.BelowNormal);
|
|
var viewModel = new SelectedProcessSummaryViewModel(memoryPriority.Object);
|
|
|
|
await viewModel.UpdateAsync(CreateProcess());
|
|
|
|
Assert.Equal(ProcessMemoryPriority.BelowNormal, viewModel.MemoryPriority);
|
|
Assert.Equal("Memory priority: BelowNormal", viewModel.MemoryPriorityText);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false, "Efficiency mode: On")]
|
|
[InlineData(true, "Efficiency mode: On (no effect: power throttling is disabled in Tweaks)")]
|
|
public async Task UpdateAsync_FlagsEfficiencyModeVoidedByTheGlobalTweak(bool throttlingOff, string expected)
|
|
{
|
|
var service = new Mock<IProcessMemoryPriorityService>();
|
|
service.Setup(s => s.GetEfficiencyModeAsync(It.IsAny<ProcessModel>())).ReturnsAsync(ProcessEfficiencyMode.On);
|
|
var viewModel = new SelectedProcessSummaryViewModel(service.Object, isPowerThrottlingOff: () => throttlingOff);
|
|
|
|
await viewModel.UpdateAsync(CreateProcess());
|
|
|
|
Assert.Equal(ProcessEfficiencyMode.On, viewModel.EfficiencyMode);
|
|
Assert.Equal(expected, viewModel.EfficiencyModeText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenMemoryPriorityUnavailable_ShowsUnavailableWithoutThrowing()
|
|
{
|
|
var memoryPriority = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriority
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ThrowsAsync(new UnauthorizedAccessException("Access denied"));
|
|
var viewModel = new SelectedProcessSummaryViewModel(memoryPriority.Object);
|
|
|
|
await viewModel.UpdateAsync(CreateProcess());
|
|
|
|
Assert.Null(viewModel.MemoryPriority);
|
|
Assert.Equal("Memory priority unavailable", viewModel.MemoryPriorityText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenSelectionChangesBeforeSlowMemoryPriorityCompletes_KeepsLatestSelection()
|
|
{
|
|
var memoryPriority = new ControlledMemoryPriorityService();
|
|
var viewModel = new SelectedProcessSummaryViewModel(memoryPriority);
|
|
var oldProcess = CreateProcess("Old.exe", 100, ProcessPriorityClass.Normal, 0x1, 10);
|
|
var latestProcess = CreateProcess("Latest.exe", 200, ProcessPriorityClass.High, 0x2, 20);
|
|
|
|
var oldUpdate = viewModel.UpdateAsync(oldProcess);
|
|
await memoryPriority.WaitForReadAsync(oldProcess.ProcessId);
|
|
|
|
memoryPriority.SetImmediatePriority(latestProcess.ProcessId, ProcessMemoryPriority.Normal);
|
|
await viewModel.UpdateAsync(latestProcess);
|
|
|
|
memoryPriority.CompleteRead(oldProcess.ProcessId, ProcessMemoryPriority.VeryLow);
|
|
await oldUpdate;
|
|
|
|
Assert.Equal(latestProcess.ProcessId, viewModel.ProcessId);
|
|
Assert.Equal(latestProcess.Name, viewModel.ProcessName);
|
|
Assert.Equal(ProcessMemoryPriority.Normal, viewModel.MemoryPriority);
|
|
Assert.Equal("Memory priority: Normal", viewModel.MemoryPriorityText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenSlowRuleLookupCompletesAfterSelectionChange_KeepsLatestRuleStatus()
|
|
{
|
|
var store = new ControlledPersistentProcessRuleStore();
|
|
var viewModel = new SelectedProcessSummaryViewModel(
|
|
persistentRuleStore: store,
|
|
persistentRuleMatcher: new PersistentProcessRuleMatcher());
|
|
var oldProcess = CreateProcess("Old.exe", 100);
|
|
var latestProcess = CreateProcess("Latest.exe", 200);
|
|
|
|
var oldUpdate = viewModel.UpdateAsync(oldProcess);
|
|
await store.WaitForLoadAsync(1);
|
|
|
|
store.EnqueueImmediateRules(new[]
|
|
{
|
|
new PersistentProcessRule
|
|
{
|
|
Name = "Latest rule",
|
|
ProcessName = latestProcess.Name,
|
|
IsEnabled = true,
|
|
},
|
|
});
|
|
await viewModel.UpdateAsync(latestProcess);
|
|
|
|
store.CompleteLoad(
|
|
1,
|
|
new[]
|
|
{
|
|
new PersistentProcessRule
|
|
{
|
|
Name = "Old rule",
|
|
ProcessName = oldProcess.Name,
|
|
IsEnabled = true,
|
|
},
|
|
});
|
|
await oldUpdate;
|
|
|
|
Assert.Equal(latestProcess.ProcessId, viewModel.ProcessId);
|
|
Assert.Equal(latestProcess.Name, viewModel.ProcessName);
|
|
Assert.True(viewModel.HasThreadPilotRule);
|
|
Assert.Equal("Saved rule exists: Latest rule", viewModel.RuleStatusText);
|
|
}
|
|
|
|
[Fact]
|
|
public void SelectedProcessSummary_HasNoPerformanceMonitoringDependency()
|
|
{
|
|
var type = typeof(SelectedProcessSummaryViewModel);
|
|
|
|
var constructorParameters = type
|
|
.GetConstructors()
|
|
.SelectMany(ctor => ctor.GetParameters())
|
|
.Select(parameter => parameter.ParameterType);
|
|
var fieldTypes = type
|
|
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
|
.Select(field => field.FieldType);
|
|
|
|
Assert.DoesNotContain(typeof(IPerformanceMonitoringService), constructorParameters);
|
|
Assert.DoesNotContain(typeof(IPerformanceMonitoringService), fieldTypes);
|
|
}
|
|
|
|
[Fact]
|
|
public void SelectedProcessSummary_DoesNotOwnTimers()
|
|
{
|
|
var fieldTypes = typeof(SelectedProcessSummaryViewModel)
|
|
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
|
.Select(field => field.FieldType);
|
|
|
|
Assert.DoesNotContain(typeof(System.Timers.Timer), fieldTypes);
|
|
Assert.DoesNotContain(typeof(System.Threading.Timer), fieldTypes);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenPersistentRuleMatches_ShowsSavedRule()
|
|
{
|
|
var store = new Mock<IPersistentProcessRuleStore>(MockBehavior.Strict);
|
|
store
|
|
.Setup(ruleStore => ruleStore.LoadAsync())
|
|
.ReturnsAsync(new[]
|
|
{
|
|
new PersistentProcessRule
|
|
{
|
|
Name = "Game rule",
|
|
ProcessName = "Game.exe",
|
|
IsEnabled = true,
|
|
},
|
|
});
|
|
var viewModel = new SelectedProcessSummaryViewModel(
|
|
persistentRuleStore: store.Object,
|
|
persistentRuleMatcher: new PersistentProcessRuleMatcher());
|
|
|
|
await viewModel.UpdateAsync(CreateProcess("Game.exe"));
|
|
|
|
Assert.True(viewModel.HasThreadPilotRule);
|
|
Assert.Equal("Saved rule exists: Game rule", viewModel.RuleStatusText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateAsync_WhenNoPersistentRuleMatches_ShowsNoSavedRule()
|
|
{
|
|
var store = new Mock<IPersistentProcessRuleStore>(MockBehavior.Strict);
|
|
store
|
|
.Setup(ruleStore => ruleStore.LoadAsync())
|
|
.ReturnsAsync(new[]
|
|
{
|
|
new PersistentProcessRule
|
|
{
|
|
Name = "Other rule",
|
|
ProcessName = "Other.exe",
|
|
IsEnabled = true,
|
|
},
|
|
});
|
|
var viewModel = new SelectedProcessSummaryViewModel(
|
|
persistentRuleStore: store.Object,
|
|
persistentRuleMatcher: new PersistentProcessRuleMatcher());
|
|
|
|
await viewModel.UpdateAsync(CreateProcess("Game.exe"));
|
|
|
|
Assert.False(viewModel.HasThreadPilotRule);
|
|
Assert.Equal("No saved rule", viewModel.RuleStatusText);
|
|
}
|
|
|
|
private static ProcessModel CreateProcess(
|
|
string name = "Game.exe",
|
|
int processId = 42,
|
|
ProcessPriorityClass priority = ProcessPriorityClass.Normal,
|
|
long affinity = 0xF,
|
|
long memoryUsage = 64 * 1024 * 1024)
|
|
=> new()
|
|
{
|
|
ProcessId = processId,
|
|
Name = name,
|
|
ExecutablePath = @"C:\Games\Game.exe",
|
|
CpuUsage = 12.5,
|
|
MemoryUsage = memoryUsage,
|
|
Priority = priority,
|
|
ProcessorAffinity = affinity,
|
|
Classification = ProcessClassification.ForegroundApp,
|
|
};
|
|
|
|
private sealed class ControlledMemoryPriorityService : IProcessMemoryPriorityService
|
|
{
|
|
private readonly Dictionary<int, TaskCompletionSource<ProcessMemoryPriority?>> pendingReads = new();
|
|
private readonly Dictionary<int, TaskCompletionSource> readSignals = new();
|
|
private readonly Dictionary<int, ProcessMemoryPriority?> immediatePriorities = new();
|
|
|
|
public Task<ProcessMemoryPriority?> GetMemoryPriorityAsync(ProcessModel process)
|
|
{
|
|
if (this.immediatePriorities.TryGetValue(process.ProcessId, out var priority))
|
|
{
|
|
return Task.FromResult(priority);
|
|
}
|
|
|
|
var pending = new TaskCompletionSource<ProcessMemoryPriority?>(
|
|
TaskCreationOptions.RunContinuationsAsynchronously);
|
|
var signal = this.GetOrCreateReadSignal(process.ProcessId);
|
|
this.pendingReads[process.ProcessId] = pending;
|
|
signal.TrySetResult();
|
|
return pending.Task;
|
|
}
|
|
|
|
public Task<ProcessOperationResult> SetMemoryPriorityAsync(ProcessModel process, ProcessMemoryPriority priority)
|
|
=> throw new NotSupportedException();
|
|
|
|
public void SetImmediatePriority(int processId, ProcessMemoryPriority? priority)
|
|
{
|
|
this.immediatePriorities[processId] = priority;
|
|
}
|
|
|
|
public Task WaitForReadAsync(int processId) => this.GetOrCreateReadSignal(processId).Task;
|
|
|
|
public void CompleteRead(int processId, ProcessMemoryPriority? priority)
|
|
{
|
|
this.pendingReads[processId].SetResult(priority);
|
|
}
|
|
|
|
private TaskCompletionSource GetOrCreateReadSignal(int processId)
|
|
{
|
|
if (!this.readSignals.TryGetValue(processId, out var signal))
|
|
{
|
|
signal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
this.readSignals[processId] = signal;
|
|
}
|
|
|
|
return signal;
|
|
}
|
|
}
|
|
|
|
private sealed class ControlledPersistentProcessRuleStore : IPersistentProcessRuleStore
|
|
{
|
|
private readonly Dictionary<int, TaskCompletionSource<IReadOnlyList<PersistentProcessRule>>> pendingLoads = new();
|
|
private readonly Dictionary<int, TaskCompletionSource> loadSignals = new();
|
|
private readonly Queue<IReadOnlyList<PersistentProcessRule>> immediateRules = new();
|
|
private int loadCount;
|
|
|
|
public Task<IReadOnlyList<PersistentProcessRule>> LoadAsync()
|
|
{
|
|
this.loadCount++;
|
|
var loadNumber = this.loadCount;
|
|
|
|
if (this.immediateRules.Count > 0)
|
|
{
|
|
this.GetOrCreateLoadSignal(loadNumber).TrySetResult();
|
|
return Task.FromResult(this.immediateRules.Dequeue());
|
|
}
|
|
|
|
var pending = new TaskCompletionSource<IReadOnlyList<PersistentProcessRule>>(
|
|
TaskCreationOptions.RunContinuationsAsynchronously);
|
|
this.pendingLoads[loadNumber] = pending;
|
|
this.GetOrCreateLoadSignal(loadNumber).TrySetResult();
|
|
return pending.Task;
|
|
}
|
|
|
|
public Task SaveAsync(IReadOnlyList<PersistentProcessRule> rules)
|
|
=> throw new NotSupportedException();
|
|
|
|
public void EnqueueImmediateRules(IReadOnlyList<PersistentProcessRule> rules)
|
|
{
|
|
this.immediateRules.Enqueue(rules);
|
|
}
|
|
|
|
public Task WaitForLoadAsync(int loadNumber) => this.GetOrCreateLoadSignal(loadNumber).Task;
|
|
|
|
public void CompleteLoad(int loadNumber, IReadOnlyList<PersistentProcessRule> rules)
|
|
{
|
|
this.pendingLoads[loadNumber].SetResult(rules);
|
|
}
|
|
|
|
private TaskCompletionSource GetOrCreateLoadSignal(int loadNumber)
|
|
{
|
|
if (!this.loadSignals.TryGetValue(loadNumber, out var signal))
|
|
{
|
|
signal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
this.loadSignals[loadNumber] = signal;
|
|
}
|
|
|
|
return signal;
|
|
}
|
|
}
|
|
}
|
|
}
|