Skip to content

Commit c9daf32

Browse files
craig[bot]dtrafiss
committed
151526: roachtest: add --cockroach-stage flag for remote binary staging r=dt a=dt Add --cockroach-stage flag that stages binaries directly from cloud storage instead of uploading local files. The flag accepts version/SHA values like "latest", "v23.2.0", or commit SHAs, is mutually exclusive with --cockroach, and normalizes "latest" to empty string for proper .LATEST URL construction. Release note: none. Epic: none 152461: fuzzystrmatch: fix out of bounds in LevenshteinLessEqual r=rafiss a=rafiss This fixes a bug that was added when this function was introduced in 7a538b3. No release note since this bug was not released yet. fixes #152418 Release note: None Co-authored-by: David Taylor <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
3 parents b168254 + eae0537 + 188150c commit c9daf32

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

pkg/cmd/roachtest/cluster.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,15 @@ func (c *clusterImpl) PutE(
19321932
}
19331933

19341934
// PutCockroach uploads a binary with or without runtime assertions enabled,
1935-
// as determined by t.Cockroach(). Note that we upload to all nodes even if they
1936-
// don't use the binary, so that the test runner can always fetch logs.
1935+
// as determined by t.Cockroach(). If --cockroach-stage flag is set, it stages
1936+
// the binary from cloud storage instead of uploading a local binary.
1937+
// Note that we upload/stage to all nodes even if they don't use the binary,
1938+
// so that the test runner can always fetch logs.
19371939
func (c *clusterImpl) PutCockroach(ctx context.Context, l *logger.Logger, t *testImpl) error {
1940+
if roachtestflags.CockroachStage != "" {
1941+
// Use staging instead of upload when --cockroach-stage is specified
1942+
return c.Stage(ctx, l, "cockroach", roachtestflags.CockroachStage, ".", c.All())
1943+
}
19381944
return c.PutE(ctx, l, t.Cockroach(), test.DefaultCockroachPath, c.All())
19391945
}
19401946

pkg/cmd/roachtest/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,16 @@ func validateAndConfigure(cmd *cobra.Command, args []string) {
573573
if roachtestflags.SelectiveTests && selectProbFlagInfo != nil {
574574
printErrAndExit(fmt.Errorf("select-probability and selective-tests=true are incompatible. Disable one of them"))
575575
}
576+
577+
// --cockroach and --cockroach-stage flags are mutually exclusive.
578+
cockroachFlagInfo := roachtestflags.Changed(&roachtestflags.CockroachPath)
579+
cockroachStageFlagInfo := roachtestflags.Changed(&roachtestflags.CockroachStage)
580+
if cockroachFlagInfo != nil && cockroachStageFlagInfo != nil {
581+
printErrAndExit(fmt.Errorf("--cockroach and --cockroach-stage are mutually exclusive. Use one or the other"))
582+
}
583+
584+
// Normalize "latest" to empty string for staging system
585+
if roachtestflags.CockroachStage == "latest" {
586+
roachtestflags.CockroachStage = ""
587+
}
576588
}

pkg/cmd/roachtest/roachtestflags/flags.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ var (
112112
Usage: `Absolute path to cockroach binary to use`,
113113
})
114114

115+
CockroachStage string
116+
_ = registerRunFlag(&CockroachStage, FlagInfo{
117+
Name: "cockroach-stage",
118+
Usage: `
119+
Stage cockroach binary from cloud storage instead of uploading local binary.
120+
Specify version/SHA (e.g., "latest", "v23.2.0", or commit SHA).
121+
Mutually exclusive with --cockroach.`,
122+
})
123+
115124
ConfigPath string
116125
_ = registerRunOpsFlag(&ConfigPath, FlagInfo{
117126
Name: "config",

pkg/util/fuzzystrmatch/leven.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func LevenshteinLessEqualDistanceWithCost(
123123
bestColumn = -netInserts
124124
}
125125
stopColumn = bestColumn + (slackDist / (insCost + delCost)) + 1
126+
if stopColumn < 0 {
127+
stopColumn = 0
128+
}
126129
if stopColumn > lenS {
127130
stopColumn = lenS + 1
128131
}

pkg/util/fuzzystrmatch/leven_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
package fuzzystrmatch
77

8-
import "testing"
8+
import (
9+
"math"
10+
"testing"
11+
)
912

1013
func TestLevenshteinDistance(t *testing.T) {
1114
tt := []struct {
@@ -482,3 +485,33 @@ func TestLevenshteinLessEqualDistanceWithCost(t *testing.T) {
482485
}
483486
}
484487
}
488+
489+
func TestLevenshtein_ExtremeValues(t *testing.T) {
490+
// Test all combinations of math.MinInt64 and math.MaxInt64 for integer
491+
// arguments. This ensures the function handles extreme values correctly
492+
// without panicking.
493+
extremeValues := []int{math.MinInt64, math.MaxInt64, 0, 1, -1, -6503603920424974249, -3160545599026710833, 3234088755759361354}
494+
testStrings := []string{"ab", "bc", "", "test"}
495+
496+
for _, source := range testStrings {
497+
for _, target := range testStrings {
498+
for _, insCost := range extremeValues {
499+
for _, delCost := range extremeValues {
500+
for _, subCost := range extremeValues {
501+
for _, maxDist := range extremeValues {
502+
// Call the functions and ensure it doesn't panic. We don't check
503+
// the exact result since extreme values may cause integer
504+
// overflow, but we ensure no panic occurs.
505+
_ = LevenshteinLessEqualDistanceWithCost(
506+
source, target, insCost, delCost, subCost, maxDist,
507+
)
508+
_ = LevenshteinDistanceWithCost(
509+
source, target, insCost, delCost, subCost,
510+
)
511+
}
512+
}
513+
}
514+
}
515+
}
516+
}
517+
}

0 commit comments

Comments
 (0)