Tweak urandom_test for Android devices without getrandom. Some Android devices in our builder pool are so old that they lack getrandom. This change attempts to make them happy. Change-Id: I5eea04f1b1dc599852e3b8448ad829bea05b9fe9 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/57527 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: Adam Langley <agl@google.com> Auto-Submit: Adam Langley <agl@google.com>
diff --git a/crypto/fipsmodule/rand/urandom_test.cc b/crypto/fipsmodule/rand/urandom_test.cc index c3f8240..b1732cf 100644 --- a/crypto/fipsmodule/rand/urandom_test.cc +++ b/crypto/fipsmodule/rand/urandom_test.cc
@@ -36,6 +36,7 @@ #include <sys/user.h> #include "fork_detect.h" +#include "getrandom_fillin.h" #if !defined(PTRACE_O_EXITKILL) #define PTRACE_O_EXITKILL (1 << 20) @@ -776,6 +777,12 @@ TEST(URandomTest, Test) { char buf[256]; + // Some Android systems lack getrandom. + uint8_t scratch[1]; + const bool has_getrandom = + (syscall(__NR_getrandom, scratch, sizeof(scratch), GRND_NONBLOCK) != -1 || + errno != ENOSYS); + #define TRACE_FLAG(flag) \ snprintf(buf, sizeof(buf), #flag ": %d", (flags & flag) != 0); \ SCOPED_TRACE(buf); @@ -788,6 +795,10 @@ continue; } + if (!has_getrandom && !(flags & NO_GETRANDOM)) { + continue; + } + TRACE_FLAG(NO_GETRANDOM); TRACE_FLAG(NO_URANDOM); TRACE_FLAG(GETRANDOM_NOT_READY);