File size: 2,014 Bytes
61bba11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fipstest
import (
"crypto/internal/fips140"
"testing"
)
func TestIndicator(t *testing.T) {
fips140.ResetServiceIndicator()
if fips140.ServiceIndicator() {
t.Error("indicator should be false if no calls are made")
}
fips140.ResetServiceIndicator()
fips140.RecordApproved()
if !fips140.ServiceIndicator() {
t.Error("indicator should be true if RecordApproved is called")
}
fips140.ResetServiceIndicator()
fips140.RecordApproved()
fips140.RecordApproved()
if !fips140.ServiceIndicator() {
t.Error("indicator should be true if RecordApproved is called multiple times")
}
fips140.ResetServiceIndicator()
fips140.RecordNonApproved()
if fips140.ServiceIndicator() {
t.Error("indicator should be false if RecordNonApproved is called")
}
fips140.ResetServiceIndicator()
fips140.RecordApproved()
fips140.RecordNonApproved()
if fips140.ServiceIndicator() {
t.Error("indicator should be false if both RecordApproved and RecordNonApproved are called")
}
fips140.ResetServiceIndicator()
fips140.RecordNonApproved()
fips140.RecordApproved()
if fips140.ServiceIndicator() {
t.Error("indicator should be false if both RecordNonApproved and RecordApproved are called")
}
fips140.ResetServiceIndicator()
fips140.RecordNonApproved()
done := make(chan struct{})
go func() {
fips140.ResetServiceIndicator()
fips140.RecordApproved()
close(done)
}()
<-done
if fips140.ServiceIndicator() {
t.Error("indicator should be false if RecordApproved is called in a different goroutine")
}
fips140.ResetServiceIndicator()
fips140.RecordApproved()
done = make(chan struct{})
go func() {
fips140.ResetServiceIndicator()
fips140.RecordNonApproved()
close(done)
}()
<-done
if !fips140.ServiceIndicator() {
t.Error("indicator should be true if RecordNonApproved is called in a different goroutine")
}
}
|