Consider the case of Linux. We hope to use the getrandom syscall and then if that fails, we fall back to doing file I/O. We should test at least the following scenerios:
- Linux returns
ENOSYS, which should trigger the fallback to file I/O.
- Linux returns
EPERM, which is presently expected to do the same fallback, though there's an issue on file to change this.
- The syscall succeeds.
This type of exhaustive testing might not be practical on all targets. However, BoringSSL has shown how to do it on Linux; see https://boringssl.googlesource.com/boringssl/+/refs/heads/master/crypto/fipsmodule/rand/urandom_test.cc.
Backends with runtime fallback logic:
Consider the case of Linux. We hope to use the
getrandomsyscall and then if that fails, we fall back to doing file I/O. We should test at least the following scenerios:ENOSYS, which should trigger the fallback to file I/O.EPERM, which is presently expected to do the same fallback, though there's an issue on file to change this.This type of exhaustive testing might not be practical on all targets. However, BoringSSL has shown how to do it on Linux; see https://boringssl.googlesource.com/boringssl/+/refs/heads/master/crypto/fipsmodule/rand/urandom_test.cc.
Backends with runtime fallback logic:
linux_android_with_fallback(fallack to/dev/urandom, tested using thegetrandom_test_linux_fallbackconfiguration flag)netbsd(fallback toKERN_ARND, tested using thegetrandom_test_netbsd_fallbackconfiguration flag)wasm_js(runtime selection between Web and Node.js APIs, tested in CI)