vmm: Refactor vmm_ctl to use error()
[akaros.git] / kern / src / manager.c
index bd4888a..9004b21 100644 (file)
@@ -5,10 +5,6 @@
  */
 
 
-#ifdef __SHARC__
-#pragma nosharc
-#endif
-
 #include <ros/common.h>
 #include <smp.h>
 #include <arch/init.h>
 #include <process.h>
 #include <schedule.h>
 #include <syscall.h>
-#include <test_infrastructure.h>
+#include <ktest.h>
 #include <kfs.h>
 #include <stdio.h>
 #include <time.h>
 #include <monitor.h>
-#include <colored_caches.h>
 #include <string.h>
 #include <pmap.h>
 #include <arch/console.h>
 #include <time.h>
 #include <ros/arch/membar.h>
 
-char *kern_test_msg; // Variable defined in test_infrastructure.h.
-
-
-void postboot_kernel_tests(void)
-{
-       printk("\nRunning %d postboot Kernel tests:\n", 
-                  num_pb_kernel_tests);
-
-       // Do not remove this line, it is being used by Jenkins.
-       printk("<-- BEGIN_KERNEL_POSTBOOT_TESTS -->\n");
-       for (int i=0; i<num_pb_kernel_tests; i++) {
-               struct pb_kernel_test *test = &pb_kernel_tests[i];
-               if (test->enabled) {
-                       uint64_t start = read_tsc();
-                       bool result = test->func();
-                       uint64_t end = read_tsc();
-                       uint64_t et_us = tsc2usec(end - start) % 1000000;
-                       uint64_t et_s = tsc2sec(end - start);
-
-                       if (result) {
-                               printk("\tPASSED   [%s](%llu.%06llus)\n", test->name, et_s, 
-                                      et_us);
-                       } else {
-                               printk("\tFAILED   [%s](%llu.%06llus)  %s\n", test->name, et_s, 
-                                      et_us, kern_test_msg);
-                               kfree(kern_test_msg);
-                       }
-               } else {
-                       printk("\tDISABLED [%s]\n", test->name);
-               }
-       }
-       // Do not remove this line, it is being used by Jenkins.
-       printk("<-- END_KERNEL_POSTBOOT_TESTS -->\n");
-}
-
 /*
  * Currently, if you leave this function by way of proc_run (process_workqueue
  * that proc_runs), you will never come back to where you left off, and the
@@ -76,40 +36,32 @@ void postboot_kernel_tests(void)
  */
 void manager(void)
 {
-       #ifndef DEVELOPER_NAME
-               #define DEVELOPER_NAME brho
-       #endif
-
        // LoL
        #define PASTE(s1,s2) s1 ## s2
        #define MANAGER_FUNC(dev) PASTE(manager_,dev)
 
-       // Run Kernel post boot tests (from tests_postboot_kernel.c).
-       #ifdef CONFIG_POSTBOOT_KERNEL_TESTING
-               postboot_kernel_tests();
+       #if !defined(DEVELOPER_NAME) && \
+           (defined(CONFIG_KERNEL_TESTING) || \
+            defined(CONFIG_USERSPACE_TESTING))
+               #define DEVELOPER_NAME jenkins
+       #endif
+
+       #ifndef DEVELOPER_NAME
+               #define DEVELOPER_NAME brho
        #endif
-       // Run userspace tests (from config specified path).
-       if (strlen(CONFIG_USERSPACE_TESTING) != 0)
-       {
-               printk("'%s' is %d chars long", CONFIG_USERSPACE_TESTING,
-                          strlen(STRINGIFY(CONFIG_USERSPACE_TESTING)));
-               char *usp_args[] = {"bin_run", "ash", CONFIG_USERSPACE_TESTING};
-               mon_bin_run(3, usp_args, NULL);
-       } 
 
        void MANAGER_FUNC(DEVELOPER_NAME)(void);
        MANAGER_FUNC(DEVELOPER_NAME)();
 }
 
 char *p_argv[] = {0, 0, 0};
-char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
 /* Helper macro for quickly running a process.  Pass it a string, *file, and a
  * *proc. */
 #define quick_proc_run(x, p, f)                                                  \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -118,20 +70,20 @@ char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
        proc_decref((p));
 
 #define quick_proc_create(x, p, f)                                               \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);
 
 #define quick_proc_color_run(x, p, c, f)                                         \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -143,10 +95,10 @@ char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
        proc_decref((p));
 
 #define quick_proc_color_create(x, p, c, f)                                      \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
-       (p) = proc_create((f), p_argv, p_envp);                                      \
+       (p) = proc_create((f), p_argv, NULL);                                        \
        kref_put(&(f)->f_kref);                                                      \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
@@ -160,7 +112,7 @@ void manager_brho(void)
        static bool first = TRUE;
        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
 
-       if (first) {    
+       if (first) {
                printk("*** IRQs must be enabled for input emergency codes ***\n");
                #ifdef CONFIG_X86
                printk("*** Hit ctrl-g to enter the monitor. ***\n");
@@ -182,7 +134,7 @@ void manager_brho(void)
 
 #if 0 /* ancient tests below: (keeping around til we ditch the manager) */
        // for testing taking cores, check in case 1 for usage
-       uint32_t corelist[MAX_NUM_CPUS];
+       uint32_t corelist[MAX_NUM_CORES];
        uint32_t num = 3;
        struct file *temp_f;
        static struct proc *p;
@@ -228,7 +180,6 @@ void manager_brho(void)
                                spin_unlock(&p->proc_lock);
                                udelay(5000000);
                                printk("Killing p\n");
-                               enable_irq();
                                proc_destroy(p);
                                printk("Killed p\n");
                        panic("This is okay");
@@ -269,6 +220,35 @@ void manager_brho(void)
 #endif
 }
 
+void manager_jenkins()
+{
+       #ifdef CONFIG_KERNEL_TESTING
+               printk("<-- BEGIN_KERNEL_TESTS -->\n");
+               run_registered_ktest_suites();
+               printk("<-- END_KERNEL_TESTS -->\n");
+       #endif
+
+       // Run userspace tests (from config specified path).
+       #ifdef CONFIG_USERSPACE_TESTING
+       if (strlen(CONFIG_USERSPACE_TESTING_SCRIPT) != 0) {
+               char exec[] = "/bin/ash";
+               char *p_argv[] = {exec, CONFIG_USERSPACE_TESTING_SCRIPT, 0};
+
+               struct file *program = do_file_open(exec, O_READ, 0);
+               struct proc *p = proc_create(program, p_argv, NULL);
+               proc_wakeup(p);
+               proc_decref(p); /* let go of the reference created in proc_create() */
+               kref_put(&program->f_kref);
+               run_scheduler();
+           // Need a way to wait for p to finish
+       } else {
+               printk("No user-space launcher file specified.\n");
+       }
+       #endif
+       smp_idle();
+       assert(0);
+}
+
 void manager_klueska()
 {
        static struct proc *envs[256];
@@ -291,19 +271,19 @@ void manager_waterman()
 {
        static bool first = true;
        if (first)
-               mon_bb(0, 0, 0);
+               mon_shell(0, 0, 0);
        smp_idle();
        assert(0);
 }
 
 void manager_yuzhu()
 {
-       
-       static uint8_t RACY progress = 0;
+
+       static uint8_t progress = 0;
        static struct proc *p;
 
        // for testing taking cores, check in case 1 for usage
-       uint32_t corelist[MAX_NUM_CPUS];
+       uint32_t corelist[MAX_NUM_CORES];
        uint32_t num = 3;
 
        //create_server(init_num_cores, loop);