okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
80f83268d
main
1// Linux selftest for the optional MAP_SHARED backing of PinnedArena. 2#include "strata/core/pinned.hpp" 3 4#include <cstdio> 5#include <cstdlib> 6#include <string> 7#include <vector> 8 9#include <unistd.h> 10 11int main () { 12char path []= "/tmp/strata-shared-arena-XXXXXX" ; 13const int fd = mkstemp (path ); 14if (fd < 0 ) { 15 std::perror ("mkstemp" ); 16return 2 ; 17 } 18close (fd ); 19 20int fail = 0 ; 21const uint64_t bytes = 64u <<10 ; 22const uint64_t pack_hash = 0x0123456789abcdefull ; 23const std::vector < uint64_t > no_bounds ; 24 { 25 strata::core::PinnedArena first (bytes ,no_bounds ,0 ,path ,pack_hash ); 26if (!first .valid ()) { 27 std::fprintf (stderr ,"first shared arena failed: %s\n" ,first .note .c_str ()); 28fail = 1 ; 29 }else { 30first .data ()[123 ]= 0x5a ; 31 32 strata::core::PinnedArena second (bytes ,no_bounds ,0 ,path ,pack_hash ); 33if (!second .valid ()) { 34 std::fprintf (stderr ,"second shared arena failed: %s\n" ,second .note .c_str ()); 35fail = 1 ; 36 }else if (second .data ()[123 ]!= 0x5a ) { 37 std::fprintf (stderr ,"shared mapping did not expose the same bytes\n" ); 38fail = 1 ; 39 } 40 41 strata::core::PinnedArena wrong_pack (bytes ,no_bounds ,0 ,path ,pack_hash + 1 ); 42if (wrong_pack .valid ()|| wrong_pack .note .find ("pack hash" )== std::string::npos ) { 43 std::fprintf (stderr ,"pack mismatch was not refused: %s\n" ,wrong_pack .note .c_str ()); 44fail = 1 ; 45 } 46 47 strata::core::PinnedArena wrong_size (bytes * 2 ,no_bounds ,0 ,path ,pack_hash ); 48if (wrong_size .valid ()|| wrong_size .note .find ("expected" )== std::string::npos ) { 49 std::fprintf (stderr ,"size mismatch was not refused: %s\n" ,wrong_size .note .c_str ()); 50fail = 1 ; 51 } 52 } 53 } 54 55if (unlink (path )!= 0 ) { 56 std::perror ("unlink" ); 57fail = 1 ; 58 } 59 std::printf ("pinned_shared_test: %s\n" ,fail ?"FAILED" :"OK" ); 60return fail ; 61}