Commit 4505e354 authored by Pankaj Kumar's avatar Pankaj Kumar

Testcase to check multiple thread capability operations

Following scenarios are covered:
1.) 20,000 capability inserts.
2.) 200 Grant operations.
3.) 100 Revoke operations.
4.) 20,500 Lookup operations.
Signed-off-by: Pankaj Kumar's avatarPankaj Kumar <pankajk@cs.utah.edu>
parent 6274bb9c
Pipeline #77 skipped
......@@ -19,6 +19,14 @@
* cd libacp/test; make
* ./libcap/test/mult
*
* Modification:
* CSPACE count : 2
* Runing threads : 20,000
* Capabilities Inserted : 20,000
* Granted to other cspace : 200
* Revoked : 100
* Lookup : 200(explicit), Otherwise: 20,500
*
*/
#include <stdio.h>
......@@ -28,7 +36,12 @@
#include <string.h>
struct cspace *scsp;
struct cspace *dcsp;
struct cptr_cache *scache;
struct cptr_cache *dcache;
cptr_t sslot_arr[500];
cptr_t dslot_arr[500];
int track = 0;
int insert (struct cspace *csp, cptr_t slot) {
int ret;
......@@ -39,7 +52,7 @@ int insert (struct cspace *csp, cptr_t slot) {
perror("malloc\n");
return 1;
}
ret = __lcd_cap_insert(csp, slot, p, LCD_CAP_TYPE_PAGE);
if (ret < 0) {
LCD_ERR("cap insertion failed\n");
......@@ -55,8 +68,6 @@ void *thread1_func(void *arg)
cptr_t sslot;
/* Not protecting this variable i. */
int *i = (int *) arg;
ret = __klcd_alloc_cptr(scache, &sslot);
if (ret < 0) {
printf("cptr aloocation failed\n");
......@@ -65,23 +76,82 @@ void *thread1_func(void *arg)
/* i may give strange values.
* Main focus is on sslot
*/
printf("Thread[%d]: 0x%lx\n", *i, cptr_val(sslot));
printf("Thread Inserting: 0x%lx\n", cptr_val(sslot));
ret = insert(scsp, sslot);
if (ret < 0) {
printf("Insert failure 0x%lx\n", cptr_val(sslot));
goto fail;
}
if (track < 500) {
sslot_arr[track] = sslot;
track++;
}
fail:
return;
}
void *thread_revoke(void* arg) {
printf("\nRevoke Called\n");
int i = 0;
int ret = 0;
while (i < 100) {
printf("Thread Revoke : 0x%lx\n", cptr_val(sslot_arr[i]));
ret = __lcd_cap_revoke(scsp, sslot_arr[i]);
if (ret < 0)
printf("Revoke failed\n");
__lcd_cap_delete(scsp, sslot_arr[i]);
if (ret < 0)
printf("Delete failed\n");
__klcd_free_cptr(scache, sslot_arr[i]);
i++;
}
}
void *thread_grant(void *arg) {
int ret = 0;
int i = 0;
printf("Grant called\n");
while(i < 200) {
cptr_t dslot;
ret = __klcd_alloc_cptr(dcache, &dslot);
if (ret < 0) {
printf("CSPACE2 LCD alloc error\n");
}
ret = libcap_grant_capability((void *)scsp, (void *)dcsp, sslot_arr[i], dslot);
if (ret < 0) {
printf("Granting capability failed\n");
} else
dslot_arr[i] = dslot;
i++;
}
}
void *thread_get(void * arg) {
int ret = 0;
int i = 0;
while(i < 200) {
struct cnode *dcnode;
ret = __lcd_cnode_get(dcsp, dslot_arr[i], &dcnode);
if (ret < 0) {
LCD_ERR("Destination CSPACE Lookup failed\n");
} else {
printf("Lookup PASS\n");
/* Release cnode Lock */
__lcd_cnode_put(dcnode);
}
i++;
}
}
int main()
{
pthread_t thread[10];
pthread_t thread[20000];
int i, ret, j;
/* 1st CSPACE */
scsp = malloc(1 * sizeof(*scsp));
if (!scsp) {
perror("malloc cspace\n");
......@@ -99,21 +169,48 @@ int main()
printf("cptr cache Initialization failed\n");
goto fail1;
}
for (i=0; i<10; i++) {
ret = pthread_create(&thread[i], NULL, thread1_func, (void *) &i);
if (ret < 0) {
perror("pthread create\n");
goto fail1;
/* 2nd CSPACE */
dcsp = malloc(1 * sizeof(*dcsp));
if (!dcsp) {
perror("malloc cspace\n");
exit(1);
}
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 fail;
}
for (i=0; i<20000; i++) {
if (i == 3000) {
ret = pthread_create(&thread[i], NULL, thread_grant, (void *) &i);
} else if (i == 5000) {
ret = pthread_create(&thread[i], NULL, thread_revoke, (void *) &i);
} else if (i == 9000) {
ret = pthread_create(&thread[i], NULL, thread_get, (void *) &i);
} else {
ret = pthread_create(&thread[i], NULL, thread1_func, (void *) &i);
} if (ret < 0) {
printf("pthread create\n");
}
}
for (j=0; j<10; j++) {
ret = pthread_join(thread[j], NULL);
for (i=0; i<20000; i++) {
ret = pthread_join(thread[i], NULL);
if (ret < 0) {
printf("Problem join %d\n", j);
printf("Problem join %d\n", i);
}
}
}
fail:
__lcd_cap_destroy_cspace(dcsp);
fail1:
__lcd_cap_destroy_cspace(scsp);
fail2:
......
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