LCOV - code coverage report
Current view: top level - tests - memoryMap.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 22 22 100.0 %
Date: 2016-03-29 17:09:06 Functions: 3 3 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2013-2016 Stefan.Eilemann@epfl.ch
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include <test.h>
      19             : #include <lunchbox/memoryMap.h>
      20             : 
      21             : using lunchbox::MemoryMap;
      22             : #define MAP_SIZE LB_10MB
      23             : #define STRIDE 23721
      24             : 
      25           1 : int main( int, char** )
      26             : {
      27           1 :     MemoryMap map( "foo.mmap", MAP_SIZE );
      28           1 :     TESTINFO( map.getSize() == MAP_SIZE, map.getSize( ));
      29           1 :     TEST( map.recreate(  "foo.mmap", MAP_SIZE ));
      30             : 
      31           1 :     uint8_t* writePtr = map.getAddress< uint8_t >();
      32           1 :     TEST( writePtr );
      33             : 
      34         444 :     for( size_t i=0; i < MAP_SIZE; i += STRIDE )
      35         443 :         writePtr[i] = uint8_t( i );
      36           1 :     map.unmap();
      37             : 
      38           1 :     const void* noPtr = map.map( "foo.map" );
      39           1 :     TEST( noPtr == 0 );
      40           1 :     TEST( map.getSize() == 0 );
      41             : 
      42           1 :     TEST( map.map( "foo.mmap" ));
      43           1 :     TEST( !map.map( "foo.mmap" ));
      44           1 :     TEST( map.remap( "foo.mmap" ));
      45           1 :     const uint8_t* readPtr = map.getAddress< uint8_t >();
      46           1 :     TEST( readPtr );
      47           1 :     TEST( map.getSize() == MAP_SIZE );
      48             : 
      49         444 :     for( size_t i=0; i < MAP_SIZE; i += STRIDE )
      50         443 :         TEST( readPtr[i] == uint8_t( i ));
      51             : 
      52           1 :     return EXIT_SUCCESS;
      53           3 : }

Generated by: LCOV version 1.11