Ejemplo n.º 1
0
static void
recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
{

  printf("unicast message received from %x.%x: '%s'\n", from->u8[0], from->u8[1], (char *) packetbuf_dataptr());
  sprintf(buff_, NET_TEST_CFG_REQUEST_MSG, rec_count);
  printf("packet: %s\n buff: %s\n",(char *) packetbuf_dataptr(), buff_);
  if(strcmp((char *) packetbuf_dataptr(), buff_) == 0){
	  static rimeaddr_t addr;
	  addr.u8[0] = 2 & 0xFF;
	  addr.u8[1] = 0 >> 8;
	  static int8_t idx = 0;
	  char buff_[30] = {'\0'};
	  sprintf(buff_, NET_TEST_CFG_REQUEST_MSG, rec_count);
	  packetbuf_copyfrom(buff_ , NET_TEST_CFG_REQUEST_MSG_LEN); 
	  unicast_send(&uc, &addr);
	  printf("send: %s\n",buff_);
	  rec_count++;
    TEST_PASS();
  }
  
  // check if done
  if (rec_count == 10) {
  	rec_count=0;
  }
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(rime_unicast_sender, ev, data)
{
  PROCESS_EXITHANDLER(unicast_close(&uc));

  PROCESS_BEGIN();
  TEST_PASS();

  unicast_open(&uc, 146, &unicast_callbacks); /* channel = 145 */

  while(1) {
    PROCESS_YIELD();
  }
  PROCESS_END();
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udtn_demo_process, ev, data)
{
	static struct registration_api reg;
	struct mmem * outgoing_bundle_memory = NULL;
	uint8_t payload[255];
	uint32_t tmp;

	PROCESS_BEGIN();

	/* Wait for the agent to be initialized */
	PROCESS_PAUSE();

	/* Register our endpoint to receive bundles */
	reg.status = APP_ACTIVE;
	reg.application_process = PROCESS_CURRENT();
	reg.app_id = 25;
	process_post(&agent_process, dtn_application_registration_event,&reg);

	/* Allocate memory for the outgoing bundle */
	outgoing_bundle_memory = bundle_create_bundle();
	if( outgoing_bundle_memory == NULL ) {
		printf("No memory to send bundle\n");
		return -1;
	}

	/* Get the bundle flags */
	bundle_get_attr(outgoing_bundle_memory, FLAGS, &tmp);

	/* Set the bundle flags to singleton */
	tmp = BUNDLE_FLAG_SINGLETON;
	bundle_set_attr(outgoing_bundle_memory, FLAGS, &tmp);

	/* Add the payload block */
	bundle_add_block(outgoing_bundle_memory, BUNDLE_BLOCK_TYPE_PAYLOAD, BUNDLE_BLOCK_FLAG_NULL, payload, 255);

	/* To send the bundle, we send an event to the agent */
	process_post(&agent_process, dtn_send_bundle_event, (void *) outgoing_bundle_memory);

	TEST_PASS();

	PROCESS_END();
}
Ejemplo n.º 4
0
PROCESS_THREAD(test_process, ev, data)
{
	static uint32_t time_start = 0;
	static uint32_t time_stop = 0;
	static uint32_t errors = 0;
	static uint32_t collisions = 0;
	uint32_t i = 0;
	uint32_t test_data[10] = {251284450, 371537862, 425973621, 81975339, 170405567, 225666122, 421777121, 118094495, 410814580, 414999832};

	PROCESS_BEGIN();
	PROCESS_PAUSE();

	printf("Init done, starting test using redudancy implementation %s\n", REDUNDANCE.name);

	// Initialize the profiling
	profiling_init();
	profiling_start();

	// Measure the current time
	time_start = test_precise_timestamp();

	// -----------------------------------
	// Check if no bundles are stored
	printf("Making sure list is empty\n");
	for(i=0; i<0xFFFFF; i++) {
		if( REDUNDANCE.check(i) ) {
			errors ++;
			printf("ERROR: %lu reported to be set but should be empty\n", i);
		}

		// Keep the watchdog happy
		if( i % 10 == 0 ) {
			watchdog_periodic();
		}

		if( i % 10000 == 0 ) {
			printf("\t%lu...\n", i);
		}
	}

	// -----------------------------------
	// Store 10 bundles
	printf("Storing 10 bundles...\n");
	for(i=0; i<10; i++) {
		REDUNDANCE.set(test_data[i]);

		// Keep the watchdog happy
		if( i % 5 == 0 ) {
			watchdog_periodic();
		}
	}

	// Keep the watchdog happy
	watchdog_periodic();

	// -----------------------------------
	// Retrieve the 10 bundles
	printf("Reading 10 bundles back...\n");
	for(i=0; i<10; i++) {
		if( !REDUNDANCE.check(test_data[i]) ) {
			printf("ERROR: %lu should be set but is not\n", i);
			errors++;
		} else {
			printf("\t%lu is fine\n", test_data[i]);
		}
	}

	// Keep the watchdog happy
	watchdog_periodic();

	// -----------------------------------
	// Check how many bundle ID are actually reported as set
	printf("Counting collisions...\n");
	for(i=0; i<0xFFFFF; i++) {
		if( REDUNDANCE.check(i) ) {
			printf("\tcollision at %lu\n", i);
			collisions ++;
		}

		// Keep the watchdog happy
		if( i % 10 == 0 ) {
			watchdog_periodic();
		}

		if( i % 10000 == 0 ) {
			printf("\t%lu...\n", i);
		}
	}

	printf("We have %lu collisions\n", collisions);

	// Keep the watchdog happy
	watchdog_periodic();

	// -----------------------------------
	// Now set 1000 bundle IDs and check the last 10 of them
	printf("Setting 1000 bundle IDs...\n");
	for(i=0; i<1000; i++) {
		REDUNDANCE.set(i);

		// Keep the watchdog happy
		if( i % 5 == 0 ) {
			watchdog_periodic();
		}
	}

	// Keep the watchdog happy
	watchdog_periodic();

	printf("Verifying IDs...\n");
	for(i=990; i<1000; i++) {
		if( !REDUNDANCE.check(i) ) {
			printf("ERROR: %lu should be set but is not\n", i);
			errors++;
		}

		// Keep the watchdog happy
		if( i % 5 == 0 ) {
			watchdog_periodic();
		}
	}

	printf("Done\n");

	// Measure the current time
	time_stop = test_precise_timestamp();

	watchdog_stop();
	profiling_report("redundancy", 0);

	TEST_REPORT("No of errors", errors, 1, "errors");
	TEST_REPORT("Duration", time_stop-time_start, CLOCK_SECOND, "s");
	TEST_REPORT("No of collisions", collisions, 1, "collisions");

	if( errors > 0 ) {
		TEST_FAIL("More than 1 error occurred");
	} else {
		TEST_PASS();
	}

	PROCESS_END();
}
Ejemplo n.º 5
0
void test_ThisTestAlwaysPasses(void)
{
    TEST_PASS();
}
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();
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coffee_test_process, ev, data)
{
  int fd_write, n, i;
  static int cnt = 0;
  uint8_t buffer[FILE_SIZE];
  clock_time_t now;
  unsigned short now_fine;
  static uint32_t time_start, time_stop;

  printf("###########################################################\n");

  PROCESS_BEGIN();

  printf("process running\n");

  // wait for 5 sec
  etimer_set(&et, CLOCK_SECOND * 5);
  PROCESS_YIELD_UNTIL(etimer_expired(&et));

#if (COFFEE_DEVICE == 6)
  int initialized = 0, i;

  SDCARD_POWER_ON();

  //--- Detecting devices and partitions
  TEST_EQUALS(diskio_detect_devices(), DISKIO_SUCCESS);

  info = diskio_devices();
  for (i = 0; i < DISKIO_MAX_DEVICES; i++) {
    if ((info + i)->type == (DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION)) {
      info += i;
      initialized = 1;
      break; 
    }
  }
  TEST_EQUALS(initialized, 1);

  diskio_set_default_device(info);
#endif

  printf("fomartting...\n");
  TEST_EQUALS(cfs_coffee_format(), 0);
  //printf("test starting\n");

  do {
    now_fine = clock_time();
    now = clock_seconds();
  } while (now_fine != clock_time());
  time_start = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND;

  while(1) {
    // Shortest possible pause
    PROCESS_PAUSE();

    // Determine the filename
    char b_file[8];
    sprintf(b_file,"%u.b", cnt);

    // Set the file size
    printf("Reserving '%s'...\n", b_file);
    TEST_EQUALS(cfs_coffee_reserve(b_file, FILE_SIZE), 0);

      // And open it
    printf("Opening '%s'...\n", b_file);
    fd_write = cfs_open(b_file, CFS_WRITE);
    TEST_NEQ(fd_write, -1);

    // fill buffer
    for(i=0; i<FILE_SIZE; i++) {
      buffer[i] = cnt % 0xFF;
    }

    // Open was successful, write has to be successful too since the size has been reserved
    printf("Writing'%s'...\n", b_file);
    n = cfs_write(fd_write, buffer, FILE_SIZE);
    cfs_close(fd_write);

    TEST_EQUALS(n, FILE_SIZE);

    printf("%s written\n", b_file);

    if( cnt >= FILES_IN_STORAGE ) {
      int fd_read;

      // Figure out the filename
      char r_file[8];
      sprintf(r_file,"%u.b", cnt - FILES_IN_STORAGE);

      // Open the bundle file
      printf("Reopening '%s'...\n", r_file);
      fd_read = cfs_open(r_file, CFS_READ);
      if(fd_read == -1) {
        // Could not open file
        printf("############# STORAGE: could not open file %s\n", r_file);
        fail();
      }

      memset(buffer, 0, FILE_SIZE);

      // And now read the bundle back from flash
      printf("Reading '%s'...\n", b_file);
      if (cfs_read(fd_read, buffer, FILE_SIZE) == -1){
        printf("############# STORAGE: cfs_read error\n");
        cfs_close(fd_read);
        fail();
      }
      cfs_close(fd_read);

      for(i=0; i<FILE_SIZE; i++) {
        if( buffer[i] != (cnt - FILES_IN_STORAGE) % 0xFF ) {
          printf("############# STORAGE: verify error\n");
          fail();
        }
      }

      if( cfs_remove(r_file) == -1 ) {
        printf("############# STORAGE: unable to remove %s\n", r_file);
        fail();
      }

      printf("%s deleted\n", r_file);
    }

    cnt ++;

    if( cnt >= 10 ) {
      do {
        now_fine = clock_time();
        now = clock_seconds();
      } while (now_fine != clock_time());
      time_stop = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND;

      TEST_REPORT("data written", FILE_SIZE*cnt*CLOCK_SECOND, time_stop-time_start, "bytes/s");
      TEST_PASS();
      watchdog_stop();
      while(1);
    }
  }

  PROCESS_END();
}
Ejemplo n.º 8
0
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();
}