forked from M-Labs/artiq
1
0
Fork 0

In case of a load error, pass the reason to host interpreter.

Fixes #654.
This commit is contained in:
whitequark 2017-01-27 12:49:48 +00:00
parent 609fd3d902
commit 74b910e97d
3 changed files with 19 additions and 8 deletions

View File

@ -59,6 +59,9 @@ class _D2HMsgType(Enum):
class UnsupportedDevice(Exception): class UnsupportedDevice(Exception):
pass pass
class LoadError(Exception):
pass
class RPCReturnValueError(ValueError): class RPCReturnValueError(ValueError):
pass pass
@ -265,7 +268,11 @@ class CommGeneric:
self._write_header(_H2DMsgType.LOAD_KERNEL) self._write_header(_H2DMsgType.LOAD_KERNEL)
self._write_bytes(kernel_library) self._write_bytes(kernel_library)
self._read_empty(_D2HMsgType.LOAD_COMPLETED) self._read_header()
if self._read_type == _D2HMsgType.LOAD_FAILED:
raise LoadError(self._read_string())
else:
self._read_expect(_D2HMsgType.LOAD_COMPLETED)
def run(self): def run(self):
self._write_empty(_H2DMsgType.RUN_KERNEL) self._write_empty(_H2DMsgType.RUN_KERNEL)

View File

@ -2,6 +2,7 @@ use std::prelude::v1::*;
use std::{mem, str}; use std::{mem, str};
use std::cell::RefCell; use std::cell::RefCell;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::error::Error;
use std::btree_set::BTreeSet; use std::btree_set::BTreeSet;
use {config, rtio_mgt, mailbox, rpc_queue, kernel}; use {config, rtio_mgt, mailbox, rpc_queue, kernel};
use logger_artiq::BufferLogger; use logger_artiq::BufferLogger;
@ -179,8 +180,10 @@ unsafe fn kern_load(io: &Io, session: &mut Session, library: &[u8]) -> io::Resul
session.kernel_state = KernelState::Loaded; session.kernel_state = KernelState::Loaded;
Ok(()) Ok(())
} }
&kern::LoadReply(Err(error)) => &kern::LoadReply(Err(error)) => {
unexpected!("cannot load kernel: {}", error), Err(io::Error::new(io::ErrorKind::Other,
format!("cannot load kernel: {}", error)))
}
other => other =>
unexpected!("unexpected reply from kernel CPU: {:?}", other) unexpected!("unexpected reply from kernel CPU: {:?}", other)
} }
@ -259,9 +262,9 @@ fn process_host_message(io: &Io,
host::Request::LoadKernel(kernel) => host::Request::LoadKernel(kernel) =>
match unsafe { kern_load(io, session, &kernel) } { match unsafe { kern_load(io, session, &kernel) } {
Ok(()) => host_write(stream, host::Reply::LoadCompleted), Ok(()) => host_write(stream, host::Reply::LoadCompleted),
Err(_) => { Err(error) => {
try!(kern_acknowledge()); host_write(stream, host::Reply::LoadFailed(error.description()));
host_write(stream, host::Reply::LoadFailed) kern_acknowledge()
} }
}, },

View File

@ -92,7 +92,7 @@ pub enum Reply<'a> {
ClockSwitchFailed, ClockSwitchFailed,
LoadCompleted, LoadCompleted,
LoadFailed, LoadFailed(&'a str),
KernelFinished, KernelFinished,
KernelStartupFailed, KernelStartupFailed,
@ -141,8 +141,9 @@ impl<'a> Reply<'a> {
Reply::LoadCompleted => { Reply::LoadCompleted => {
try!(write_u8(writer, 5)); try!(write_u8(writer, 5));
}, },
Reply::LoadFailed => { Reply::LoadFailed(reason) => {
try!(write_u8(writer, 6)); try!(write_u8(writer, 6));
try!(write_string(writer, reason));
}, },
Reply::KernelFinished => { Reply::KernelFinished => {