Skip to content

Commit

Permalink
Merge #98011
Browse files Browse the repository at this point in the history
98011: bazel: add `gcassert` job in TC r=healthy-pod a=rickystewart

This simple job generates code then runs `gcassert` as a standalone
binary.

Closes #65485.

Epic: none
Release note: None

Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
craig[bot] and rickystewart committed Mar 6, 2023
2 parents f959dd6 + f9de621 commit 856658b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 38 deletions.
12 changes: 12 additions & 0 deletions build/teamcity/cockroach/ci/tests/gcassert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -euo pipefail

dir="$(dirname $(dirname $(dirname $(dirname $(dirname "${0}")))))"

source "$dir/teamcity-support.sh" # For $root
source "$dir/teamcity-bazel-support.sh" # For run_bazel

tc_start_block "GcAssert"
run_bazel build/teamcity/cockroach/ci/tests/gcassert_impl.sh
tc_end_block "GcAssert"
15 changes: 15 additions & 0 deletions build/teamcity/cockroach/ci/tests/gcassert_impl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -xeuo pipefail

bazel build @com_github_jordanlewis_gcassert//cmd/gcassert:gcassert --config=ci
bazel run //pkg/gen:code
GODIR=$(dirname $(bazel run @go_sdk//:bin/go --run_under=realpath))
echo "##teamcity[testStarted name='GcAssert' captureStandardOutput='true']"
exit_status=0
PATH=$GODIR:$PATH $(bazel info bazel-bin --config=ci)/external/com_github_jordanlewis_gcassert/cmd/gcassert/gcassert_/gcassert $(cat ./pkg/testutils/lint/gcassert_paths.txt | sed 's|^|./pkg/|') || exit_status=$?
if [ "$exit_status" -ne 0 ]; then
echo "##teamcity[testFailed name='GcAssert']"
fi
echo "##teamcity[testFinished name='GcAssert']"

1 change: 1 addition & 0 deletions pkg/testutils/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_test(
args = ["-test.timeout=295s"],
data = glob(["testdata/**"]),
embed = [":lint"],
embedsrcs = ["gcassert_paths.txt"],
gotags = ["lint"],
tags = ["integration"],
visibility = ["//build/bazelutil:__subpackages__"],
Expand Down
29 changes: 29 additions & 0 deletions pkg/testutils/lint/gcassert_paths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
col/coldata
col/colserde
keys
kv/kvclient/rangecache
kv/kvpb
roachpb
sql/catalog/descs
sql/colcontainer
sql/colconv
sql/colexec
sql/colexec/colexecagg
sql/colexec/colexecbase
sql/colexec/colexechash
sql/colexec/colexecjoin
sql/colexec/colexecproj
sql/colexec/colexecprojconst
sql/colexec/colexecsel
sql/colexec/colexecspan
sql/colexec/colexecwindow
sql/colfetcher
sql/opt
sql/row
storage
storage/enginepb
storage/pebbleiter
util
util/admission
util/hlc
util/intsets
59 changes: 21 additions & 38 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lint
import (
"bufio"
"bytes"
_ "embed"
"encoding/json"
"fmt"
"os"
Expand All @@ -41,6 +42,9 @@ import (

const cockroachDB = "github.com/cockroachdb/cockroach"

//go:embed gcassert_paths.txt
var rawGcassertPaths string

func dirCmd(
dir string, name string, args ...string,
) (*exec.Cmd, *bytes.Buffer, stream.Filter, error) {
Expand Down Expand Up @@ -2036,46 +2040,23 @@ func TestLint(t *testing.T) {

t.Run("TestGCAssert", func(t *testing.T) {
skip.UnderShort(t)
skip.UnderBazelWithIssue(t, 65485, "Doesn't work in Bazel -- not really sure why yet")

t.Parallel()

gcassertPaths := []string{
"../../col/coldata",
"../../col/colserde",
"../../keys",
"../../kv/kvclient/rangecache",
"../../kv/kvpb",
"../../roachpb",
"../../sql/catalog/descs",
"../../sql/colcontainer",
"../../sql/colconv",
"../../sql/colexec",
"../../sql/colexec/colexecagg",
"../../sql/colexec/colexecbase",
"../../sql/colexec/colexechash",
"../../sql/colexec/colexecjoin",
"../../sql/colexec/colexecproj",
"../../sql/colexec/colexecprojconst",
"../../sql/colexec/colexecsel",
"../../sql/colexec/colexecspan",
"../../sql/colexec/colexecwindow",
"../../sql/colfetcher",
"../../sql/opt",
"../../sql/row",
"../../storage",
"../../storage/enginepb",
"../../storage/pebbleiter",
"../../util",
"../../util/admission",
"../../util/hlc",
"../../util/intsets",
var gcassertPaths []string
for _, path := range strings.Split(rawGcassertPaths, "\n") {
path = strings.TrimSpace(path)
if path == "" {
continue
}
gcassertPaths = append(gcassertPaths, fmt.Sprintf("../../%s", path))
}

// Ensure that all packages that have '//gcassert' or '// gcassert'
// assertions are included into gcassertPaths.
t.Run("Coverage", func(t *testing.T) {
t.Parallel()

cmd, stderr, filter, err := dirCmd(
pkgDir,
"git",
Expand Down Expand Up @@ -2120,13 +2101,15 @@ func TestLint(t *testing.T) {
}
})

var buf strings.Builder
if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil {
t.Fatal(err)
}
output := buf.String()
if len(output) > 0 {
t.Fatalf("failed gcassert:\n%s", output)
if !bazel.BuiltWithBazel() {
var buf strings.Builder
if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil {
t.Fatal(err)
}
output := buf.String()
if len(output) > 0 {
t.Fatalf("failed gcassert:\n%s", output)
}
}
})

Expand Down

0 comments on commit 856658b

Please sign in to comment.