Add another kernel test, fix small bugs (#156)

* temp

* run function in process test

* windows debug

* debug

* update

* update

* again

* update

* fix same bug in debugger
This commit is contained in:
water111
2020-12-10 20:26:40 -05:00
committed by GitHub
parent e05f3ceefc
commit ba919a069c
10 changed files with 131 additions and 22 deletions
@@ -1,3 +1,35 @@
; (defun get-saved-regs ((dest (pointer uint64)))
; (rlet ((s0 :reg rbx :type uint)
; (s1 :reg rbp :type uint)
; (s2 :reg r10 :type uint)
; (s3 :reg r11 :type uint)
; (s4 :reg r12 :type uint))
; (set! (-> dest 0) s0)
; (set! (-> dest 1) s1)
; (set! (-> dest 2) s2)
; (set! (-> dest 3) s3)
; (set! (-> dest 4) s4)
; )
; )
(defmacro with-named-reg-vars-check (&rest body)
`(let ((one 1)
(two 2)
(three 3)
(four 4)
(five 5)
(six 6)
(seven 7)
(eight 8)
(nine 9))
,@body
(format 0 "~d ~d ~d ~d ~d ~d " one two three four five six)
(format 0 "~d ~d ~d~%" seven eight nine)
)
)
(defun deactivate-myself ()
"Deactivate the current process. A workaround because rlet isn't working well."
(rlet ((pp :reg r13 :type process))
@@ -62,3 +94,44 @@
0 0 0 0 0 0)
0
)
(defun init-child-proc (a0 a1 a2 a3 a4 a5)
(format #t "Args: ~D ~D ~D~%" a0 a1 a2)
(format #t "~D ~D ~D~%" a3 a4 a5)
(let ((stack-arr (new 'stack 'array 'uint8 12)))
(format #t "Stack Alignemnt ~D/16~%" (logand 15 (the uint stack-arr)))
)
(if (eq? a0 (the int 0))
(deactivate-myself)
)
'init-child-proc-result
)
(defun initializer-process-function (a0)
(let ((child-proc (get-process *nk-dead-pool* process 1024)))
;; let's go
(activate child-proc *active-pool* 'child-proc *kernel-dram-stack*)
(let ((result (run-function-in-process child-proc init-child-proc a0 2 3 4 5 6)))
(format #t "run-function-in-process result: ~A~%" result)
)
)
(deactivate-myself)
)
(defun kernel-test-2 ()
(define initalizer-process (get-process *nk-dead-pool* process 1024))
(activate initalizer-process *active-pool* 'initializer-proc *kernel-dram-stack*)
(set-to-run (-> initalizer-process main-thread)
initializer-process-function
0 0 0 0 0 0
)
(define initalizer-process-2 (get-process *nk-dead-pool* process 1024))
(activate initalizer-process-2 *active-pool* 'initializer-proc-2 *kernel-dram-stack*)
(set-to-run (-> initalizer-process-2 main-thread)
initializer-process-function
1 0 0 0 0 0
)
0
)
+32 -10
View File
@@ -40,27 +40,32 @@ std::thread KernelTest::runtime_thread;
Compiler KernelTest::compiler;
GoalTest::CompilerTestRunner KernelTest::runner;
TEST_F(KernelTest, Basic) {
// first, let's load the kernel test code
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
auto& listener = runner.c->listener();
namespace {
std::string send_code_and_get_multiple_responses(const std::string& code,
int n_responses,
GoalTest::CompilerTestRunner* runner) {
auto& listener = runner->c->listener();
// record all print messages
listener.record_messages(ListenerMessageKind::MSG_PRINT);
// run the test.
runner.c->compile_and_send_from_string("(kernel-test)");
// kinda hacky, but wait until the kernel runs and sends all the messages
while (listener.get_received_message_count() < 10) {
runner->c->compile_and_send_from_string(code);
std::string result;
while (listener.get_received_message_count() < n_responses) {
std::this_thread::sleep_for(std::chrono::microseconds(1000));
}
auto messages = listener.stop_recording_messages();
std::string result;
for (auto& m : messages) {
result += m;
}
return result;
}
} // namespace
TEST_F(KernelTest, Basic) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(kernel-test)", 10, &runner);
std::string expected =
"0\n"
@@ -86,4 +91,21 @@ TEST_F(KernelTest, Basic) {
"proc2: 54\n";
EXPECT_EQ(expected, result);
}
TEST_F(KernelTest, RunFunctionInProcess) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(kernel-test-2)", 1, &runner);
std::string expected =
"0\n"
"Args: 1 2 3\n"
"4 5 6\n"
"Stack Alignemnt 0/16\n"
"run-function-in-process result: init-child-proc-result\n"
"Args: 0 2 3\n"
"4 5 6\n"
"Stack Alignemnt 0/16\n"
"run-function-in-process result: #f\n";
EXPECT_EQ(expected, result);
}