119ea8026Sopenharmony_ci[cases.bench_file_read] 219ea8026Sopenharmony_ci# 0 = in-order 319ea8026Sopenharmony_ci# 1 = reversed-order 419ea8026Sopenharmony_ci# 2 = random-order 519ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 619ea8026Sopenharmony_cidefines.SIZE = '128*1024' 719ea8026Sopenharmony_cidefines.CHUNK_SIZE = 64 819ea8026Sopenharmony_cicode = ''' 919ea8026Sopenharmony_ci lfs_t lfs; 1019ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 1119ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 1219ea8026Sopenharmony_ci lfs_size_t chunks = (SIZE+CHUNK_SIZE-1)/CHUNK_SIZE; 1319ea8026Sopenharmony_ci 1419ea8026Sopenharmony_ci // first write the file 1519ea8026Sopenharmony_ci lfs_file_t file; 1619ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 1719ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, "file", 1819ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; 1919ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < chunks; i++) { 2019ea8026Sopenharmony_ci uint32_t chunk_prng = i; 2119ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) { 2219ea8026Sopenharmony_ci buffer[j] = BENCH_PRNG(&chunk_prng); 2319ea8026Sopenharmony_ci } 2419ea8026Sopenharmony_ci 2519ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 2619ea8026Sopenharmony_ci } 2719ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 2819ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 2919ea8026Sopenharmony_ci 3019ea8026Sopenharmony_ci // then read the file 3119ea8026Sopenharmony_ci BENCH_START(); 3219ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, "file", LFS_O_RDONLY) => 0; 3319ea8026Sopenharmony_ci 3419ea8026Sopenharmony_ci uint32_t prng = 42; 3519ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < chunks; i++) { 3619ea8026Sopenharmony_ci lfs_off_t i_ 3719ea8026Sopenharmony_ci = (ORDER == 0) ? i 3819ea8026Sopenharmony_ci : (ORDER == 1) ? (chunks-1-i) 3919ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % chunks; 4019ea8026Sopenharmony_ci lfs_file_seek(&lfs, &file, i_*CHUNK_SIZE, LFS_SEEK_SET) 4119ea8026Sopenharmony_ci => i_*CHUNK_SIZE; 4219ea8026Sopenharmony_ci lfs_file_read(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 4319ea8026Sopenharmony_ci 4419ea8026Sopenharmony_ci uint32_t chunk_prng = i_; 4519ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) { 4619ea8026Sopenharmony_ci assert(buffer[j] == BENCH_PRNG(&chunk_prng)); 4719ea8026Sopenharmony_ci } 4819ea8026Sopenharmony_ci } 4919ea8026Sopenharmony_ci 5019ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 5119ea8026Sopenharmony_ci BENCH_STOP(); 5219ea8026Sopenharmony_ci 5319ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 5419ea8026Sopenharmony_ci''' 5519ea8026Sopenharmony_ci 5619ea8026Sopenharmony_ci[cases.bench_file_write] 5719ea8026Sopenharmony_ci# 0 = in-order 5819ea8026Sopenharmony_ci# 1 = reversed-order 5919ea8026Sopenharmony_ci# 2 = random-order 6019ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 6119ea8026Sopenharmony_cidefines.SIZE = '128*1024' 6219ea8026Sopenharmony_cidefines.CHUNK_SIZE = 64 6319ea8026Sopenharmony_cicode = ''' 6419ea8026Sopenharmony_ci lfs_t lfs; 6519ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 6619ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 6719ea8026Sopenharmony_ci lfs_size_t chunks = (SIZE+CHUNK_SIZE-1)/CHUNK_SIZE; 6819ea8026Sopenharmony_ci 6919ea8026Sopenharmony_ci BENCH_START(); 7019ea8026Sopenharmony_ci lfs_file_t file; 7119ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, "file", 7219ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; 7319ea8026Sopenharmony_ci 7419ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 7519ea8026Sopenharmony_ci uint32_t prng = 42; 7619ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < chunks; i++) { 7719ea8026Sopenharmony_ci lfs_off_t i_ 7819ea8026Sopenharmony_ci = (ORDER == 0) ? i 7919ea8026Sopenharmony_ci : (ORDER == 1) ? (chunks-1-i) 8019ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % chunks; 8119ea8026Sopenharmony_ci uint32_t chunk_prng = i_; 8219ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) { 8319ea8026Sopenharmony_ci buffer[j] = BENCH_PRNG(&chunk_prng); 8419ea8026Sopenharmony_ci } 8519ea8026Sopenharmony_ci 8619ea8026Sopenharmony_ci lfs_file_seek(&lfs, &file, i_*CHUNK_SIZE, LFS_SEEK_SET) 8719ea8026Sopenharmony_ci => i_*CHUNK_SIZE; 8819ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 8919ea8026Sopenharmony_ci } 9019ea8026Sopenharmony_ci 9119ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 9219ea8026Sopenharmony_ci BENCH_STOP(); 9319ea8026Sopenharmony_ci 9419ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 9519ea8026Sopenharmony_ci''' 96