| 1 |
// Copyright 2024 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 fipstest |
| 6 |
|
| 7 |
import ( |
| 8 |
"crypto/internal/fips140" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func TestIndicator(t *testing.T) { |
| 13 |
fips140.ResetServiceIndicator() |
| 14 |
if fips140.ServiceIndicator() { |
| 15 |
t.Error("indicator should be false if no calls are made") |
| 16 |
} |
| 17 |
|
| 18 |
fips140.ResetServiceIndicator() |
| 19 |
fips140.RecordApproved() |
| 20 |
if !fips140.ServiceIndicator() { |
| 21 |
t.Error("indicator should be true if RecordApproved is called") |
| 22 |
} |
| 23 |
|
| 24 |
fips140.ResetServiceIndicator() |
| 25 |
fips140.RecordApproved() |
| 26 |
fips140.RecordApproved() |
| 27 |
if !fips140.ServiceIndicator() { |
| 28 |
t.Error("indicator should be true if RecordApproved is called multiple times") |
| 29 |
} |
| 30 |
|
| 31 |
fips140.ResetServiceIndicator() |
| 32 |
fips140.RecordNonApproved() |
| 33 |
if fips140.ServiceIndicator() { |
| 34 |
t.Error("indicator should be false if RecordNonApproved is called") |
| 35 |
} |
| 36 |
|
| 37 |
fips140.ResetServiceIndicator() |
| 38 |
fips140.RecordApproved() |
| 39 |
fips140.RecordNonApproved() |
| 40 |
if fips140.ServiceIndicator() { |
| 41 |
t.Error("indicator should be false if both RecordApproved and RecordNonApproved are called") |
| 42 |
} |
| 43 |
|
| 44 |
fips140.ResetServiceIndicator() |
| 45 |
fips140.RecordNonApproved() |
| 46 |
fips140.RecordApproved() |
| 47 |
if fips140.ServiceIndicator() { |
| 48 |
t.Error("indicator should be false if both RecordNonApproved and RecordApproved are called") |
| 49 |
} |
| 50 |
|
| 51 |
fips140.ResetServiceIndicator() |
| 52 |
fips140.RecordNonApproved() |
| 53 |
done := make(chan struct{}) |
| 54 |
go func() { |
| 55 |
fips140.ResetServiceIndicator() |
| 56 |
fips140.RecordApproved() |
| 57 |
close(done) |
| 58 |
}() |
| 59 |
<-done |
| 60 |
if fips140.ServiceIndicator() { |
| 61 |
t.Error("indicator should be false if RecordApproved is called in a different goroutine") |
| 62 |
} |
| 63 |
|
| 64 |
fips140.ResetServiceIndicator() |
| 65 |
fips140.RecordApproved() |
| 66 |
done = make(chan struct{}) |
| 67 |
go func() { |
| 68 |
fips140.ResetServiceIndicator() |
| 69 |
fips140.RecordNonApproved() |
| 70 |
close(done) |
| 71 |
}() |
| 72 |
<-done |
| 73 |
if !fips140.ServiceIndicator() { |
| 74 |
t.Error("indicator should be true if RecordNonApproved is called in a different goroutine") |
| 75 |
} |
| 76 |
} |