Skip to content
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

[coro_http][ut]Tests for 0381 #873

Open
wants to merge 13 commits into
base: 0.3.8.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/actions/coverage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Alibaba designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#

name: 'Coverage test'

inputs:
reset-commit-id:
required: false
type: string
outputs:
data:
value: ${{ steps.get-cov-report.outputs.data }}

runs:
using: composite
steps:
- name: 'Checkout source code'
uses: actions/checkout@v4
with:
fetch-depth: 100

- name: 'Reset to specific commit'
run: |
echo "${{ inputs.reset-commit-id }}"
git reset --hard ${{ inputs.reset-commit-id }}
shell: bash
if: ${{ inputs.reset-commit-id }} != ""

- name: 'Install dependencies'
run: |
apt --help &>/dev/null
if [ $? -eq 0 ];then
sudo apt-get install -y openssl libssl-dev llvm jq
else
yum --help &>/dev/null
if [ $? -eq 0 ];then
sudo yum install -y openssl openssl-devel llvm jq
else
exit 1
fi
fi
shell: bash

- name: 'Install newer clang'
run: |
apt --help &>/dev/null
if [ $? -eq 0 ];then
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update -y
else
yum --help &>/dev/null
[ $? -eq 0 ] && sudo yum update -y
fi
wget https://apt.llvm.org/llvm.sh -O llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
shell: bash

- name: 'Build and test'
id: get-cov-report
run: |
cp -r src/coro_rpc/tests/openssl_files .
rm -rf build
mkdir -p build
cd build
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF
make -j
export LLVM_PROFILE_FILE="test_ylt-%m.profraw"
cd output/tests
find . -maxdepth 1 -type f -executable | xargs -I {} sh -c '{}'
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata
if [ -n "${{ inputs.reset-commit-id }}" ];then
report=base-ylt-cov-report
else
report=ylt-cov-report
fi
llvm-cov show $(find . -maxdepth 1 -type f -executable | awk '{print "-object " $0}' | xargs) -instr-profile=test_ylt.profdata -format=html -output-dir=$report -ignore-filename-regex='thirdparty|src|template_switch|concurrentqueue|dragonbox_to_chars|dragonbox|expected' -show-instantiations=false
echo "path=build/output/tests/$report" >> $GITHUB_OUTPUT
cov_data=$(grep -w '<pre>Totals</pre>' $report/index.html | awk -F 'Totals' '{print $NF}' | cut -d ')' -f 2 | awk -F '>' '{print $NF}' | awk -F '%' '{print $1}')
echo "coverage data: $cov_data"
echo "report=$report" >> $GITHUB_OUTPUT
echo "data=$cov_data" >> $GITHUB_OUTPUT
shell: bash

- name: 'Upload coverage results'
uses: actions/[email protected]
with:
name: ${{ steps.get-cov-report.outputs.report }}
path: ${{ steps.get-cov-report.outputs.path }}

- name: 'Checkout source code'
uses: actions/checkout@v4
if: ${{ inputs.reset-commit-id }} != ""
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: install clang-format
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean_cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
contents: read
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cleanup
run: |
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Alibaba designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#

name: Cov Report Comment

on:
workflow_run:
workflows: ["Ubuntu 22.04 (llvm cov)"]
types:
- completed

jobs:
comment:
runs-on: ubuntu-22.04
permissions: write-all
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "action_msg"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/action_msg.zip`, Buffer.from(download.data));
- name: 'Comment'
run: |
unzip action_msg.zip
pr_id=`grep 'pr_id' action_msg | cut -d '=' -f 2`
action_id=`grep 'action_id' action_msg | cut -d '=' -f 2`
content=$(echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${action_id}) download Artifacts \`base-ylt-cov-report\`(base commit coverage report) and \`ylt-cov-report\`(current pull request coverage report)")
curl -L -X POST "https://api.github.com/repos/${{github.repository}}/issues/${pr_id}/comments" -H "Authorization: Bearer ${{github.token}}" -H 'Content-Type: application/json' -d "{\"body\": \"$content\"}"
shell: bash
145 changes: 92 additions & 53 deletions .github/workflows/linux_llvm_cov.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,109 @@
#
# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Alibaba designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#

name: Ubuntu 22.04 (llvm cov)

on:
pull_request_target:
pull_request:
branches:
- main
- fix_coverage_show
- 0.3.8.1
- tests_for_0381

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
prerequisites:
runs-on: ubuntu-22.04

permissions: write-all
outputs:
id: ${{ steps.get-base-commit.outputs.id }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Dependencies
- name: 'Get Base Commit id'
id: get-base-commit
run: |
sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install llvm

- name: Install newer Clang
sudo apt install -y jq
base_commit_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .base.sha)
echo "::set-output name=id::$base_commit_id"
shell: bash
- name: 'Store Message'
run: |
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
mkdir -p ./msg
echo "action_id=${{github.run_id}}" >> ./msg/action_msg
echo "pr_id=${{github.event.pull_request.number}}" >> ./msg/action_msg
shell: bash
- name: 'Upload Action Message'
uses: actions/upload-artifact@v4
with:
name: action_msg
path: msg/

- name: Run Coverage
run: |
ls
cp -r src/coro_rpc/tests/openssl_files .
ls
mkdir build && cd build
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON
make -j
export LLVM_PROFILE_FILE="test_ylt-%m.profraw"
cd output
cd tests
./coro_io_test
./coro_rpc_test
./easylog_test
./struct_pack_test
./struct_pack_test_with_optimize
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata
llvm-cov show coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|asio|src" -show-instantiations=false
echo "Done!"
base-cov-test:
needs: prerequisites
runs-on: ubuntu-22.04
outputs:
data: ${{ steps.base-cov.outputs.data }}
steps:
- name: 'Checkout source code'
uses: actions/checkout@v4
- name: 'Base coverage test'
id: base-cov
uses: ./.github/actions/coverage
with:
reset-commit-id: ${{ needs.prerequisites.outputs.id }}

- name: Upload Coverage Results
uses: actions/upload-artifact@v3
cov-test:
needs: prerequisites
runs-on: ubuntu-22.04
outputs:
data: ${{ steps.cov.outputs.data }}
steps:
- name: 'Checkout source code'
uses: actions/checkout@v4
- name: 'Coverage test'
id: cov
uses: ./.github/actions/coverage
with:
name: llvm-cov
path: ${{ github.workspace }}/build/.coverage_llvm_cov
reset-commit-id: ""

- name: Create Code Coverage Report
working-directory: ${{github.workspace}}/build/output/tests
compare-cov-data:
needs:
- base-cov-test
- cov-test
runs-on: ubuntu-22.04
steps:
- name: 'Compare data'
run: |
echo "Code Coverage Report" > tmp.log
echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts `llvm-cov`" >> tmp.log
echo "\`\`\`" >> tmp.log
llvm-cov report coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -instr-profile=test_ylt.profdata -ignore-filename-regex="thirdparty|asio|src" -show-region-summary=false >> tmp.log
echo "\`\`\`" >> tmp.log

- name: Create Comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body-file: '${{github.workspace}}/build/output/tests/tmp.log'
sudo apt install -y bc
result=$(echo "${{ needs.cov-test.outputs.data }} > 70" | bc)
if [ "$result" -ne 1 ];then
echo "coverage cannot be lower than 70%!"
exit 1
fi
result=$(echo "${{ needs.cov-test.outputs.data }} > $(echo "${{ needs.base-cov-test.outputs.data}} * 0.97" | bc)" | bc)
if [ "$result" -ne 1 ];then
echo "coverage has decreased over 3%!"
exit 1
fi
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
mode: [ Debug ] #mode: [Release, Debug]
ssl: [ ON, OFF ]

runs-on: macos-12
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# - name: SetUp HomeBrew
# id: set-up-homebrew
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/s390x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Build Linux on s390x arch and run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v2
name: Test
id: runcmd
Expand Down
Loading
Loading