Commit 7213ef68 authored by Pankaj Kumar's avatar Pankaj Kumar
Browse files

Add testcase for capability revocation. Fix wrong check error in try_revoke.

parent 3263c80f
......@@ -1048,8 +1048,7 @@ static int try_revoke(struct cspace *cspace, struct cnode *cnode)
* If the child is in the cdt, its type should match cnode's
* type (it shouldn't be invalid, free, or a cnode).
*/
//BUG_ON(child->type != cnode->type);
assert(child->type != cnode->type);
assert(child->type == cnode->type);
/*
* Delete from cdt.
*/
......
......@@ -21,7 +21,7 @@
*/
int testcase1()
{
int ret;
int ret = 0;
struct cspace * csp;
struct cnode *cnode;
cptr_t slot_out, slot_out_orig;
......@@ -109,7 +109,7 @@ int testcase1()
*/
ret = __lcd_cap_insert(csp, slot_out, p, LCD_CAP_TYPE_PAGE);
if (ret) {
if (ret < 0) {
printf("Cspace Deletion Passed\n");
goto fail;
}
......@@ -118,6 +118,9 @@ fail:
return ret;
}
/*
* Testcase to check the grant functionality
*/
int testcase_grant()
{
int ret;
......@@ -208,11 +211,162 @@ fail1:
return ret;
}
/*
* capability insert
*/
int insert(struct cspace *csp, cptr_t slot)
{
int ret = 0;
void *p;
p = malloc(1 * sizeof(*p));
if (!p) {
perror("malloc\n");
ret = -1;
goto fail;
}
ret = __lcd_cap_insert(csp, slot, p, LCD_CAP_TYPE_PAGE);
if (ret < 0) {
LCD_ERR("cap insertion failed\n");
}
fail:
return ret;
}
/*
*Capability grant
*/
int grant(struct cspace *scsp, struct cspace *dcsp, cptr_t sslot, cptr_t dslot) {
int ret = 0;
ret = libcap_grant_capability((void *)scsp, (void *)dcsp, sslot, dslot);
if (ret < 0)
printf("Granting capability failed\n");
return ret;
}
/*
*Get Cnode
*/
int get_cnode(struct cspace *csp, cptr_t sslot) {
int ret = 0;
struct cnode *dcnode;
ret = __lcd_cnode_get(csp, sslot, &dcnode);
if (ret < 0)
LCD_ERR("Destination CSPACE Lookup failed\n");
/* Release cnode Lock */
__lcd_cnode_put(dcnode);
return ret;
}
/*
* Capability Revoke
*/
int revoke(struct cspace *csp, cptr_t sslot, struct cptr_cache *scache) {
int ret = 0;
ret = __lcd_cap_revoke(csp, sslot);
if (ret < 0)
printf("Revoke failed\n");
__klcd_free_cptr(scache, sslot);
return ret;
}
/*
* This testcase is checking capability revoke function.
* Here a capability is inserted in CSPACE A and granted to CSPACE B.
* Capability is then revoked from CSPACE A.
* Check is performed if Capability is still present in CSPACE B.
* It should not be present in CSPACE B.
*/
int testcase_revoke() {
int ret = 0;
struct cspace *scsp, *dcsp;
struct cptr_cache *scache, *dcache;
cptr_t sslot, dslot;
printf("\nTestcase : Capability Revocation\n");
/* 1st CSPACE */
scsp = malloc(1 * sizeof(*scsp));
if (!scsp) {
perror("malloc cspace\n");
exit(1);
}
ret = __lcd_cap_init_cspace(scsp);
if (ret < 0) {
printf("Cspace Initialization failed\n");
goto fail1;
}
ret = cptr_cache_init(&scache);
if (ret < 0) {
printf("cptr cache Initialization failed\n");
goto fail1;
}
/* 2nd CSPACE */
dcsp = malloc(1 * sizeof(*dcsp));
if (!dcsp) {
perror("malloc cspace\n");
goto fail1;
}
ret = __lcd_cap_init_cspace(dcsp);
if (ret < 0) {
printf("Cspace Initialization failed\n");
goto fail2;
}
ret = cptr_cache_init(&dcache);
if (ret < 0) {
printf("cptr cache Initialization failed\n");
goto fail2;
}
ret = __klcd_alloc_cptr(scache, &sslot);
if (ret < 0) {
printf("cptr aloocation failed\n");
goto fail;
}
ret = __klcd_alloc_cptr(dcache, &dslot);
if (ret < 0) {
printf("cptr aloocation failed\n");
goto fail;
}
ret = insert(scsp, sslot);
if (ret < 0)
goto fail2;
ret = grant(scsp, dcsp, sslot, dslot);
if (ret < 0)
goto fail2;
ret = revoke(scsp, sslot, scache);
if (ret < 0)
goto fail2;
ret = get_cnode(dcsp, dslot);
if (ret < 0) {
printf("\nTestcase Capability Revocation Passed\n");
goto fail2;
}
printf("\nTestcase capability Revocation Failed\n");
fail2:
__lcd_cap_destroy_cspace(dcsp);
fail1:
__lcd_cap_destroy_cspace(scsp);
fail:
return ret;
}
int main()
{
int ret;
int ret = 0;
ret = testcase1();
printf("\n\nTestcase : Capability Grant.\n");
ret = testcase_grant();
ret = testcase_revoke();
return ret;
}
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