diff mbox

mtd-utils: tests: avoid using only one block in nandpagetest

Message ID 20170823135732.12899-1-miquel.raynal@free-electrons.com
State Superseded
Headers show

Commit Message

Miquel Raynal Aug. 23, 2017, 1:57 p.m. UTC
Forbid the use of -c1 in nandpagetest which limits the number of blocks
to use at one. In that case, get_first_and_last_block() will return the
same id for both the first and the last blocks. In erasecrosstest(),
the logic is:
- erase/write/read/verify first block
- erase/write again first block
- erase *last* block
- read/verify first block
The case 'first == last' leads to erasing the block before reading it.
Hence the test will fail with no actual reason.

The patch does not forbid the use of -c1 as it could do it in
process_options() with a errmsg_die(). Instead, it warns the user and
uses a second block in order to avoid risking to break existing scripts.

Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
---
 tests/mtd-tests/nandpagetest.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

David Oberhollenzer Aug. 24, 2017, 8:40 a.m. UTC | #1
Hi,

On 08/23/2017 03:57 PM, Miquel Raynal wrote:
> Forbid the use of -c1 in nandpagetest which limits the number of blocks
> to use at one. In that case, get_first_and_last_block() will return the
> same id for both the first and the last blocks. In erasecrosstest(),
> the logic is:
> - erase/write/read/verify first block
> - erase/write again first block
> - erase *last* block
> - read/verify first block
> The case 'first == last' leads to erasing the block before reading it.
> Hence the test will fail with no actual reason.
> 
So if some existing automated test setup were to use this, it would
(as of right now) *always* fail and terminate with EXIT_FAILURE.

> The patch does not forbid the use of -c1 as it could do it in
> process_options() with a errmsg_die(). Instead, it warns the user and
> uses a second block in order to avoid risking to break existing scripts.
> 
But wouldn't exactly that change the behavior of such a setup by suddenly
having all tests succeed?

If this combination of options always fails anyway, wouldn't it be more
appropriate to terminate with an error message in process_options instead?


Thanks,

David
Miquel Raynal Aug. 24, 2017, 9:01 a.m. UTC | #2
Hi David,

> > The case 'first == last' leads to erasing the block before reading
> > it. Hence the test will fail with no actual reason.
> >   
> So if some existing automated test setup were to use this, it would
> (as of right now) *always* fail and terminate with EXIT_FAILURE.
> 
> > The patch does not forbid the use of -c1 as it could do it in
> > process_options() with a errmsg_die(). Instead, it warns the user
> > and uses a second block in order to avoid risking to break existing
> > scripts. 
> But wouldn't exactly that change the behavior of such a setup by
> suddenly having all tests succeed?
> 
> If this combination of options always fails anyway, wouldn't it be
> more appropriate to terminate with an error message in
> process_options instead?

I though you would prefer to do not exit with an error but I it is ok
for me, I will resend the patch, with an error thrown in
process_options().

Regards,
Miquèl
diff mbox

Patch

diff --git a/tests/mtd-tests/nandpagetest.c b/tests/mtd-tests/nandpagetest.c
index 4145ef7..ef6c126 100644
--- a/tests/mtd-tests/nandpagetest.c
+++ b/tests/mtd-tests/nandpagetest.c
@@ -452,6 +452,12 @@  int main(int argc, char **argv)
 	if (ebcnt < 0)
 		ebcnt = (mtd.eb_cnt - peb) / (skip + 1);
 
+	if (ebcnt == 1) {
+		fprintf(stderr,	PROGRAM_NAME
+			" cannot run on a single block, will use 2 instead.\n");
+		ebcnt = 2;
+	}
+
 	if (peb >= mtd.eb_cnt)
 		return errmsg("physical erase block %d is out of range!", peb);