Skip to content
Merged
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
7 changes: 1 addition & 6 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ jobs:
with:
go-version-file: ./go.mod
- name: Generate coverage and badge
run: |
make test
mkdir -p ./ci/out/static
cp ./ci/out/coverage.html ./ci/out/static/coverage.html
percent=$(go tool cover -func ./ci/out/coverage.prof | tail -n1 | awk '{print $3}' | tr -d '%')
wget -O ./ci/out/static/coverage.svg "https://img.shields.io/badge/coverage-${percent}%25-success"
run: make static
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ lint:
test:
./ci/test.sh

.PHONY: static
static: test
./ci/static.sh

.PHONY: bench
bench:
./ci/bench.sh
./ci/bench.sh
21 changes: 10 additions & 11 deletions ci/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ cd -- "$(dirname "$0")/.."
go test --run=^$ --bench=. --benchmem "$@" ./...
# For profiling add: --memprofile ci/out/prof.mem --cpuprofile ci/out/prof.cpu -o ci/out/websocket.test
(
cd ./internal/thirdparty
go test --run=^$ --bench=. --benchmem "$@" .
cd ./internal/thirdparty
go test --run=^$ --bench=. --benchmem "$@" .

GOARCH=arm64 go test -c -o ../../ci/out/thirdparty-arm64.test "$@" .
if [ "$#" -eq 0 ]; then
if [ "${CI-}" ]; then
sudo apt-get update
sudo apt-get install -y qemu-user-static
ln -s /usr/bin/qemu-aarch64-static /usr/local/bin/qemu-aarch64
fi
qemu-aarch64 ../../ci/out/thirdparty-arm64.test --test.run=^$ --test.bench=Benchmark_mask --test.benchmem
fi
GOARCH=arm64 go test -c -o ../../ci/out/thirdparty-arm64.test "$@" .
if [ "$#" -eq 0 ]; then
if [ "${CI-}" ]; then
sudo apt-get update
sudo apt-get install -y qemu-user
fi
qemu-aarch64 ../../ci/out/thirdparty-arm64.test --test.run=^$ --test.bench=Benchmark_mask --test.benchmem
fi
)
20 changes: 20 additions & 0 deletions ci/static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

cd -- "$(dirname "$0")/.."

if [[ ! -f ./ci/out/profile.txt ]]; then
echo "No coverage profile found, run 'make test' first"
exit 1
fi

if [[ ! -f ./ci/out/coverage.html ]]; then
echo "No coverage report found, run 'make test' first"
exit 1
fi

rm -rf ./ci/out/static
mkdir -p ./ci/out/static
cp ./ci/out/coverage.html ./ci/out/static/coverage.html
percent=$(go tool cover -func ./ci/out/profile.txt | tail -n1 | awk '{print $3}' | tr -d '%')
curl -fsSL -o ./ci/out/static/coverage.svg "https://img.shields.io/badge/coverage-${percent}%25-success"
70 changes: 43 additions & 27 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
#!/bin/sh
set -eu
#!/usr/bin/env bash
set -euo pipefail

cd -- "$(dirname "$0")/.."

(
cd ./internal/examples
go test "$@" ./...
)
(
cd ./internal/thirdparty
go test "$@" ./...
)

(
GOARCH=arm64 go test -c -o ./ci/out/websocket-arm64.test "$@" .
if [ "$#" -eq 0 ]; then
go install github.com/agnivade/wasmbrowsertest@8be019f6c6dceae821467b4c589eb195c2b761ce

echo "+++ Testing websocket library and generating coverage"
rm -rf ci/out/profile.txt ci/out/profile
coverdir="$(pwd)/ci/out/profile"
mkdir -p "$coverdir"

coverpkgs=$(go list ./... | grep -v websocket/internal/test | paste -sd, -)

echo "++++ Running main tests"
# -test.gocoverdir is a test binary flag, so it goes after -args. Each test
# binary runs in its package directory, so the path must be absolute.
go test -race --bench=. --timeout=1h -cover -covermode=atomic -coverpkg="$coverpkgs" "$@" ./... -args -test.gocoverdir="$coverdir"

echo "+++ Testing examples"
pushd internal/examples
go test "$@" ./...
popd

echo "+++ Testing thirdparty"
pushd internal/thirdparty
go test "$@" ./...
popd

if [[ $# -eq 0 ]]; then
echo "+++ Running TestMask for arm64"

run_test=(go test .)
if [[ $(go env GOARCH) != "arm64" ]]; then
if [ "${CI-}" ]; then
sudo apt-get update
sudo apt-get install -y qemu-user-static
ln -s /usr/bin/qemu-aarch64-static /usr/local/bin/qemu-aarch64
sudo apt-get install -y qemu-user
fi
qemu-aarch64 ./ci/out/websocket-arm64.test -test.run=TestMask
GOARCH=arm64 go test -c -o ./ci/out/websocket-arm64.test "$@" .
run_test=(qemu-aarch64 ./ci/out/websocket-arm64.test)
fi
)

go install github.com/agnivade/wasmbrowsertest@8be019f6c6dceae821467b4c589eb195c2b761ce
go test --race --bench=. --timeout=1h --covermode=atomic --coverprofile=ci/out/coverage.prof --coverpkg=./... "$@" ./...
sed -i.bak '/stringer\.go/d' ci/out/coverage.prof
sed -i.bak '/github\.com\/coder\/websocket\/internal\/test\//d' ci/out/coverage.prof
sed -i.bak '/examples/d' ci/out/coverage.prof
"${run_test[@]}" -test.run=TestMask
fi

# Last line is the total coverage.
go tool cover -func ci/out/coverage.prof | tail -n1
echo "++++ Generating test coverage data"
go tool covdata textfmt -i="$coverdir" -o ci/out/profile.txt
sed -i.bak '/stringer\.go/d' ci/out/profile.txt
go tool cover -func ci/out/profile.txt | tail -n1 # Last line is the total coverage.
go tool cover -html=ci/out/profile.txt -o=ci/out/coverage.html

go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html
echo "+++ Done"
Loading