Commit 4913f462 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: avoid panic in debug print routines

Add `isTest` to avoid panicking outside of test scenarios, in case we
mess up the flag definitions. The latter can easily happen, due to
subtle differences between architectures.

Change-Id: I4085de49e39eddf328269a7a3e694818c693e195
parent cb99d1d8
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
) )
var ( var (
isTest bool
writeFlagNames = newFlagNames([]flagNameEntry{ writeFlagNames = newFlagNames([]flagNameEntry{
{WRITE_CACHE, "CACHE"}, {WRITE_CACHE, "CACHE"},
{WRITE_LOCKOWNER, "LOCKOWNER"}, {WRITE_LOCKOWNER, "LOCKOWNER"},
...@@ -111,7 +112,7 @@ func (names *flagNames) set(flag int64, name string) { ...@@ -111,7 +112,7 @@ func (names *flagNames) set(flag int64, name string) {
entry := flagNameEntry{bits: flag, name: name} entry := flagNameEntry{bits: flag, name: name}
for i := 0; i < 64; i++ { for i := 0; i < 64; i++ {
if flag&(1<<i) != 0 { if flag&(1<<i) != 0 {
if ie := names[i]; ie.bits != 0 { if ie := names[i]; ie.bits != 0 && isTest {
panic(fmt.Sprintf("%s (%x) overlaps with %s (%x)", name, flag, ie.name, ie.bits)) panic(fmt.Sprintf("%s (%x) overlaps with %s (%x)", name, flag, ie.name, ie.bits))
} }
names[i] = entry names[i] = entry
......
...@@ -8,6 +8,10 @@ import ( ...@@ -8,6 +8,10 @@ import (
"testing" "testing"
) )
func init() {
isTest = true
}
// verify that flagString always formats flags in the same order. // verify that flagString always formats flags in the same order.
func TestFlagStringOrder(t *testing.T) { func TestFlagStringOrder(t *testing.T) {
var flags int64 = CAP_ASYNC_READ | CAP_SPLICE_WRITE | CAP_READDIRPLUS | CAP_MAX_PAGES | CAP_EXPLICIT_INVAL_DATA var flags int64 = CAP_ASYNC_READ | CAP_SPLICE_WRITE | CAP_READDIRPLUS | CAP_MAX_PAGES | CAP_EXPLICIT_INVAL_DATA
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment