public async Task DefaultsToCurrentSystemOemEncoding() { // This test verifies that the additional code pages encoding provider is registered. // By default, only Unicode encodings, ASCII, and code page 28591 are supported. An // additional provider must be registered to support the full set of encodings that // were included in Full .NET prior to 4.6. // // For example, on an en-US box, this is required for loading the encoding for the // default console output code page '437'. Without loading the correct encoding for // code page IBM437, some characters cannot be translated correctly, e.g. write 'ç' // from powershell.exe. using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var processInvoker = new ProcessInvokerWrapper(); processInvoker.Initialize(hc); var stdout = new List <string>(); var stderr = new List <string>(); processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) => { stdout.Add(e.Data); }; processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) => { stderr.Add(e.Data); }; await processInvoker.ExecuteAsync( workingDirectory : "", fileName : "powershell.exe", arguments : $@"-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ""Write-Host 'From STDOUT ''ç''' ; Write-Error 'From STDERR ''ç'''""", environment : null, requireExitCodeZero : false, cancellationToken : CancellationToken.None); Assert.Equal(1, stdout.Count); Assert.Equal("From STDOUT 'ç'", stdout[0]); Assert.True(stderr.Count > 0); Assert.Contains("From STDERR 'ç'", stderr[0]); } }
public async Task RunnerLayoutParts_NewRunnerCoreAssets() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var runnerCoreAssetsFile = Path.Combine(TestUtil.GetSrcPath(), @"Misc/runnercoreassets"); var coreAssets = await File.ReadAllLinesAsync(runnerCoreAssetsFile); string layoutBin = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/bin"); var newFiles = new List <string>(); if (Directory.Exists(layoutBin)) { var binDirs = Directory.GetDirectories(TestUtil.GetSrcPath(), "net6.0", SearchOption.AllDirectories); foreach (var binDir in binDirs) { if (binDir.Contains("Test") || binDir.Contains("obj")) { continue; } Directory.GetFiles(binDir, "*", SearchOption.TopDirectoryOnly).ToList().ForEach(x => { if (!x.Contains("runtimeconfig.dev.json")) { if (!coreAssets.Any(y => x.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).EndsWith(y))) { newFiles.Add(x); } } }); } if (newFiles.Count > 0) { Assert.True(false, $"Found new files '{string.Join('\n', newFiles)}'. These will break runner update using trimmed packages. You might need to update `Misc/runnercoreassets`."); } } } }
public async Task OomScoreAdjIsWriten_FromEnv() { // We are on a system that supports oom_score_adj in procfs as assumed by ProcessInvoker string testProcPath = $"/proc/{Process.GetCurrentProcess().Id}/oom_score_adj"; if (File.Exists(testProcPath)) { using (TestHostContext hc = new TestHostContext(this)) using (var tokenSource = new CancellationTokenSource()) { Tracing trace = hc.GetTrace(); var processInvoker = new ProcessInvokerWrapper(); processInvoker.Initialize(hc); int oomScoreAdj = -9999; processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) => { oomScoreAdj = int.Parse(e.Data); tokenSource.Cancel(); }; try { var proc = await processInvoker.ExecuteAsync("", "bash", "-c \"cat /proc/$$/oom_score_adj\"", new Dictionary <string, string> { { "PIPELINE_JOB_OOMSCOREADJ", "1234" } }, false, null, false, null, false, false, highPriorityProcess : false, cancellationToken : tokenSource.Token); Assert.Equal(oomScoreAdj, 1234); } catch (OperationCanceledException) { trace.Info("Caught expected OperationCanceledException"); } } } }