metalsvm/kernel/tests.c

291 lines
6 KiB
C
Raw Normal View History

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#include <metalsvm/stddef.h>
#include <metalsvm/stdio.h>
#include <metalsvm/time.h>
#include <metalsvm/tasks.h>
#include <metalsvm/semaphore.h>
#include <metalsvm/mailbox.h>
#include <metalsvm/syscall.h>
#ifdef CONFIG_ROCKCREEK
#include <asm/icc.h>
2011-06-27 12:31:06 +02:00
#include <asm/RCCE.h>
#include <asm/RCCE_lib.h>
#include <asm/iRCCE.h>
#include <asm/iRCCE_lib.h>
#include <asm/SCC_API.h>
#include <lwip/sockets.h>
2011-07-12 12:56:48 +02:00
#include "client.h"
#include "server.h"
2011-07-12 15:01:10 +02:00
#include "shell.h"
#endif
static sem_t consuming, producing;
static mailbox_int32_t mbox;
static int val = 0;
static int consumer(void* arg)
{
int i, m = 0;
for(i=0; i<5; i++) {
sem_wait(&consuming, 0);
kprintf("Consumer got %d\n", val);
val = 0;
sem_post(&producing);
}
for(i=0; i<5; i++) {
mailbox_int32_fetch(&mbox, &m, 0);
kprintf("Got mail %d\n", m);
}
return 0;
}
static int producer(void* arg)
{
int i;
int mail[5] = {1, 2, 3, 4, 5};
for(i=0; i<5; i++) {
sem_wait(&producing, 0);
kprintf("Produce value: current val %d\n", val);
val = 42;
sem_post(&consuming);
}
for(i=0; i<5; i++) {
//kprintf("Send mail %d\n", mail[i]);
mailbox_int32_post(&mbox, mail[i]);
}
return 0;
}
static int foo(void* arg)
{
int i;
if (!arg)
return 0;
for(i=0; i<5; i++) {
kprintf("Message from core %d: %s\n", smp_id(), (char*) arg);
sleep(1);
}
return 42;
}
#ifdef CONFIG_ROCKCREEK
int mail_ping(void* arg) {
int i;
for(i=0; i<20; i++) {
if (BUILTIN_EXPECT(icc_mail_ping(), 0))
return -1;
2011-06-29 12:29:04 -07:00
udelay(500000);
}
return 0;
}
#endif
static int join_test(void* arg)
{
tid_t id, ret;
int result = -1234;
create_kernel_task(&id, foo, "Hello from foo2");
kprintf("Wait for child %u\n", id);
do {
ret = wait(&result);
} while(ret != id);
kprintf("Child %u finished: result = %d\n", id, result);
return 0;
}
2011-07-04 13:02:19 -07:00
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
2011-08-04 14:45:55 +02:00
#define SHELLDEBUGPRINTF(x,...) kprintf(x,##__VA_ARGS__);
2011-07-12 12:56:48 +02:00
static int srv_cnt = 0;
2011-08-02 13:20:06 +02:00
static Server srv;
2011-07-12 12:56:48 +02:00
void srv_on_read(ServerEventArgs* e)
2011-06-27 12:31:06 +02:00
{
2011-07-12 13:39:29 +02:00
// kprintf("%i:",srv_cnt);
// hex_dump(e->dwLen,e->pBuffer);
// srv_cnt++;
2011-07-12 12:56:48 +02:00
/* printf("%i:",cnt);
puts(e->pBuffer);
puts("\n");
cnt++;
*/
}
2011-06-27 12:31:06 +02:00
2011-07-12 12:56:48 +02:00
void srv_on_disc(ServerEventArgs*e )
{
kprintf("connection lost!!!\n");
}
2011-06-27 12:31:06 +02:00
2011-07-12 13:42:06 +02:00
void srv_on_conn(ServerEventArgs* e)
2011-06-27 12:31:06 +02:00
{
2011-08-02 13:10:15 +02:00
int i = 0, err = 0;
2011-07-12 12:56:48 +02:00
int tmp1,tmp2;
2011-08-04 16:00:22 +02:00
char buff[1024];
2011-07-12 12:56:48 +02:00
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("someone finally connected\n");
2011-07-12 12:56:48 +02:00
tmp1 = get_clock_tick();
2011-08-03 14:19:43 +02:00
for (i = 0; i < 1024*4; i++)
2011-07-12 12:56:48 +02:00
{
2011-08-02 13:19:12 +02:00
err = srv_sendBuffer(&srv,e->ClientID,buff,sizeof(buff));
2011-08-02 13:10:15 +02:00
if ( err < 0)
2011-08-04 14:39:50 +02:00
{
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("err: %d", err);
2011-08-04 14:39:50 +02:00
}
2011-08-02 13:04:02 +02:00
2011-08-03 13:58:44 +02:00
if (!(i%10))
2011-08-04 14:39:50 +02:00
{
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("\r-%d-",i);
2011-08-04 14:39:50 +02:00
}
2011-08-02 13:04:02 +02:00
2011-07-12 12:56:48 +02:00
}
tmp2 = get_clock_tick();
2011-08-04 14:45:55 +02:00
// SHELLDEBUGPRINTF("send with %f kb/s",((float)i*sizeof(buff))/(tmp2-tmp1));
2011-08-04 15:02:23 +02:00
SHELLDEBUGPRINTF("send %d bytes in %d ticks",i*sizeof(buff),(tmp2-tmp1));
2011-06-27 12:31:06 +02:00
}
2011-08-02 13:19:12 +02:00
void* server_task(void* e)
2011-06-27 12:31:06 +02:00
{
2011-08-04 14:45:55 +02:00
SHELLDEBUGPRINTF("created server\n");
2011-06-27 12:31:06 +02:00
2011-08-03 13:36:46 +02:00
server_init(&srv,5555,2);
2011-06-28 15:55:21 +02:00
2011-08-02 13:19:12 +02:00
srv._OnRead = srv_on_read;
srv._OnDisconnect = srv_on_disc;
srv._OnConnect = srv_on_conn;
2011-06-27 12:31:06 +02:00
2011-08-02 13:19:12 +02:00
while(1)
sleep(2);
2011-06-27 12:31:06 +02:00
2011-07-12 12:56:48 +02:00
return NULL;
2011-06-27 12:31:06 +02:00
}
2011-07-12 12:56:48 +02:00
static int cli_cnt = 0;
void cli_on_read(ClientEventArgs* e)
{
kprintf("\r-%d-",cli_cnt);
cli_cnt++;
// printf("%i:",cnt);
// hex_dump(e->dwLen,e->pBuffer);
// cnt++;
/* puts(e->pBuffer);
puts("\n");
cnt++;
*/
}
2011-06-27 12:31:06 +02:00
2011-07-12 12:56:48 +02:00
void cli_on_disc(ClientEventArgs*e )
{
kprintf("connection lost!!!\n");
}
2011-06-27 12:31:06 +02:00
void* client_task(void* e)
{
2011-08-03 13:43:50 +02:00
int err = -2;
2011-07-12 12:56:48 +02:00
Client cli;
char netbuffer[256];
2011-07-12 13:08:21 +02:00
kprintf("created client");
2011-07-12 12:56:48 +02:00
cli_init(&cli);
cli._OnRead = cli_on_read;
cli._OnDisconnect = cli_on_disc;
2011-08-04 14:45:55 +02:00
sleep(2);
2011-08-02 15:01:40 +02:00
2011-08-03 14:17:10 +02:00
SHELLDEBUGPRINTF("Client is ready...\n");
2011-08-03 13:43:50 +02:00
while (err)
2011-08-02 17:13:08 +02:00
{
2011-08-04 14:36:45 +02:00
sleep(1);
2011-08-04 14:46:38 +02:00
err = cli_ConnectTo(&cli,"192.168.0.1",5555,0);
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("retry connect err = %d socket: %d\n",err,cli.sSocket);
2011-08-02 17:13:08 +02:00
}
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("connected\n");
2011-08-04 14:45:55 +02:00
2011-07-12 12:56:48 +02:00
sleep(1);
2011-08-02 17:33:44 +02:00
err = cli_sendBuffer(&cli,"Hallo Welt",sizeof("Hallo Welt"));
2011-08-04 14:28:30 +02:00
SHELLDEBUGPRINTF("send message err = %d\n",err);
2011-07-12 12:56:48 +02:00
while(1)
2011-08-04 14:45:55 +02:00
sleep(2);
2011-06-27 12:31:06 +02:00
2011-08-06 08:52:07 -07:00
return NULL;
2011-06-27 12:31:06 +02:00
}
2011-07-04 13:02:19 -07:00
#endif
int test_init(void)
{
2011-08-10 18:56:40 +02:00
// char* argv[] = {"/bin/mshell", NULL};
// char* argv[] = {"/bin/tests", NULL};
2011-08-10 18:56:40 +02:00
char* server_argv[] = {"/bin/server", "6789", NULL};
char* client_argv[] = {"/bin/client", "127.0.0.1", "6789", NULL};
2011-04-01 13:43:59 +02:00
//sem_init(&producing, 1);
//sem_init(&consuming, 0);
//mailbox_int32_init(&mbox);
2011-08-02 12:24:05 +02:00
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
2011-06-27 12:31:06 +02:00
2011-08-04 14:45:55 +02:00
// shell_init(RCCE_ue());
//
// sleep(10);
// SHELLDEBUGPRINTF("hello World! I AM CORE NO. %d =) \n",RCCE_ue());
2011-08-02 16:16:53 +02:00
2011-08-06 08:52:07 -07:00
// if (!RCCE_ue())
// create_kernel_task(NULL,server_task,NULL);
// else
// create_kernel_task(NULL,client_task,NULL);
2011-07-04 13:02:19 -07:00
#endif
//create_kernel_task(NULL, foo, "Hello from foo1");
//create_kernel_task(NULL, join_test, NULL);
2011-02-18 21:20:15 +01:00
//create_kernel_task(NULL, producer, NULL);
//create_kernel_task(NULL, consumer, NULL);
2011-06-29 12:29:04 -07:00
//create_kernel_task(NULL, mail_ping, NULL);
2011-03-09 18:35:23 +01:00
//create_user_task(NULL, "/bin/hello", argv);
2011-08-10 18:56:40 +02:00
//create_user_task(NULL, "/bin/mshell", argv);
//create_user_task(NULL, "/bin/jacobi", argv);
create_user_task(NULL, "/bin/server", server_argv);
2011-08-10 18:56:40 +02:00
sleep(5);
create_user_task(NULL, "/bin/client", client_argv);
return 0;
}