Commit ff9b74cf authored by Charlie Jacobsen's avatar Charlie Jacobsen
Browse files

lcd: Port rpc test from old2 code for new code.

Builds, but not yet tested.
parent 3446cf5f
......@@ -10,4 +10,5 @@
aclocal.m4
autom4te.cache
config.h.in
config.h
\ No newline at end of file
config.h
configure
\ No newline at end of file
......@@ -136,6 +136,7 @@ AC_CONFIG_FILES(
src/platform/kernel/include/Makefile
src/platform/kernel/tests/Makefile
src/platform/kernel/tests/Kbuild
src/platform/kernel/tests/rpc/Kbuild
)
AC_OUTPUT
# Empty for now
\ No newline at end of file
obj-m += rpc/
\ No newline at end of file
......@@ -6,8 +6,8 @@ src = @abs_top_srcdir@/src/platform/kernel/tests/rpc
obj-m = libfipc_test_rpc.o
libfipc_test_rpc-objs = main.o callee.o caller.o
libfipc_test_rpc-objs = $(LIBFIPC)
libfipc_test_rpc-y += main.o callee.o caller.o
libfipc_test_rpc-y += $(LIBFIPC)
# Add -DCHECK_MESSAGES to check that message values contain what is expected
ccflags-y += $(CFLAGS) $(AM_CPPFLAGS) -DCHECK_MESSAGES
......@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <libfipc.h>
#include "rpc.h"
#include "../test_helpers.h"
/*
* We use "noinline" because we want the function call to actually
......@@ -78,7 +79,7 @@ static inline int send_response(struct fipc_ring_channel *chnl,
/*
* Response
*/
ret = blocking_send_start(chnl, &response);
ret = test_fipc_blocking_send_start(chnl, &response);
if (ret) {
pr_err("Error getting send slot");
return ret;
......@@ -110,9 +111,9 @@ int callee(void *_callee_channel_header)
/*
* Try to receive a message
*/
ret = blocking_recv_start(chan, &recvd_msg);
ret = test_fipc_blocking_recv_start(chan, &recvd_msg);
if (ret) {
pr_err("Error receiving message, ret = %d", ret);
pr_err("Error receiving message, ret = %d, exiting...", ret);
goto out;
}
/*
......@@ -156,13 +157,16 @@ int callee(void *_callee_channel_header)
fipc_get_reg4(recvd_msg),
fipc_get_reg5(recvd_msg));
break;
default:
pr_err("Bad function type %d, exiting...\n", type);
goto out;
}
/*
* Send response back
*/
ret = send_response(chan, recvd_msg, temp_res, type);
if (ret) {
pr_err("Error sending response back, ret = %d", ret);
pr_err("Error sending response back, ret = %d, exiting...", ret);
goto out;
}
}
......
......@@ -8,6 +8,7 @@
#include <linux/random.h>
#include "rpc.h"
#include "../test_helpers.h"
static inline int send_and_get_response(
struct fipc_ring_channel *chan,
......@@ -27,7 +28,7 @@ static inline int send_and_get_response(
/*
* Try to get the response
*/
ret = blocking_recv_start(chan, &resp);
ret = test_fipc_blocking_recv_start(chan, &resp);
if (ret) {
pr_err("failed to get a response, ret = %d\n", ret);
goto fail2;
......@@ -47,6 +48,7 @@ static inline int finish_response_check_fn_type(struct fipc_ring_channel *chnl,
struct fipc_message *response,
enum fn_type expected_type)
{
int ret;
enum fn_type actual_type = get_fn_type(response);
ret = fipc_recv_msg_end(chnl, response);
if (ret) {
......@@ -67,6 +69,7 @@ static inline int finish_response_check_fn_type_and_reg0(
enum fn_type expected_type,
unsigned long expected_reg0)
{
int ret;
enum fn_type actual_type = get_fn_type(response);
unsigned long actual_reg0 = fipc_get_reg0(response);
......@@ -117,7 +120,7 @@ null_invocation(struct fipc_ring_channel *chan)
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -134,7 +137,7 @@ null_invocation(struct fipc_ring_channel *chan)
/*
* Maybe check message
*/
return finish_response_check_fn_type(response, NULL_INVOCATION);
return finish_response_check_fn_type(chan, response, NULL_INVOCATION);
fail:
return ret;
......@@ -149,7 +152,7 @@ add_constant(struct fipc_ring_channel *chan, unsigned long trans)
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -168,6 +171,7 @@ add_constant(struct fipc_ring_channel *chan, unsigned long trans)
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_CONSTANT,
trans + 50);
......@@ -186,7 +190,7 @@ add_nums(struct fipc_ring_channel *chan, unsigned long trans,
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -206,6 +210,7 @@ add_nums(struct fipc_ring_channel *chan, unsigned long trans,
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_NUMS,
trans + res1);
......@@ -224,7 +229,7 @@ add_3_nums(struct fipc_ring_channel *chan, unsigned long trans,
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -245,6 +250,7 @@ add_3_nums(struct fipc_ring_channel *chan, unsigned long trans,
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_3_NUMS,
trans + res1 + res2);
......@@ -263,7 +269,7 @@ add_4_nums(struct fipc_ring_channel *chan, unsigned long trans,
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -285,6 +291,7 @@ add_4_nums(struct fipc_ring_channel *chan, unsigned long trans,
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_4_NUMS,
trans + res1 + res2 + res3);
......@@ -304,7 +311,7 @@ add_5_nums(struct fipc_ring_channel *chan, unsigned long trans,
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -327,6 +334,7 @@ add_5_nums(struct fipc_ring_channel *chan, unsigned long trans,
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_5_NUMS,
trans + res1 + res2 + res3 + res4);
......@@ -346,7 +354,7 @@ add_6_nums(struct fipc_ring_channel *chan, unsigned long trans,
/*
* Set up request
*/
ret = blocking_send_start(chan, &request);
ret = test_fipc_blocking_send_start(chan, &request);
if (ret) {
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
......@@ -370,6 +378,7 @@ add_6_nums(struct fipc_ring_channel *chan, unsigned long trans,
* Maybe check message
*/
return finish_response_check_fn_type_and_reg0(
chan,
response,
ADD_6_NUMS,
trans + res1 + res2 + res3 + res4 + res5);
......@@ -378,12 +387,13 @@ fail:
return ret;
}
int caller(void *_caller_channel_header);
int caller(void *_caller_channel_header)
{
struct fipc_ring_channel *chan = _caller_channel_header;
unsigned long transaction_id;
unsigned long res1, res2, res3, res4, res5;
unsigned long start, end;
int ret = 0;
get_random_bytes(&res1, sizeof(res1));
res2 = res1 + res1;
......@@ -398,9 +408,15 @@ int caller(void *_caller_channel_header);
transaction_id < TRANSACTIONS/2;
transaction_id++) {
start = start_stopwatch();
null_invocation();
end = stop_stopwatch();
start = test_fipc_start_stopwatch();
ret = null_invocation(chan);
end = test_fipc_stop_stopwatch();
if (ret) {
pr_err("error doing null invocation, ret = %d, exiting...\n",
ret);
goto out;
}
pr_err("\t%lu\n", end - start);
}
......@@ -412,13 +428,24 @@ int caller(void *_caller_channel_header);
transaction_id < TRANSACTIONS;
transaction_id++) {
start = start_stopwatch();
res6 = add_6_nums(num_transactions,res1,res2,res3,res4,res5);
end = stop_stopwatch();
start = test_fipc_start_stopwatch();
ret = add_6_nums(chan,
transaction_id,
res1, res2, res3, res4, res5);
end = test_fipc_stop_stopwatch();
if (ret) {
pr_err("error doing add6nums invocation, ret = %d, exiting...\n",
ret);
goto out;
}
pr_err("\t%lu\n", end - start);
}
pr_err("Complete\n");
out:
return ret;
}
......@@ -24,7 +24,8 @@ static int setup_and_run_test(void)
/*
* Set up channel
*/
ret = create_channel(CHANNEL_ORDER, &caller_header, &callee_header);
ret = test_fipc_create_channel(CHANNEL_ORDER, &caller_header,
&callee_header);
if (ret) {
pr_err("Error creating channel, ret = %d", ret);
goto fail1;
......@@ -32,14 +33,16 @@ static int setup_and_run_test(void)
/*
* Set up threads
*/
caller_thread = spawn_thread_with_channel(caller_header, caller,
CALLER_CPU);
caller_thread = test_fipc_spawn_thread_with_channel(caller_header,
caller,
CALLER_CPU);
if (!caller_thread) {
pr_err("Error setting up caller thread");
goto fail2;
}
callee_thread = spawn_thread_with_channel(callee_header, callee,
CALLEE_CPU);
callee_thread = test_fipc_spawn_thread_with_channel(callee_header,
callee,
CALLEE_CPU);
if (!callee_thread) {
pr_err("Error setting up callee thread");
goto fail3;
......@@ -50,18 +53,25 @@ static int setup_and_run_test(void)
wake_up_process(caller_thread);
wake_up_process(callee_thread);
/*
* Release our reference on them since we are going to exit
* before they finish
* Wait for them to complete, so we can tear things down
*/
release_thread(caller_thread);
release_thread(callee_thread);
ret = test_fipc_wait_for_thread(caller_thread);
if (ret)
pr_err("Caller returned non-zero exit status %d\n", ret);
ret = test_fipc_wait_for_thread(callee_thread);
if (ret)
pr_err("Callee returned non-zero exit status %d\n", ret);
/*
* Tear things down
*/
test_fipc_free_channel(CHANNEL_ORDER, caller_header, callee_header);
return 0;
fail3:
release_thread(caller_thread);
test_fipc_release_thread(caller_thread);
fail2:
free_channel(CHANNEL_ORDER, caller_header, callee_header);
test_fipc_free_channel(CHANNEL_ORDER, caller_header, callee_header);
fail1:
return ret;
}
......@@ -74,10 +84,9 @@ static int __init rpc_init(void)
return ret;
}
static int __exit rpc_rmmod(void)
static void __exit rpc_rmmod(void)
{
return 0;
return;
}
module_init(rpc_init);
......
......@@ -10,7 +10,7 @@
#include <libfipc.h>
enum fn_types {
enum fn_type {
NULL_INVOCATION,
ADD_CONSTANT,
ADD_NUMS,
......
......@@ -13,13 +13,14 @@
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/kernel.h>
#include <libfipc.h>
static inline
struct task_struct *
spawn_thread_with_channel(struct fipc_ring_channel *channel,
int (*threadfn)(void *data),
int cpu_pin)
test_fipc_spawn_thread_with_channel(struct fipc_ring_channel *channel,
int (*threadfn)(void *data),
int cpu_pin)
{
struct cpumask cpu_core;
struct task_struct* thread = NULL;
......@@ -57,14 +58,14 @@ fail1:
static inline
void
release_thread(struct kthread *thread)
test_fipc_release_thread(struct task_struct *thread)
{
put_task_struct(thread);
}
static inline
int
wait_for_thread(struct kthread *thread)
test_fipc_wait_for_thread(struct task_struct *thread)
{
int ret;
ret = kthread_stop(thread);
......@@ -74,9 +75,9 @@ wait_for_thread(struct kthread *thread)
static inline
int
create_channel(unsigned int buf_nr_pages_order, /* in pages */
struct fipc_ring_channel **header_1,
struct fipc_ring_channel **header_2)
test_fipc_create_channel(unsigned int buf_nr_pages_order, /* in pages */
struct fipc_ring_channel **header_1,
struct fipc_ring_channel **header_2)
{
int ret;
void *buf1, *buf2;
......@@ -85,12 +86,12 @@ create_channel(unsigned int buf_nr_pages_order, /* in pages */
/*
* Allocate buffer pages
*/
buf1 = __get_free_pages(buf_nr_pages_order, GFP_KERNEL);
buf1 = (void *)__get_free_pages(buf_nr_pages_order, GFP_KERNEL);
if (!buf1) {
ret = -ENOMEM;
goto fail1;
}
buf2 = __get_free_pages(buf_nr_pages_order, GFP_KERNEL);
buf2 = (void *)__get_free_pages(buf_nr_pages_order, GFP_KERNEL);
if (!buf2) {
ret = -ENOMEM;
goto fail2;
......@@ -142,9 +143,9 @@ fail1:
static inline
void
free_channel(unsigned int buf_nr_pages_order, /* in pages */
struct fipc_ring_channel *header_1,
struct fipc_ring_channel *header_2)
test_fipc_free_channel(unsigned int buf_nr_pages_order, /* in pages */
struct fipc_ring_channel *header_1,
struct fipc_ring_channel *header_2)
{
/*
* Free buffers
......@@ -160,7 +161,8 @@ free_channel(unsigned int buf_nr_pages_order, /* in pages */
static inline
int
blocking_recv_start(struct fipc_ring_channel *chnl, struct fipc_message **out)
test_fipc_blocking_recv_start(struct fipc_ring_channel *chnl,
struct fipc_message **out)
{
int ret;
for (;;) {
......@@ -174,7 +176,8 @@ blocking_recv_start(struct fipc_ring_channel *chnl, struct fipc_message **out)
static inline
int
blocking_send_start(struct fipc_ring_channel *chnl, struct fipc_message **out)
test_fipc_blocking_send_start(struct fipc_ring_channel *chnl,
struct fipc_message **out)
{
int ret;
for (;;) {
......@@ -186,7 +189,7 @@ blocking_send_start(struct fipc_ring_channel *chnl, struct fipc_message **out)
}
}
static inline unsigned long start_stopwatch(void)
static inline unsigned long test_fipc_start_stopwatch(void)
{
unsigned long stamp;
/*
......@@ -210,11 +213,11 @@ static inline unsigned long start_stopwatch(void)
"or %%rdx, %%rax\n\t"
: "=a" (stamp)
:
: "rax", "rdx");
: "rdx");
return stamp;
}
static inline unsigned long stop_stopwatch(void)
static inline unsigned long test_fipc_stop_stopwatch(void)
{
unsigned long stamp;
/*
......@@ -230,7 +233,7 @@ static inline unsigned long stop_stopwatch(void)
"or %%rdx, %%rax\n\t"
: "=a" (stamp)
:
: "rax", "rdx", "rcx");
: "rdx", "rcx");
return stamp;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment