Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 20de14d in mainline


Ignore:
Timestamp:
2012-01-28T14:39:23Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
7b3b571, bf3dd35
Parents:
61ac34d
Message:

Streamline mapping1 test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/mm/mapping1.c

    r61ac34d r20de14d  
    3131#include <mm/page.h>
    3232#include <mm/frame.h>
    33 #include <mm/as.h>
    3433#include <arch/mm/page.h>
     34#include <mm/km.h>
    3535#include <typedefs.h>
    3636#include <debug.h>
    3737#include <arch.h>
    3838
    39 #define PAGE0  0x10000000
    40 #define PAGE1  (PAGE0 + PAGE_SIZE)
    41 
    42 #define VALUE0  UINT32_C(0x01234567)
    43 #define VALUE1  UINT32_C(0x89abcdef)
     39#define TEST_MAGIC  UINT32_C(0x01234567)
    4440
    4541const char *test_mapping1(void)
    4642{
    47         uintptr_t frame0, frame1;
    48         uint32_t v0, v1;
     43        uintptr_t page0, page1;
     44        uintptr_t frame;
     45        uint32_t v;
     46        int i;
    4947       
    50         frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
    51         frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
     48        frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE);
     49
     50        page0 = km_map(frame, FRAME_SIZE,
     51            PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     52        TPRINTF("Virtual address %p mapped to physical address %p.\n",
     53            (void *) page0, (void *) frame);
     54        page1 = km_map(frame, FRAME_SIZE,
     55            PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
     56        TPRINTF("Virtual address %p mapped to physical address %p.\n",
     57            (void *) page1, (void *) frame);
    5258       
    53         TPRINTF("Writing %#" PRIx32 " to physical address %p.\n",
    54             (uint32_t) VALUE0, (void *) KA2PA(frame0));
    55         *((uint32_t *) frame0) = VALUE0;
     59        for (i = 0; i < 2; i++) {
     60                TPRINTF("Writing magic using the first virtual address.\n");
     61
     62                *((uint32_t *) page0) = TEST_MAGIC;
     63
     64                TPRINTF("Reading magic using the second virtual address.\n");
     65
     66                v = *((uint32_t *) page1);
    5667       
    57         TPRINTF("Writing %#" PRIx32 " to physical address %p.\n",
    58             (uint32_t) VALUE1, (void *) KA2PA(frame1));
    59         *((uint32_t *) frame1) = VALUE1;
     68                if (v != TEST_MAGIC)
     69                        return "Criss-cross read does not match the value written.";
     70
     71                TPRINTF("Writing zero using the second virtual address.\n");
    6072       
    61         page_table_lock(AS, true);
     73                *((uint32_t *) page1) = 0;
    6274
    63         TPRINTF("Mapping virtual address %p to physical address %p.\n",
    64             (void *) PAGE0, (void *) KA2PA(frame0));
    65         page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
     75                TPRINTF("Reading zero using the first virtual address.\n");
    6676       
    67         TPRINTF("Mapping virtual address %p to physical address %p.\n",
    68             (void *) PAGE1, (void *) KA2PA(frame1));
    69         page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
     77                v = *((uint32_t *) page0);
     78       
     79                if (v != 0)
     80                        return "Criss-cross read does not match the value written.";
     81        }
    7082
    71         page_table_unlock(AS, true);
    72        
    73         v0 = *((uint32_t *) PAGE0);
    74         v1 = *((uint32_t *) PAGE1);
    75         TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
    76             (void *) PAGE0, v0);
    77         TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
    78             (void *) PAGE1, v1);
    79        
    80         if (v0 != VALUE0)
    81                 return "Value at v0 not equal to VALUE0";
    82         if (v1 != VALUE1)
    83                 return "Value at v1 not equal to VALUE1";
    84        
    85         TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n",
    86             (uint32_t) 0, (void *) PAGE0);
    87         *((uint32_t *) PAGE0) = 0;
    88        
    89         TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n",
    90             (uint32_t) 0, (void *) PAGE1);
    91         *((uint32_t *) PAGE1) = 0;
    92        
    93         v0 = *((uint32_t *) PAGE0);
    94         v1 = *((uint32_t *) PAGE1);
    95        
    96         TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
    97             (void *) PAGE0, *((uint32_t *) PAGE0));
    98         TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
    99             (void *) PAGE1, *((uint32_t *) PAGE1));
    100        
    101         if (v0 != 0)
    102                 return "Value at v0 not equal to 0";
    103         if (v1 != 0)
    104                 return "Value at v1 not equal to 0";
     83        // FIXME: do not leak frame, page0 and page1
    10584       
    10685        return NULL;
Note: See TracChangeset for help on using the changeset viewer.