Merge branch 'net-dev'. See body of commit for details.
[akaros.git] / kern / src / testing.c
index e6a1740..55bf00d 100644 (file)
@@ -1,9 +1,14 @@
 
+#ifdef __SHARC__
+#pragma nosharc
+#endif
+
 #include <arch/mmu.h>
 #include <arch/arch.h>
 #include <smp.h>
 
 #include <ros/memlayout.h>
+#include <ros/common.h>
 
 #include <atomic.h>
 #include <stdio.h>
@@ -11,6 +16,7 @@
 #include <string.h>
 #include <testing.h>
 #include <trap.h>
+#include <arch/trap.h>
 #include <process.h>
 #include <syscall.h>
 #include <timing.h>
 #include <multiboot.h>
 #include <pmap.h>
 #include <page_alloc.h>
-
 #include <pmap.h>
 
-#define test_vector 0xeb
-
 #ifdef __i386__
 
 void test_ipi_sending(void)
 {
-       extern handler_t (COUNT(NUM_INTERRUPT_HANDLERS) interrupt_handlers)[];
+       extern handler_t (CT(NUM_INTERRUPT_HANDLERS) RO interrupt_handlers)[];
        int8_t state = 0;
 
-       register_interrupt_handler(interrupt_handlers, test_vector,
+       register_interrupt_handler(interrupt_handlers, I_TESTING,
                                   test_hello_world_handler, NULL);
        enable_irqsave(&state);
        cprintf("\nCORE 0 sending broadcast\n");
-       send_broadcast_ipi(test_vector);
+       send_broadcast_ipi(I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending all others\n");
-       send_all_others_ipi(test_vector);
+       send_all_others_ipi(I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending self\n");
-       send_self_ipi(test_vector);
+       send_self_ipi(I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to physical 1\n");
-       send_ipi(0x01, 0, test_vector);
+       send_ipi(0x01, 0, I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to physical 2\n");
-       send_ipi(0x02, 0, test_vector);
+       send_ipi(0x02, 0, I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to physical 3\n");
-       send_ipi(0x03, 0, test_vector);
+       send_ipi(0x03, 0, I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to physical 15\n");
-       send_ipi(0x0f, 0, test_vector);
+       send_ipi(0x0f, 0, I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to logical 2\n");
-       send_ipi(0x02, 1, test_vector);
+       send_ipi(0x02, 1, I_TESTING);
        udelay(3000000);
        cprintf("\nCORE 0 sending ipi to logical 1\n");
-       send_ipi(0x01, 1, test_vector);
+       send_ipi(0x01, 1, I_TESTING);
        udelay(3000000);
        cprintf("\nDone!\n");
        disable_irqsave(&state);
@@ -121,6 +124,14 @@ void test_page_coloring(void)
        //Declare a local variable for allocating pages 
        page_t* page;
 
+       cprintf("Contents of the page free list:\n");
+       for(int i=0; i<llc_num_colors; i++) {
+               cprintf("  COLOR %d:\n", i);
+               LIST_FOREACH(page, &colored_page_free_list[i], page_link) {
+                       cprintf("    Page: %d\n", page2ppn(page));
+               }
+       }
+
        //Run through and allocate all pages through l1_page_alloc
        cprintf("Allocating from L1 page colors:\n");
        for(int i=0; i<get_cache_num_page_colors(&l1); i++) {
@@ -175,7 +186,6 @@ void test_page_coloring(void)
                cprintf("Page: %d\n", page2ppn(page));  
 }
 
-extern uint8_t num_cpus;
 barrier_t test_cpu_array;
 
 void test_barrier(void)
@@ -324,8 +334,6 @@ void test_checklist_handler(trapframe_t *tf, void* data)
        down_checklist(the_global_list);
 }
 
-extern uint8_t num_cpus;
-
 void test_checklists(void)
 {
        INIT_CHECKLIST(a_list, MAX_NUM_CPUS);
@@ -361,7 +369,11 @@ void test_checklists(void)
 
 atomic_t a, b, c;
 
-void test_incrementer_handler(trapframe_t *tf, atomic_t* data)
+#ifdef __IVY__
+void test_incrementer_handler(trapframe_t *tf, atomic_t *data)
+#else
+void test_incrementer_handler(trapframe_t *tf, void *data)
+#endif
 {
        assert(data);
        atomic_inc(data);
@@ -481,13 +493,13 @@ void test_smp_call_functions(void)
 #ifdef __i386__
 void test_lapic_status_bit(void)
 {
-       register_interrupt_handler(interrupt_handlers, test_vector,
+       register_interrupt_handler(interrupt_handlers, I_TESTING,
                                   test_incrementer_handler, &a);
        #define NUM_IPI 100000
        atomic_set(&a,0);
        printk("IPIs received (should be 0): %d\n", a);
        for(int i = 0; i < NUM_IPI; i++) {
-               send_ipi(7, 0, test_vector);
+               send_ipi(7, 0, I_TESTING);
                lapic_wait_to_send();
        }
        // need to wait a bit to let those IPIs get there
@@ -695,9 +707,13 @@ void test_barrier_handler(trapframe_t *tf, void* data)
        //cprintf("Round 4: Core %d\n", core_id());
 }
 
-static void test_waiting_handler(trapframe_t *tf, atomic_t * data)
+#ifdef __IVY__
+static void test_waiting_handler(trapframe_t *tf, atomic_t *data)
+#else
+static void test_waiting_handler(trapframe_t *tf, void *data)
+#endif
 {
-       {HANDLER_ATOMIC atomic_dec(data);}
+       atomic_dec(data);
 }
 
 #ifdef __i386__
@@ -716,10 +732,63 @@ void test_pit(void)
 
        atomic_t waiting;
        atomic_init(&waiting, 1);
-       register_interrupt_handler(interrupt_handlers, test_vector,
+       register_interrupt_handler(interrupt_handlers, I_TESTING,
                                   test_waiting_handler, &waiting);
        while(atomic_read(&waiting))
                cpu_relax();
        cprintf("End now\n");
 }
+
+void test_circ_buffer(void)
+{
+       int arr[5] = {0, 1, 2, 3, 4};
+
+       for (int i = 0; i < 5; i++) {
+               FOR_CIRC_BUFFER(i, 5, j)
+                       printk("Starting with current = %d, each value = %d\n", i, j);
+       }
+       return;
+}
+
+#ifdef __IVY__
+void test_am_handler(trapframe_t* tf, uint32_t srcid, uint32_t a0, uint32_t a1,
+                     uint32_t a2)
+#else
+void test_am_handler(trapframe_t* tf, uint32_t srcid, void * a0, void * a1,
+                     void * a2)
+#endif
+{
+       printk("Received AM on core %d from core %d: arg0= 0x%08x, arg1 = "
+              "0x%08x, arg2 = 0x%08x\n", core_id(), srcid, a0, a1, a2);
+       return;
+}
+
+void test_active_messages(void)
+{
+       // basic tests, make sure we can handle a wraparound and that the error
+       // messages work.
+       printk("sending NUM_ACTIVE_MESSAGES to core 1, sending (#,deadbeef,0)\n");
+       for (int i = 0; i < NUM_ACTIVE_MESSAGES; i++)
+#ifdef __IVY__
+               while (send_active_message(1, test_am_handler, i, 0xdeadbeef, 0))
+                       cpu_relax();
+#else
+               while (send_active_message(1, test_am_handler, (void *)i,
+                                          (void *)0xdeadbeef, (void *)0))
+                       cpu_relax();
+#endif
+       udelay(5000000);
+       printk("sending 2*NUM_ACTIVE_MESSAGES to core 1, sending (#,cafebabe,0)\n");
+       for (int i = 0; i < 2*NUM_ACTIVE_MESSAGES; i++)
+#ifdef __IVY__
+               while (send_active_message(1, test_am_handler, i, 0xdeadbeef, 0))
+                       cpu_relax();
+#else
+               while (send_active_message(1, test_am_handler, (void *)i,
+                                          (void *)0xdeadbeef, (void *)0))
+                       cpu_relax();
+#endif
+       udelay(5000000);
+       return;
+}
 #endif // __i386__