LCOV - code coverage report
Current view: top level - test - test-sigbus.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 26 26 100.0 %
Date: 2019-08-23 13:36:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 26 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <fcntl.h>
       4                 :            : #include <sys/mman.h>
       5                 :            : #include <unistd.h>
       6                 :            : 
       7                 :            : #if HAVE_VALGRIND_VALGRIND_H
       8                 :            : #  include <valgrind/valgrind.h>
       9                 :            : #endif
      10                 :            : 
      11                 :            : #include "fd-util.h"
      12                 :            : #include "memory-util.h"
      13                 :            : #include "sigbus.h"
      14                 :            : #include "tests.h"
      15                 :            : 
      16                 :          4 : int main(int argc, char *argv[]) {
      17                 :          4 :         _cleanup_close_ int fd = -1;
      18                 :          4 :         char template[] = "/tmp/sigbus-test-XXXXXX";
      19                 :          4 :         void *addr = NULL;
      20                 :            :         uint8_t *p;
      21                 :            : 
      22                 :          4 :         test_setup_logging(LOG_INFO);
      23                 :            : 
      24                 :            : #if HAS_FEATURE_ADDRESS_SANITIZER
      25                 :            :         return log_tests_skipped("address-sanitizer is enabled");
      26                 :            : #endif
      27                 :            : #if HAVE_VALGRIND_VALGRIND_H
      28                 :            :         if (RUNNING_ON_VALGRIND)
      29                 :            :                 return log_tests_skipped("This test cannot run on valgrind");
      30                 :            : #endif
      31                 :            : 
      32                 :          4 :         sigbus_install();
      33                 :            : 
      34         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) == 0);
      35                 :            : 
      36         [ -  + ]:          4 :         assert_se((fd = mkostemp(template, O_RDWR|O_CREAT|O_EXCL)) >= 0);
      37         [ -  + ]:          4 :         assert_se(unlink(template) >= 0);
      38         [ -  + ]:          4 :         assert_se(posix_fallocate(fd, 0, page_size() * 8) >= 0);
      39                 :            : 
      40                 :          4 :         p = mmap(NULL, page_size() * 16, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
      41         [ -  + ]:          4 :         assert_se(p != MAP_FAILED);
      42                 :            : 
      43         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) == 0);
      44                 :            : 
      45                 :          4 :         p[0] = 0xFF;
      46         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) == 0);
      47                 :            : 
      48                 :          4 :         p[page_size()] = 0xFF;
      49         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) == 0);
      50                 :            : 
      51                 :          4 :         p[page_size()*8] = 0xFF;
      52                 :          4 :         p[page_size()*8+1] = 0xFF;
      53                 :          4 :         p[page_size()*10] = 0xFF;
      54         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) > 0);
      55         [ -  + ]:          4 :         assert_se(addr == p + page_size() * 8);
      56         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) > 0);
      57         [ -  + ]:          4 :         assert_se(addr == p + page_size() * 10);
      58         [ -  + ]:          4 :         assert_se(sigbus_pop(&addr) == 0);
      59                 :            : 
      60                 :          4 :         sigbus_reset();
      61                 :            : }

Generated by: LCOV version 1.14