Added first part of extended ipc support.

- Extended ipc tests
- Need to copy from ktcb-to-ktcb instead of ktcb-to-user
- Need to check flags of both ipc parties before ipc copy type.
This commit is contained in:
Bahadir Balban
2009-05-27 14:07:17 +03:00
parent 19c71cc658
commit 3ff519439b
8 changed files with 222 additions and 41 deletions

View File

@@ -17,6 +17,7 @@
/*** IPC Tags used between server tasks ***/
/* For ping ponging */
#define L4_IPC_TAG_SYNC_EXTENDED 1
#define L4_IPC_TAG_SYNC_FULL 2
#define L4_IPC_TAG_SYNC 3

View File

@@ -14,6 +14,7 @@
extern pid_t parent_of_all;
void ipc_full_test(void);
void ipc_extended_test(void);
int shmtest(void);
int forktest(void);

View File

@@ -49,6 +49,9 @@ void main(void)
clonetest();
if (parent_of_all == getpid())
ipc_extended_test();
exectest();
while (1)

View File

@@ -1,5 +1,15 @@
/*
* Tests for more complex ipc such as full and extended
*
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
*/
#include <l4lib/arch/syslib.h>
#include <l4lib/ipcdefs.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <tests.h>
/*
* Full ipc test. Sends/receives full utcb, done with the pager.
@@ -15,7 +25,8 @@ void ipc_full_test(void)
}
/* Call the pager */
if ((ret = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_SYNC_FULL)) < 0) {
if ((ret = l4_sendrecv_full(PAGER_TID, PAGER_TID,
L4_IPC_TAG_SYNC_FULL)) < 0) {
printf("%s: Failed with %d\n", __FUNCTION__, ret);
BUG();
}
@@ -34,3 +45,100 @@ void ipc_full_test(void)
printf("FULL IPC TEST: -- FAILED --\n");
}
/*
* This is an extended ipc test that is done between 2 tasks that fork.
*/
void ipc_extended_test(void)
{
pid_t child, parent;
void *base;
char *ipcbuf;
int err;
/* Get parent pid */
parent = getpid();
/* Fork the current task */
if ((child = fork()) < 0) {
printf("%s: Fork failed with %d\n", __FUNCTION__, errno);
goto out_err;
}
if (child)
printf("%d: Created child with pid %d\n", getpid(), child);
else
printf("Child %d running.\n", getpid());
/* This test makes this assumption */
BUG_ON(L4_IPC_EXTENDED_MAX_SIZE > PAGE_SIZE);
/*
* Both child and parent gets 2 pages
* of privately mapped anonymous memory
*/
if ((int)(base = mmap(0, PAGE_SIZE*2, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0)) < 0) {
printf("%s: mmap for extended ipc buffer failed: %d\n",
__FUNCTION__, (int)base);
goto out_err;
} else
printf("mmap: Anonymous private buffer at %p\n", base);
/*
* Both tasks read/write both pages
* across the page boundary for messages
*/
ipcbuf = base + PAGE_SIZE - L4_IPC_EXTENDED_MAX_SIZE / 2;
if (!child) {
/* Child creates a string of maximum extended ipc size */
for (int i = 0; i < L4_IPC_EXTENDED_MAX_SIZE; i++) {
ipcbuf[i] = 'A' + i % 20;
}
/* Finish string with newline and null pointer */
ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 2] = '\n';
ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 1] = '\0';
/* Send message to parent */
printf("Child sending message: %s\n", ipcbuf);
if ((err = l4_send_extended(parent, L4_IPC_TAG_SYNC_EXTENDED,
L4_IPC_EXTENDED_MAX_SIZE,
ipcbuf)) < 0) {
printf("Extended ipc error: %d\n", err);
goto out_err;
}
} else {
/*
* Parent receives on the buffer - we are sure that the
* buffer is not paged in because we did not touch it.
* This should prove that page faults are handled during
* the ipc.
*/
printf("Parent: extended receiving from child.\n");
if ((err = l4_receive_extended(child, L4_IPC_EXTENDED_MAX_SIZE,
ipcbuf)) < 0) {
printf("Extended ipc error: %d\n", err);
goto out_err;
}
/* We now print the message created by child. */
printf("(%d): Message received from child: %s\n",
getpid(), ipcbuf);
/* Check that child string is there */
for (int i = 0; i < L4_IPC_EXTENDED_MAX_SIZE; i++) {
if (ipcbuf[i] != ('A' + i % 20))
goto out_err;
}
printf("EXTENDED IPC TEST: -- PASSED --\n");
}
return;
out_err:
printf("EXTENDED IPC TEST: -- FAILED --\n");
}