PROCESS_THREAD(test_process, ev, data) { static int n; static uint32_t i; static int errors = 0; static struct etimer timer; static uint32_t time_start, time_stop; PROCESS_BEGIN(); /* Initialize the flash before the storage comes along */ PRINTF("Intializing Flash...\n"); BUNDLE_STORAGE.format(); PROCESS_PAUSE(); profiling_init(); profiling_start(); // Wait again etimer_set(&timer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); printf("Init done, starting test using %s storage\n", BUNDLE_STORAGE.name); profiling_init(); profiling_start(); // Measure the current time time_start = test_precise_timestamp(); PRINTF("Create and Verify bundles in sequence\n"); for(i=0; i<TEST_BUNDLES; i++) { PROCESS_PAUSE(); if( my_create_bundle(i, &bundle_numbers[i], 3600) ) { PRINTF("\tBundle %lu created successfully \n", i); } else { PRINTF("\tBundle %lu could not be created \n", i); errors ++; continue; } if( my_verify_bundle(bundle_numbers[i], i) ) { PRINTF("\tBundle %lu read back successfully \n", i); } else { PRINTF("\tBundle %lu could not be read back and verified \n", i); errors ++; } } printf("Reinitialize storage\n"); /* Reinitialize the storage and see, if the bundles persist */ BUNDLE_STORAGE.init(); PRINTF("Verify and Delete bundles in sequence\n"); for(i=0; i<TEST_BUNDLES; i++) { if( my_verify_bundle(bundle_numbers[i], i) ) { PRINTF("\tBundle %lu read back successfully \n", i); } else { PRINTF("\tBundle %lu could not be read back and verified \n", i); errors ++; } n = BUNDLE_STORAGE.del_bundle(bundle_numbers[i], REASON_DELIVERED); if( n ) { PRINTF("\tBundle %lu deleted successfully\n", i); } else { PRINTF("\tBundle %lu could not be deleted\n", i); errors++; } } time_stop = test_precise_timestamp(); watchdog_stop(); profiling_report("persistent-storage", 0); TEST_REPORT("No of errors", errors, 1, "errors"); TEST_REPORT("Duration", time_stop-time_start, CLOCK_SECOND, "s"); if( errors > 0 ) { TEST_FAIL("More than 1 error occured"); } else { TEST_PASS(); } PROCESS_END(); }
PROCESS_THREAD(test_process, ev, data) { static int n; static int i; static int errors = 0; static struct etimer timer; static uint32_t time_start, time_stop; uint8_t buffer[128]; int bundle_length; struct mmem * bundle_original = NULL; struct mmem * bundle_restored = NULL; struct mmem * bundle_spare = NULL; uint32_t bundle_number; uint32_t bundle_number_spare; PROCESS_BEGIN(); PROCESS_PAUSE(); profiling_init(); profiling_start(); // Wait again etimer_set(&timer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); /* Profile initialization separately */ profiling_stop(); watchdog_stop(); profiling_report("init", 0); watchdog_start(); printf("Init done, starting test using %s storage\n", BUNDLE_STORAGE.name); profiling_init(); profiling_start(); // Measure the current time time_start = test_precise_timestamp(); for(i=0; i<=1; i++) { struct mmem bla; if( i > 0 ) { mmem_alloc(&bla, 1); } printf("Serializing and deserializing bundle...\n"); if( my_create_bundle(0, &bundle_number, 3600) ) { printf("\tBundle created successfully \n"); } else { printf("\tBundle could not be created \n"); errors ++; } printf("Serializing and deserializing bundle...\n"); if( my_create_bundle(1, &bundle_number_spare, 3600) ) { printf("\tSpare Bundle created successfully \n"); } else { printf("\tSpare Bundle could not be created \n"); errors ++; } bundle_original = BUNDLE_STORAGE.read_bundle(bundle_number); if( bundle_original == NULL ) { printf("VERIFY: MMEM ptr is invalid\n"); errors ++; } bundle_spare = BUNDLE_STORAGE.read_bundle(bundle_number_spare); if( bundle_spare == NULL ) { printf("VERIFY: MMEM ptr is invalid\n"); errors ++; } // Fake timing information in the bundle to make verify successful struct bundle_t * bundle_original_bundle = (struct bundle_t *) MMEM_PTR(bundle_original); bundle_original_bundle->aeb_value_ms = 54; bundle_original_bundle->rec_time = clock_time(); // Serialize the bundle memset(buffer, 0, 128); bundle_length = bundle_encode_bundle(bundle_original, buffer, 128); if( bundle_length < 0 ) { printf("SERIALIZE: fail\n"); errors ++; } n = my_static_compare(buffer, bundle_length); if( n > 0 ) { printf("COMPARE: fail\n"); errors += n; } // Deserialize it bundle_restored = bundle_recover_bundle(buffer, bundle_length); if( bundle_restored == NULL ) { printf("DESERIALIZE: unable to recover\n"); errors ++; } n = my_compare_bundles(bundle_original, bundle_restored); if( n == 0 ) { printf("\tBundle serialized and deserialized successfully\n"); } else { printf("COMPARE: differences\n"); errors ++; } // Dellocate memory bundle_decrement(bundle_restored); bundle_restored = NULL; bundle_decrement(bundle_original); bundle_original = NULL; bundle_decrement(bundle_spare); bundle_spare = NULL; memset(buffer, 0, 128); // Delete bundle from storage n = BUNDLE_STORAGE.del_bundle(bundle_number, REASON_DELIVERED); if( n ) { printf("\tBundle deleted successfully\n"); } else { printf("\tBundle could not be deleted\n"); errors++; } printf("Comparing static bundle...\n"); if( my_create_bundle(0, &bundle_number, 3600) ) { printf("\tReference Bundle created successfully \n"); } else { printf("\ttReference Bundle could not be created \n"); errors ++; } bundle_original = BUNDLE_STORAGE.read_bundle(bundle_number); if( bundle_original == NULL ) { printf("VERIFY: MMEM ptr is invalid\n"); errors ++; } // Deserialize it bundle_restored = bundle_recover_bundle(static_compare_bundle, sizeof(static_compare_bundle)); if( bundle_restored == NULL ) { printf("DESERIALIZE: unable to recover static bundle\n"); errors ++; } // Deserialize it one more time bundle_spare = bundle_recover_bundle(static_compare_bundle, sizeof(static_compare_bundle)); if( bundle_spare == NULL ) { printf("DESERIALIZE: unable to recover static bundle\n"); errors ++; } n = my_compare_bundles(bundle_original, bundle_restored); if( n == 0 ) { printf("\tStatic Bundle verified successfully\n"); } else { printf("COMPARE: differences\n"); errors ++; } n = my_compare_bundles(bundle_original, bundle_spare); if( n == 0 ) { printf("\tStatic Bundle verified successfully\n"); } else { printf("COMPARE: differences\n"); errors ++; } // Dellocate memory bundle_decrement(bundle_restored); bundle_restored = NULL; bundle_decrement(bundle_original); bundle_original = NULL; bundle_decrement(bundle_spare); bundle_spare = NULL; } time_stop = test_precise_timestamp(); watchdog_stop(); profiling_report("serializer", 0); TEST_REPORT("No of errors", errors, 1, "errors"); TEST_REPORT("Duration", time_stop-time_start, CLOCK_SECOND, "s"); if( errors > 0 ) { TEST_FAIL("More than 0 errors occured"); } else { TEST_PASS(); } PROCESS_END(); }