Skip to content

Commit c534fa1

Browse files
dkegel-fastlydeadprogram
authored andcommitted
On baremetal platforms, use simpler test matcher. Fixes #2666.
Uses same matcher in testdata (because now we can't replace it in testdata).
1 parent eed7833 commit c534fa1

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

src/testing/is_baremetal.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
//go:build baremetal
6+
// +build baremetal
7+
8+
package testing
9+
10+
const isBaremetal = true

src/testing/is_not_baremetal.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
//go:build !baremetal
6+
// +build !baremetal
7+
8+
package testing
9+
10+
const isBaremetal = false

src/testing/match.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ type matcher struct {
2626
var matchMutex sync.Mutex
2727

2828
func newMatcher(matchString func(pat, str string) (bool, error), patterns, name string) *matcher {
29+
if isBaremetal {
30+
// Probably not enough ram to load regexp, substitute something simpler.
31+
matchString = fakeMatchString
32+
}
33+
2934
var filter []string
3035
if patterns != "" {
3136
filter = splitRegexp(patterns)
@@ -166,3 +171,14 @@ func isSpace(r rune) bool {
166171
}
167172
return false
168173
}
174+
175+
// A fake regexp matcher.
176+
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
177+
// and lets tests pass on cortex-m.
178+
func fakeMatchString(pat, str string) (bool, error) {
179+
if pat == ".*" {
180+
return true, nil
181+
}
182+
matched := strings.Contains(str, pat)
183+
return matched, nil
184+
}

testdata/testing.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"flag"
88
"io"
9+
"strings"
910
"testing"
1011
)
1112

@@ -32,7 +33,7 @@ func TestAllLowercase(t *testing.T) {
3233
"alpha",
3334
"BETA",
3435
"gamma",
35-
"DELTA",
36+
"BELTA",
3637
}
3738

3839
for _, name := range names {
@@ -56,23 +57,22 @@ var benchmarks = []testing.InternalBenchmark{}
5657

5758
var examples = []testing.InternalExample{}
5859

59-
// A fake regexp matcher that can only handle two patterns.
60+
// A fake regexp matcher.
6061
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
61-
// and lets tests pass on cortex-m3.
62+
// and lets tests pass on cortex-m.
63+
// Must match the one in src/testing/match.go that is substituted on bare-metal platforms,
64+
// or "make test" will fail there.
6265
func fakeMatchString(pat, str string) (bool, error) {
6366
if pat == ".*" {
6467
return true, nil
6568
}
66-
if pat == "[BD]" {
67-
return (str[0] == 'B' || str[0] == 'D'), nil
68-
}
69-
println("BUG: fakeMatchString does not grok", pat)
70-
return false, nil
69+
matched := strings.Contains(str, pat)
70+
return matched, nil
7171
}
7272

7373
func main() {
7474
testing.Init()
75-
flag.Set("test.run", ".*/[BD]")
75+
flag.Set("test.run", ".*/B")
7676
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
7777

7878
exitcode := m.Run()

testdata/testing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
--- FAIL: TestAllLowercase (0.00s)
1616
--- FAIL: TestAllLowercase/BETA (0.00s)
1717
expected lowercase name, got BETA
18-
--- FAIL: TestAllLowercase/DELTA (0.00s)
19-
expected lowercase name, got DELTA
18+
--- FAIL: TestAllLowercase/BELTA (0.00s)
19+
expected lowercase name, got BELTA
2020
FAIL
2121
exitcode: 1

0 commit comments

Comments
 (0)