From d427957749c10f249809a95197d2095e223f77a0 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Mon, 31 Jan 2022 22:06:46 +0100 Subject: [PATCH 1/6] Remove missing type inside CoreLib from the ModuleTrackerTemplate (#1286) Remove missing type inside CoreLib from the ModuleTrackerTemplate --- src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs b/src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs index 653178782..8321a704f 100644 --- a/src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs +++ b/src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs @@ -25,6 +25,7 @@ internal static class ModuleTrackerTemplate public static bool SingleHit; public static bool FlushHitFile; private static readonly bool _enableLog = int.TryParse(Environment.GetEnvironmentVariable("COVERLET_ENABLETRACKERLOG"), out int result) ? result == 1 : false; + private static string _sessionId = Guid.NewGuid().ToString(); static ModuleTrackerTemplate() { @@ -173,7 +174,7 @@ private static void WriteHits(object sender) Assembly currentAssembly = Assembly.GetExecutingAssembly(); DirectoryInfo location = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(currentAssembly.Location), "TrackersHitsLog")); location.Create(); - string logFile = Path.Combine(location.FullName, $"{Path.GetFileName(currentAssembly.Location)}_{DateTime.UtcNow.Ticks}_{Process.GetCurrentProcess().Id}.txt"); + string logFile = Path.Combine(location.FullName, $"{Path.GetFileName(currentAssembly.Location)}_{DateTime.UtcNow.Ticks}_{_sessionId}.txt"); using (var fs = new FileStream(HitsFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) using (var log = new FileStream(logFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)) using (var logWriter = new StreamWriter(log)) @@ -197,7 +198,7 @@ private static void WriteLog(string logText) // We don't set path as global var to keep benign possible errors inside try/catch // I'm not sure that location will be ok in every scenario string location = Assembly.GetExecutingAssembly().Location; - File.AppendAllText(Path.Combine(Path.GetDirectoryName(location), Path.GetFileName(location) + "_tracker.txt"), $"[{DateTime.UtcNow} P:{Process.GetCurrentProcess().Id} T:{Thread.CurrentThread.ManagedThreadId}]{logText}{Environment.NewLine}"); + File.AppendAllText(Path.Combine(Path.GetDirectoryName(location), Path.GetFileName(location) + "_tracker.txt"), $"[{DateTime.UtcNow} S:{_sessionId} T:{Thread.CurrentThread.ManagedThreadId}]{logText}{Environment.NewLine}"); } } } From f4f0bad94f1ce05d21eaca89b4540a7ab080a338 Mon Sep 17 00:00:00 2001 From: Alberto Monteiro Date: Mon, 31 Jan 2022 18:53:00 -0300 Subject: [PATCH 2/6] Update documentation for powershell users (#1283) Update documentation for powershell users --- Documentation/MSBuildIntegration.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/MSBuildIntegration.md b/Documentation/MSBuildIntegration.md index e19cf8ddb..bde9f364e 100644 --- a/Documentation/MSBuildIntegration.md +++ b/Documentation/MSBuildIntegration.md @@ -4,6 +4,11 @@ In this mode, Coverlet doesn't require any additional setup other than including If a property takes multiple comma-separated values please note that [you will have to add escaped quotes around the string](https://github.com/Microsoft/msbuild/issues/2999#issuecomment-366078677) like this: `/p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*\"`, `/p:Include=\"[coverlet.*]*,[*]Coverlet.Core*\"`, or `/p:CoverletOutputFormat=\"json,opencover\"`. +To achieve same behavior above using **powershell** you need to use the verbatim argument marker `--%` like this: +```powershell +dotnet test /p:CollectCoverage=true --% /p:CoverletOutputFormat=\"opencover,lcov\" +``` + ## Code Coverage Enabling code coverage is as simple as setting the `CollectCoverage` property to `true` From c8eafe5297e629deede0966c5de3e79468ca12fc Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sat, 5 Feb 2022 19:39:38 +0100 Subject: [PATCH 3/6] Put AppContext.OnProcessExit body inside a try/finally (#1290) Put AppContext.OnProcessExit body inside a try/finally --- .../Instrumentation/Instrumenter.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 10e301730..7d8f6f192 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -297,10 +297,27 @@ private void InstrumentModule() var onProcessExitMethod = new MethodReference("OnProcessExit", module.TypeSystem.Void, appContextType).Resolve(); var onProcessExitIl = onProcessExitMethod.Body.GetILProcessor(); - lastInstr = onProcessExitIl.Body.Instructions.Last(); - onProcessExitIl.InsertBefore(lastInstr, Instruction.Create(OpCodes.Ldnull)); - onProcessExitIl.InsertBefore(lastInstr, Instruction.Create(OpCodes.Ldnull)); - onProcessExitIl.InsertBefore(lastInstr, Instruction.Create(OpCodes.Call, customTrackerUnloadModule)); + // Put the OnProcessExit body inside try/finally to ensure the call to the UnloadModule. + var lastInst = onProcessExitMethod.Body.Instructions.Last(); + var firstNullParam = Instruction.Create(OpCodes.Ldnull); + var secondNullParam = Instruction.Create(OpCodes.Ldnull); + var callUnload = Instruction.Create(OpCodes.Call, customTrackerUnloadModule); + onProcessExitIl.InsertAfter(lastInst, firstNullParam); + onProcessExitIl.InsertAfter(firstNullParam, secondNullParam); + onProcessExitIl.InsertAfter(secondNullParam, callUnload); + var ret = onProcessExitIl.Create(OpCodes.Ret); + var leave = onProcessExitIl.Create(OpCodes.Leave, ret); + onProcessExitIl.InsertAfter(callUnload, leave); + onProcessExitIl.InsertAfter(leave, ret); + var handler = new ExceptionHandler(ExceptionHandlerType.Finally) + { + TryStart = onProcessExitIl.Body.Instructions.First(), + TryEnd = firstNullParam, + HandlerStart = firstNullParam, + HandlerEnd = ret + }; + + onProcessExitMethod.Body.ExceptionHandlers.Add(handler); } module.Write(stream, new WriterParameters { WriteSymbols = true }); From 83b5b35ae341d5bda44c2e0f1b4f23fa5ef5ac39 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sat, 5 Feb 2022 23:13:07 +0100 Subject: [PATCH 4/6] Fix finally generation for AppContext.OnProcessExit (#1291) Fix finally generation for AppContext.OnProcessExit --- .../Instrumentation/Instrumenter.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 7d8f6f192..cf80e90a3 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -305,10 +305,22 @@ private void InstrumentModule() onProcessExitIl.InsertAfter(lastInst, firstNullParam); onProcessExitIl.InsertAfter(firstNullParam, secondNullParam); onProcessExitIl.InsertAfter(secondNullParam, callUnload); + var endFinally = Instruction.Create(OpCodes.Endfinally); + onProcessExitIl.InsertAfter(callUnload, endFinally); var ret = onProcessExitIl.Create(OpCodes.Ret); - var leave = onProcessExitIl.Create(OpCodes.Leave, ret); - onProcessExitIl.InsertAfter(callUnload, leave); - onProcessExitIl.InsertAfter(leave, ret); + var leaveAfterFinally = onProcessExitIl.Create(OpCodes.Leave, ret); + onProcessExitIl.InsertAfter(endFinally, ret); + foreach (var inst in onProcessExitMethod.Body.Instructions.ToArray()) + { + // Patch ret to leave after the finally + if (inst.OpCode == OpCodes.Ret && inst != ret) + { + var leaveBodyInstAfterFinally = onProcessExitIl.Create(OpCodes.Leave, ret); + var prevInst = inst.Previous; + onProcessExitMethod.Body.Instructions.Remove(inst); + onProcessExitIl.InsertAfter(prevInst, leaveBodyInstAfterFinally); + } + } var handler = new ExceptionHandler(ExceptionHandlerType.Finally) { TryStart = onProcessExitIl.Body.Instructions.First(), From e335b1a8025e49e2f2de6b40ef12ec9d3ed11ceb Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sun, 6 Feb 2022 17:17:46 +0100 Subject: [PATCH 5/6] Prepare release 3.1.2 (#1293) Prepare release 3.1.2 --- src/coverlet.core/coverlet.core.csproj | 2 +- version.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coverlet.core/coverlet.core.csproj b/src/coverlet.core/coverlet.core.csproj index 884744854..7ef394311 100644 --- a/src/coverlet.core/coverlet.core.csproj +++ b/src/coverlet.core/coverlet.core.csproj @@ -3,7 +3,7 @@ Library netstandard2.0 - 5.7.1 + 5.7.2 false diff --git a/version.json b/version.json index 9591bc471..ba30b4c1b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "3.1.2-preview.{height}", + "version": "3.1.2", "publicReleaseRefSpec": [ "^refs/heads/master$" ], From 1e74dd43824fc49e90622a3442133c2d9f4e8e01 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sun, 6 Feb 2022 17:39:02 +0100 Subject: [PATCH 6/6] Bump versions (#1294) Bump versions --- Documentation/Changelog.md | 10 ++++++++++ Documentation/ReleasePlan.md | 7 ++++--- version.json | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Documentation/Changelog.md b/Documentation/Changelog.md index c9ffe9323..5c551ceec 100644 --- a/Documentation/Changelog.md +++ b/Documentation/Changelog.md @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Release date 2022-02-06 +### Packages +coverlet.msbuild 3.1.2 +coverlet.console 3.1.2 +coverlet.collector 3.1.2 + +### Fixed +-Fix CoreLib's coverage measurement is broken [#1286](https://github.com/coverlet-coverage/coverlet/pull/1286) +-Fix UnloadModule injection [1291](https://github.com/coverlet-coverage/coverlet/pull/1291) + ## Release date 2022-01-30 ### Packages coverlet.msbuild 3.1.1 diff --git a/Documentation/ReleasePlan.md b/Documentation/ReleasePlan.md index da7b5db46..630f2941c 100644 --- a/Documentation/ReleasePlan.md +++ b/Documentation/ReleasePlan.md @@ -23,13 +23,14 @@ We release 3 components as NuGet packages: | Package | Version | |:----------------------|:--------| -|**coverlet.msbuild** | 3.1.1 | -|**coverlet.console** | 3.1.1 | -|**coverlet.collector** | 3.1.1 | +|**coverlet.msbuild** | 3.1.2 | +|**coverlet.console** | 3.1.2 | +|**coverlet.collector** | 3.1.2 | | Release Date | coverlet.msbuild | coverlet.console | coverlet.collector| commit hash | notes | | :-----------------|:-----------------|:------------------|:------------------|:-----------------------------------------|:-------------------------------| +| 06 Feb 2022 | 3.1.2 | 3.1.2 | 3.1.2 | e335b1a8025e49e2f2de6b40ef12ec9d3ed11ceb | Fix CoreLib coverage issues | | 30 Jan 2022 | 3.1.1 | 3.1.1 | 3.1.1 | e4278c06faba63122a870df15a1a1b934f6bc81d | | | 19 July 2021 | 3.1.0 | 3.1.0 | 3.1.0 | 5a0ecc1e92fd754e2439dc3e4c828ff7386aa1a7 | Support for determistic build | | 21 February 2021 | 3.0.3 | 3.0.3 | 3.0.3 | adfabfd58de0aabe263e7d2080324e0b8541071e | Fix regressions | diff --git a/version.json b/version.json index ba30b4c1b..8db7c19a6 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "3.1.2", + "version": "3.1.3-preview.{height}", "publicReleaseRefSpec": [ "^refs/heads/master$" ],