LCOV - code coverage report
Current view: top level - journal - test-mmap-cache.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 32 32 100.0 %
Date: 2019-08-22 15:41:25 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <fcntl.h>
       4             : #include <stdlib.h>
       5             : #include <sys/mman.h>
       6             : #include <unistd.h>
       7             : 
       8             : #include "fd-util.h"
       9             : #include "macro.h"
      10             : #include "mmap-cache.h"
      11             : #include "tmpfile-util.h"
      12             : #include "util.h"
      13             : 
      14           1 : int main(int argc, char *argv[]) {
      15             :         MMapFileDescriptor *fx;
      16             :         int x, y, z, r;
      17           1 :         char px[] = "/tmp/testmmapXXXXXXX", py[] = "/tmp/testmmapYXXXXXX", pz[] = "/tmp/testmmapZXXXXXX";
      18             :         MMapCache *m;
      19             :         void *p, *q;
      20             : 
      21           1 :         assert_se(m = mmap_cache_new());
      22             : 
      23           1 :         x = mkostemp_safe(px);
      24           1 :         assert_se(x >= 0);
      25           1 :         unlink(px);
      26             : 
      27           1 :         assert_se(fx = mmap_cache_add_fd(m, x));
      28             : 
      29           1 :         y = mkostemp_safe(py);
      30           1 :         assert_se(y >= 0);
      31           1 :         unlink(py);
      32             : 
      33           1 :         z = mkostemp_safe(pz);
      34           1 :         assert_se(z >= 0);
      35           1 :         unlink(pz);
      36             : 
      37           1 :         r = mmap_cache_get(m, fx, PROT_READ, 0, false, 1, 2, NULL, &p, NULL);
      38           1 :         assert_se(r >= 0);
      39             : 
      40           1 :         r = mmap_cache_get(m, fx, PROT_READ, 0, false, 2, 2, NULL, &q, NULL);
      41           1 :         assert_se(r >= 0);
      42             : 
      43           1 :         assert_se((uint8_t*) p + 1 == (uint8_t*) q);
      44             : 
      45           1 :         r = mmap_cache_get(m, fx, PROT_READ, 1, false, 3, 2, NULL, &q, NULL);
      46           1 :         assert_se(r >= 0);
      47             : 
      48           1 :         assert_se((uint8_t*) p + 2 == (uint8_t*) q);
      49             : 
      50           1 :         r = mmap_cache_get(m, fx, PROT_READ, 0, false, 16ULL*1024ULL*1024ULL, 2, NULL, &p, NULL);
      51           1 :         assert_se(r >= 0);
      52             : 
      53           1 :         r = mmap_cache_get(m, fx, PROT_READ, 1, false, 16ULL*1024ULL*1024ULL+1, 2, NULL, &q, NULL);
      54           1 :         assert_se(r >= 0);
      55             : 
      56           1 :         assert_se((uint8_t*) p + 1 == (uint8_t*) q);
      57             : 
      58           1 :         mmap_cache_free_fd(m, fx);
      59           1 :         mmap_cache_unref(m);
      60             : 
      61           1 :         safe_close(x);
      62           1 :         safe_close(y);
      63           1 :         safe_close(z);
      64             : 
      65           1 :         return 0;
      66             : }

Generated by: LCOV version 1.14