All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 20006364 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Updated lcd tests.

parent d71afeb4
......@@ -12,9 +12,10 @@ static int test01(void)
struct lcd *lcd;
int ret;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test01 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
ret = -1;
goto fail;
}
......@@ -27,105 +28,37 @@ fail:
}
static int test02(void)
{
struct lcd *lcd;
int ret;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test02 failed to create lcd\n");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
if (ret) {
printk(KERN_ERR "lcd test: test02 failed to init gva\n");
goto fail2;
}
lcd_destroy(lcd);
return 0;
fail2:
lcd_destroy(lcd);
fail1:
return ret;
}
static int test03(void)
{
struct lcd *lcd;
int ret;
gpa_t gpa;
hpa_t hpa;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test03 failed to create lcd\n");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
if (ret) {
printk(KERN_ERR "lcd test: test03 failed to init gva\n");
goto fail2;
}
ret = lcd_mm_gva_alloc(lcd, &gpa, &hpa);
if (ret) {
printk(KERN_ERR "lcd test: test03 failed to alloc pg mem\n");
goto fail3;
}
ret = 0;
goto done;
done:
free_page(hva_val(hpa2hva(hpa)));
lcd_arch_ept_unmap_range(lcd->lcd_arch, gpa, 1);
fail3:
fail2:
lcd_destroy(lcd);
fail1:
return ret;
}
static int test04(void)
{
struct lcd *lcd;
int ret;
gpa_t gpa;
hpa_t hpa;
hva_t hva;
pmd_t *pmd_entry;
pte_t *pt;
pte_t *pte_entry;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test04 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test04 failed to init gva\n");
LCD_ERR("failed to init gv");
goto fail2;
}
ret = lcd_mm_gva_alloc(lcd, &gpa, &hpa);
ret = lcd_mm_alloc_gv_page(lcd, &gpa, &hva);
if (ret) {
printk(KERN_ERR "lcd test: test04 failed to alloc pg mem\n");
LCD_ERR("failed to alloc pg mem");
goto fail3;
}
/*
* Map gva = 0x4000 (start of 5th page frame) to gpa = 0x1234000UL
*/
pt = (pte_t *)hpa2va(hpa);
pt = (pte_t *)hva2va(hva);
set_pte_gpa(pt + 4, __gpa(0x1234000UL));
/*
......@@ -140,7 +73,7 @@ static int test04(void)
ret = lcd_mm_gva_lookup_pte(lcd, __gva(0x4000UL),
pmd_entry, &pte_entry);
if (ret) {
printk(KERN_ERR "lcd test: test04 failed to lookup pte\n");
LCD_ERR("failed to lookup pte");
goto fail5;
}
......@@ -148,8 +81,7 @@ static int test04(void)
* Check
*/
if (gpa_val(pte_gpa(pte_entry)) != 0x1234000UL) {
printk(KERN_ERR "lcd test: test04 pte gpa is %lx\n",
gpa_val(pte_gpa(pte_entry)));
LCD_ERR("pte gpa is %lx\n", gpa_val(pte_gpa(pte_entry)));
ret = -1;
goto fail6;
}
......@@ -162,7 +94,7 @@ fail6:
fail5:
kfree(pmd_entry);
fail4:
free_page(hva_val(hpa2hva(hpa)));
free_page(hva_val(hva));
lcd_arch_ept_unmap_range(lcd->lcd_arch, gpa, 1);
fail3:
fail2:
......@@ -171,32 +103,31 @@ fail1:
return ret;
}
static int test05(void)
static int test03(void)
{
struct lcd *lcd;
int ret;
gpa_t gpa;
hpa_t hpa;
hva_t hva;
pud_t *pud_entry;
pmd_t *pmd;
pmd_t *pmd_entry;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test05 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test05 failed to init gva\n");
LCD_ERR("failed to init gva");
goto fail2;
}
ret = lcd_mm_gva_alloc(lcd, &gpa, &hpa);
ret = lcd_mm_alloc_gv_page(lcd, &gpa, &hva);
if (ret) {
printk(KERN_ERR "lcd test: test05 failed to alloc pg mem\n");
LCD_ERR("failed to alloc pg mem");
goto fail3;
}
......@@ -204,7 +135,7 @@ static int test05(void)
* Populate 5th entry in pmd to point to a (bogus) page table at
* gpa 0x1234000UL.
*/
pmd = (pmd_t *)hpa2va(hpa);
pmd = (pmd_t *)hva2va(hpa);
set_pmd_gpa(pmd + 4, __gpa(0x1234000UL));
/*
......@@ -219,7 +150,7 @@ static int test05(void)
ret = lcd_mm_gva_lookup_pmd(lcd, __gva(0x4UL << PMD_SHIFT),
pud_entry, &pmd_entry);
if (ret) {
printk(KERN_ERR "lcd test: test05 failed to lookup pmd\n");
LCD_ERR("failed to lookup pmd");
goto fail5;
}
......@@ -227,8 +158,7 @@ static int test05(void)
* Check
*/
if (gpa_val(pmd_gpa(pmd_entry)) != 0x1234000UL) {
printk(KERN_ERR "lcd test: test05 pte gpa is %lx\n",
gpa_val(pmd_gpa(pmd_entry)));
LCD_ERR("pte gpa is %lx\n", gpa_val(pmd_gpa(pmd_entry)));
ret = -1;
goto fail6;
}
......@@ -241,7 +171,7 @@ fail6:
fail5:
kfree(pud_entry);
fail4:
free_page(hva_val(hpa2hva(hpa)));
free_page(hva_val(hva));
lcd_arch_ept_unmap_range(lcd->lcd_arch, gpa, 1);
fail3:
fail2:
......@@ -250,32 +180,31 @@ fail1:
return ret;
}
static int test06(void)
static int test04(void)
{
struct lcd *lcd;
int ret;
gpa_t gpa;
hpa_t hpa;
hva_t hva;
pgd_t *pgd_entry;
pud_t *pud;
pud_t *pud_entry;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test06 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test06 failed to init gva\n");
LCD_ERR("failed to init gv");
goto fail2;
}
ret = lcd_mm_gva_alloc(lcd, &gpa, &hpa);
ret = lcd_mm_alloc_gv_page(lcd, &gpa, &hva);
if (ret) {
printk(KERN_ERR "lcd test: test06 failed to alloc pg mem\n");
LCD_ERR("failed to alloc pg mem");
goto fail3;
}
......@@ -283,7 +212,7 @@ static int test06(void)
* Populate 5th entry in pud to point to a (bogus) pmd at
* gpa 0x1234000UL.
*/
pud = (pud_t *)hpa2va(hpa);
pud = (pud_t *)hva2va(hva);
set_pud_gpa(pud + 4, __gpa(0x1234000UL));
/*
......@@ -298,7 +227,7 @@ static int test06(void)
ret = lcd_mm_gva_lookup_pud(lcd, __gva(0x4UL << PUD_SHIFT),
pgd_entry, &pud_entry);
if (ret) {
printk(KERN_ERR "lcd test: test06 failed to lookup pud\n");
LCD_ERR("failed to lookup pud");
goto fail5;
}
......@@ -306,8 +235,7 @@ static int test06(void)
* Check
*/
if (gpa_val(pud_gpa(pud_entry)) != 0x1234000UL) {
printk(KERN_ERR "lcd test: test06 pmd gpa is %lx\n",
gpa_val(pud_gpa(pud_entry)));
LCD_ERR("pmd gpa is %lx\n", gpa_val(pud_gpa(pud_entry)));
ret = -1;
goto fail6;
}
......@@ -320,7 +248,7 @@ fail6:
fail5:
kfree(pgd_entry);
fail4:
free_page(hva_val(hpa2hva(hpa)));
free_page(hva_val(hva));
lcd_arch_ept_unmap_range(lcd->lcd_arch, gpa, 1);
fail3:
fail2:
......@@ -329,22 +257,21 @@ fail1:
return ret;
}
static int test07(void)
static int test05(void)
{
struct lcd *lcd;
int ret;
gpa_t gpa;
ret = lcd_create(&lcd);
lcd = __lcd_create();
if (ret) {
printk(KERN_ERR "lcd test: test07 failed to create lcd\n");
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test07 failed to init gva\n");
LCD_ERR("failed to init gv");
goto fail2;
}
......@@ -353,7 +280,7 @@ static int test07(void)
*/
ret = lcd_mm_gva_map(lcd, __gva(0x1234000UL), __gpa(0x5678000UL));
if (ret) {
printk(KERN_ERR "lcd test: test07 failed to map\n");
LCD_ERR("failed to map");
goto fail3;
}
......@@ -362,19 +289,18 @@ static int test07(void)
*/
ret = lcd_mm_gva_to_gpa(lcd, __gva(0x1234000UL), &gpa);
if (ret) {
printk(KERN_ERR "lcd test: test07 failed to lookup\n");
LCD_ERR("failed to lookup");
goto fail4;
}
if (gpa_val(gpa) != 0x5678000UL) {
printk(KERN_ERR "lcd test: test07 got phys addr %lx\n",
gpa_val(gpa));
LCD_ERR("got phys addr %lx\n", gpa_val(gpa));
goto fail5;
}
ret = lcd_mm_gva_unmap(lcd, __gva(0x1234000UL));
if (ret) {
printk(KERN_ERR "lcd test: test07 failed to unmap\n");
LCD_ERR("failed to unmap");
goto fail6;
}
......@@ -392,7 +318,7 @@ fail1:
return ret;
}
static int test08(void)
static int test06(void)
{
struct lcd *lcd;
int ret;
......@@ -401,55 +327,46 @@ static int test08(void)
gpa_t gpa1;
gpa_t gpa2;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test08 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 2 * PAGE_SIZE));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test08 failed to init gva\n");
LCD_ERR("failed to init gv");
goto fail2;
}
/* (should map entry on the fly) */
ret = lcd_mm_gva_walk_pgd(lcd, __gva(0x1234000UL), &pgd_entry1);
if (ret) {
printk(KERN_ERR "lcd test: test08 failed to walk pgd\n");
LCD_ERR("failed to walk pgd");
goto fail3;
}
/* (should map entry on the fly) */
ret = lcd_mm_gva_walk_pgd(lcd, __gva(0x1234000UL), &pgd_entry2);
if (ret) {
printk(KERN_ERR "lcd test: test08 failed to walk pgd2\n");
LCD_ERR("failed to walk pgd2");
goto fail4;
}
if (pgd_entry1 != pgd_entry2) {
printk(KERN_ERR "lcd test: test08 entries differ\n");
LCD_ERR("entries differ");
ret = -1;
goto fail5;
}
if (!pgd_present(*pgd_entry1) || !pgd_present(*pgd_entry2)) {
printk(KERN_ERR "lcd test: test08 entries not present\n");
LCD_ERR("entries not present\n");
ret = -1;
goto fail5;
}
gpa1 = pgd_gpa(pgd_entry1);
gpa2 = pgd_gpa(pgd_entry2);
if (gpa_val(gpa1) < gpa_val(LCD_ARCH_FREE) ||
gpa_val(gpa1) > gpa_val(gpa_add(LCD_ARCH_FREE,2 * PAGE_SIZE))){
printk(KERN_ERR "lcd test: test08 bad gpa %lx\n",
gpa_val(gpa1));
ret = -1;
goto fail5;
}
if (gpa_val(gpa1) != gpa_val(gpa2)) {
printk(KERN_ERR "lcd test: test08 two diff gpa's: first = %lx, second %lx\n",
LCD_ERR("two diff gpa's: first = %lx, second %lx\n",
gpa_val(gpa1), gpa_val(gpa2));
ret = -1;
goto fail5;
......@@ -468,19 +385,18 @@ fail1:
return ret;
}
static int test09_help(struct lcd *lcd, unsigned long base)
static int test07_help(struct lcd *lcd, unsigned long base)
{
unsigned long off;
gpa_t actual;
for (off = 0; off < (1 << 22); off += PAGE_SIZE) {
if (lcd_mm_gva_to_gpa(lcd, __gva(base + off), &actual)) {
printk(KERN_ERR "lcd test: test09 failed lookup at %lx\n",
base + off);
LCD_ERR("failed lookup at %lx", base + off);
return -1;
}
if (gpa_val(actual) != base + off) {
printk(KERN_ERR "lcd test: test09 expected gpa %lx got %lx\n",
LCD_ERR("expected gpa %lx got %lx",
base + off,
gpa_val(actual));
return -1;
......@@ -489,22 +405,21 @@ static int test09_help(struct lcd *lcd, unsigned long base)
return 0;
}
static int test09(void)
static int test07(void)
{
struct lcd *lcd;
int ret;
unsigned long base;
ret = lcd_create(&lcd);
if (ret) {
printk(KERN_ERR "lcd test: test09 failed to create lcd\n");
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
ret = lcd_mm_gva_init(lcd, LCD_ARCH_FREE,
gpa_add(LCD_ARCH_FREE, 4 * (1 << 20)));
ret = lcd_mm_gv_init(lcd);
if (ret) {
printk(KERN_ERR "lcd test: test09 failed to init gva\n");
LCD_ERR("failed to init gv");
goto fail2;
}
......@@ -513,7 +428,7 @@ static int test09(void)
*/
ret = lcd_mm_gva_map_range(lcd, __gva(0), __gpa(0), 1024);
if (ret) {
printk(KERN_ERR "lcd test: test09 failed to map first 4 MBs\n");
LCD_ERR("failed to map first 4 MBs");
goto fail3;
}
......@@ -522,7 +437,7 @@ static int test09(void)
*/
ret = lcd_mm_gva_map_range(lcd, __gva(1 << 30), __gpa(1 << 30), 1024);
if (ret) {
printk(KERN_ERR "lcd test: test09 failed to map 2nd 4 MBs\n");
LCD_ERR("failed to map 2nd 4 MBs");
goto fail4;
}
......@@ -532,7 +447,7 @@ static int test09(void)
ret = lcd_mm_gva_map_range(lcd, __gva(1UL << 39),
__gpa(1UL << 39), 1024);
if (ret) {
printk(KERN_ERR "lcd test: test09 failed to map 3rd 4 MBs\n");
LCD_ERR("failed to map 3rd 4 MBs");
goto fail5;
}
......@@ -567,29 +482,26 @@ fail1:
return ret;
}
static int test10(void)
static int test08(void)
{
struct task_struct *t;
struct lcd *lcd;
int r;
/*
* lcd-module-load-test.c is in virt/lcd-domains/
*/
/*
* Create it
*/
t = lcd_create_as_module("lcd_module_load_test");
if (!t) {
LCD_ERR("create");
ret = lcd_create(&lcd);
if (ret) {
LCD_ERR("creating lcd");
goto fail1;
}
/*
* Run it (once)
* Run init thread
*/
r = lcd_run_as_module(t);
if (r) {
ret = lcd_thread_start(lcd->init_thread);
if (ret) {
LCD_ERR("run");
goto fail2;
}
......@@ -600,11 +512,15 @@ static int test10(void)
/*
* Tear it down
*/
lcd_destroy_as_module(t, "lcd_module_load_test");
ret = lcd_thread_kill(lcd->init_thread);
LCD_MSG("lcd_module_load_test ret val = %d", ret);
lcd_destroy(lcd);
return 0;
fail2:
lcd_destroy_as_module(t, "lcd_module_load_test");
lcd_thread_kill(lcd->init_thread);
lcd_destroy(lcd);
fail1:
return -1;
}
......@@ -627,10 +543,6 @@ static void lcd_tests(void)
return;
if (test08())
return;
if (test09())
return;
if (test10())
return;
printk(KERN_ERR "lcd-domains: all tests passed!\n");
LCD_MSG("all tests passed!");
return;
}
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