LCOV - code coverage report
Current view: top level - src/compat - glibc_sanity.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 11 12 91.7 %
Date: 2015-10-12 22:39:14 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2009-2014 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             : #if defined(HAVE_SYS_SELECT_H)
      12             : #include <sys/select.h>
      13             : #endif
      14             : 
      15             : extern "C" void* memcpy(void* a, const void* b, size_t c);
      16           0 : void* memcpy_int(void* a, const void* b, size_t c)
      17             : {
      18          95 :     return memcpy(a, b, c);
      19             : }
      20             : 
      21             : namespace
      22             : {
      23             : // trigger: Use the memcpy_int wrapper which calls our internal memcpy.
      24             : //   A direct call to memcpy may be optimized away by the compiler.
      25             : // test: Fill an array with a sequence of integers. memcpy to a new empty array.
      26             : //   Verify that the arrays are equal. Use an odd size to decrease the odds of
      27             : //   the call being optimized away.
      28             : template <unsigned int T>
      29          95 : bool sanity_test_memcpy()
      30             : {
      31             :     unsigned int memcpy_test[T];
      32             :     unsigned int memcpy_verify[T] = {};
      33       97470 :     for (unsigned int i = 0; i != T; ++i)
      34       97375 :         memcpy_test[i] = i;
      35             : 
      36             :     memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test));
      37             : 
      38       97470 :     for (unsigned int i = 0; i != T; ++i) {
      39       97375 :         if (memcpy_verify[i] != i)
      40             :             return false;
      41             :     }
      42             :     return true;
      43             : }
      44             : 
      45             : #if defined(HAVE_SYS_SELECT_H)
      46             : // trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined
      47             : //   as >0 and optimizations must be set to at least -O2.
      48             : // test: Add a file descriptor to an empty fd_set. Verify that it has been
      49             : //   correctly added.
      50             : bool sanity_test_fdelt()
      51             : {
      52             :     fd_set fds;
      53          95 :     FD_ZERO(&fds);
      54          95 :     FD_SET(0, &fds);
      55          95 :     return FD_ISSET(0, &fds);
      56             : }
      57             : #endif
      58             : 
      59             : } // anon namespace
      60             : 
      61          95 : bool glibc_sanity_test()
      62             : {
      63             : #if defined(HAVE_SYS_SELECT_H)
      64             :     if (!sanity_test_fdelt())
      65             :         return false;
      66             : #endif
      67          95 :     return sanity_test_memcpy<1025>();
      68             : }

Generated by: LCOV version 1.11