Add test for urandom.c

This change adds a test to try and prevent errors like b8f760191e. Since
it's challenging to test this code, it uses ptrace to capture a trace of
the PRNG behaviour and checks that the observed behaviour matches a much
smaller model of the code. The model is hopefully easier to read and
believe correct.

Change-Id: I00b811dc5692e2fbe3dcc16c622d4eb706f16ce0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38265
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 57e5e1b..8a5df75 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -272,6 +272,8 @@
       self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
       self.PrintVariableSection(out, 'crypto_test_data',
                                 files['crypto_test_data'])
+      self.PrintVariableSection(out, 'urandom_test_sources',
+                                files['urandom_test'])
 
 
 class Eureka(object):
@@ -685,6 +687,12 @@
       'src/crypto/test/file_test_gtest.cc',
       'src/crypto/test/gtest_main.cc',
   ]
+  # urandom_test.cc is in a separate binary so that it can be test PRNG
+  # initialisation.
+  crypto_test_files = [
+      file for file in crypto_test_files
+      if not file.endswith('/urandom_test.cc')
+  ]
 
   ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
   ssl_test_files += [
@@ -692,6 +700,10 @@
       'src/crypto/test/gtest_main.cc',
   ]
 
+  urandom_test_files = [
+      'src/crypto/fipsmodule/rand/urandom_test.cc',
+  ]
+
   fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
 
   ssl_h_files = (
@@ -729,6 +741,7 @@
       'tool_headers': tool_h_files,
       'test_support': test_support_c_files,
       'test_support_headers': test_support_h_files,
+      'urandom_test': sorted(urandom_test_files),
   }
 
   asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())