Commit 6e4c229a authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Two more tests for cap.

parent 0b6630db
......@@ -14,43 +14,175 @@
#define LCD_FAIL(msg...) do{ LCD_ERR(msg); return -1; } while(0)
#define LCD_PASS() do{ return 0; } while(0)
static inline int test_rm_cspace(struct cspace *cspace, int ret_val)
{
int ret;
ret = lcd_cap_lock();
if (ret) {
LCD_ERR("lock failed with %d", ret);
return ret;
}
__lcd_rm_cspace(cspace);
lcd_cap_unlock();
return ret_val;
}
static int test01(void)
{
struct cspace *cspace;
if (lcd_mk_cspace(&cspace))
LCD_FAIL("mk cspace");
if (!cspace)
LCD_FAIL("cspace null");
lcd_cap_lock();
__lcd_rm_cspace(&cspace);
lcd_cap_unlock();
if (cspace)
LCD_FAIL("cspace non-null");
LCD_PASS();
}
#if 0
static int test02(void)
{
struct cspace *cspace;
struct cnode *cnode;
cptr_t cptr;
int ret;
if (lcd_mk_cspace(&cspace))
LCD_FAIL("mk cspace");
ret = lcd_lock_cspace(cspace);
if (ret) {
lcd_rm_cspace(cspace);
LCD_FAIL("lock cspace returned %d", ret);
if (lcd_cnode_alloc(cspace, &cptr)) {
LCD_ERR("alloc");
goto fail;
}
lcd_unlock_cspace(cspace);
lcd_rm_cspace(cspace);
LCD_PASS();
if (cptr >= LCD_NUM_CAPS) {
LCD_ERR("cptr = %d >= %d = LCD_NUM_CAPS",
cptr, LCD_NUM_CAPS);
goto fail;
}
/*
* LOCK cap
*/
lcd_cap_lock();
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("lookup");
goto fail_unlock;
}
if (!__lcd_cnode_is_unformed(cnode)) {
LCD_ERR("cnode not unformed");
goto fail_unlock;
}
if (__lcd_cnode_rights(cnode) != 0) {
LCD_ERR("cnode rights non-zero");
goto fail_unlock;
}
if (cnode->cspace != cspace) {
LCD_ERR("cnode bad parent");
goto fail_unlock;
}
if (!list_empty(&cnode->free_list)) {
LCD_ERR("cnode still in free list?");
goto fail_unlock;
}
if (!list_empty(&cnode->children)) {
LCD_ERR("cnode children non-empty");
goto fail_unlock;
}
if (!list_empty(&cnode->child_list)) {
LCD_ERR("cnode child list non-empty");
goto fail_unlock;
}
/*
* UNLOCK cap
*/
__lcd_rm_cspace(&cspace);
lcd_cap_unlock();
return 0;
fail_unlock:
/*
* UNLOCK cap
*/
lcd_cap_unlock();
fail:
return test_rm_cspace(&cspace, -1);
}
static int test03(void)
{
struct cspace *cspace;
cptr_t cptr;
int ret;
int x;
if (lcd_mk_cspace(&cspace))
LCD_FAIL("mk cspace");
if (lcd_cnode_alloc(cspace, &cptr)) {
LCD_ERR("alloc");
goto fail;
}
/*
* Insert object
*/
x = 517;
if (lcd_cnode_insert(cspace, cptr, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_WRITE)) {
LCD_ERR("insert");
goto fail;
}
/*
* LOCK cap
*/
lcd_cap_lock();
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("lookup");
goto fail_unlock;
}
if (__lcd_cnode_is_sync_ep(cnode)) {
LCD_ERR("cnode not sync ep");
goto fail_unlock;
}
if (__lcd_cnode_rights(cnode) != LCD_CAP_RIGHT_WRITE) {
LCD_ERR("cnode rights not write");
goto fail_unlock;
}
if (__lcd_cnode_object(cnode) != &x) {
LCD_ERR("cnode bad object");
goto fail_unlock;
}
__lcd_rm_cspace(&cspace);
/*
* UNLOCK cap
*/
lcd_cap_unlock();
return 0;
fail_unlock:
/*
* UNLOCK cap
*/
lcd_cap_unlock();
fail:
return test_rm_cspace(&cspace, -1);
}
#if 0
static int test03(void)
{
struct cspace *cspace;
cptr_t cptr;
int i;
if (lcd_mk_cspace(&cspace))
LCD_FAIL("mk cspace");
for (i = 0; i < 5; i++) {
if (lcd_cap_alloc(cspace, &cptr)) {
lcd_rm_cspace(cspace);
......@@ -166,10 +298,10 @@ int api_tests(void)
{
if (test01())
return -1;
/* if (test02()) */
/* return -1; */
/* if (test03()) */
/* return -1; */
if (test02())
return -1;
if (test03())
return -1;
/* if (test04()) */
/* return -1; */
/* if (test05()) */
......
......@@ -98,7 +98,6 @@ struct cspace;
struct cnode {
enum lcd_cap_type type;
int rights;
struct mutex lock;
/* Pointer to containing cspace */
struct cspace *cspace;
/* Linked list of free cnodes */
......@@ -249,6 +248,10 @@ static inline void __lcd_cnode_set_type(struct cnode *cnode,
{
cnode->type = t;
}
static inline void * __lcd_cnode_object(struct cnode *cnode)
{
return cnode->object;
}
/* IPC -------------------------------------------------- */
......
Markdown is supported
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