Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki
This commit is contained in:
commit
e472c6ea97
5 changed files with 329 additions and 270 deletions
|
@ -94,7 +94,15 @@ data_packet_forward(struct multihop_conn *multihop,
|
||||||
|
|
||||||
rt = route_lookup(dest);
|
rt = route_lookup(dest);
|
||||||
if(rt == NULL) {
|
if(rt == NULL) {
|
||||||
|
if(c->queued_data != NULL) {
|
||||||
|
queuebuf_free(c->queued_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTF("data_packet_forward: queueing data, sending rreq\n");
|
||||||
|
c->queued_data = queuebuf_new_from_packetbuf();
|
||||||
|
rimeaddr_copy(&c->queued_data_dest, dest);
|
||||||
route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
|
route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
route_refresh(rt);
|
route_refresh(rt);
|
||||||
|
@ -106,15 +114,21 @@ data_packet_forward(struct multihop_conn *multihop,
|
||||||
static void
|
static void
|
||||||
found_route(struct route_discovery_conn *rdc, const rimeaddr_t *dest)
|
found_route(struct route_discovery_conn *rdc, const rimeaddr_t *dest)
|
||||||
{
|
{
|
||||||
|
struct route_entry *rt;
|
||||||
struct mesh_conn *c = (struct mesh_conn *)
|
struct mesh_conn *c = (struct mesh_conn *)
|
||||||
((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn));
|
((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn));
|
||||||
|
|
||||||
|
PRINTF("found_route\n");
|
||||||
|
|
||||||
if(c->queued_data != NULL &&
|
if(c->queued_data != NULL &&
|
||||||
rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
rimeaddr_cmp(dest, &c->queued_data_dest)) {
|
||||||
queuebuf_to_packetbuf(c->queued_data);
|
queuebuf_to_packetbuf(c->queued_data);
|
||||||
queuebuf_free(c->queued_data);
|
queuebuf_free(c->queued_data);
|
||||||
c->queued_data = NULL;
|
c->queued_data = NULL;
|
||||||
if(multihop_send(&c->multihop, dest)) {
|
|
||||||
|
rt = route_lookup(dest);
|
||||||
|
if (rt != NULL) {
|
||||||
|
multihop_resend(&c->multihop, &rt->nexthop);
|
||||||
c->cb->sent(c);
|
c->cb->sent(c);
|
||||||
} else {
|
} else {
|
||||||
c->cb->timedout(c);
|
c->cb->timedout(c);
|
||||||
|
@ -175,15 +189,7 @@ mesh_send(struct mesh_conn *c, const rimeaddr_t *to)
|
||||||
could_send = multihop_send(&c->multihop, to);
|
could_send = multihop_send(&c->multihop, to);
|
||||||
|
|
||||||
if(!could_send) {
|
if(!could_send) {
|
||||||
if(c->queued_data != NULL) {
|
PRINTF("mesh_send: could not send\n");
|
||||||
queuebuf_free(c->queued_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
PRINTF("mesh_send: queueing data, sending rreq\n");
|
|
||||||
c->queued_data = queuebuf_new_from_packetbuf();
|
|
||||||
rimeaddr_copy(&c->queued_data_dest, to);
|
|
||||||
route_discovery_discover(&c->route_discovery_conn, to,
|
|
||||||
PACKET_TIMEOUT);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
c->cb->sent(c);
|
c->cb->sent(c);
|
||||||
|
|
|
@ -94,11 +94,10 @@ data_packet_received(struct unicast_conn *uc, const rimeaddr_t *from)
|
||||||
} else {
|
} else {
|
||||||
nexthop = NULL;
|
nexthop = NULL;
|
||||||
if(c->cb->forward) {
|
if(c->cb->forward) {
|
||||||
nexthop = c->cb->forward(c, &sender, &receiver,
|
|
||||||
from, packetbuf_attr(PACKETBUF_ATTR_HOPS));
|
|
||||||
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
|
packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
|
||||||
packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
|
packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
|
||||||
|
nexthop = c->cb->forward(c, &sender, &receiver,
|
||||||
|
from, packetbuf_attr(PACKETBUF_ATTR_HOPS) - 1);
|
||||||
}
|
}
|
||||||
if(nexthop) {
|
if(nexthop) {
|
||||||
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
||||||
|
@ -133,6 +132,9 @@ multihop_send(struct multihop_conn *c, const rimeaddr_t *to)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
packetbuf_compact();
|
packetbuf_compact();
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
|
||||||
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
||||||
|
|
||||||
if(nexthop == NULL) {
|
if(nexthop == NULL) {
|
||||||
|
@ -141,12 +143,15 @@ multihop_send(struct multihop_conn *c, const rimeaddr_t *to)
|
||||||
} else {
|
} else {
|
||||||
PRINTF("multihop_send: sending data towards %d.%d\n",
|
PRINTF("multihop_send: sending data towards %d.%d\n",
|
||||||
nexthop->u8[0], nexthop->u8[1]);
|
nexthop->u8[0], nexthop->u8[1]);
|
||||||
packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
|
|
||||||
packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
|
|
||||||
unicast_send(&c->c, nexthop);
|
unicast_send(&c->c, nexthop);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
multihop_resend(struct multihop_conn *c, const rimeaddr_t *nexthop)
|
||||||
|
{
|
||||||
|
unicast_send(&c->c, nexthop);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -104,6 +104,7 @@ void multihop_open(struct multihop_conn *c, uint16_t channel,
|
||||||
const struct multihop_callbacks *u);
|
const struct multihop_callbacks *u);
|
||||||
void multihop_close(struct multihop_conn *c);
|
void multihop_close(struct multihop_conn *c);
|
||||||
int multihop_send(struct multihop_conn *c, const rimeaddr_t *to);
|
int multihop_send(struct multihop_conn *c, const rimeaddr_t *to);
|
||||||
|
void multihop_resend(struct multihop_conn *c, const rimeaddr_t *nexthop);
|
||||||
|
|
||||||
#endif /* __MULTIHOP_H__ */
|
#endif /* __MULTIHOP_H__ */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -56,43 +56,14 @@ AUTOSTART_PROCESSES(&testcoffee_process);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
coffee_gc_test(void)
|
coffee_test_basic(void)
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
cfs_remove("alpha");
|
|
||||||
cfs_remove("beta");
|
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 100; i++) {
|
|
||||||
if (i & 1) {
|
|
||||||
if(cfs_coffee_reserve("alpha", random_rand() & 0xffff) < 0) {
|
|
||||||
return -i;
|
|
||||||
}
|
|
||||||
cfs_remove("beta");
|
|
||||||
} else {
|
|
||||||
if(cfs_coffee_reserve("beta", 93171) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
cfs_remove("alpha");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
coffee_file_test(void)
|
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
int wfd, rfd, afd;
|
int wfd, rfd, afd;
|
||||||
unsigned char buf[256], buf2[11];
|
unsigned char buf[256];
|
||||||
int r, i, j, total_read;
|
int r;
|
||||||
unsigned offset;
|
|
||||||
|
|
||||||
cfs_remove("T1");
|
cfs_remove("T1");
|
||||||
cfs_remove("T2");
|
|
||||||
cfs_remove("T3");
|
|
||||||
|
|
||||||
wfd = rfd = afd = -1;
|
wfd = rfd = afd = -1;
|
||||||
|
|
||||||
|
@ -103,130 +74,207 @@ coffee_file_test(void)
|
||||||
/* Test 1: Open for writing. */
|
/* Test 1: Open for writing. */
|
||||||
wfd = cfs_open("T1", CFS_WRITE);
|
wfd = cfs_open("T1", CFS_WRITE);
|
||||||
if(wfd < 0) {
|
if(wfd < 0) {
|
||||||
FAIL(-1);
|
FAIL(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 2: Write buffer. */
|
/* Test 2 and 3: Write buffer. */
|
||||||
r = cfs_write(wfd, buf, sizeof(buf));
|
r = cfs_write(wfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-2);
|
FAIL(2);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(-3);
|
FAIL(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 3: Deny reading. */
|
/* Test 4: Deny reading. */
|
||||||
r = cfs_read(wfd, buf, sizeof(buf));
|
r = cfs_read(wfd, buf, sizeof(buf));
|
||||||
if(r >= 0) {
|
if(r >= 0) {
|
||||||
FAIL(-4);
|
FAIL(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 4: Open for reading. */
|
/* Test 5: Open for reading. */
|
||||||
rfd = cfs_open("T1", CFS_READ);
|
rfd = cfs_open("T1", CFS_READ);
|
||||||
if(rfd < 0) {
|
if(rfd < 0) {
|
||||||
FAIL(-5);
|
FAIL(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 5: Write to read-only file. */
|
/* Test 6: Write to read-only file. */
|
||||||
r = cfs_write(rfd, buf, sizeof(buf));
|
r = cfs_write(rfd, buf, sizeof(buf));
|
||||||
if(r >= 0) {
|
if(r >= 0) {
|
||||||
FAIL(-6);
|
FAIL(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 7: Read the buffer written in Test 2. */
|
/* Test 7 and 8: Read the buffer written in Test 2. */
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
r = cfs_read(rfd, buf, sizeof(buf));
|
r = cfs_read(rfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-8);
|
FAIL(7);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
printf("r=%d\n", r);
|
printf("r=%d\n", r);
|
||||||
FAIL(-9);
|
FAIL(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 8: Verify that the buffer is correct. */
|
/* Test 9: Verify that the buffer is correct. */
|
||||||
for(r = 0; r < sizeof(buf); r++) {
|
for(r = 0; r < sizeof(buf); r++) {
|
||||||
if(buf[r] != r) {
|
if(buf[r] != r) {
|
||||||
printf("r=%d. buf[r]=%d\n", r, buf[r]);
|
printf("r=%d. buf[r]=%d\n", r, buf[r]);
|
||||||
FAIL(-10);
|
FAIL(9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 9: Seek to beginning. */
|
/* Test 10: Seek to beginning. */
|
||||||
if(cfs_seek(wfd, 0, CFS_SEEK_SET) != 0) {
|
if(cfs_seek(wfd, 0, CFS_SEEK_SET) != 0) {
|
||||||
FAIL(-11);
|
FAIL(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 10: Write to the log. */
|
/* Test 11 and 12: Write to the log. */
|
||||||
r = cfs_write(wfd, buf, sizeof(buf));
|
r = cfs_write(wfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-12);
|
FAIL(11);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(-13);
|
FAIL(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 11: Read the data from the log. */
|
/* Test 13 and 14: Read the data from the log. */
|
||||||
cfs_seek(rfd, 0, CFS_SEEK_SET);
|
cfs_seek(rfd, 0, CFS_SEEK_SET);
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
r = cfs_read(rfd, buf, sizeof(buf));
|
r = cfs_read(rfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-14);
|
FAIL(14);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(-15);
|
FAIL(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 12: Verify that the data is correct. */
|
/* Test 16: Verify that the data is correct. */
|
||||||
for(r = 0; r < sizeof(buf); r++) {
|
for(r = 0; r < sizeof(buf); r++) {
|
||||||
if(buf[r] != r) {
|
if(buf[r] != r) {
|
||||||
FAIL(-16);
|
FAIL(16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 13: Write a reversed buffer to the file. */
|
/* Test 17 to 20: Write a reversed buffer to the file. */
|
||||||
for(r = 0; r < sizeof(buf); r++) {
|
for(r = 0; r < sizeof(buf); r++) {
|
||||||
buf[r] = sizeof(buf) - r - 1;
|
buf[r] = sizeof(buf) - r - 1;
|
||||||
}
|
}
|
||||||
if(cfs_seek(wfd, 0, CFS_SEEK_SET) != 0) {
|
if(cfs_seek(wfd, 0, CFS_SEEK_SET) != 0) {
|
||||||
FAIL(-17);
|
FAIL(17);
|
||||||
}
|
}
|
||||||
r = cfs_write(wfd, buf, sizeof(buf));
|
r = cfs_write(wfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-18);
|
FAIL(18);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(-19);
|
FAIL(19);
|
||||||
}
|
}
|
||||||
if(cfs_seek(rfd, 0, CFS_SEEK_SET) != 0) {
|
if(cfs_seek(rfd, 0, CFS_SEEK_SET) != 0) {
|
||||||
FAIL(-20);
|
FAIL(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 14: Read the reversed buffer. */
|
/* Test 21 and 22: Read the reversed buffer. */
|
||||||
cfs_seek(rfd, 0, CFS_SEEK_SET);
|
cfs_seek(rfd, 0, CFS_SEEK_SET);
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
r = cfs_read(rfd, buf, sizeof(buf));
|
r = cfs_read(rfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(-21);
|
FAIL(21);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
printf("r = %d\n", r);
|
printf("r = %d\n", r);
|
||||||
FAIL(-22);
|
FAIL(22);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 15: Verify that the data is correct. */
|
/* Test 23: Verify that the data is correct. */
|
||||||
for(r = 0; r < sizeof(buf); r++) {
|
for(r = 0; r < sizeof(buf); r++) {
|
||||||
if(buf[r] != sizeof(buf) - r - 1) {
|
if(buf[r] != sizeof(buf) - r - 1) {
|
||||||
FAIL(-23);
|
FAIL(23);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfs_close(rfd);
|
error = 0;
|
||||||
|
end:
|
||||||
cfs_close(wfd);
|
cfs_close(wfd);
|
||||||
|
cfs_close(rfd);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
coffee_test_append(void)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
int afd;
|
||||||
|
unsigned char buf[256], buf2[11];
|
||||||
|
int r, i, j, total_read;
|
||||||
|
#define APPEND_BYTES 1000
|
||||||
|
#define BULK_SIZE 10
|
||||||
|
|
||||||
if(cfs_coffee_reserve("T2", FILE_SIZE) < 0) {
|
cfs_remove("T2");
|
||||||
FAIL(-24);
|
|
||||||
|
/* Test 1 and 2: Append data to the same file many times. */
|
||||||
|
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
||||||
|
afd = cfs_open("T3", CFS_WRITE | CFS_APPEND);
|
||||||
|
if(afd < 0) {
|
||||||
|
FAIL(1);
|
||||||
|
}
|
||||||
|
for(j = 0; j < BULK_SIZE; j++) {
|
||||||
|
buf[j] = 1 + ((i + j) & 0x7f);
|
||||||
|
}
|
||||||
|
if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) {
|
||||||
|
printf("r=%d\n", r);
|
||||||
|
FAIL(2);
|
||||||
|
}
|
||||||
|
cfs_close(afd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test 3-6: Read back the data written previously and verify that it
|
||||||
|
is correct. */
|
||||||
|
afd = cfs_open("T3", CFS_READ);
|
||||||
|
if(afd < 0) {
|
||||||
|
FAIL(3);
|
||||||
|
}
|
||||||
|
total_read = 0;
|
||||||
|
while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) {
|
||||||
|
for(j = 0; j < r; j++) {
|
||||||
|
if(buf2[j] != 1 + ((total_read + j) & 0x7f)) {
|
||||||
|
FAIL(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total_read += r;
|
||||||
|
}
|
||||||
|
if(r < 0) {
|
||||||
|
FAIL(5);
|
||||||
|
}
|
||||||
|
if(total_read != APPEND_BYTES) {
|
||||||
|
FAIL(6);
|
||||||
|
}
|
||||||
|
cfs_close(afd);
|
||||||
|
|
||||||
|
error = 0;
|
||||||
|
end:
|
||||||
|
cfs_close(afd);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
coffee_test_modify(void)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
int wfd;
|
||||||
|
unsigned char buf[256];
|
||||||
|
int r, i;
|
||||||
|
unsigned offset;
|
||||||
|
|
||||||
|
cfs_remove("T3");
|
||||||
|
wfd = -1;
|
||||||
|
|
||||||
|
if(cfs_coffee_reserve("T3", FILE_SIZE) < 0) {
|
||||||
|
FAIL(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cfs_coffee_configure_log("T3", FILE_SIZE / 2, 11) < 0) {
|
||||||
|
FAIL(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 16: Test multiple writes at random offset. */
|
/* Test 16: Test multiple writes at random offset. */
|
||||||
for(r = 0; r < 100; r++) {
|
for(r = 0; r < 100; r++) {
|
||||||
wfd = cfs_open("T2", CFS_WRITE | CFS_READ);
|
wfd = cfs_open("T2", CFS_WRITE | CFS_READ);
|
||||||
if(wfd < 0) {
|
if(wfd < 0) {
|
||||||
FAIL(-25);
|
FAIL(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = random_rand() % FILE_SIZE;
|
offset = random_rand() % FILE_SIZE;
|
||||||
|
@ -236,88 +284,101 @@ coffee_file_test(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
||||||
FAIL(-26);
|
FAIL(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_write(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
if(cfs_write(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
||||||
FAIL(-27);
|
FAIL(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
||||||
FAIL(-28);
|
FAIL(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
if(cfs_read(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
if(cfs_read(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
||||||
FAIL(-29);
|
FAIL(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < sizeof(buf); i++) {
|
for(i = 0; i < sizeof(buf); i++) {
|
||||||
if(buf[i] != i) {
|
if(buf[i] != i) {
|
||||||
printf("buf[%d] != %d\n", i, buf[i]);
|
printf("buf[%d] != %d\n", i, buf[i]);
|
||||||
FAIL(-30);
|
FAIL(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 17: Append data to the same file many times. */
|
|
||||||
#define APPEND_BYTES 1000
|
|
||||||
#define BULK_SIZE 10
|
|
||||||
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
|
||||||
afd = cfs_open("T3", CFS_WRITE | CFS_APPEND);
|
|
||||||
if(afd < 0) {
|
|
||||||
FAIL(-31);
|
|
||||||
}
|
|
||||||
for(j = 0; j < BULK_SIZE; j++) {
|
|
||||||
buf[j] = 1 + ((i + j) & 0x7f);
|
|
||||||
}
|
|
||||||
if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) {
|
|
||||||
printf("r=%d\n", r);
|
|
||||||
FAIL(-32);
|
|
||||||
}
|
|
||||||
cfs_close(afd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 18: Read back the data written in Test 17 and verify that it
|
|
||||||
is correct. */
|
|
||||||
afd = cfs_open("T3", CFS_READ);
|
|
||||||
if(afd < 0) {
|
|
||||||
FAIL(-33);
|
|
||||||
}
|
|
||||||
total_read = 0;
|
|
||||||
while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) {
|
|
||||||
for(j = 0; j < r; j++) {
|
|
||||||
if(buf2[j] != 1 + ((total_read + j) & 0x7f)) {
|
|
||||||
FAIL(-34);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
total_read += r;
|
|
||||||
}
|
|
||||||
if(r < 0) {
|
|
||||||
FAIL(-35);
|
|
||||||
}
|
|
||||||
if(total_read != APPEND_BYTES) {
|
|
||||||
FAIL(-36);
|
|
||||||
}
|
|
||||||
cfs_close(afd);
|
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
end:
|
end:
|
||||||
cfs_close(wfd); cfs_close(rfd); cfs_close(afd);
|
cfs_close(wfd);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
coffee_test_gc(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cfs_remove("alpha");
|
||||||
|
cfs_remove("beta");
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < 100; i++) {
|
||||||
|
if (i & 1) {
|
||||||
|
if(cfs_coffee_reserve("alpha", random_rand() & 0xffff) < 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
cfs_remove("beta");
|
||||||
|
} else {
|
||||||
|
if(cfs_coffee_reserve("beta", 93171) < 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
cfs_remove("alpha");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
print_result(const char *test_name, int result)
|
||||||
|
{
|
||||||
|
printf("%s: ", test_name);
|
||||||
|
if(result == 0) {
|
||||||
|
printf("OK\n");
|
||||||
|
} else {
|
||||||
|
printf("ERROR (test %d)\n", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS_THREAD(testcoffee_process, ev, data)
|
PROCESS_THREAD(testcoffee_process, ev, data)
|
||||||
{
|
{
|
||||||
int start;
|
int start;
|
||||||
|
int result;
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
start = clock_seconds();
|
start = clock_seconds();
|
||||||
printf("Coffee format: %d\n", cfs_coffee_format());
|
|
||||||
printf("Coffee file test: %d\n", coffee_file_test());
|
printf("Coffee test started\n");
|
||||||
printf("Coffee garbage collection test: %d\n", coffee_gc_test());
|
|
||||||
printf("Test time: %d seconds\n", (int)(clock_seconds() - start));
|
result = cfs_coffee_format();
|
||||||
|
print_result("Formatting", result);
|
||||||
|
|
||||||
|
result = coffee_test_basic();
|
||||||
|
print_result("Basic operations", result);
|
||||||
|
|
||||||
|
result = coffee_test_append();
|
||||||
|
print_result("File append", result);
|
||||||
|
|
||||||
|
result = coffee_test_modify();
|
||||||
|
print_result("File modification", result);
|
||||||
|
|
||||||
|
result = coffee_test_gc();
|
||||||
|
print_result("Garbage collection", result);
|
||||||
|
|
||||||
|
printf("Coffee test finished. Duration: %d seconds\n",
|
||||||
|
(int)(clock_seconds() - start));
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,132 +1,118 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<simconf>
|
<simconf>
|
||||||
<project>../apps/mrm</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||||
<project>../apps/mspsim</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||||
<project>../apps/avrora</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||||
<project>../apps/native_gateway</project>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||||
<simulation>
|
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
|
||||||
<title>test</title>
|
<simulation>
|
||||||
<delaytime>0</delaytime>
|
<title>test</title>
|
||||||
<randomseed>generated</randomseed>
|
<delaytime>0</delaytime>
|
||||||
<motedelay_us>0</motedelay_us>
|
<randomseed>generated</randomseed>
|
||||||
<radiomedium>
|
<motedelay_us>0</motedelay_us>
|
||||||
se.sics.cooja.radiomediums.UDGM
|
<radiomedium>
|
||||||
<transmitting_range>50.0</transmitting_range>
|
se.sics.cooja.radiomediums.UDGM
|
||||||
<interference_range>100.0</interference_range>
|
<transmitting_range>50.0</transmitting_range>
|
||||||
<success_ratio_tx>1.0</success_ratio_tx>
|
<interference_range>100.0</interference_range>
|
||||||
<success_ratio_rx>1.0</success_ratio_rx>
|
<success_ratio_tx>1.0</success_ratio_tx>
|
||||||
</radiomedium>
|
<success_ratio_rx>1.0</success_ratio_rx>
|
||||||
<motetype>
|
</radiomedium>
|
||||||
se.sics.cooja.mspmote.SkyMoteType
|
<events>
|
||||||
<identifier>sky1</identifier>
|
<logoutput>40000</logoutput>
|
||||||
<description>Sky Mote Type #1</description>
|
</events>
|
||||||
<source>../../../examples/sky/test-coffee.c</source>
|
<motetype>
|
||||||
<commands>make clean TARGET=sky
|
se.sics.cooja.mspmote.SkyMoteType
|
||||||
make test-coffee.sky TARGET=sky</commands>
|
<identifier>sky1</identifier>
|
||||||
<firmware>../../../examples/sky/test-coffee.sky</firmware>
|
<description>Sky Mote Type #1</description>
|
||||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/sky/test-coffee.c</source>
|
||||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
<commands EXPORT="discard">make clean TARGET=sky
|
||||||
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
make test-coffee.sky TARGET=sky</commands>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/sky/test-coffee.sky</firmware>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.SkySerial</moteinterface>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||||
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||||
</motetype>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||||
<mote>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
|
||||||
se.sics.cooja.mspmote.SkyMote
|
<moteinterface>se.sics.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||||
<motetype_identifier>sky1</motetype_identifier>
|
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||||
<breakpoints />
|
</motetype>
|
||||||
<interface_config>
|
<mote>
|
||||||
se.sics.cooja.interfaces.Position
|
<breakpoints />
|
||||||
<x>97.11078411573273</x>
|
<interface_config>
|
||||||
<y>56.790978919276014</y>
|
se.sics.cooja.interfaces.Position
|
||||||
<z>0.0</z>
|
<x>97.11078411573273</x>
|
||||||
</interface_config>
|
<y>56.790978919276014</y>
|
||||||
<interface_config>
|
<z>0.0</z>
|
||||||
se.sics.cooja.mspmote.interfaces.MspMoteID
|
</interface_config>
|
||||||
<id>1</id>
|
<interface_config>
|
||||||
</interface_config>
|
se.sics.cooja.mspmote.interfaces.MspMoteID
|
||||||
</mote>
|
<id>1</id>
|
||||||
</simulation>
|
</interface_config>
|
||||||
<plugin>
|
<motetype_identifier>sky1</motetype_identifier>
|
||||||
se.sics.cooja.plugins.SimControl
|
</mote>
|
||||||
<width>248</width>
|
</simulation>
|
||||||
<z>3</z>
|
<plugin>
|
||||||
<height>200</height>
|
se.sics.cooja.plugins.SimControl
|
||||||
<location_x>0</location_x>
|
<width>248</width>
|
||||||
<location_y>0</location_y>
|
<z>0</z>
|
||||||
<minimized>false</minimized>
|
<height>200</height>
|
||||||
</plugin>
|
<location_x>0</location_x>
|
||||||
<plugin>
|
<location_y>0</location_y>
|
||||||
se.sics.cooja.plugins.Visualizer
|
</plugin>
|
||||||
<plugin_config>
|
<plugin>
|
||||||
<skin>Mote IDs</skin>
|
se.sics.cooja.plugins.Visualizer
|
||||||
<skin>Log output: printf()'s</skin>
|
<plugin_config>
|
||||||
</plugin_config>
|
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||||
<width>246</width>
|
<skin>se.sics.cooja.plugins.skins.LogVisualizerSkin</skin>
|
||||||
<z>2</z>
|
<viewport>0.9090909090909091 0.0 0.0 0.9090909090909091 28.717468985697536 3.3718373461127142</viewport>
|
||||||
<height>170</height>
|
</plugin_config>
|
||||||
<location_x>1</location_x>
|
<width>246</width>
|
||||||
<location_y>200</location_y>
|
<z>3</z>
|
||||||
<minimized>false</minimized>
|
<height>170</height>
|
||||||
</plugin>
|
<location_x>1</location_x>
|
||||||
<plugin>
|
<location_y>200</location_y>
|
||||||
se.sics.cooja.plugins.LogListener
|
</plugin>
|
||||||
<plugin_config>
|
<plugin>
|
||||||
<filter />
|
se.sics.cooja.plugins.LogListener
|
||||||
</plugin_config>
|
<plugin_config>
|
||||||
<width>846</width>
|
<filter />
|
||||||
<z>1</z>
|
</plugin_config>
|
||||||
<height>209</height>
|
<width>846</width>
|
||||||
<location_x>2</location_x>
|
<z>2</z>
|
||||||
<location_y>370</location_y>
|
<height>209</height>
|
||||||
<minimized>false</minimized>
|
<location_x>2</location_x>
|
||||||
</plugin>
|
<location_y>370</location_y>
|
||||||
<plugin>
|
</plugin>
|
||||||
se.sics.cooja.plugins.ScriptRunner
|
<plugin>
|
||||||
<plugin_config>
|
se.sics.cooja.plugins.ScriptRunner
|
||||||
<script>TIMEOUT(80000);
|
<plugin_config>
|
||||||
|
<script>TIMEOUT(80000);
|
||||||
fileOK = null;
|
|
||||||
gcOK = null;
|
fileOK = null;
|
||||||
|
gcOK = null;
|
||||||
while (fileOK == null || gcOK == null) {
|
|
||||||
YIELD();
|
while (fileOK == null || gcOK == null) {
|
||||||
|
YIELD();
|
||||||
if (msg.startsWith('Coffee file test: 0')) {
|
|
||||||
fileOK = true;
|
if(msg.contains("ERROR")) {
|
||||||
} else if (msg.startsWith('Coffee file test')) {
|
log.log(msg);
|
||||||
fileOK = false;
|
log.testFailed();
|
||||||
} else if (msg.startsWith('Coffee garbage collection test: 0')) {
|
}
|
||||||
gcOK = true;
|
|
||||||
} else if (msg.startsWith('Coffee garbage collection test')) {
|
if (msg.startsWith('Coffee test finished')) {
|
||||||
gcOK = false;
|
log.testOK();
|
||||||
}
|
}
|
||||||
|
}</script>
|
||||||
}
|
<active>true</active>
|
||||||
|
</plugin_config>
|
||||||
if (gcOK == false) {
|
<width>601</width>
|
||||||
log.log("coffee garbage collection failed\n");
|
<z>1</z>
|
||||||
}
|
<height>370</height>
|
||||||
if (fileOK == false) {
|
<location_x>247</location_x>
|
||||||
log.log("coffee file test failed\n");
|
<location_y>0</location_y>
|
||||||
}
|
</plugin>
|
||||||
if (!fileOK || !gcOK) {
|
</simconf>
|
||||||
log.testFailed();
|
|
||||||
} else {
|
|
||||||
log.testOK();
|
|
||||||
}</script>
|
|
||||||
<active>true</active>
|
|
||||||
</plugin_config>
|
|
||||||
<width>601</width>
|
|
||||||
<z>0</z>
|
|
||||||
<height>370</height>
|
|
||||||
<location_x>247</location_x>
|
|
||||||
<location_y>0</location_y>
|
|
||||||
<minimized>false</minimized>
|
|
||||||
</plugin>
|
|
||||||
</simconf>
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue