Make CFS and Coffee examples platform-independent
Move the CFS and Coffee examples from sky to a common cfs-coffee folder in order to have unified examples for multiple platforms.
This commit is contained in:
parent
d70c75914a
commit
4ed5c50a4e
11
examples/cfs-coffee/Makefile
Normal file
11
examples/cfs-coffee/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
CONTIKI = ../..
|
||||||
|
|
||||||
|
all: test-cfs test-coffee example-coffee
|
||||||
|
|
||||||
|
CONTIKI_WITH_RIME = 1
|
||||||
|
|
||||||
|
ifeq ($(TARGET),avr-raven)
|
||||||
|
COFFEE_FILES = 4
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(CONTIKI)/Makefile.include
|
26
examples/cfs-coffee/README.md
Normal file
26
examples/cfs-coffee/README.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
Contiki File System (CFS) and Coffee Examples
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
Coffee is a very simple, relatively small and easy to use file system that you
|
||||||
|
are most likely going to be very familiar with if you have done any C file
|
||||||
|
access in the past. The notion is the same as on a normal PC: you open a file,
|
||||||
|
read and write to it and close it. Contiki will take care of the underlying
|
||||||
|
flash memory, giving you more time to focus on the real issues.
|
||||||
|
|
||||||
|
Coffee is a full implementation of the CFS API.
|
||||||
|
|
||||||
|
An extended explanation on CFS and Coffee internals and how they work can be
|
||||||
|
found at the [CFS](https://github.com/contiki-os/contiki/wiki/File-systems) and
|
||||||
|
[Coffee](https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example)
|
||||||
|
wiki pages.
|
||||||
|
|
||||||
|
Supported Hardware (tested or known to work)
|
||||||
|
--------------------------------------------
|
||||||
|
* sky
|
||||||
|
* z1
|
||||||
|
* wismote
|
||||||
|
* avr-raven
|
||||||
|
|
||||||
|
The examples are known to build for the 'avr-raven' platform. However,
|
||||||
|
some of them currently fail at runtime due to file system overflow.
|
||||||
|
Tweaking the file sizes in the examples is necessary.
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "cfs/cfs.h"
|
#include "cfs/cfs.h"
|
||||||
#include "cfs/cfs-coffee.h"
|
#include "cfs/cfs-coffee.h"
|
|
@ -49,7 +49,7 @@
|
||||||
PROCESS(testcoffee_process, "Test CFS/Coffee process");
|
PROCESS(testcoffee_process, "Test CFS/Coffee process");
|
||||||
AUTOSTART_PROCESSES(&testcoffee_process);
|
AUTOSTART_PROCESSES(&testcoffee_process);
|
||||||
|
|
||||||
#define FAIL(x) error = (x); goto end;
|
#define TEST_FAIL(x) error = (x); goto end;
|
||||||
|
|
||||||
#define FILE_SIZE 4096
|
#define FILE_SIZE 4096
|
||||||
|
|
||||||
|
@ -73,64 +73,64 @@ coffee_test_basic(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);
|
TEST_FAIL(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 2 and 3: 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);
|
TEST_FAIL(2);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(3);
|
TEST_FAIL(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 4: 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);
|
TEST_FAIL(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 5: 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);
|
TEST_FAIL(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 6: 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);
|
TEST_FAIL(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 7 and 8: 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(7);
|
TEST_FAIL(7);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
printf("r=%d\n", r);
|
printf("r=%d\n", r);
|
||||||
FAIL(8);
|
TEST_FAIL(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 9: 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(9);
|
TEST_FAIL(9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 10: 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(10);
|
TEST_FAIL(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 11 and 12: 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(11);
|
TEST_FAIL(11);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(12);
|
TEST_FAIL(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 13 and 14: Read the data from the log. */
|
/* Test 13 and 14: Read the data from the log. */
|
||||||
|
@ -138,15 +138,15 @@ coffee_test_basic(void)
|
||||||
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);
|
TEST_FAIL(14);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(15);
|
TEST_FAIL(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 16: 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);
|
TEST_FAIL(16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,16 +155,16 @@ coffee_test_basic(void)
|
||||||
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);
|
TEST_FAIL(17);
|
||||||
}
|
}
|
||||||
r = cfs_write(wfd, buf, sizeof(buf));
|
r = cfs_write(wfd, buf, sizeof(buf));
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(18);
|
TEST_FAIL(18);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
FAIL(19);
|
TEST_FAIL(19);
|
||||||
}
|
}
|
||||||
if(cfs_seek(rfd, 0, CFS_SEEK_SET) != 0) {
|
if(cfs_seek(rfd, 0, CFS_SEEK_SET) != 0) {
|
||||||
FAIL(20);
|
TEST_FAIL(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 21 and 22: Read the reversed buffer. */
|
/* Test 21 and 22: Read the reversed buffer. */
|
||||||
|
@ -172,16 +172,16 @@ coffee_test_basic(void)
|
||||||
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);
|
TEST_FAIL(21);
|
||||||
} else if(r < sizeof(buf)) {
|
} else if(r < sizeof(buf)) {
|
||||||
printf("r = %d\n", r);
|
printf("r = %d\n", r);
|
||||||
FAIL(22);
|
TEST_FAIL(22);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test 23: 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);
|
TEST_FAIL(23);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,14 +208,14 @@ coffee_test_append(void)
|
||||||
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) {
|
||||||
afd = cfs_open("T3", CFS_WRITE | CFS_APPEND);
|
afd = cfs_open("T3", CFS_WRITE | CFS_APPEND);
|
||||||
if(afd < 0) {
|
if(afd < 0) {
|
||||||
FAIL(1);
|
TEST_FAIL(1);
|
||||||
}
|
}
|
||||||
for(j = 0; j < BULK_SIZE; j++) {
|
for(j = 0; j < BULK_SIZE; j++) {
|
||||||
buf[j] = 1 + ((i + j) & 0x7f);
|
buf[j] = 1 + ((i + j) & 0x7f);
|
||||||
}
|
}
|
||||||
if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) {
|
if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) {
|
||||||
printf("r=%d\n", r);
|
printf("r=%d\n", r);
|
||||||
FAIL(2);
|
TEST_FAIL(2);
|
||||||
}
|
}
|
||||||
cfs_close(afd);
|
cfs_close(afd);
|
||||||
}
|
}
|
||||||
|
@ -224,22 +224,22 @@ coffee_test_append(void)
|
||||||
is correct. */
|
is correct. */
|
||||||
afd = cfs_open("T3", CFS_READ);
|
afd = cfs_open("T3", CFS_READ);
|
||||||
if(afd < 0) {
|
if(afd < 0) {
|
||||||
FAIL(3);
|
TEST_FAIL(3);
|
||||||
}
|
}
|
||||||
total_read = 0;
|
total_read = 0;
|
||||||
while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) {
|
while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) {
|
||||||
for(j = 0; j < r; j++) {
|
for(j = 0; j < r; j++) {
|
||||||
if(buf2[j] != 1 + ((total_read + j) & 0x7f)) {
|
if(buf2[j] != 1 + ((total_read + j) & 0x7f)) {
|
||||||
FAIL(4);
|
TEST_FAIL(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
total_read += r;
|
total_read += r;
|
||||||
}
|
}
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
FAIL(5);
|
TEST_FAIL(5);
|
||||||
}
|
}
|
||||||
if(total_read != APPEND_BYTES) {
|
if(total_read != APPEND_BYTES) {
|
||||||
FAIL(6);
|
TEST_FAIL(6);
|
||||||
}
|
}
|
||||||
cfs_close(afd);
|
cfs_close(afd);
|
||||||
|
|
||||||
|
@ -262,18 +262,18 @@ coffee_test_modify(void)
|
||||||
wfd = -1;
|
wfd = -1;
|
||||||
|
|
||||||
if(cfs_coffee_reserve("T3", FILE_SIZE) < 0) {
|
if(cfs_coffee_reserve("T3", FILE_SIZE) < 0) {
|
||||||
FAIL(1);
|
TEST_FAIL(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_coffee_configure_log("T3", FILE_SIZE / 2, 11) < 0) {
|
if(cfs_coffee_configure_log("T3", FILE_SIZE / 2, 11) < 0) {
|
||||||
FAIL(2);
|
TEST_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(3);
|
TEST_FAIL(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = random_rand() % FILE_SIZE;
|
offset = random_rand() % FILE_SIZE;
|
||||||
|
@ -283,26 +283,26 @@ coffee_test_modify(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
||||||
FAIL(4);
|
TEST_FAIL(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_write(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
if(cfs_write(wfd, buf, sizeof(buf)) != sizeof(buf)) {
|
||||||
FAIL(5);
|
TEST_FAIL(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
if(cfs_seek(wfd, offset, CFS_SEEK_SET) != offset) {
|
||||||
FAIL(6);
|
TEST_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(7);
|
TEST_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(8);
|
TEST_FAIL(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ ifndef TARGET
|
||||||
TARGET=sky
|
TARGET=sky
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: blink sky-collect #rt-leds test-button test-cfs tcprudolph0
|
all: blink sky-collect #rt-leds test-button tcprudolph0
|
||||||
|
|
||||||
%.tgz: %.ihex
|
%.tgz: %.ihex
|
||||||
mkdir $(basename $<) ; \
|
mkdir $(basename $<) ; \
|
||||||
|
|
|
@ -37,8 +37,11 @@ settings-example/avr-raven \
|
||||||
ipv6/multicast/sky \
|
ipv6/multicast/sky \
|
||||||
ipv6/rpl-tsch/z1 \
|
ipv6/rpl-tsch/z1 \
|
||||||
ipv6/rpl-tsch/z1:MAKE_WITH_ORCHESTRA=1 \
|
ipv6/rpl-tsch/z1:MAKE_WITH_ORCHESTRA=1 \
|
||||||
ipv6/rpl-tsch/z1:MAKE_WITH_SECURITY=1
|
ipv6/rpl-tsch/z1:MAKE_WITH_SECURITY=1 \
|
||||||
|
cfs-coffee/sky \
|
||||||
|
cfs-coffee/z1 \
|
||||||
|
cfs-coffee/wismote \
|
||||||
|
cfs-coffee/avr-raven
|
||||||
|
|
||||||
TOOLS=
|
TOOLS=
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
org.contikios.cooja.mspmote.SkyMoteType
|
org.contikios.cooja.mspmote.SkyMoteType
|
||||||
<identifier>sky1</identifier>
|
<identifier>sky1</identifier>
|
||||||
<description>Sky Mote Type #1</description>
|
<description>Sky Mote Type #1</description>
|
||||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/sky/test-coffee.c</source>
|
<source EXPORT="discard">[CONTIKI_DIR]/examples/cfs-coffee/test-coffee.c</source>
|
||||||
<commands EXPORT="discard">make clean TARGET=sky
|
<commands EXPORT="discard">make clean TARGET=sky
|
||||||
make test-coffee.sky TARGET=sky</commands>
|
make test-coffee.sky TARGET=sky</commands>
|
||||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/sky/test-coffee.sky</firmware>
|
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/cfs-coffee/test-coffee.sky</firmware>
|
||||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||||
|
|
Loading…
Reference in a new issue