mars/mars_test.c

214 lines
5.2 KiB
C
Raw Normal View History

2010-06-14 14:27:40 +00:00
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
2010-07-23 11:55:18 +00:00
//#define BRICK_DEBUGGING
//#define MARS_DEBUGGING
2010-06-14 14:27:40 +00:00
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/major.h>
#include <linux/genhd.h>
#include <linux/blkdev.h>
#define _STRATEGY
#include "mars.h"
#include "mars_if_device.h"
2010-07-30 05:46:22 +00:00
#include "mars_dummy.h"
2010-06-15 18:31:06 +00:00
#include "mars_device_sio.h"
2010-07-23 11:55:18 +00:00
#include "mars_buf.h"
2010-07-30 05:46:22 +00:00
#include "mars_usebuf.h"
2010-06-14 14:27:40 +00:00
2010-06-15 18:31:06 +00:00
GENERIC_MAKE_CONNECT(if_device, device_sio);
2010-07-23 11:55:18 +00:00
GENERIC_MAKE_CONNECT(if_device, buf);
2010-07-30 05:46:22 +00:00
GENERIC_MAKE_CONNECT(if_device, dummy);
GENERIC_MAKE_CONNECT(if_device, usebuf);
GENERIC_MAKE_CONNECT(usebuf, dummy);
2010-07-23 11:55:18 +00:00
GENERIC_MAKE_CONNECT(buf, device_sio);
2010-07-30 05:46:22 +00:00
GENERIC_MAKE_CONNECT(dummy, buf);
2010-06-14 14:27:40 +00:00
static struct if_device_brick *if_brick = NULL;
2010-07-30 05:46:22 +00:00
static struct usebuf_brick *usebuf_brick = NULL;
static struct dummy_brick *dummy_brick = NULL;
2010-07-23 11:55:18 +00:00
static struct buf_brick *buf_brick = NULL;
2010-06-15 18:31:06 +00:00
static struct device_sio_brick *device_brick = NULL;
2010-06-14 14:27:40 +00:00
2010-07-30 11:50:20 +00:00
static int test_endio(struct mars_buf_object *mbuf)
2010-07-23 11:55:18 +00:00
{
2010-07-30 11:50:20 +00:00
MARS_DBG("test_endio() called! error=%d\n", mbuf->cb_error);
2010-07-23 11:55:18 +00:00
return 0;
}
2010-06-14 14:27:40 +00:00
void make_test_instance(void)
{
static char *names[] = { "brick" };
2010-06-18 11:44:14 +00:00
int size = 4096;
2010-07-23 11:55:18 +00:00
int buf_size = 4096 * 8;
2010-06-14 14:27:40 +00:00
int status;
2010-07-23 11:55:18 +00:00
void *mem;
mem = kzalloc(size, GFP_KERNEL);
2010-06-14 14:27:40 +00:00
if (!mem) {
MARS_ERR("cannot grab test memory\n");
return;
}
MARS_DBG("starting....\n");
2010-06-15 18:31:06 +00:00
status = device_sio_brick_init_full(mem, size, &device_sio_brick_type, NULL, NULL, names);
2010-06-14 14:27:40 +00:00
MARS_DBG("done (status=%d)\n", status);
2010-07-23 11:55:18 +00:00
if (status) {
MARS_ERR("cannot init brick device_sio\n");
return;
}
device_brick = mem;
2010-06-14 14:27:40 +00:00
mem = kzalloc(size, GFP_KERNEL);
if (!mem) {
MARS_ERR("cannot grab test memory\n");
return;
}
status = if_device_brick_init_full(mem, size, &if_device_brick_type, NULL, NULL, names);
MARS_DBG("done (status=%d)\n", status);
2010-07-23 11:55:18 +00:00
if (status) {
MARS_ERR("cannot init brick if_device\n");
return;
}
if_brick = mem;
2010-07-30 05:46:22 +00:00
mem = kzalloc(size, GFP_KERNEL);
if (!mem) {
MARS_ERR("cannot grab test memory\n");
return;
}
status = dummy_brick_init_full(mem, size, &dummy_brick_type, NULL, NULL, names);
MARS_DBG("done (status=%d)\n", status);
if (status) {
MARS_ERR("cannot init brick dummy\n");
return;
}
dummy_brick = mem;
#if 1 // usebuf zwischenschalten
mem = kzalloc(size, GFP_KERNEL);
if (!mem) {
MARS_ERR("cannot grab test memory\n");
return;
}
status = usebuf_brick_init_full(mem, size, &usebuf_brick_type, NULL, NULL, names);
MARS_DBG("done (status=%d)\n", status);
if (status) {
MARS_ERR("cannot init brick usebuf\n");
return;
}
usebuf_brick = mem;
status = if_device_usebuf_connect(if_brick->inputs[0], usebuf_brick->outputs[0]);
MARS_DBG("connect (status=%d)\n", status);
status = usebuf_dummy_connect(usebuf_brick->inputs[0], dummy_brick->outputs[0]);
MARS_DBG("connect (status=%d)\n", status);
#else
(void)usebuf_brick;
status = if_device_dummy_connect(if_brick->inputs[0], dummy_brick->outputs[0]);
MARS_DBG("connect (status=%d)\n", status);
#endif
#if 1 // buf zwischenschalten
2010-07-23 11:55:18 +00:00
mem = kzalloc(buf_size, GFP_KERNEL);
if (!mem) {
MARS_ERR("cannot grab test memory\n");
return;
}
status = buf_brick_init_full(mem, buf_size, &buf_brick_type, NULL, NULL, names);
MARS_DBG("done (status=%d)\n", status);
if (status) {
MARS_ERR("cannot init brick buf\n");
return;
}
buf_brick = mem;
buf_brick->backing_order = 0;
buf_brick->backing_size = PAGE_SIZE << buf_brick->backing_order;
buf_brick->max_count = 512;
status = buf_device_sio_connect(buf_brick->inputs[0], device_brick->outputs[0]);
MARS_DBG("connect (status=%d)\n", status);
2010-07-30 05:46:22 +00:00
status = dummy_buf_connect(dummy_brick->inputs[0], buf_brick->outputs[0]);
2010-07-23 11:55:18 +00:00
MARS_DBG("connect (status=%d)\n", status);
if (true) {
struct buf_output *output = buf_brick->outputs[0];
struct mars_buf_object *mbuf = NULL;
2010-08-01 20:21:18 +00:00
struct generic_object_layout ol = {};
2010-07-23 11:55:18 +00:00
2010-07-30 11:50:20 +00:00
//mars_init_helper(&h);
2010-07-23 11:55:18 +00:00
2010-08-01 20:21:18 +00:00
status = GENERIC_OUTPUT_CALL(output, mars_buf_get, &mbuf, &ol, 0, PAGE_SIZE);
2010-07-23 11:55:18 +00:00
MARS_DBG("buf_get (status=%d)\n", status);
if (mbuf) {
if (true) {
2010-07-30 11:50:20 +00:00
mbuf->cb_rw = READ;
mbuf->cb_buf_endio = test_endio;
status = GENERIC_OUTPUT_CALL(output, mars_buf_io, mbuf);
2010-07-23 11:55:18 +00:00
MARS_DBG("buf_io (status=%d)\n", status);
}
status = GENERIC_OUTPUT_CALL(output, mars_buf_put, mbuf);
MARS_DBG("buf_put (status=%d)\n", status);
}
}
#else
2010-06-14 14:27:40 +00:00
2010-07-30 05:46:22 +00:00
status = dummy_device_sio_connect(dummy_brick->inputs[0], device_brick->outputs[0]);
2010-06-14 14:27:40 +00:00
MARS_DBG("connect (status=%d)\n", status);
2010-07-23 11:55:18 +00:00
#endif
2010-06-14 14:27:40 +00:00
}
void destroy_test_instance(void)
{
if (if_brick) {
2010-06-15 18:31:06 +00:00
if_device_device_sio_disconnect(if_brick->inputs[0]);
2010-06-14 14:27:40 +00:00
if_device_brick_exit_full(if_brick);
kfree(if_brick);
if_brick = NULL;
}
2010-07-23 11:55:18 +00:00
if (buf_brick) {
buf_device_sio_disconnect(buf_brick->inputs[0]);
buf_brick_exit_full(buf_brick);
kfree(buf_brick);
buf_brick = NULL;
}
2010-06-14 14:27:40 +00:00
if (device_brick) {
2010-06-15 18:31:06 +00:00
device_sio_brick_exit_full(device_brick);
2010-06-14 14:27:40 +00:00
kfree(device_brick);
device_brick = NULL;
}
}
static void __exit exit_test(void)
{
MARS_DBG("destroy_test_instance()\n");
destroy_test_instance();
}
static int __init init_test(void)
{
MARS_DBG("make_test_instance()\n");
make_test_instance();
return 0;
}
MODULE_DESCRIPTION("MARS TEST");
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
MODULE_LICENSE("GPL");
module_init(init_test);
module_exit(exit_test);