...

Source file src/runtime/lockrank_test.go

Documentation: runtime

		 1  // Copyright 2021 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  package runtime_test
		 6  
		 7  import (
		 8  	. "runtime"
		 9  	"testing"
		10  )
		11  
		12  // Check that the partial order in lockPartialOrder fits within the total order
		13  // determined by the order of the lockRank constants.
		14  func TestLockRankPartialOrder(t *testing.T) {
		15  	for r, list := range LockPartialOrder {
		16  		rank := LockRank(r)
		17  		for _, e := range list {
		18  			entry := LockRank(e)
		19  			if entry > rank {
		20  				t.Errorf("lockPartialOrder row %v entry %v is inconsistent with total lock ranking order", rank, entry)
		21  			}
		22  		}
		23  	}
		24  }
		25  
		26  // Verify that partial order lists are kept sorted. This is a purely cosemetic
		27  // check to make manual reviews simpler. It does not affect correctness, unlike
		28  // the above test.
		29  func TestLockRankPartialOrderSortedEntries(t *testing.T) {
		30  	for r, list := range LockPartialOrder {
		31  		rank := LockRank(r)
		32  		var prev LockRank
		33  		for _, e := range list {
		34  			entry := LockRank(e)
		35  			if entry <= prev {
		36  				t.Errorf("Partial order for rank %v out of order: %v <= %v in %v", rank, entry, prev, list)
		37  			}
		38  			prev = entry
		39  		}
		40  	}
		41  }
		42  

View as plain text