Changeset 77968 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Mar 31, 2019 7:30:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/fs/FsPerf.cpp
r77931 r77968 3778 3778 } 3779 3779 3780 static char s_abContent[256*1024]; 3781 RTRandBytes(s_abContent, sizeof(s_abContent)); 3782 RTTESTI_CHECK_RC(RTFileWrite(hFile2, s_abContent, sizeof(s_abContent), NULL), VINF_SUCCESS); 3780 static char s_abContentUnaligned[256*1024 + PAGE_SIZE - 1]; 3781 char * const pbContent = &s_abContentUnaligned[PAGE_SIZE - ((uintptr_t)&s_abContentUnaligned[0] & PAGE_OFFSET_MASK)]; 3782 size_t const cbContent = 256*1024; 3783 RTRandBytes(pbContent, cbContent); 3784 RTTESTI_CHECK_RC(rc = RTFileWrite(hFile2, pbContent, cbContent, NULL), VINF_SUCCESS); 3783 3785 RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS); 3784 3785 /* Reopen the file with normal caching. Every second time, we also 3786 does a read-only open of it to confuse matters. */ 3787 RTFILE hFile3 = NIL_RTFILE; 3788 if ((i & 3) == 3) 3789 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS); 3790 hFile2 = NIL_RTFILE; 3791 RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), 3792 VINF_SUCCESS); 3793 if ((i & 3) == 1) 3794 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS); 3795 3796 /* Memory map it read-write (no COW). */ 3786 if (RT_SUCCESS(rc)) 3787 { 3788 /* Reopen the file with normal caching. Every second time, we also 3789 does a read-only open of it to confuse matters. */ 3790 RTFILE hFile3 = NIL_RTFILE; 3791 if ((i & 3) == 3) 3792 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS); 3793 hFile2 = NIL_RTFILE; 3794 RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), 3795 VINF_SUCCESS); 3796 if ((i & 3) == 1) 3797 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS); 3798 3799 /* Memory map it read-write (no COW). */ 3797 3800 #ifdef RT_OS_WINDOWS 3798 HANDLE hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile2), NULL, PAGE_READWRITE, 0, sizeof(s_abContent), NULL);3799 RTTESTI_CHECK_MSG(hSection != NULL, ("last error %u\n", GetLastError));3800 uint8_t *pbMapping = (uint8_t *)MapViewOfFile(hSection, FILE_MAP_WRITE, 0, 0, sizeof(s_abContent));3801 RTTESTI_CHECK_MSG(pbMapping != NULL, ("last error %u\n", GetLastError));3802 RTTESTI_CHECK_MSG(CloseHandle(hSection), ("last error %u\n", GetLastError));3801 HANDLE hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile2), NULL, PAGE_READWRITE, 0, cbContent, NULL); 3802 RTTESTI_CHECK_MSG(hSection != NULL, ("last error %u\n", GetLastError)); 3803 uint8_t *pbMapping = (uint8_t *)MapViewOfFile(hSection, FILE_MAP_WRITE, 0, 0, cbContent); 3804 RTTESTI_CHECK_MSG(pbMapping != NULL, ("last error %u\n", GetLastError)); 3805 RTTESTI_CHECK_MSG(CloseHandle(hSection), ("last error %u\n", GetLastError)); 3803 3806 # else 3804 uint8_t *pbMapping = (uint8_t *)mmap(NULL, sizeof(s_abContent), PROT_READ | PROT_WRITE, MAP_SHARED,3805 (int)RTFileToNative(hFile2), 0);3806 if ((void *)pbMapping == MAP_FAILED)3807 pbMapping = NULL;3808 RTTESTI_CHECK_MSG(pbMapping != NULL, ("errno=%s (%d)\n", strerror(errno), errno));3807 uint8_t *pbMapping = (uint8_t *)mmap(NULL, cbContent, PROT_READ | PROT_WRITE, MAP_SHARED, 3808 (int)RTFileToNative(hFile2), 0); 3809 if ((void *)pbMapping == MAP_FAILED) 3810 pbMapping = NULL; 3811 RTTESTI_CHECK_MSG(pbMapping != NULL, ("errno=%s (%d)\n", strerror(errno), errno)); 3809 3812 # endif 3810 3813 3811 /* Close the file handles. */ 3812 if ((i & 7) == 7) 3813 { 3814 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3815 hFile3 = NIL_RTFILE; 3816 } 3817 RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS); 3818 if ((i & 7) == 5) 3819 { 3820 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3821 hFile3 = NIL_RTFILE; 3822 } 3823 if (pbMapping) 3824 { 3825 RTThreadSleep(2); /* fudge for cleanup/whatever */ 3826 3827 /* Page in the mapping by comparing with the content we wrote above. */ 3828 RTTESTI_CHECK(memcmp(pbMapping, s_abContent, sizeof(s_abContent)) == 0); 3829 3830 /* Now dirty everything by inverting everything. */ 3831 size_t *puCur = (size_t *)pbMapping; 3832 size_t cLeft = sizeof(s_abContent) / sizeof(*puCur); 3833 while (cLeft-- > 0) 3814 /* Close the file handles. */ 3815 if ((i & 7) == 7) 3834 3816 { 3835 *puCur = ~*puCur;3836 puCur++;3817 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3818 hFile3 = NIL_RTFILE; 3837 3819 } 3838 3839 /* Sync it all. */ 3820 RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS); 3821 if ((i & 7) == 5) 3822 { 3823 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3824 hFile3 = NIL_RTFILE; 3825 } 3826 if (pbMapping) 3827 { 3828 RTThreadSleep(2); /* fudge for cleanup/whatever */ 3829 3830 /* Page in the mapping by comparing with the content we wrote above. */ 3831 RTTESTI_CHECK(memcmp(pbMapping, pbContent, cbContent) == 0); 3832 3833 /* Now dirty everything by inverting everything. */ 3834 size_t *puCur = (size_t *)pbMapping; 3835 size_t cLeft = cbContent / sizeof(*puCur); 3836 while (cLeft-- > 0) 3837 { 3838 *puCur = ~*puCur; 3839 puCur++; 3840 } 3841 3842 /* Sync it all. */ 3840 3843 # ifdef RT_OS_WINDOWS 3841 RTTESTI_CHECK(FlushViewOfFile(pbMapping, sizeof(s_abContent)));3844 RTTESTI_CHECK(FlushViewOfFile(pbMapping, cbContent)); 3842 3845 # else 3843 RTTESTI_CHECK(msync(pbMapping, sizeof(s_abContent), MS_SYNC) == 0);3846 RTTESTI_CHECK(msync(pbMapping, cbContent, MS_SYNC) == 0); 3844 3847 # endif 3845 3848 3846 /* Unmap it. */3849 /* Unmap it. */ 3847 3850 # ifdef RT_OS_WINDOWS 3848 RTTESTI_CHECK(UnmapViewOfFile(pbMapping));3851 RTTESTI_CHECK(UnmapViewOfFile(pbMapping)); 3849 3852 # else 3850 RTTESTI_CHECK(munmap(pbMapping, sizeof(s_abContent)) == 0);3853 RTTESTI_CHECK(munmap(pbMapping, cbContent) == 0); 3851 3854 # endif 3852 } 3853 3854 if (hFile3 != NIL_RTFILE) 3855 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3855 } 3856 3857 if (hFile3 != NIL_RTFILE) 3858 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS); 3859 } 3856 3860 RTTESTI_CHECK_RC(RTFileDelete(szFile2), VINF_SUCCESS); 3857 3861 }
Note:
See TracChangeset
for help on using the changeset viewer.