Use sources.cmake for test binaries

CMake and the generate builds now broadly share a source of truth for
the test files.

Update-Note: In the standalone CMake build, build/crypto/crypto_test is
now build/crypto_test, etc. For now, the build still copies the outputs
to the subdirectories (it's cheap and avoids some workflow turbulence),
but I'm thinking we keep that for six months or so and then remove it.

Bug: 542
Change-Id: I8f97e1fcedea1375d48567dfd2da01a6e66ec4e8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61286
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
chromium-stable
David Benjamin 1 year ago committed by Boringssl LUCI CQ
parent 8e8f87ea94
commit 197b57154f
  1. 27
      CMakeLists.txt
  2. 12
      cmake/paths.cmake
  3. 85
      crypto/CMakeLists.txt
  4. 1
      crypto/test/CMakeLists.txt
  5. 14
      decrepit/CMakeLists.txt
  6. 94
      sources.cmake
  7. 10
      ssl/CMakeLists.txt
  8. 24
      util/all_tests.json
  9. 30
      util/generate_build_files.py

@ -520,6 +520,26 @@ add_subdirectory(util/fipstools)
add_subdirectory(util/fipstools/acvp/modulewrapper)
add_subdirectory(decrepit)
# urandom_test is a separate binary because it needs to be able to observe the
# PRNG initialisation, which means that it can't have other tests running before
# it does.
add_executable(urandom_test ${URANDOM_TEST_SOURCES})
target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto)
add_dependencies(all_tests urandom_test)
add_executable(crypto_test ${CRYPTO_TEST_SOURCES} $<TARGET_OBJECTS:crypto_test_data>)
target_link_libraries(crypto_test test_support_lib boringssl_gtest_main crypto)
add_dependencies(all_tests crypto_test)
add_executable(ssl_test ${SSL_TEST_SOURCES})
target_link_libraries(ssl_test test_support_lib boringssl_gtest_main ssl crypto)
add_dependencies(all_tests ssl_test)
add_executable(decrepit_test ${DECREPIT_TEST_SOURCES})
target_link_libraries(decrepit_test test_support_lib boringssl_gtest_main
decrepit crypto)
add_dependencies(all_tests decrepit_test)
if(APPLE)
set(PKI_CXX_FLAGS "-fno-aligned-new")
endif()
@ -541,6 +561,13 @@ set_target_properties(
CXX_STANDARD_REQUIRED YES
COMPILE_FLAGS "${PKI_CXX_FLAGS}")
# Historically, targets were built in subdirectories. For compatibility with
# existing tools, we, for now, copy the targets into the subdirectories. This
# will be removed sometime in 2024.
copy_post_build(crypto crypto_test urandom_test)
copy_post_build(ssl ssl_test)
copy_post_build(decrepit decrepit_test)
if(FUZZ)
if(LIBFUZZER_FROM_DEPS)
file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")

@ -9,3 +9,15 @@ function(binary_dir_relative_path cur_bin_dir_relative outvar)
string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}/${cur_bin_dir_relative}" ${root_dir_length} -1 result)
set(${outvar} ${result} PARENT_SCOPE)
endfunction()
# copy_post_build causes targets in ${ARGN} to be copied to
# ${CMAKE_CURRENT_BINARY_DIR}/${dir} after being built.
function(copy_post_build dir)
foreach(target ${ARGN})
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${dir}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> "${CMAKE_CURRENT_BINARY_DIR}/${dir}")
endforeach()
endfunction()

@ -345,88 +345,3 @@ endif()
if(USE_CUSTOM_LIBCXX)
target_link_libraries(crypto libcxx)
endif()
# urandom_test is a separate binary because it needs to be able to observe the
# PRNG initialisation, which means that it can't have other tests running before
# it does.
add_executable(
urandom_test
fipsmodule/rand/urandom_test.cc
)
target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto)
add_dependencies(all_tests urandom_test)
add_executable(
crypto_test
abi_self_test.cc
asn1/asn1_test.cc
base64/base64_test.cc
bio/bio_test.cc
blake2/blake2_test.cc
buf/buf_test.cc
bytestring/bytestring_test.cc
chacha/chacha_test.cc
cipher_extra/aead_test.cc
cipher_extra/cipher_test.cc
compiler_test.cc
conf/conf_test.cc
constant_time_test.cc
cpu_arm_linux_test.cc
crypto_test.cc
curve25519/ed25519_test.cc
curve25519/spake25519_test.cc
curve25519/x25519_test.cc
ecdh_extra/ecdh_test.cc
dh_extra/dh_test.cc
digest_extra/digest_test.cc
dsa/dsa_test.cc
err/err_test.cc
evp/evp_extra_test.cc
evp/evp_test.cc
evp/pbkdf_test.cc
evp/scrypt_test.cc
fipsmodule/aes/aes_test.cc
fipsmodule/bn/bn_test.cc
fipsmodule/cmac/cmac_test.cc
fipsmodule/ec/ec_test.cc
fipsmodule/ec/p256-nistz_test.cc
fipsmodule/ecdsa/ecdsa_test.cc
fipsmodule/hkdf/hkdf_test.cc
fipsmodule/md5/md5_test.cc
fipsmodule/modes/gcm_test.cc
fipsmodule/rand/ctrdrbg_test.cc
fipsmodule/rand/fork_detect_test.cc
fipsmodule/service_indicator/service_indicator_test.cc
fipsmodule/sha/sha_test.cc
hpke/hpke_test.cc
hmac_extra/hmac_test.cc
hrss/hrss_test.cc
impl_dispatch_test.cc
kyber/kyber_test.cc
lhash/lhash_test.cc
obj/obj_test.cc
pem/pem_test.cc
pkcs7/pkcs7_test.cc
pkcs8/pkcs8_test.cc
pkcs8/pkcs12_test.cc
poly1305/poly1305_test.cc
pool/pool_test.cc
rand_extra/rand_test.cc
refcount_test.cc
rsa_extra/rsa_test.cc
self_test.cc
stack/stack_test.cc
siphash/siphash_test.cc
test/file_test_gtest.cc
thread_test.cc
trust_token/trust_token_test.cc
x509/x509_test.cc
x509/x509_time_test.cc
x509v3/tab_test.cc
$<TARGET_OBJECTS:crypto_test_data>
)
target_link_libraries(crypto_test test_support_lib boringssl_gtest_main crypto)
add_dependencies(all_tests crypto_test)

@ -5,6 +5,7 @@ add_library(
abi_test.cc
file_test.cc
file_test_gtest.cc
test_util.cc
wycheproof_util.cc
)

@ -20,17 +20,3 @@ add_library(
xts/xts.c
)
target_link_libraries(decrepit crypto ssl)
add_executable(
decrepit_test
blowfish/blowfish_test.cc
cast/cast_test.cc
cfb/cfb_test.cc
evp/evp_test.cc
ripemd/ripemd_test.cc
xts/xts_test.cc
)
target_link_libraries(decrepit_test test_support_lib boringssl_gtest_main
decrepit crypto)
add_dependencies(all_tests decrepit_test)

@ -3,6 +3,75 @@
#
# TODO(davidben): Move the other source lists into this file.
set(
CRYPTO_TEST_SOURCES
crypto/abi_self_test.cc
crypto/asn1/asn1_test.cc
crypto/base64/base64_test.cc
crypto/bio/bio_test.cc
crypto/blake2/blake2_test.cc
crypto/buf/buf_test.cc
crypto/bytestring/bytestring_test.cc
crypto/chacha/chacha_test.cc
crypto/cipher_extra/aead_test.cc
crypto/cipher_extra/cipher_test.cc
crypto/compiler_test.cc
crypto/conf/conf_test.cc
crypto/constant_time_test.cc
crypto/cpu_arm_linux_test.cc
crypto/crypto_test.cc
crypto/curve25519/ed25519_test.cc
crypto/curve25519/spake25519_test.cc
crypto/curve25519/x25519_test.cc
crypto/ecdh_extra/ecdh_test.cc
crypto/dh_extra/dh_test.cc
crypto/digest_extra/digest_test.cc
crypto/dsa/dsa_test.cc
crypto/err/err_test.cc
crypto/evp/evp_extra_test.cc
crypto/evp/evp_test.cc
crypto/evp/pbkdf_test.cc
crypto/evp/scrypt_test.cc
crypto/fipsmodule/aes/aes_test.cc
crypto/fipsmodule/bn/bn_test.cc
crypto/fipsmodule/cmac/cmac_test.cc
crypto/fipsmodule/ec/ec_test.cc
crypto/fipsmodule/ec/p256-nistz_test.cc
crypto/fipsmodule/ecdsa/ecdsa_test.cc
crypto/fipsmodule/hkdf/hkdf_test.cc
crypto/fipsmodule/md5/md5_test.cc
crypto/fipsmodule/modes/gcm_test.cc
crypto/fipsmodule/rand/ctrdrbg_test.cc
crypto/fipsmodule/rand/fork_detect_test.cc
crypto/fipsmodule/service_indicator/service_indicator_test.cc
crypto/fipsmodule/sha/sha_test.cc
crypto/hpke/hpke_test.cc
crypto/hmac_extra/hmac_test.cc
crypto/hrss/hrss_test.cc
crypto/impl_dispatch_test.cc
crypto/kyber/kyber_test.cc
crypto/lhash/lhash_test.cc
crypto/obj/obj_test.cc
crypto/pem/pem_test.cc
crypto/pkcs7/pkcs7_test.cc
crypto/pkcs8/pkcs8_test.cc
crypto/pkcs8/pkcs12_test.cc
crypto/poly1305/poly1305_test.cc
crypto/pool/pool_test.cc
crypto/rand_extra/rand_test.cc
crypto/refcount_test.cc
crypto/rsa_extra/rsa_test.cc
crypto/self_test.cc
crypto/stack/stack_test.cc
crypto/siphash/siphash_test.cc
crypto/thread_test.cc
crypto/trust_token/trust_token_test.cc
crypto/x509/x509_test.cc
crypto/x509/x509_time_test.cc
crypto/x509v3/tab_test.cc
)
set(
CRYPTO_TEST_DATA
@ -239,6 +308,31 @@ set(
third_party/wycheproof_testvectors/xchacha20_poly1305_test.txt
)
set(
URANDOM_TEST_SOURCES
crypto/fipsmodule/rand/urandom_test.cc
)
set(
SSL_TEST_SOURCES
ssl/span_test.cc
ssl/ssl_test.cc
ssl/ssl_c_test.c
)
set(
DECREPIT_TEST_SOURCES
decrepit/blowfish/blowfish_test.cc
decrepit/cast/cast_test.cc
decrepit/cfb/cfb_test.cc
decrepit/evp/evp_test.cc
decrepit/ripemd/ripemd_test.cc
decrepit/xts/xts_test.cc
)
set(
PKI_SOURCES

@ -45,13 +45,3 @@ add_library(
install_if_enabled(TARGETS ssl EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT})
set_property(TARGET ssl PROPERTY EXPORT_NAME SSL)
target_link_libraries(ssl crypto)
add_executable(
ssl_test
span_test.cc
ssl_test.cc
ssl_c_test.c
)
target_link_libraries(ssl_test test_support_lib boringssl_gtest_main ssl crypto)
add_dependencies(all_tests ssl_test)

@ -1,52 +1,52 @@
[
{
"cmd": ["crypto/crypto_test"],
"cmd": ["crypto_test"],
"shard": true
},
{
"cmd": ["crypto/crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=BNTest.DISABLED_WycheproofPrimality"]
"cmd": ["crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=BNTest.DISABLED_WycheproofPrimality"]
},
{
"cmd": ["crypto/crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=RSATest.DISABLED_BlindingCacheConcurrency"],
"cmd": ["crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=RSATest.DISABLED_BlindingCacheConcurrency"],
"skip_sde": true
},
{
"cmd": ["crypto/urandom_test"]
"cmd": ["urandom_test"]
},
{
"comment": "Without RDRAND",
"cmd": ["crypto/urandom_test"],
"cmd": ["urandom_test"],
"env": ["OPENSSL_ia32cap=~0x4000000000000000"]
},
{
"comment": "Potentially with RDRAND, but not Intel",
"cmd": ["crypto/urandom_test"],
"cmd": ["urandom_test"],
"env": ["OPENSSL_ia32cap=~0x0000000040000000"]
},
{
"comment": "Potentially with RDRAND, and forced to Intel",
"cmd": ["crypto/urandom_test"],
"cmd": ["urandom_test"],
"env": ["OPENSSL_ia32cap=|0x0000000040000000"]
},
{
"comment": "No RDRAND and without WIPEONFORK",
"cmd": ["crypto/urandom_test"],
"cmd": ["urandom_test"],
"env": ["OPENSSL_ia32cap=~0x4000000000000000", "BORINGSSL_IGNORE_MADV_WIPEONFORK=1"]
},
{
"comment": "Potentially with RDRAND, but not Intel, and no WIPEONFORK",
"cmd": ["crypto/urandom_test"],
"cmd": ["urandom_test"],
"env": ["OPENSSL_ia32cap=~0x0000000040000000", "BORINGSSL_IGNORE_MADV_WIPEONFORK=1"]
},
{
"cmd": ["crypto/crypto_test", "--fork_unsafe_buffering", "--gtest_filter=RandTest.*:-RandTest.Fork"]
"cmd": ["crypto_test", "--fork_unsafe_buffering", "--gtest_filter=RandTest.*:-RandTest.Fork"]
},
{
"cmd": ["decrepit/decrepit_test"],
"cmd": ["decrepit_test"],
"shard": true
},
{
"cmd": ["ssl/ssl_test"],
"cmd": ["ssl_test"],
"shard": true
},
{

@ -584,14 +584,6 @@ def NoTests(path, dent, is_dir):
return 'test.' not in dent
def OnlyTests(path, dent, is_dir):
"""Filter function that can be passed to FindCFiles in order to remove
non-test sources."""
if is_dir:
return dent != 'test'
return '_test.' in dent
def AllFiles(path, dent, is_dir):
"""Filter function that can be passed to FindCFiles in order to include all
sources."""
@ -761,6 +753,10 @@ def ExtractVariablesFromCMakeFile(cmakefile):
return variables
def PrefixWithSrc(files):
return ['src/' + x for x in files]
def main(platforms):
cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
@ -799,31 +795,21 @@ def main(platforms):
stdout=out)
crypto_test_files += ['crypto_test_data.cc']
crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
crypto_test_files += PrefixWithSrc(cmake['CRYPTO_TEST_SOURCES'])
crypto_test_files += [
'src/crypto/test/abi_test.cc',
'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')
]
crypto_test_files.sort()
ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
ssl_test_files = PrefixWithSrc(cmake['SSL_TEST_SOURCES'])
ssl_test_files += [
'src/crypto/test/abi_test.cc',
'src/crypto/test/gtest_main.cc',
]
ssl_test_files.sort()
urandom_test_files = [
'src/crypto/fipsmodule/rand/urandom_test.cc',
]
fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
ssl_h_files = FindHeaderFiles(os.path.join('src', 'include', 'openssl'),
@ -862,7 +848,7 @@ def main(platforms):
'crypto_headers': crypto_h_files,
'crypto_internal_headers': crypto_internal_h_files,
'crypto_test': crypto_test_files,
'crypto_test_data': sorted('src/' + x for x in cmake['CRYPTO_TEST_DATA']),
'crypto_test_data': sorted(PrefixWithSrc(cmake['CRYPTO_TEST_DATA'])),
'fips_fragments': fips_fragments,
'fuzz': fuzz_c_files,
'ssl': ssl_source_files,
@ -873,7 +859,7 @@ def main(platforms):
'tool_headers': tool_h_files,
'test_support': test_support_c_files,
'test_support_headers': test_support_h_files,
'urandom_test': urandom_test_files,
'urandom_test': PrefixWithSrc(cmake['URANDOM_TEST_SOURCES']),
}
for platform in platforms:

Loading…
Cancel
Save