Added optional read/prog/erase delays to testbd

These have no real purpose other than slowing down the simulation
for inspection/fun.

Note this did reveal an issue in pretty_asserts.py which was clobbering
feature macros. Added explicit, and maybe a bit hacky, #undef _FEATURE_H
to avoid this.
This commit is contained in:
Christopher Haster
2022-08-23 17:01:04 -05:00
parent 3f4f85986e
commit 552336eba9
5 changed files with 129 additions and 1 deletions

View File

@@ -7,12 +7,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L
#endif
#include "bd/lfs_testbd.h"
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#ifdef _WIN32
#include <windows.h>
@@ -238,6 +243,18 @@ int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block,
size);
}
if (bd->cfg->read_delay) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->read_delay/1000000000,
.tv_nsec=bd->cfg->read_delay%1000000000},
NULL);
if (err) {
err = -errno;
LFS_TESTBD_TRACE("lfs_testbd_read -> %d", err);
return err;
}
}
LFS_TESTBD_TRACE("lfs_testbd_read -> %d", 0);
return 0;
}
@@ -306,6 +323,18 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block,
}
}
if (bd->cfg->prog_delay) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->prog_delay/1000000000,
.tv_nsec=bd->cfg->prog_delay%1000000000},
NULL);
if (err) {
err = -errno;
LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", err);
return err;
}
}
// lose power?
if (bd->power_cycles > 0) {
bd->power_cycles -= 1;
@@ -386,6 +415,18 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) {
}
}
if (bd->cfg->erase_delay) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->erase_delay/1000000000,
.tv_nsec=bd->cfg->erase_delay%1000000000},
NULL);
if (err) {
err = -errno;
LFS_TESTBD_TRACE("lfs_testbd_erase -> %d", err);
return err;
}
}
// lose power?
if (bd->power_cycles > 0) {
bd->power_cycles -= 1;

View File

@@ -57,6 +57,10 @@ typedef int32_t lfs_testbd_swear_t;
typedef uint32_t lfs_testbd_powercycles_t;
typedef int32_t lfs_testbd_spowercycles_t;
// Type for delays in nanoseconds
typedef uint64_t lfs_testbd_delay_t;
typedef int64_t lfs_testbd_sdelay_t;
// testbd config, this is required for testing
struct lfs_testbd_config {
// 8-bit erase value to use for simulating erases. -1 does not simulate
@@ -93,6 +97,18 @@ struct lfs_testbd_config {
// Path to file to use as a mirror of the disk. This provides a way to view
// the current state of the block device.
const char *disk_path;
// Artificial delay in nanoseconds, there is no purpose for this other
// than slowing down the simulation.
lfs_testbd_delay_t read_delay;
// Artificial delay in nanoseconds, there is no purpose for this other
// than slowing down the simulation.
lfs_testbd_delay_t prog_delay;
// Artificial delay in nanoseconds, there is no purpose for this other
// than slowing down the simulation.
lfs_testbd_delay_t erase_delay;
};
// A reference counted block