Browse Source

imported test projects (from projects repository)

dev/timer
Oleg Hahm 9 years ago
parent
commit
5dcf64d9de
  1. 6
      Makefile.unsupported
  2. 1
      tests/test_bloom/.gitignore
  3. 24
      tests/test_bloom/Makefile
  4. 38
      tests/test_bloom/generate_sets.py
  5. 50
      tests/test_bloom/main.c
  6. BIN
      tests/test_bloom/words.txt.gz
  7. 20
      tests/test_bloom_bytes/Makefile
  8. 91
      tests/test_bloom_bytes/main.c
  9. 10
      tests/test_float/Makefile
  10. 17
      tests/test_float/main.c
  11. 9
      tests/test_hwtimer/Makefile
  12. 44
      tests/test_hwtimer/main.c
  13. 48
      tests/test_hwtimer/tests/test_hwtimer
  14. 14
      tests/test_hwtimer_spin/Makefile
  15. 27
      tests/test_hwtimer_spin/main.c
  16. 26
      tests/test_irq/Makefile
  17. 48
      tests/test_irq/main.c
  18. 34
      tests/test_nativenet/Makefile
  19. 148
      tests/test_nativenet/main.c
  20. 13
      tests/test_semaphore/Makefile
  21. 133
      tests/test_semaphore/main.c
  22. 13
      tests/test_sha256/Makefile
  23. 53
      tests/test_sha256/main.c
  24. 18
      tests/test_shell/Makefile
  25. 15
      tests/test_shell/ReadMe.txt
  26. 90
      tests/test_shell/main.c
  27. 32
      tests/test_shell/tests/01-basic
  28. 83
      tests/test_shell/tests/02-inputlength-regression
  29. 21
      tests/test_shell/tests/02-unknown-command
  30. 10
      tests/test_thread_basic/Makefile
  31. 18
      tests/test_thread_basic/main.c
  32. 15
      tests/test_thread_basic/tests/test_thread.py
  33. 10
      tests/test_thread_exit/Makefile
  34. 64
      tests/test_thread_exit/main.c
  35. 13
      tests/test_thread_exit/tests/hello-world
  36. 9
      tests/test_thread_msg/Makefile
  37. 73
      tests/test_thread_msg/main.c

6
Makefile.unsupported

@ -0,0 +1,6 @@
.PHONY: all clean
all:
$(error Project $(PROJECT) currently not supported for $(BOARD))
clean: all

1
tests/test_bloom/.gitignore vendored

@ -0,0 +1 @@
sets.h

24
tests/test_bloom/Makefile

@ -0,0 +1,24 @@
# name of your project
export PROJECT = test_bloom
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
ifneq (,$(findstring msb-430,$(BOARD)))
include $(RIOTBASE)/Makefile.unsupported
else
## Modules to include.
USEMODULE += hashes
USEMODULE += bloom
export PROJDEPS = sets.h
include $(RIOTBASE)/Makefile.include
endif
sets.h: generate_sets.py words.txt.gz
./generate_sets.py 10000 20

38
tests/test_bloom/generate_sets.py

@ -0,0 +1,38 @@
#!/usr/bin/env python2
import gzip
import random
import sys
sizeOfA = 10 * 1000
sizeOfB = 20
print sys.argv
if len(sys.argv) == 3:
sizeOfA = int(sys.argv[1])
sizeOfB = int(sys.argv[2])
# read all words
lines = [line.strip() for line in gzip.open('words.txt.gz')]
# get A lines
A = random.sample(lines, sizeOfA + sizeOfB)
# get B from the first sieOfB element
B = A[:sizeOfB]
A = A[sizeOfB:]
SetsFile = open('sets.h', 'w')
SetsFile.write('const int lenA = ' + str(sizeOfA) + ';\n')
SetsFile.write('const char* A[' + str(sizeOfA) + '] = {')
SetsFile.writelines(",".join('"' + x + '"\n' for x in A))
SetsFile.write('};\n')
SetsFile.write('const int lenB = ' + str(sizeOfB) + ';\n')
SetsFile.write('const char* B[' + str(sizeOfB) + '] = {')
SetsFile.writelines(",".join('"' + x + '"\n' for x in B))
SetsFile.write('};\n')
print("sets.h: sizeOfA = " + str(len(A) + len(B)) + " generated...")

50
tests/test_bloom/main.c

@ -0,0 +1,50 @@
/*
* Copyright (C) 2013 Christian Mehlis <christian.mehlis@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdio.h>
#include <string.h>
#include "hashes.h"
#include "bloom.h"
#include "sets.h"
int main(void)
{
struct bloom_t *bloom = bloom_new(1 << 7, 6, fnv_hash, sax_hash, sdbm_hash,
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
printf("Testing Bloom filter.\n\n");
printf("m: %zd\nk: %zd\n\n", bloom->m, bloom->k);
for (int i = 0; i < lenB; i++) {
bloom_add(bloom, (const uint8_t *) B[i], strlen(B[i]));
printf("Added \"%s\"\n", B[i]);
}
int in = 0;
int not_in = 0;
for (int i = 0; i < lenA; i++) {
if (bloom_check(bloom, (const uint8_t *) A[i], strlen(A[i]))) {
in++;
} else {
not_in++;
}
}
printf("\n");
printf("%d elements probably in the filter.\n", in);
printf("%d elements not in the filter.\n", not_in);
double false_positive_rate = (double) in / (double) lenA;
printf("%f false positive rate.\n", false_positive_rate);
bloom_del(bloom);
printf("\nAll done!\n");
return 0;
}

BIN
tests/test_bloom/words.txt.gz

Binary file not shown.

20
tests/test_bloom_bytes/Makefile

@ -0,0 +1,20 @@
# name of your project
export PROJECT = test_bloom
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
ifneq (,$(findstring msb-430,$(BOARD)))
include $(RIOTBASE)/Makefile.unsupported
else
## Modules to include.
USEMODULE += hashes
USEMODULE += bloom
USEMODULE += random
include $(RIOTBASE)/Makefile.include
endif

91
tests/test_bloom_bytes/main.c

@ -0,0 +1,91 @@
/*
* Copyright (C) 2013 Christian Mehlis <christian.mehlis@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "hwtimer.h"
#include "hashes.h"
#include "bloom.h"
#include "random.h"
#define lenB 512
#define lenA (10 * 1000)
#define MAGIC_A 0xafafafaf
#define MAGIC_B 0x0c0c0c0c
#define myseed 0x83d385c0 /* random number */
#define BUF_SIZE 50
static uint32_t buf[BUF_SIZE];
static void buf_fill(uint32_t *buf, int len)
{
for (int k = 0; k < len; k++) {
buf[k] = genrand_uint32();
}
}
int main(void)
{
hwtimer_init();
struct bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash,
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
printf("Testing Bloom filter.\n\n");
printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom->m,
(uint32_t) bloom->k);
genrand_init(myseed);
unsigned long t1 = hwtimer_now();
for (int i = 0; i < lenB; i++) {
buf_fill(buf, BUF_SIZE);
buf[0] = MAGIC_B;
bloom_add(bloom,
(uint8_t *) buf,
BUF_SIZE * sizeof(uint32_t)/ sizeof(uint8_t));
}
unsigned long t2 = hwtimer_now();
printf("adding %d elements took %" PRIu32 "ms\n", lenB,
(uint32_t) HWTIMER_TICKS_TO_US(t2-t1) / 1000);
int in = 0;
int not_in = 0;
unsigned long t3 = hwtimer_now();
for (int i = 0; i < lenA; i++) {
buf_fill(buf, BUF_SIZE);
buf[0] = MAGIC_A;
if (bloom_check(bloom,
(uint8_t *) buf,
BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t))) {
in++;
} else {
not_in++;
}
}
unsigned long t4 = hwtimer_now();
printf("checking %d elements took %" PRIu32 "ms\n", lenA,
(uint32_t) HWTIMER_TICKS_TO_US(t4-t3) / 1000);
printf("\n");
printf("%d elements probably in the filter.\n", in);
printf("%d elements not in the filter.\n", not_in);
double false_positive_rate = (double) in / (double) lenA;
printf("%f false positive rate.\n", false_positive_rate);
bloom_del(bloom);
printf("\nAll done!\n");
return 0;
}

10
tests/test_float/Makefile

@ -0,0 +1,10 @@
# name of your project
export PROJECT = test_float
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
include $(RIOTBASE)/Makefile.include

17
tests/test_float/main.c

@ -0,0 +1,17 @@
#include <stdio.h>
#include <board.h>
#include <math.h>
int main(void)
{
double x = 1234567./1024., z;
while (1) {
x += 0.1;
z = x - floor(x);
if (z >= 1) {
putchar('+');
} else {
putchar('-');
}
}
}

9
tests/test_hwtimer/Makefile

@ -0,0 +1,9 @@
# name of your project
export PROJECT = test_hwtimer
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
include $(RIOTBASE)/Makefile.include

44
tests/test_hwtimer/main.c

@ -0,0 +1,44 @@
#include <stdio.h>
#include "hwtimer.h"
void callback(void* ptr)
{
puts((char*) ptr);
}
int main(void)
{
puts("hwtimer test project...");
puts("Initializing hwtimer...");
hwtimer_init();
puts("Initializing hwtimer [OK].");
#define BASE_DELAY 100000UL
#define DELTA_DELAY 10000UL
#define MSGLEN 12 // == strlen("callback %2i")
char msg[MSGLEN * ARCH_MAXTIMERS]; // == [callback 1\0callback 2\0...]
unsigned long delay = BASE_DELAY + (ARCH_MAXTIMERS * DELTA_DELAY);
/* make the first timer first to fire so timers do not run out linearly */
char *msgn = msg;
snprintf(msgn, MSGLEN, "callback %2x", 1);
hwtimer_set(BASE_DELAY, callback, (void*) msgn);
printf("set %s\n", msgn);
/* set up to ARCH_MAXTIMERS-1 because hwtimer_wait below also
* needs a timer */
for (int i = 1; i < (ARCH_MAXTIMERS - 1); i++) {
msgn = msg + (i*MSGLEN);
delay -= DELTA_DELAY;
snprintf(msgn, MSGLEN, "callback %2x", i+1);
hwtimer_set(delay, callback, (void*) msgn);
printf("set %s\n", msgn);
}
hwtimer_wait(HWTIMER_TICKS(1000UL * 1000UL));
puts("hwtimer set.");
}

48
tests/test_hwtimer/tests/test_hwtimer

@ -0,0 +1,48 @@
#!/usr/bin/expect
set timeout 5
spawn pseudoterm $env(PORT)
expect {
"OK" {}
timeout { exit 1 }
}
expect {
"set callback 1" {}
timeout { exit 1 }
}
expect {
"set callback 2" {}
timeout { exit 1 }
}
expect {
"set callback 3" {}
timeout { exit 1 }
}
expect {
"callback 1" {}
timeout { exit 1 }
}
expect {
"callback 3" {}
timeout { exit 1 }
}
expect {
"callback 2" {}
timeout { exit 1 }
}
expect {
"hwtimer set." {}
timeout { exit 1 }
}
puts "\nTest successful!\n"

14
tests/test_hwtimer_spin/Makefile

@ -0,0 +1,14 @@
# define project name
export PROJECT = test_hwtimer_spin
# for easy switching of boards
export BOARD ?= native
# the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
# modules to include
USEMODULE += auto_init
USEMODULE += hwtimer
include $(RIOTBASE)/Makefile.include

27
tests/test_hwtimer_spin/main.c

@ -0,0 +1,27 @@
/*
* Copyright (C) 2013 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include "board_uart0.h"
#include "posix_io.h"
#include "hwtimer.h"
#include "thread.h"
int main(void)
{
printf("when the race condition is hit, hwtimer will wait a very very long time...\n");
while(1) {
for (unsigned long i = 256; i; i = i>>1) {
printf("wait %lu\n", i);
hwtimer_wait(i);
}
}
}

26
tests/test_irq/Makefile

@ -0,0 +1,26 @@
valgrind: CFLAGS += -g
valgrind: CFLAGS += -DHAVE_VALGRIND_VALGRIND_H
# name of your project
export PROJECT = test_irq
#
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
ifeq (,$(findstring native,$(BOARD)))
include $(RIOTBASE)/Makefile.unsupported
else
## Modules to include.
USEMODULE += auto_init
USEMODULE += hwtimer
USEMODULE += uart0
USEMODULE += posix
include $(RIOTBASE)/Makefile.include
valgrind: all
endif

48
tests/test_irq/main.c

@ -0,0 +1,48 @@
/*
* Copyright (C) 2013 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*/
#include <stdio.h>
#include "board_uart0.h"
#include "posix_io.h"
#include "hwtimer.h"
#include "thread.h"
char busy_stack[KERNEL_CONF_STACKSIZE_PRINTF];
int busy, i, k;
void busy_thread(void)
{
int j;
printf("busy_thread starting\n");
i = 0;
while (busy) {
k = j = ++i;
}
printf("i: %i\n", i);
printf("j: %i\n", j);
printf("k: %i\n", k);
printf("success\n");
}
int main(void)
{
posix_open(uart0_handler_pid, 0);
busy = 1;
k = 23;
thread_create(busy_stack, KERNEL_CONF_STACKSIZE_PRINTF,
PRIORITY_MAIN+1, CREATE_WOUT_YIELD, busy_thread,
"busy_thread");
printf("busy_thread created\n");
printf("hwtimer_wait()\n");
hwtimer_wait(HWTIMER_TICKS(10));
busy = 0;
printf("main: return\n");
}

34
tests/test_nativenet/Makefile

@ -0,0 +1,34 @@
debug: CFLAGS += -g
debug: CFLAGS += -DENABLE_DEBUG
# name of your project
export PROJECT = test_nativenet
#
# for easy switching of boards
export BOARD = native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
ifeq (,$(findstring native,$(BOARD)))
include $(RIOTBASE)/Makefile.unsupported
else
## Modules to include.
USEMODULE += auto_init
USEMODULE += hwtimer
USEMODULE += nativenet
USEMODULE += transceiver
include $(RIOTBASE)/Makefile.include
debug: all
FORCE:
touch main.c
sender: CFLAGS += -DSENDER
sender: PROJECT = test_nativenet_sender
sender: FORCE all
endif

148
tests/test_nativenet/main.c

@ -0,0 +1,148 @@
/*
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <time.h>
#include "hwtimer.h"
#include "board.h"
#include "transceiver.h"
#include "nativenet.h"
#include "msg.h"
#include "thread.h"
#define SENDER_ADDR (1)
#define DEFAULT_RCV_ADDR (2)
#define PACKET_SIZE (42)
#define WAIT_TIME (60)
#define SECOND (1000 * 1000)
#define SENDING_DELAY (10 * 1000)
#define RCV_BUFFER_SIZE (64)
#define RADIO_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
char radio_stack_buffer[RADIO_STACK_SIZE];
msg_t msg_q[RCV_BUFFER_SIZE];
uint8_t snd_buffer[NATIVE_MAX_DATA_LENGTH];
uint8_t receiving = 1;
unsigned int last_seq = 0, missed_cnt = 0;
int first = -1;
void radio(void) {
msg_t m;
radio_packet_t *p;
unsigned int tmp = 0, cur_seq = 0;
msg_init_queue(msg_q, RCV_BUFFER_SIZE);
puts("Start receiving");
while (receiving) {
msg_receive(&m);
if (m.type == PKT_PENDING) {
p = (radio_packet_t*) m.content.ptr;
if ((p->src == SENDER_ADDR) && (p->length == PACKET_SIZE)) {
puts("received");
cur_seq = (p->data[0] << 8) + p->data[1];
if (first < 0) {
first = cur_seq;
}
else {
tmp = cur_seq - last_seq;
if (last_seq && (tmp > 1)) {
missed_cnt += (tmp - 1);
}
}
last_seq = cur_seq;
}
else {
printf("sender was %i\n", p->src);
}
p->processing--;
}
else if (m.type == ENOBUFFER) {
puts("Transceiver buffer full");
}
else {
puts("Unknown packet received");
}
}
}
void sender(void) {
unsigned int i=0;
msg_t mesg;
transceiver_command_t tcmd;
radio_packet_t p;
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_NATIVE;
tcmd.data = &p;
p.length = PACKET_SIZE;
p.dst = 0;
puts("Start sending packets");
while (1) {
/* filling uint8_t buffer with uint16_t sequence number */
snd_buffer[0] = (i & 0xFF00) >> 8;
snd_buffer[1] = i & 0x00FF;
p.data = snd_buffer;
i++;
msg_send(&mesg, transceiver_pid, 1);
hwtimer_wait(HWTIMER_TICKS(SENDING_DELAY));
}
}
int main(void)
{
#ifndef SENDER
int radio_pid;
#endif
int16_t a;
msg_t mesg;
transceiver_command_t tcmd;
printf("\n\tmain(): initializing transceiver\n");
transceiver_init(TRANSCEIVER_NATIVE);
printf("\n\tmain(): starting transceiver\n");
transceiver_start();
#ifndef SENDER
printf("\n\tmain(): starting radio thread\n");
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
transceiver_register(TRANSCEIVER_NATIVE, radio_pid);
#endif
#ifdef SENDER
a = SENDER_ADDR;
#elif defined ADDR
a = ADDR;
#else
a = DEFAULT_RCV_ADDR;
#endif
tcmd.transceivers = TRANSCEIVER_NATIVE;
tcmd.data = &a;
mesg.content.ptr = (char *) &tcmd;
mesg.type = SET_ADDRESS;
printf("[nativenet] trying to set address %" PRIi16 "\n", a);
msg_send_receive(&mesg, &mesg, transceiver_pid);
#ifdef SENDER
hwtimer_wait(HWTIMER_TICKS(SECOND));
sender();
#else
hwtimer_wait(HWTIMER_TICKS(WAIT_TIME * SECOND));
receiving = 0;
printf("Missed %u of %u packets after %u seconds\n", missed_cnt, (last_seq - first), WAIT_TIME);
#endif
return 0;
}

13
tests/test_semaphore/Makefile

@ -0,0 +1,13 @@
# name of your project
export PROJECT = test_semaphore
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
## Modules to include.
USEMODULE += semaphore
include $(RIOTBASE)/Makefile.include

133
tests/test_semaphore/main.c

@ -0,0 +1,133 @@
/*
* Copyright (C) 2013 Christian Mehlis <christian.mehlis@fu-berlin.de>
* Copyright (C) 2013 René Kijewski <rene.kijewski@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdio.h>
#include "thread.h"
#include "semaphore.h"
#define SEMAPHORE_TEST_THREADS 10
char test1_thread_stack[KERNEL_CONF_STACKSIZE_PRINTF];
char test2_thread_stack[SEMAPHORE_TEST_THREADS][KERNEL_CONF_STACKSIZE_PRINTF];
sem_t s;
static void test1_second_thread(void)
{
puts("second: sem_trywait");
if (sem_trywait(&s) == 0) {
puts("second: sem_trywait failed");
}
puts("second: sem_trywait done with == 0");
puts("second: wait for post");
if (sem_wait(&s) != 1) {
puts("second: sem_wait failed");
}
puts("second: sem was posted");
puts("second: end");
}
static void test1(void)
{
puts("first: sem_init");
if (sem_init(&s, 0, 0) != 0) {
puts("first: sem_init failed");
}
puts("first: thread create");
int pid = thread_create(test1_thread_stack, KERNEL_CONF_STACKSIZE_PRINTF,
PRIORITY_MAIN - 1, CREATE_STACKTEST | CREATE_WOUT_YIELD,
test1_second_thread, "second");
if (pid < 0) {
puts("first: thread create failed");
}
puts("first: thread created");
puts("first: sem_getvalue");
int val;
if (sem_getvalue(&s, &val) != 0 || val != 0) {
puts("first: sem_getvalue failed");
}
puts("first: sem_getvalue != 0");
puts("first: do yield");
thread_yield();
puts("first: done yield");
/*****************************************************************************/
puts("first: sem_trywait");
if (sem_trywait(&s) != -1) {
puts("first: sem_trywait failed");
}
puts("first: sem_trywait done");
puts("first: sem_post");
if (sem_post(&s) != 1) {
puts("first: sem_post failed");
}
puts("first: sem_post done");
/*****************************************************************************/
puts("first: sem_destroy");
if (sem_destroy(&s) != 0) {
puts("first: sem_destroy failed");
}
puts("first: end");
}
static void priority_sema_thread(void)
{
sem_wait(&s);
printf("Thread '%s' woke up.\n", thread_getname(thread_getpid()));
}
char names[SEMAPHORE_TEST_THREADS][16];
void test2(void)
{
puts("first: sem_init");
if (sem_init(&s, 0, 0) != 0) {
puts("first: sem_init failed");
}
for (int i = 0; i < SEMAPHORE_TEST_THREADS; i++) {
int priority = PRIORITY_MAIN - (i + 3) % 10 + 1;
snprintf(names[i], sizeof(names[i]), "priority %d", priority);
printf("first: thread create: %d\n", priority);
int pid = thread_create(test2_thread_stack[i],
KERNEL_CONF_STACKSIZE_PRINTF, priority, CREATE_STACKTEST,
priority_sema_thread, names[i]);
if (pid < 0) {
puts("first: thread create failed");
}
printf("first: thread created: %s (%d/%d)\n", names[i], i + 1, SEMAPHORE_TEST_THREADS);
}
puts("------------------------------------------");
for (int i = 0; i < SEMAPHORE_TEST_THREADS; i++) {
printf("post no. %d\n", i);
sem_post(&s);
puts("Back in main thread.");
}
}
int main(void)
{
puts("#########################");
test1();
puts("#########################");
test2();
puts("#########################");
}

13
tests/test_sha256/Makefile

@ -0,0 +1,13 @@
# name of your project
export PROJECT = test_sha256
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
## Modules to include.
USEMODULE += crypto_sha256
include $(RIOTBASE)/Makefile.include

53
tests/test_sha256/main.c

@ -0,0 +1,53 @@
/*
* Copyright (C) 2013 Christian Mehlis <christian.mehlis@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "crypto/sha256.h"
unsigned char hash[SHA256_DIGEST_LENGTH];
void sha256_calc(const char *str, const char *expected)
{
sha256_context_t sha256;
sha256_init(&sha256);
sha256_update(&sha256, str, strlen(str));
sha256_final(hash, &sha256);
printf("Input: %s\n"
"Expected: %s\n"
"Calculated: ", str, expected);
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
printf("%02x", hash[i]);
}
printf("\n\n");
}
int main(void)
{
sha256_calc("1234567890_1",
"3eda9ffe5537a588f54d0b2a453e5fa932986d0bc0f9556924f5c2379b2c91b0");
sha256_calc("1234567890_2",
"a144d0b4d285260ebbbab6840baceaa09eab3e157443c9458de764b7262c8ace");
sha256_calc("1234567890_3",
"9f839169d293276d1b799707d2171ac1fd5b78d0f3bc7693dbed831524dd2d77");
sha256_calc("1234567890_4",
"6c5fe2a8e3de58a5e5ac061031a8e802ae1fb9e7197862ec1aedf236f0e23475");
sha256_calc("0123456789abcde-0123456789abcde-0123456789abcde-0123456789abcde-",
"945ab9d52b069923680c2c067fa6092cbbd9234cf7a38628f3033b2d54d3d3bf");
sha256_calc("Franz jagt im komplett verwahrlosten Taxi quer durch Bayern",
"d32b568cd1b96d459e7291ebf4b25d007f275c9f13149beeb782fac0716613f8");
sha256_calc("Frank jagt im komplett verwahrlosten Taxi quer durch Bayern",
"78206a866dbb2bf017d8e34274aed01a8ce405b69d45db30bafa00f5eeed7d5e");
sha256_calc("",
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
return 0;
}

18
tests/test_shell/Makefile

@ -0,0 +1,18 @@
# name of your project
export PROJECT = test_shell
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
## Modules to include.
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps
USEMODULE += uart0
USEMODULE += posix
include $(RIOTBASE)/Makefile.include

15
tests/test_shell/ReadMe.txt

@ -0,0 +1,15 @@
This project shows how to use own or the system shell commands. In order to use
the system shell commands:
1. Additionally to the module: shell, shell_commands, uart0 and posix,
the module for the corresponding system command is to include, e.g.
module ps for the ps command (cf. the Makefile in the project root
directory).
2. The shell must be initialized as follows:
2.1 shell_t sys_shell;
2.2 shell_init(&shell, shell_commands, shell_bufsize shell_readc,
shell_putchar);
or shell_init(&sys_shell, NULL, shell_bufsize,
shell_readc, shell_putchar);
/* to initialize without the built-in shell commands */
2.3 shell_run(&sys_shell);

90
tests/test_shell/main.c

@ -0,0 +1,90 @@
/*
* main.c - Main function of the test_shell project.
* Copyright (C) 2013 Kaspar Schleiser <kaspar@schleiser.de>
*
* This source code is licensed under the LGPLv2 license,
* See the file LICENSE for more details.
*
*/
/**
* @file
* @internal
* @brief shows how to set up own and use the system shell commands.
* By typing help in the serial console, all the supported commands
* are listed.
*
* @author Freie Universität Berlin, Computer Systems & Telematics
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
* @version $Revision: 3855 $
*
* @note $Id: main.c 3855 2013-09-04 17:00:33 kasmi $
*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <shell_commands.h>
#include <posix_io.h>
#include <shell.h>
#include <board_uart0.h>
#define SHELL_BUFSIZE (UART0_BUFSIZE)
void print_teststart(char *unused)
{
(void) unused;
printf("[TEST_START]\n");
}
void print_testend(char *unused)
{
(void) unused;
printf("[TEST_END]\n");
}
int shell_readc(void)
{
char c = 0;
posix_read(uart0_handler_pid, &c, 1);
return c;
}
void shell_putchar(int c)
{
putchar(c);
}
const shell_command_t shell_commands[] = {
{ "start_test", "starts a test", print_teststart },
{ "end_test", "ends a test", print_testend },
{ NULL, NULL, NULL }
};
int main(void)
{
printf("test_shell.\n");
board_uart0_init();
posix_open(uart0_handler_pid, 0);
/* define own shell commands */
shell_t shell;
shell_init(&shell, shell_commands, SHELL_BUFSIZE, shell_readc,
shell_putchar);
shell_run(&shell);
/* or use only system shell commands */
/*
shell_t sys_shell;
shell_init(&sys_shell, NULL, SHELL_BUFSIZE, shell_readc, shell_putchar);
shell_run(&sys_shell);
*/
return 0;
}

32
tests/test_shell/tests/01-basic

@ -0,0 +1,32 @@
#!/usr/bin/expect
set timeout 5
spawn pseudoterm $env(PORT)
sleep 1
send "\n"
send "\n"
expect {
">" {}
timeout { exit 1 }
}
send "start_test\n"
expect {
"\[TEST_START\]" {}
timeout { exit 1 }
}
expect {
">" {}
timeout { exit 1 }
}
send "end_test\n"
expect {
"\[TEST_END\]" {}
timeout { exit 1 }
}
puts "\nTest successful!\n"

83
tests/test_shell/tests/02-inputlength-regression

@ -0,0 +1,83 @@
#!/usr/bin/expect
set timeout 1
spawn pseudoterm $env(PORT)
sleep 1
send "\n"
send "\n"
expect {
">" {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "123456789012345678901234567890123456789012345678901234567890\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
send "start_test\n"
expect {
"\[TEST_START\]" {}
timeout { exit 1 }
}
expect {
">" {}
timeout { exit 1 }
}
send "end_test\n"
expect {
"\[TEST_END\]" {}
timeout { exit 1 }
}
sleep 1
puts "\nTest successful!\n"

21
tests/test_shell/tests/02-unknown-command

@ -0,0 +1,21 @@
#!/usr/bin/expect
set timeout 2
spawn pseudoterm $env(PORT)
sleep 1
send "\n"
send "\n"
expect {
">" {}
timeout { exit 1 }
}
send "some_definately_unknown_command\n"
expect {
"shell: command not found." {}
timeout { exit 1 }
}
puts "\nTest successful!\n"

10
tests/test_thread_basic/Makefile

@ -0,0 +1,10 @@
# name of your project
export PROJECT = test_thread_basic
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
include $(RIOTBASE)/Makefile.include

18
tests/test_thread_basic/main.c

@ -0,0 +1,18 @@
#include <stdio.h>
#include <thread.h>
#include <flags.h>
#include <kernel.h>
#define STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT + KERNEL_CONF_STACKSIZE_PRINTF)
char t2_stack[STACK_SIZE];
void second_thread(void) {
puts("second thread\n");
}
int main(void)
{
(void) thread_create(t2_stack, STACK_SIZE, PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "nr2");
puts("first thread\n");
}

15
tests/test_thread_basic/tests/test_thread.py

@ -0,0 +1,15 @@
#!/usr/bin/python
import pexpect
import os
import subprocess
child = pexpect.spawn("board/msba2/tools/bin/pseudoterm %s" % os.environ["PORT"])
null = open('/dev/null', 'wb')
subprocess.call(['jam', 'reset'], stdout=null)
child.expect ('first thread\r\n')
child.expect ('second thread\r\n')
print("Test successful!")

10
tests/test_thread_exit/Makefile

@ -0,0 +1,10 @@
# name of your project
export PROJECT = test_thread_exit
# for easy switching of boards
export BOARD ?= native
# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../..
include $(RIOTBASE)/Makefile.include

64
tests/test_thread_exit/main.c

@ -0,0 +1,64 @@
#include <stdio.h>
#include "thread.h"
#include "flags.h"
#include "kernel.h"
char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
char third_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
void fourth_thread(void) {
puts("4th: starting");
puts("4th: exiting");
}
void third_thread(void) {
puts("3rd: starting");
puts("3rd: exiting");
}
void second_thread(void) {
puts("2nd: starting");
if ((thread_create(
third_thread_stack,
sizeof(third_thread_stack),
PRIORITY_MAIN-2,
CREATE_STACKTEST,
third_thread,
"nr3")
) == -1) {
puts("2nd: Error creating 3rd thread.");
}
/* thread should have returned already */
if ((thread_create(
third_thread_stack,
sizeof(third_thread_stack),
PRIORITY_MAIN-1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
fourth_thread,
"nr4")
) == -1) {
puts("2nd: Error creating 4rd thread.");
}
puts("2nd: exiting");
}
int main(void)
{
puts("main: starting");
if ((thread_create(
second_thread_stack,
sizeof(second_thread_stack),
PRIORITY_MAIN-1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
second_thread,
"nr2")
) == -1) {
puts("main: Error creating 3rd thread.");
}
puts("main: exiting");
}

13
tests/test_thread_exit/tests/hello-world

@ -0,0 +1,13 @@
#!/usr/bin/expect
set timeout 5
spawn board/msba2/tools/bin/pseudoterm $env(PORT)
expect {
"Hello World!" {}
timeout { exit 1 }
}
puts "\nTest successful!\n"

9
tests/test_thread_msg/Makefile

@ -0,0 +1,9 @@
# name of your project
export PROJECT = test_thread_msg
export BOARD ?= native
# the absolute path of the RIOT-base dir
export RIOTBASE =$(CURDIR)/../..
include $(RIOTBASE)/Makefile.include

73
tests/test_thread_msg/main.c

@ -0,0 +1,73 @@
/*
* Copyright (C) 2013 Christian Mehlis <christian.mehlis@fu-berlin.de>
*
* This file subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <stdio.h>
#include "thread.h"
#include "msg.h"
char t1_stack[KERNEL_CONF_STACKSIZE_PRINTF];
char t2_stack[KERNEL_CONF_STACKSIZE_PRINTF];
char t3_stack[KERNEL_CONF_STACKSIZE_PRINTF];
uint16_t p1, p2, p3;
void thread1(void)
{
puts("THREAD 1 start\n");
for (int i = 0; i < 3; ++i) {
msg_t msg, reply;
msg_receive(&msg);
printf("T1 recv: %d (i=%d)\n", msg.content.value, i);
msg.content.value = i;
msg_send_receive(&msg, &reply, p2);
printf("T1 got reply: %d (i=%d)\n", reply.content.value, i);
}
puts("THREAD 1 end\n");
}
void thread2(void)
{
puts("THREAD 2\n");
for (int i = 0;; ++i) {
msg_t msg, reply;
msg_receive(&msg);
printf("T2 got %d (i=%d)\n", msg.content.value, i);
reply.content.value = msg.content.value;
msg_reply(&msg, &reply);
}
}
void thread3(void)
{
puts("THREAD 3\n");
for (int i = 0;; ++i) {
msg_t msg;
msg.content.value = i;
printf("T3 i=%d\n", i);
msg_send(&msg, p1, 1);
}
}
int main(void)
{
p1 = thread_create(t1_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST, thread1, "nr1");
p2 = thread_create(t2_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST, thread2, "nr2");
p3 = thread_create(t3_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST, thread3, "nr3");
puts("THREADS CREATED\n");
}
Loading…
Cancel
Save