119ea8026Sopenharmony_ci[cases.bench_dir_open] 219ea8026Sopenharmony_ci# 0 = in-order 319ea8026Sopenharmony_ci# 1 = reversed-order 419ea8026Sopenharmony_ci# 2 = random-order 519ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 619ea8026Sopenharmony_cidefines.N = 1024 719ea8026Sopenharmony_cidefines.FILE_SIZE = 8 819ea8026Sopenharmony_cidefines.CHUNK_SIZE = 8 919ea8026Sopenharmony_cicode = ''' 1019ea8026Sopenharmony_ci lfs_t lfs; 1119ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 1219ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 1319ea8026Sopenharmony_ci 1419ea8026Sopenharmony_ci // first create the files 1519ea8026Sopenharmony_ci char name[256]; 1619ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 1719ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 1819ea8026Sopenharmony_ci sprintf(name, "file%08x", i); 1919ea8026Sopenharmony_ci lfs_file_t file; 2019ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, name, 2119ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; 2219ea8026Sopenharmony_ci 2319ea8026Sopenharmony_ci uint32_t file_prng = i; 2419ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < FILE_SIZE; j += CHUNK_SIZE) { 2519ea8026Sopenharmony_ci for (lfs_size_t k = 0; k < CHUNK_SIZE; k++) { 2619ea8026Sopenharmony_ci buffer[k] = BENCH_PRNG(&file_prng); 2719ea8026Sopenharmony_ci } 2819ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 2919ea8026Sopenharmony_ci } 3019ea8026Sopenharmony_ci 3119ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 3219ea8026Sopenharmony_ci } 3319ea8026Sopenharmony_ci 3419ea8026Sopenharmony_ci // then read the files 3519ea8026Sopenharmony_ci BENCH_START(); 3619ea8026Sopenharmony_ci uint32_t prng = 42; 3719ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 3819ea8026Sopenharmony_ci lfs_off_t i_ 3919ea8026Sopenharmony_ci = (ORDER == 0) ? i 4019ea8026Sopenharmony_ci : (ORDER == 1) ? (N-1-i) 4119ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % N; 4219ea8026Sopenharmony_ci sprintf(name, "file%08x", i_); 4319ea8026Sopenharmony_ci lfs_file_t file; 4419ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, name, LFS_O_RDONLY) => 0; 4519ea8026Sopenharmony_ci 4619ea8026Sopenharmony_ci uint32_t file_prng = i_; 4719ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < FILE_SIZE; j += CHUNK_SIZE) { 4819ea8026Sopenharmony_ci lfs_file_read(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 4919ea8026Sopenharmony_ci for (lfs_size_t k = 0; k < CHUNK_SIZE; k++) { 5019ea8026Sopenharmony_ci assert(buffer[k] == BENCH_PRNG(&file_prng)); 5119ea8026Sopenharmony_ci } 5219ea8026Sopenharmony_ci } 5319ea8026Sopenharmony_ci 5419ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 5519ea8026Sopenharmony_ci } 5619ea8026Sopenharmony_ci BENCH_STOP(); 5719ea8026Sopenharmony_ci 5819ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 5919ea8026Sopenharmony_ci''' 6019ea8026Sopenharmony_ci 6119ea8026Sopenharmony_ci[cases.bench_dir_creat] 6219ea8026Sopenharmony_ci# 0 = in-order 6319ea8026Sopenharmony_ci# 1 = reversed-order 6419ea8026Sopenharmony_ci# 2 = random-order 6519ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 6619ea8026Sopenharmony_cidefines.N = 1024 6719ea8026Sopenharmony_cidefines.FILE_SIZE = 8 6819ea8026Sopenharmony_cidefines.CHUNK_SIZE = 8 6919ea8026Sopenharmony_cicode = ''' 7019ea8026Sopenharmony_ci lfs_t lfs; 7119ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 7219ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 7319ea8026Sopenharmony_ci 7419ea8026Sopenharmony_ci BENCH_START(); 7519ea8026Sopenharmony_ci uint32_t prng = 42; 7619ea8026Sopenharmony_ci char name[256]; 7719ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 7819ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 7919ea8026Sopenharmony_ci lfs_off_t i_ 8019ea8026Sopenharmony_ci = (ORDER == 0) ? i 8119ea8026Sopenharmony_ci : (ORDER == 1) ? (N-1-i) 8219ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % N; 8319ea8026Sopenharmony_ci sprintf(name, "file%08x", i_); 8419ea8026Sopenharmony_ci lfs_file_t file; 8519ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, name, 8619ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; 8719ea8026Sopenharmony_ci 8819ea8026Sopenharmony_ci uint32_t file_prng = i_; 8919ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < FILE_SIZE; j += CHUNK_SIZE) { 9019ea8026Sopenharmony_ci for (lfs_size_t k = 0; k < CHUNK_SIZE; k++) { 9119ea8026Sopenharmony_ci buffer[k] = BENCH_PRNG(&file_prng); 9219ea8026Sopenharmony_ci } 9319ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 9419ea8026Sopenharmony_ci } 9519ea8026Sopenharmony_ci 9619ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 9719ea8026Sopenharmony_ci } 9819ea8026Sopenharmony_ci BENCH_STOP(); 9919ea8026Sopenharmony_ci 10019ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 10119ea8026Sopenharmony_ci''' 10219ea8026Sopenharmony_ci 10319ea8026Sopenharmony_ci[cases.bench_dir_remove] 10419ea8026Sopenharmony_ci# 0 = in-order 10519ea8026Sopenharmony_ci# 1 = reversed-order 10619ea8026Sopenharmony_ci# 2 = random-order 10719ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 10819ea8026Sopenharmony_cidefines.N = 1024 10919ea8026Sopenharmony_cidefines.FILE_SIZE = 8 11019ea8026Sopenharmony_cidefines.CHUNK_SIZE = 8 11119ea8026Sopenharmony_cicode = ''' 11219ea8026Sopenharmony_ci lfs_t lfs; 11319ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 11419ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 11519ea8026Sopenharmony_ci 11619ea8026Sopenharmony_ci // first create the files 11719ea8026Sopenharmony_ci char name[256]; 11819ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 11919ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 12019ea8026Sopenharmony_ci sprintf(name, "file%08x", i); 12119ea8026Sopenharmony_ci lfs_file_t file; 12219ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, name, 12319ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; 12419ea8026Sopenharmony_ci 12519ea8026Sopenharmony_ci uint32_t file_prng = i; 12619ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < FILE_SIZE; j += CHUNK_SIZE) { 12719ea8026Sopenharmony_ci for (lfs_size_t k = 0; k < CHUNK_SIZE; k++) { 12819ea8026Sopenharmony_ci buffer[k] = BENCH_PRNG(&file_prng); 12919ea8026Sopenharmony_ci } 13019ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 13119ea8026Sopenharmony_ci } 13219ea8026Sopenharmony_ci 13319ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 13419ea8026Sopenharmony_ci } 13519ea8026Sopenharmony_ci 13619ea8026Sopenharmony_ci // then remove the files 13719ea8026Sopenharmony_ci BENCH_START(); 13819ea8026Sopenharmony_ci uint32_t prng = 42; 13919ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 14019ea8026Sopenharmony_ci lfs_off_t i_ 14119ea8026Sopenharmony_ci = (ORDER == 0) ? i 14219ea8026Sopenharmony_ci : (ORDER == 1) ? (N-1-i) 14319ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % N; 14419ea8026Sopenharmony_ci sprintf(name, "file%08x", i_); 14519ea8026Sopenharmony_ci int err = lfs_remove(&lfs, name); 14619ea8026Sopenharmony_ci assert(!err || err == LFS_ERR_NOENT); 14719ea8026Sopenharmony_ci } 14819ea8026Sopenharmony_ci BENCH_STOP(); 14919ea8026Sopenharmony_ci 15019ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 15119ea8026Sopenharmony_ci''' 15219ea8026Sopenharmony_ci 15319ea8026Sopenharmony_ci[cases.bench_dir_read] 15419ea8026Sopenharmony_cidefines.N = 1024 15519ea8026Sopenharmony_cidefines.FILE_SIZE = 8 15619ea8026Sopenharmony_cidefines.CHUNK_SIZE = 8 15719ea8026Sopenharmony_cicode = ''' 15819ea8026Sopenharmony_ci lfs_t lfs; 15919ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 16019ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 16119ea8026Sopenharmony_ci 16219ea8026Sopenharmony_ci // first create the files 16319ea8026Sopenharmony_ci char name[256]; 16419ea8026Sopenharmony_ci uint8_t buffer[CHUNK_SIZE]; 16519ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 16619ea8026Sopenharmony_ci sprintf(name, "file%08x", i); 16719ea8026Sopenharmony_ci lfs_file_t file; 16819ea8026Sopenharmony_ci lfs_file_open(&lfs, &file, name, 16919ea8026Sopenharmony_ci LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; 17019ea8026Sopenharmony_ci 17119ea8026Sopenharmony_ci uint32_t file_prng = i; 17219ea8026Sopenharmony_ci for (lfs_size_t j = 0; j < FILE_SIZE; j += CHUNK_SIZE) { 17319ea8026Sopenharmony_ci for (lfs_size_t k = 0; k < CHUNK_SIZE; k++) { 17419ea8026Sopenharmony_ci buffer[k] = BENCH_PRNG(&file_prng); 17519ea8026Sopenharmony_ci } 17619ea8026Sopenharmony_ci lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE; 17719ea8026Sopenharmony_ci } 17819ea8026Sopenharmony_ci 17919ea8026Sopenharmony_ci lfs_file_close(&lfs, &file) => 0; 18019ea8026Sopenharmony_ci } 18119ea8026Sopenharmony_ci 18219ea8026Sopenharmony_ci // then read the directory 18319ea8026Sopenharmony_ci BENCH_START(); 18419ea8026Sopenharmony_ci lfs_dir_t dir; 18519ea8026Sopenharmony_ci lfs_dir_open(&lfs, &dir, "/") => 0; 18619ea8026Sopenharmony_ci struct lfs_info info; 18719ea8026Sopenharmony_ci lfs_dir_read(&lfs, &dir, &info) => 1; 18819ea8026Sopenharmony_ci assert(info.type == LFS_TYPE_DIR); 18919ea8026Sopenharmony_ci assert(strcmp(info.name, ".") == 0); 19019ea8026Sopenharmony_ci lfs_dir_read(&lfs, &dir, &info) => 1; 19119ea8026Sopenharmony_ci assert(info.type == LFS_TYPE_DIR); 19219ea8026Sopenharmony_ci assert(strcmp(info.name, "..") == 0); 19319ea8026Sopenharmony_ci for (int i = 0; i < N; i++) { 19419ea8026Sopenharmony_ci sprintf(name, "file%08x", i); 19519ea8026Sopenharmony_ci lfs_dir_read(&lfs, &dir, &info) => 1; 19619ea8026Sopenharmony_ci assert(info.type == LFS_TYPE_REG); 19719ea8026Sopenharmony_ci assert(strcmp(info.name, name) == 0); 19819ea8026Sopenharmony_ci } 19919ea8026Sopenharmony_ci lfs_dir_read(&lfs, &dir, &info) => 0; 20019ea8026Sopenharmony_ci lfs_dir_close(&lfs, &dir) => 0; 20119ea8026Sopenharmony_ci BENCH_STOP(); 20219ea8026Sopenharmony_ci 20319ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 20419ea8026Sopenharmony_ci''' 20519ea8026Sopenharmony_ci 20619ea8026Sopenharmony_ci[cases.bench_dir_mkdir] 20719ea8026Sopenharmony_ci# 0 = in-order 20819ea8026Sopenharmony_ci# 1 = reversed-order 20919ea8026Sopenharmony_ci# 2 = random-order 21019ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 21119ea8026Sopenharmony_cidefines.N = 8 21219ea8026Sopenharmony_cicode = ''' 21319ea8026Sopenharmony_ci lfs_t lfs; 21419ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 21519ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 21619ea8026Sopenharmony_ci 21719ea8026Sopenharmony_ci BENCH_START(); 21819ea8026Sopenharmony_ci uint32_t prng = 42; 21919ea8026Sopenharmony_ci char name[256]; 22019ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 22119ea8026Sopenharmony_ci lfs_off_t i_ 22219ea8026Sopenharmony_ci = (ORDER == 0) ? i 22319ea8026Sopenharmony_ci : (ORDER == 1) ? (N-1-i) 22419ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % N; 22519ea8026Sopenharmony_ci printf("hm %d\n", i); 22619ea8026Sopenharmony_ci sprintf(name, "dir%08x", i_); 22719ea8026Sopenharmony_ci int err = lfs_mkdir(&lfs, name); 22819ea8026Sopenharmony_ci assert(!err || err == LFS_ERR_EXIST); 22919ea8026Sopenharmony_ci } 23019ea8026Sopenharmony_ci BENCH_STOP(); 23119ea8026Sopenharmony_ci 23219ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 23319ea8026Sopenharmony_ci''' 23419ea8026Sopenharmony_ci 23519ea8026Sopenharmony_ci[cases.bench_dir_rmdir] 23619ea8026Sopenharmony_ci# 0 = in-order 23719ea8026Sopenharmony_ci# 1 = reversed-order 23819ea8026Sopenharmony_ci# 2 = random-order 23919ea8026Sopenharmony_cidefines.ORDER = [0, 1, 2] 24019ea8026Sopenharmony_cidefines.N = 8 24119ea8026Sopenharmony_cicode = ''' 24219ea8026Sopenharmony_ci lfs_t lfs; 24319ea8026Sopenharmony_ci lfs_format(&lfs, cfg) => 0; 24419ea8026Sopenharmony_ci lfs_mount(&lfs, cfg) => 0; 24519ea8026Sopenharmony_ci 24619ea8026Sopenharmony_ci // first create the dirs 24719ea8026Sopenharmony_ci char name[256]; 24819ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 24919ea8026Sopenharmony_ci sprintf(name, "dir%08x", i); 25019ea8026Sopenharmony_ci lfs_mkdir(&lfs, name) => 0; 25119ea8026Sopenharmony_ci } 25219ea8026Sopenharmony_ci 25319ea8026Sopenharmony_ci // then remove the dirs 25419ea8026Sopenharmony_ci BENCH_START(); 25519ea8026Sopenharmony_ci uint32_t prng = 42; 25619ea8026Sopenharmony_ci for (lfs_size_t i = 0; i < N; i++) { 25719ea8026Sopenharmony_ci lfs_off_t i_ 25819ea8026Sopenharmony_ci = (ORDER == 0) ? i 25919ea8026Sopenharmony_ci : (ORDER == 1) ? (N-1-i) 26019ea8026Sopenharmony_ci : BENCH_PRNG(&prng) % N; 26119ea8026Sopenharmony_ci sprintf(name, "dir%08x", i_); 26219ea8026Sopenharmony_ci int err = lfs_remove(&lfs, name); 26319ea8026Sopenharmony_ci assert(!err || err == LFS_ERR_NOENT); 26419ea8026Sopenharmony_ci } 26519ea8026Sopenharmony_ci BENCH_STOP(); 26619ea8026Sopenharmony_ci 26719ea8026Sopenharmony_ci lfs_unmount(&lfs) => 0; 26819ea8026Sopenharmony_ci''' 26919ea8026Sopenharmony_ci 27019ea8026Sopenharmony_ci 271