@@ -690,6 +690,40 @@ void test_deinit_bd()
690
690
block_device = NULL ;
691
691
}
692
692
693
+ void test_write_deinit_init ()
694
+ {
695
+ TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
696
+ // Determine start_address & stop_address
697
+ bd_addr_t addr = sectors_addr[rand () % num_of_sectors];
698
+ bd_size_t erase_size = block_device->get_erase_size (addr);
699
+ bd_size_t prog_size = block_device->get_program_size ();
700
+ uint8_t *prog = (uint8_t *) malloc (prog_size);
701
+ TEST_ASSERT_NOT_EQUAL (prog, 0 );
702
+ uint8_t *buf = (uint8_t *) malloc (prog_size);
703
+ TEST_ASSERT_NOT_EQUAL (buf, 0 );
704
+
705
+ for (int i = 0 ; i < 3 ; i++) {
706
+ // Generate test pattern
707
+ for (int j = 0 ; j < prog_size; j++) {
708
+ prog[j] = (uint8_t )' 0' + i + j;
709
+ }
710
+
711
+ int err;
712
+ err = block_device->erase (addr, erase_size);
713
+ TEST_ASSERT_EQUAL (err, 0 );
714
+ err = block_device->program (prog, addr, prog_size);
715
+ TEST_ASSERT_EQUAL (err, 0 );
716
+ err = block_device->deinit ();
717
+ TEST_ASSERT_EQUAL (0 , err);
718
+ err = block_device->init ();
719
+ TEST_ASSERT_EQUAL (0 , err);
720
+ err = block_device->read (buf, addr, prog_size);
721
+ TEST_ASSERT_EQUAL (0 , memcmp (prog, buf, prog_size));
722
+ }
723
+ free (prog);
724
+ free (buf);
725
+ }
726
+
693
727
void test_get_type_functionality ()
694
728
{
695
729
utest_printf (" \n Test get blockdevice type..\n " );
@@ -727,6 +761,7 @@ typedef struct {
727
761
728
762
template_case_t template_cases[] = {
729
763
{" Testing Init block device" , test_init_bd, greentea_failure_handler},
764
+ {" Testing write -> deinit -> init -> read" , test_write_deinit_init, greentea_failure_handler},
730
765
{" Testing read write random blocks" , test_random_program_read_erase, greentea_failure_handler},
731
766
#if defined(MBED_CONF_RTOS_PRESENT)
732
767
{" Testing multi threads erase program read" , test_multi_threads, greentea_failure_handler},
0 commit comments