LCOV - code coverage report
Current view: top level - src/compat - glibc_sanity.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 14 15 93.3 %
Date: 2020-09-26 01:30:44 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2019 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #if defined(HAVE_CONFIG_H)
       6             : #include <config/bitcoin-config.h>
       7             : #endif
       8             : 
       9             : #include <cstddef>
      10             : 
      11             : extern "C" void* memcpy(void* a, const void* b, size_t c);
      12         531 : void* memcpy_int(void* a, const void* b, size_t c)
      13             : {
      14         531 :     return memcpy(a, b, c);
      15             : }
      16             : 
      17             : namespace
      18             : {
      19             : // trigger: Use the memcpy_int wrapper which calls our internal memcpy.
      20             : //   A direct call to memcpy may be optimized away by the compiler.
      21             : // test: Fill an array with a sequence of integers. memcpy to a new empty array.
      22             : //   Verify that the arrays are equal. Use an odd size to decrease the odds of
      23             : //   the call being optimized away.
      24             : template <unsigned int T>
      25         531 : bool sanity_test_memcpy()
      26             : {
      27         531 :     unsigned int memcpy_test[T];
      28         531 :     unsigned int memcpy_verify[T] = {};
      29      544806 :     for (unsigned int i = 0; i != T; ++i)
      30      544275 :         memcpy_test[i] = i;
      31             : 
      32         531 :     memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test));
      33             : 
      34      544806 :     for (unsigned int i = 0; i != T; ++i) {
      35      544275 :         if (memcpy_verify[i] != i)
      36           0 :             return false;
      37             :     }
      38         531 :     return true;
      39         531 : }
      40             : } // namespace
      41             : 
      42         531 : bool glibc_sanity_test()
      43             : {
      44         531 :     return sanity_test_memcpy<1025>();
      45             : }

Generated by: LCOV version 1.15