Skip to content

Commit

Permalink
Add C# coverage report generation
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Dec 3, 2024
1 parent 71b8054 commit d225bee
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Generate API Coverage

on:
workflow_dispatch:
push:
branches: ["coverage-test"]

jobs:
generate-coverage-report:
generate-cpp-overage-report:
runs-on: macos-15
steps:
- name: Checkout repository
Expand Down Expand Up @@ -50,3 +52,44 @@ jobs:
AWS_S3_CODE_BUCKET: ${{ secrets.AWS_S3_CODE_BUCKET }}
AWS_DEFAULT_REGION: us-east-1
if: github.ref == 'refs/heads/main'

generate-csharp-coverage-report:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Dependencies
uses: ./.github/actions/setup-dependencies
with:
use_ccache: false

- name: Build C#
working-directory: ./csharp
run: make

- name: Generate C# Coverage
working-directory: ./csharp
run: |
dotnet-coverage collect --server-mode --background --session-id ice-coverage --output output.cobertura.xml --output-format cobertura
python3 allTests.py --all --dotnet-command "dotnet-coverage connect ice-coverage dotnet"
dotnet-coverage shutdown ice-coverage
- name: Generate Coverage Reports
uses: danielpalme/ReportGenerator-GitHub-Action@5.3.8
with:
reports: csharp/coverage.cobertura.xml
targetdir: coveragereport
reporttypes: Html;Badges
license: ${{ secrets.REPORT_GENERATOR_LICENSE }}

- name: Sync Documentation to S3
working-directory: ./csharp/coveragereport
run: aws s3 sync . s3://${AWS_S3_CODE_BUCKET}/ice/csharp/main/coverage --delete

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_CODE_BUCKET: ${{ secrets.AWS_S3_CODE_BUCKET }}
AWS_DEFAULT_REGION: us-east-1
if: github.ref == 'refs/heads/main'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ Carthage
# SPM build artifacts
.build
.swiftpm


# LLVM Code Coverage maps
*.profraw
*.profdata
51 changes: 45 additions & 6 deletions scripts/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3246,9 +3246,11 @@ def pop(self):

def createFile(self, path, lines, encoding=None):
path = os.path.join(self.testsuite.getPath(), path)
with open(path, "w", encoding=encoding) if encoding else open(
path, "w"
) as file:
with (
open(path, "w", encoding=encoding)
if encoding
else open(path, "w") as file
):
for line in lines:
file.write("%s\n" % line)
self.files.append(path)
Expand Down Expand Up @@ -3437,7 +3439,9 @@ def getProps(self, process, current):
props = {}
if isinstance(process, IceProcess):
if not self.host:
props["Ice.Default.Host"] = ("::1" if current.config.ipv6 else "127.0.0.1")
props["Ice.Default.Host"] = (
"::1" if current.config.ipv6 else "127.0.0.1"
)
else:
props["Ice.Default.Host"] = self.host
return props
Expand Down Expand Up @@ -3677,7 +3681,7 @@ def _getDefaultSource(self, processType):
"subscriber": "Subscriber.cpp",
"publisher": "Publisher.cpp",
"reader": "Reader.cpp",
"writer": "Writer.cpp"
"writer": "Writer.cpp",
}[processType]

def _getDefaultExe(self, processType):
Expand Down Expand Up @@ -3827,6 +3831,31 @@ def getActivityName(self):


class CSharpMapping(Mapping):
class Config(Mapping.Config):
@classmethod
def getSupportedArgs(self):
return ("", ["coverage-session="])

@classmethod
def usage(self):
print("")
print("C# mapping options:")
print(
"--coverage-session=<id> Run tests the dotnet-coverage using the given session ID."
)

def __init__(self, options=[]):
Mapping.Config.__init__(self, options)
self.dotnetCoverageSession = ""

parseOptions(
self,
options,
{
"coverage-session": "dotnetCoverageSession",
},
)

def getTargetFramework(self, current):
return "net8.0"

Expand Down Expand Up @@ -3915,7 +3944,17 @@ def getCommandLine(self, current, process, exe, args):
path = os.path.join(
current.testcase.getPath(current), current.getBuildDir(exe)
)
return "dotnet {}.dll {}".format(os.path.join(path, exe), args)

cmd = "dotnet {}.dll {}".format(os.path.join(path, exe), args)

if current.config.dotnetCoverageSession != "":
# escapign \" is requried for passing though from dotnet-coverage -> dotnet -> exe
cmd = cmd.replace('\\"', '\\\\\\"')
cmd = (
f"dotnet-coverage connect {current.config.dotnetCoverageSession} {cmd}"
)

return cmd


class CppBasedMapping(Mapping):
Expand Down

0 comments on commit d225bee

Please sign in to comment.