summaryrefslogtreecommitdiffhomepage
path: root/tools/checklocks/test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/checklocks/test')
-rw-r--r--tools/checklocks/test/BUILD30
-rw-r--r--tools/checklocks/test/aliases.go26
-rw-r--r--tools/checklocks/test/alignment.go51
-rw-r--r--tools/checklocks/test/anon.go35
-rw-r--r--tools/checklocks/test/atomics.go91
-rw-r--r--tools/checklocks/test/basics.go145
-rw-r--r--tools/checklocks/test/branches.go72
-rw-r--r--tools/checklocks/test/closures.go118
-rw-r--r--tools/checklocks/test/defer.go38
-rw-r--r--tools/checklocks/test/globals.go85
-rw-r--r--tools/checklocks/test/incompat.go45
-rw-r--r--tools/checklocks/test/inferred.go35
-rw-r--r--tools/checklocks/test/locker.go33
-rw-r--r--tools/checklocks/test/methods.go117
-rw-r--r--tools/checklocks/test/parameters.go48
-rw-r--r--tools/checklocks/test/return.go61
-rw-r--r--tools/checklocks/test/rwmutex.go52
-rw-r--r--tools/checklocks/test/test.go64
18 files changed, 0 insertions, 1146 deletions
diff --git a/tools/checklocks/test/BUILD b/tools/checklocks/test/BUILD
deleted file mode 100644
index 21a68fbdf..000000000
--- a/tools/checklocks/test/BUILD
+++ /dev/null
@@ -1,30 +0,0 @@
-load("//tools:defs.bzl", "go_library")
-
-package(licenses = ["notice"])
-
-go_library(
- name = "test",
- srcs = [
- "aliases.go",
- "alignment.go",
- "anon.go",
- "atomics.go",
- "basics.go",
- "branches.go",
- "closures.go",
- "defer.go",
- "globals.go",
- "incompat.go",
- "inferred.go",
- "locker.go",
- "methods.go",
- "parameters.go",
- "return.go",
- "rwmutex.go",
- "test.go",
- ],
- # This ensures that there are no dependencies, since we want to explicitly
- # control expected failures for analysis.
- marshal = False,
- stateify = False,
-)
diff --git a/tools/checklocks/test/aliases.go b/tools/checklocks/test/aliases.go
deleted file mode 100644
index e28027fe5..000000000
--- a/tools/checklocks/test/aliases.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2021 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-// +checklocks:tc.mu
-// +checklocksalias:tc2.mu=tc.mu
-func testAliasValid(tc *oneGuardStruct, tc2 *oneGuardStruct) {
- tc2.guardedField = 1
-}
-
-// +checklocks:tc.mu
-func testAliasInvalid(tc *oneGuardStruct, tc2 *oneGuardStruct) {
- tc2.guardedField = 1 // +checklocksfail
-}
diff --git a/tools/checklocks/test/alignment.go b/tools/checklocks/test/alignment.go
deleted file mode 100644
index cd857ff73..000000000
--- a/tools/checklocks/test/alignment.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-type alignedStruct32 struct {
- v int32
-}
-
-type alignedStruct64 struct {
- v int64
-}
-
-type alignedStructGood struct {
- v0 alignedStruct32
- v1 alignedStruct32
- v2 alignedStruct64
-}
-
-type alignedStructGoodArray0 struct {
- v0 [3]alignedStruct32
- v1 [3]alignedStruct32
- v2 alignedStruct64
-}
-
-type alignedStructGoodArray1 [16]alignedStructGood
-
-type alignedStructBad struct {
- v0 alignedStruct32
- v1 alignedStruct64
- v2 alignedStruct32
-}
-
-type alignedStructBadArray0 struct {
- v0 [3]alignedStruct32
- v1 [2]alignedStruct64
- v2 [1]alignedStruct32
-}
-
-type alignedStructBadArray1 [16]alignedStructBad
diff --git a/tools/checklocks/test/anon.go b/tools/checklocks/test/anon.go
deleted file mode 100644
index a1f6bddda..000000000
--- a/tools/checklocks/test/anon.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2021 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import "sync"
-
-type anonStruct struct {
- anon struct {
- mu sync.RWMutex
- // +checklocks:mu
- x int
- }
-}
-
-func testAnonAccessValid(tc *anonStruct) {
- tc.anon.mu.Lock()
- tc.anon.x = 1
- tc.anon.mu.Unlock()
-}
-
-func testAnonAccessInvalid(tc *anonStruct) {
- tc.anon.x = 1 // +checklocksfail
-}
diff --git a/tools/checklocks/test/atomics.go b/tools/checklocks/test/atomics.go
deleted file mode 100644
index 8e060d8a2..000000000
--- a/tools/checklocks/test/atomics.go
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
- "sync/atomic"
-)
-
-type atomicStruct struct {
- accessedNormally int32
-
- // +checkatomic
- accessedAtomically int32
-
- // +checklocksignore
- ignored int32
-}
-
-func testNormalAccess(tc *atomicStruct, v chan int32, p chan *int32) {
- v <- tc.accessedNormally
- p <- &tc.accessedNormally
-}
-
-func testAtomicAccess(tc *atomicStruct, v chan int32) {
- v <- atomic.LoadInt32(&tc.accessedAtomically)
-}
-
-func testAtomicAccessInvalid(tc *atomicStruct, v chan int32) {
- v <- atomic.LoadInt32(&tc.accessedNormally) // +checklocksfail
-}
-
-func testNormalAccessInvalid(tc *atomicStruct, v chan int32, p chan *int32) {
- v <- tc.accessedAtomically // +checklocksfail
- p <- &tc.accessedAtomically // +checklocksfail
-}
-
-func testIgnored(tc *atomicStruct, v chan int32, p chan *int32) {
- v <- atomic.LoadInt32(&tc.ignored)
- v <- tc.ignored
- p <- &tc.ignored
-}
-
-type atomicMixedStruct struct {
- mu sync.Mutex
-
- // +checkatomic
- // +checklocks:mu
- accessedMixed int32
-}
-
-func testAtomicMixedValidRead(tc *atomicMixedStruct, v chan int32) {
- v <- atomic.LoadInt32(&tc.accessedMixed)
-}
-
-func testAtomicMixedInvalidRead(tc *atomicMixedStruct, v chan int32, p chan *int32) {
- v <- tc.accessedMixed // +checklocksfail
- p <- &tc.accessedMixed // +checklocksfail
-}
-
-func testAtomicMixedValidLockedWrite(tc *atomicMixedStruct, v chan int32, p chan *int32) {
- tc.mu.Lock()
- atomic.StoreInt32(&tc.accessedMixed, 1)
- tc.mu.Unlock()
-}
-
-func testAtomicMixedInvalidLockedWrite(tc *atomicMixedStruct, v chan int32, p chan *int32) {
- tc.mu.Lock()
- tc.accessedMixed = 1 // +checklocksfail:2
- tc.mu.Unlock()
-}
-
-func testAtomicMixedInvalidAtomicWrite(tc *atomicMixedStruct, v chan int32, p chan *int32) {
- atomic.StoreInt32(&tc.accessedMixed, 1) // +checklocksfail
-}
-
-func testAtomicMixedInvalidWrite(tc *atomicMixedStruct, v chan int32, p chan *int32) {
- tc.accessedMixed = 1 // +checklocksfail:2
-}
diff --git a/tools/checklocks/test/basics.go b/tools/checklocks/test/basics.go
deleted file mode 100644
index e941fba5b..000000000
--- a/tools/checklocks/test/basics.go
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-func testLockedAccessValid(tc *oneGuardStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-func testLockedAccessIgnore(tc *oneGuardStruct) {
- tc.mu.Lock()
- tc.unguardedField = 1
- tc.mu.Unlock()
-}
-
-func testUnlockedAccessInvalidWrite(tc *oneGuardStruct) {
- tc.guardedField = 2 // +checklocksfail
-}
-
-func testUnlockedAccessInvalidRead(tc *oneGuardStruct) {
- x := tc.guardedField // +checklocksfail
- _ = x
-}
-
-func testUnlockedAccessValid(tc *oneGuardStruct) {
- tc.unguardedField = 2
-}
-
-func testCallValidAccess(tc *oneGuardStruct) {
- callValidAccess(tc)
-}
-
-func callValidAccess(tc *oneGuardStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-func testCallValueMixup(tc *oneGuardStruct) {
- callValueMixup(tc, tc)
-}
-
-func callValueMixup(tc1, tc2 *oneGuardStruct) {
- tc1.mu.Lock()
- tc2.guardedField = 2 // +checklocksfail
- tc1.mu.Unlock()
-}
-
-func testCallPreconditionsInvalid(tc *oneGuardStruct) {
- callPreconditions(tc) // +checklocksfail
-}
-
-func testCallPreconditionsValid(tc *oneGuardStruct) {
- tc.mu.Lock()
- callPreconditions(tc)
- tc.mu.Unlock()
-}
-
-// +checklocks:tc.mu
-func callPreconditions(tc *oneGuardStruct) {
- tc.guardedField = 1
-}
-
-type nestedFieldsStruct struct {
- mu sync.Mutex
-
- // +checklocks:mu
- nestedStruct struct {
- nested1 int
- nested2 int
- }
-}
-
-func testNestedGuardValid(tc *nestedFieldsStruct) {
- tc.mu.Lock()
- tc.nestedStruct.nested1 = 1
- tc.nestedStruct.nested2 = 2
- tc.mu.Unlock()
-}
-
-func testNestedGuardInvalid(tc *nestedFieldsStruct) {
- tc.nestedStruct.nested1 = 1 // +checklocksfail
-}
-
-type rwGuardStruct struct {
- rwMu sync.RWMutex
-
- // +checklocks:rwMu
- guardedField int
-}
-
-func testRWValidRead(tc *rwGuardStruct) {
- tc.rwMu.Lock()
- _ = tc.guardedField
- tc.rwMu.Unlock()
-}
-
-func testRWValidWrite(tc *rwGuardStruct) {
- tc.rwMu.Lock()
- tc.guardedField = 2
- tc.rwMu.Unlock()
-}
-
-func testRWInvalidWrite(tc *rwGuardStruct) {
- tc.guardedField = 3 // +checklocksfail
-}
-
-func testRWInvalidRead(tc *rwGuardStruct) {
- x := tc.guardedField + 3 // +checklocksfail
- _ = x
-}
-
-func testTwoLocksDoubleGuardStructValid(tc *twoLocksDoubleGuardStruct) {
- tc.mu.Lock()
- tc.secondMu.Lock()
- tc.doubleGuardedField = 1
- tc.secondMu.Unlock()
-}
-
-func testTwoLocksDoubleGuardStructOnlyOne(tc *twoLocksDoubleGuardStruct) {
- tc.mu.Lock()
- tc.doubleGuardedField = 2 // +checklocksfail
- tc.mu.Unlock()
-}
-
-func testTwoLocksDoubleGuardStructInvalid(tc *twoLocksDoubleGuardStruct) {
- tc.doubleGuardedField = 3 // +checklocksfail:2
-}
diff --git a/tools/checklocks/test/branches.go b/tools/checklocks/test/branches.go
deleted file mode 100644
index 247885a49..000000000
--- a/tools/checklocks/test/branches.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "math/rand"
-)
-
-func testInconsistentReturn(tc *oneGuardStruct) { // +checklocksfail
- if x := rand.Intn(10); x%2 == 1 {
- tc.mu.Lock()
- }
-}
-
-func testConsistentBranching(tc *oneGuardStruct) {
- x := rand.Intn(10)
- if x%2 == 1 {
- tc.mu.Lock()
- } else {
- tc.mu.Lock()
- }
- tc.guardedField = 1
- if x%2 == 1 {
- tc.mu.Unlock()
- } else {
- tc.mu.Unlock()
- }
-}
-
-func testInconsistentBranching(tc *oneGuardStruct) { // +checklocksfail:2
- // We traverse the control flow graph in all consistent ways. We cannot
- // determine however, that the first if block and second if block will
- // evaluate to the same condition. Therefore, there are two consistent
- // paths through this code, and two inconsistent paths. Either way, the
- // guardedField should be also marked as an invalid access.
- x := rand.Intn(10)
- if x%2 == 1 {
- tc.mu.Lock()
- }
- tc.guardedField = 1 // +checklocksfail
- if x%2 == 1 {
- tc.mu.Unlock() // +checklocksforce
- }
-}
-
-func testUnboundedLocks(tc []*oneGuardStruct) {
- for _, l := range tc {
- l.mu.Lock()
- }
- // This test should have the above *not fail*, though the exact
- // lock state cannot be tracked through the below. Therefore, we
- // expect the next loop to actually fail, and we force the unlock
- // loop to succeed in exactly the same way.
- for _, l := range tc {
- l.guardedField = 1 // +checklocksfail
- }
- for _, l := range tc {
- l.mu.Unlock() // +checklocksforce
- }
-}
diff --git a/tools/checklocks/test/closures.go b/tools/checklocks/test/closures.go
deleted file mode 100644
index 316d12ce1..000000000
--- a/tools/checklocks/test/closures.go
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-func testClosureInvalid(tc *oneGuardStruct) {
- // This is expected to fail.
- callClosure(func() {
- tc.guardedField = 1 // +checklocksfail
- })
-}
-
-func testClosureUnsupported(tc *oneGuardStruct) {
- // Locked outside the closure, so may or may not be valid. This cannot
- // be handled and we should explicitly fail. This can't be handled
- // because of the call through callClosure, below, which means the
- // closure will actually be passed as a value somewhere.
- tc.mu.Lock()
- callClosure(func() {
- tc.guardedField = 1 // +checklocksfail
- })
- tc.mu.Unlock()
-}
-
-func testClosureValid(tc *oneGuardStruct) {
- // All locking happens within the closure. This should not present a
- // problem for analysis.
- callClosure(func() {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
- })
-}
-
-func testClosureInline(tc *oneGuardStruct) {
- // If the closure is being dispatching inline only, then we should be
- // able to analyze this call and give it a thumbs up.
- tc.mu.Lock()
- func() {
- tc.guardedField = 1
- }()
- tc.mu.Unlock()
-}
-
-// +checklocksignore
-func testClosureIgnore(tc *oneGuardStruct) {
- // Inherit the checklocksignore.
- x := func() {
- tc.guardedField = 1
- }
- x()
-}
-
-func testAnonymousInvalid(tc *oneGuardStruct) {
- // Invalid, as per testClosureInvalid above.
- callAnonymous(func(tc *oneGuardStruct) {
- tc.guardedField = 1 // +checklocksfail
- }, tc)
-}
-
-func testAnonymousUnsupported(tc *oneGuardStruct) {
- // Not supportable, as per testClosureUnsupported above.
- tc.mu.Lock()
- callAnonymous(func(tc *oneGuardStruct) {
- tc.guardedField = 1 // +checklocksfail
- }, tc)
- tc.mu.Unlock()
-}
-
-func testAnonymousValid(tc *oneGuardStruct) {
- // Valid, as per testClosureValid above.
- callAnonymous(func(tc *oneGuardStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
- }, tc)
-}
-
-func testAnonymousInline(tc *oneGuardStruct) {
- // Unlike the closure case, we are able to dynamically infer the set of
- // preconditions for the function dispatch and assert that this is
- // a valid call.
- tc.mu.Lock()
- func(tc *oneGuardStruct) {
- tc.guardedField = 1
- }(tc)
- tc.mu.Unlock()
-}
-
-// +checklocksignore
-func testAnonymousIgnore(tc *oneGuardStruct) {
- // Inherit the checklocksignore.
- x := func(tc *oneGuardStruct) {
- tc.guardedField = 1
- }
- x(tc)
-}
-
-//go:noinline
-func callClosure(fn func()) {
- fn()
-}
-
-//go:noinline
-func callAnonymous(fn func(*oneGuardStruct), tc *oneGuardStruct) {
- fn(tc)
-}
diff --git a/tools/checklocks/test/defer.go b/tools/checklocks/test/defer.go
deleted file mode 100644
index 6e574e5eb..000000000
--- a/tools/checklocks/test/defer.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-func testDeferValidUnlock(tc *oneGuardStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- defer tc.mu.Unlock()
-}
-
-func testDeferValidAccess(tc *oneGuardStruct) {
- tc.mu.Lock()
- defer func() {
- tc.guardedField = 1
- tc.mu.Unlock()
- }()
-}
-
-func testDeferInvalidAccess(tc *oneGuardStruct) {
- tc.mu.Lock()
- defer func() {
- // N.B. Executed after tc.mu.Unlock().
- tc.guardedField = 1 // +checklocksfail
- }()
- tc.mu.Unlock()
-}
diff --git a/tools/checklocks/test/globals.go b/tools/checklocks/test/globals.go
deleted file mode 100644
index 656b0c9a3..000000000
--- a/tools/checklocks/test/globals.go
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-var (
- globalMu sync.Mutex
- globalRWMu sync.RWMutex
-)
-
-var globalStruct struct {
- mu sync.Mutex
- // +checklocks:mu
- guardedField int
-}
-
-var otherStruct struct {
- // +checklocks:globalMu
- guardedField1 int
- // +checklocks:globalRWMu
- guardedField2 int
- // +checklocks:globalStruct.mu
- guardedField3 int
-}
-
-func testGlobalValid() {
- globalMu.Lock()
- otherStruct.guardedField1 = 1
- globalMu.Unlock()
-
- globalRWMu.Lock()
- otherStruct.guardedField2 = 1
- globalRWMu.Unlock()
-
- globalRWMu.RLock()
- _ = otherStruct.guardedField2
- globalRWMu.RUnlock()
-
- globalStruct.mu.Lock()
- globalStruct.guardedField = 1
- otherStruct.guardedField3 = 1
- globalStruct.mu.Unlock()
-}
-
-// +checklocks:globalStruct.mu
-func testGlobalValidPreconditions0() {
- globalStruct.guardedField = 1
-}
-
-// +checklocks:globalMu
-func testGlobalValidPreconditions1() {
- otherStruct.guardedField1 = 1
-}
-
-// +checklocks:globalRWMu
-func testGlobalValidPreconditions2() {
- otherStruct.guardedField2 = 1
-}
-
-// +checklocks:globalStruct.mu
-func testGlobalValidPreconditions3() {
- otherStruct.guardedField3 = 1
-}
-
-func testGlobalInvalid() {
- globalStruct.guardedField = 1 // +checklocksfail
- otherStruct.guardedField1 = 1 // +checklocksfail
- otherStruct.guardedField2 = 1 // +checklocksfail
- otherStruct.guardedField3 = 1 // +checklocksfail
-}
diff --git a/tools/checklocks/test/incompat.go b/tools/checklocks/test/incompat.go
deleted file mode 100644
index f55fa532d..000000000
--- a/tools/checklocks/test/incompat.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-// badFieldsStruct verifies that refering invalid fields fails.
-type badFieldsStruct struct {
- // +checklocks:mu
- x int // +checklocksfail
-}
-
-// redundantStruct verifies that redundant annotations fail.
-type redundantStruct struct {
- mu sync.Mutex
-
- // +checklocks:mu
- // +checklocks:mu
- x int // +checklocksfail
-}
-
-// conflictsStruct verifies that conflicting annotations fail.
-type conflictsStruct struct {
- // +checkatomicignore
- // +checkatomic
- x int // +checklocksfail
-
- // +checkatomic
- // +checkatomicignore
- y int // +checklocksfail
-}
diff --git a/tools/checklocks/test/inferred.go b/tools/checklocks/test/inferred.go
deleted file mode 100644
index 5495bdb2a..000000000
--- a/tools/checklocks/test/inferred.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-type inferredStruct struct {
- mu sync.Mutex
- guardedField int // +checklocksfail
- unguardedField int
-}
-
-func testInferredPositive(tc *inferredStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-func testInferredNegative(tc *inferredStruct) {
- tc.unguardedField = 1
-}
diff --git a/tools/checklocks/test/locker.go b/tools/checklocks/test/locker.go
deleted file mode 100644
index b0e7d1143..000000000
--- a/tools/checklocks/test/locker.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2021 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import "sync"
-
-type lockerStruct struct {
- mu sync.Locker
- // +checklocks:mu
- guardedField int
-}
-
-func testLockerValid(tc *lockerStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-func testLockerInvalid(tc *lockerStruct) {
- tc.guardedField = 1 // +checklocksfail
-}
diff --git a/tools/checklocks/test/methods.go b/tools/checklocks/test/methods.go
deleted file mode 100644
index b67657b61..000000000
--- a/tools/checklocks/test/methods.go
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-type testMethods struct {
- mu sync.Mutex
-
- // +checklocks:mu
- guardedField int
-}
-
-func (t *testMethods) methodValid() {
- t.mu.Lock()
- t.guardedField = 1
- t.mu.Unlock()
-}
-
-func (t *testMethods) methodInvalid() {
- t.guardedField = 2 // +checklocksfail
-}
-
-// +checklocks:t.mu
-func (t *testMethods) MethodLocked(a, b, c int) {
- t.guardedField = 3
-}
-
-// +checklocksignore
-func (t *testMethods) methodIgnore() {
- t.guardedField = 2
-}
-
-func testMethodCallsValid(tc *testMethods) {
- tc.methodValid()
-}
-
-func testMethodCallsValidPreconditions(tc *testMethods) {
- tc.mu.Lock()
- tc.MethodLocked(1, 2, 3)
- tc.mu.Unlock()
-}
-
-func testMethodCallsInvalid(tc *testMethods) {
- tc.MethodLocked(4, 5, 6) // +checklocksfail
-}
-
-func testMultipleParameters(tc1, tc2, tc3 *testMethods) {
- tc1.mu.Lock()
- tc1.guardedField = 1
- tc2.guardedField = 2 // +checklocksfail
- tc3.guardedField = 3 // +checklocksfail
- tc1.mu.Unlock()
-}
-
-type testMethodsWithParameters struct {
- mu sync.Mutex
-
- // +checklocks:mu
- guardedField int
-}
-
-type ptrToTestMethodsWithParameters *testMethodsWithParameters
-
-// +checklocks:t.mu
-// +checklocks:a.mu
-func (t *testMethodsWithParameters) methodLockedWithParameters(a *testMethodsWithParameters, b *testMethodsWithParameters) {
- t.guardedField = a.guardedField
- b.guardedField = a.guardedField // +checklocksfail
-}
-
-// +checklocks:t.mu
-// +checklocks:a.mu
-// +checklocks:b.mu
-func (t *testMethodsWithParameters) methodLockedWithPtrType(a *testMethodsWithParameters, b ptrToTestMethodsWithParameters) {
- t.guardedField = a.guardedField
- b.guardedField = a.guardedField
-}
-
-// +checklocks:a.mu
-func standaloneFunctionWithGuard(a *testMethodsWithParameters) {
- a.guardedField = 1
- a.mu.Unlock()
- a.guardedField = 1 // +checklocksfail
-}
-
-type testMethodsWithEmbedded struct {
- mu sync.Mutex
-
- // +checklocks:mu
- guardedField int
- p *testMethodsWithParameters // +checklocksignore: Inferred as protected by mu.
-}
-
-// +checklocks:t.mu
-func (t *testMethodsWithEmbedded) DoLocked(a, b *testMethodsWithParameters) {
- t.guardedField = 1
- a.mu.Lock()
- b.mu.Lock()
- t.p.methodLockedWithParameters(a, b) // +checklocksfail
- a.mu.Unlock()
- b.mu.Unlock()
-}
diff --git a/tools/checklocks/test/parameters.go b/tools/checklocks/test/parameters.go
deleted file mode 100644
index 5b9e664b6..000000000
--- a/tools/checklocks/test/parameters.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-func testParameterPassingbyAddrValid(tc *oneGuardStruct) {
- tc.mu.Lock()
- nestedWithGuardByAddr(&tc.guardedField, &tc.unguardedField)
- tc.mu.Unlock()
-}
-
-func testParameterPassingByAddrInalid(tc *oneGuardStruct) {
- nestedWithGuardByAddr(&tc.guardedField, &tc.unguardedField) // +checklocksfail
-}
-
-func testParameterPassingByValueValid(tc *oneGuardStruct) {
- tc.mu.Lock()
- nestedWithGuardByValue(tc.guardedField, tc.unguardedField)
- tc.mu.Unlock()
-}
-
-func testParameterPassingByValueInalid(tc *oneGuardStruct) {
- nestedWithGuardByValue(tc.guardedField, tc.unguardedField) // +checklocksfail
-}
-
-func nestedWithGuardByAddr(guardedField, unguardedField *int) {
- *guardedField = 4
- *unguardedField = 5
-}
-
-func nestedWithGuardByValue(guardedField, unguardedField int) {
- // read the fields to keep SA4009 static analyzer happy.
- _ = guardedField
- _ = unguardedField
- guardedField = 4
- unguardedField = 5
-}
diff --git a/tools/checklocks/test/return.go b/tools/checklocks/test/return.go
deleted file mode 100644
index 47c7b6773..000000000
--- a/tools/checklocks/test/return.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-// +checklocks:tc.mu
-func testReturnInvalidGuard() (tc *oneGuardStruct) { // +checklocksfail
- return new(oneGuardStruct)
-}
-
-// +checklocksrelease:tc.mu
-func testReturnInvalidRelease() (tc *oneGuardStruct) { // +checklocksfail
- return new(oneGuardStruct)
-}
-
-// +checklocksacquire:tc.mu
-func testReturnInvalidAcquire() (tc *oneGuardStruct) {
- return new(oneGuardStruct) // +checklocksfail
-}
-
-// +checklocksacquire:tc.mu
-func testReturnValidAcquire() (tc *oneGuardStruct) {
- tc = new(oneGuardStruct)
- tc.mu.Lock()
- return tc
-}
-
-func testReturnAcquireCall() {
- tc := testReturnValidAcquire()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-// +checklocksacquire:tc.val.mu
-// +checklocksacquire:tc.ptr.mu
-func testReturnValidNestedAcquire() (tc *nestedGuardStruct) {
- tc = new(nestedGuardStruct)
- tc.ptr = new(oneGuardStruct)
- tc.val.mu.Lock()
- tc.ptr.mu.Lock()
- return tc
-}
-
-func testReturnNestedAcquireCall() {
- tc := testReturnValidNestedAcquire()
- tc.val.guardedField = 1
- tc.ptr.guardedField = 1
- tc.val.mu.Unlock()
- tc.ptr.mu.Unlock()
-}
diff --git a/tools/checklocks/test/rwmutex.go b/tools/checklocks/test/rwmutex.go
deleted file mode 100644
index d27ed10e3..000000000
--- a/tools/checklocks/test/rwmutex.go
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2021 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package test
-
-import (
- "sync"
-)
-
-// oneReadGuardStruct has one read-guarded field.
-type oneReadGuardStruct struct {
- mu sync.RWMutex
- // +checklocks:mu
- guardedField int
-}
-
-func testRWAccessValidRead(tc *oneReadGuardStruct) {
- tc.mu.Lock()
- _ = tc.guardedField
- tc.mu.Unlock()
- tc.mu.RLock()
- _ = tc.guardedField
- tc.mu.RUnlock()
-}
-
-func testRWAccessValidWrite(tc *oneReadGuardStruct) {
- tc.mu.Lock()
- tc.guardedField = 1
- tc.mu.Unlock()
-}
-
-func testRWAccessInvalidWrite(tc *oneReadGuardStruct) {
- tc.guardedField = 2 // +checklocksfail
- tc.mu.RLock()
- tc.guardedField = 2 // +checklocksfail
- tc.mu.RUnlock()
-}
-
-func testRWAccessInvalidRead(tc *oneReadGuardStruct) {
- _ = tc.guardedField // +checklocksfail
-}
diff --git a/tools/checklocks/test/test.go b/tools/checklocks/test/test.go
deleted file mode 100644
index d1a9992fb..000000000
--- a/tools/checklocks/test/test.go
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Package test is a test package.
-//
-// Tests are all compilation tests in separate files.
-package test
-
-import (
- "sync"
-)
-
-// oneGuardStruct has one guarded field.
-type oneGuardStruct struct {
- mu sync.Mutex
- // +checklocks:mu
- guardedField int
- unguardedField int
-}
-
-// twoGuardStruct has two guarded fields.
-type twoGuardStruct struct {
- mu sync.Mutex
- // +checklocks:mu
- guardedField1 int
- // +checklocks:mu
- guardedField2 int
-}
-
-// twoLocksStruct has two locks and two fields.
-type twoLocksStruct struct {
- mu sync.Mutex
- secondMu sync.Mutex
- // +checklocks:mu
- guardedField1 int
- // +checklocks:secondMu
- guardedField2 int
-}
-
-// twoLocksDoubleGuardStruct has two locks and a single field with two guards.
-type twoLocksDoubleGuardStruct struct {
- mu sync.Mutex
- secondMu sync.Mutex // +checklocksignore: mu is inferred as requisite.
- // +checklocks:mu
- // +checklocks:secondMu
- doubleGuardedField int
-}
-
-// nestedGuardStruct nests oneGuardStruct fields.
-type nestedGuardStruct struct {
- val oneGuardStruct
- ptr *oneGuardStruct
-}