Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Userland app for servomotor #558

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions unittest/src/fake/servo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod tests;
const DRIVER_NUM: u32 = 0x90009;

// Command numbers
const EXISTS: u32 = 0;
const SERVO_COUNT: u32 = 1;
const SET_ANGLE: u32 = 2;
const GET_ANGLE: u32 = 3;
// const EXISTS: u32 = 0;
inesmaria08 marked this conversation as resolved.
Show resolved Hide resolved
// const SERVO_COUNT: u32 = 1;
// const SET_ANGLE: u32 = 2;
// const GET_ANGLE: u32 = 3;
25 changes: 11 additions & 14 deletions unittest/src/fake/servo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ use libtock_platform::CommandReturn;
fn command() {
use fake::SyscallDriver;
let servo = Servo::<1>::new();
let value = servo.command(EXISTS, 0, 0);
let value = servo.command(0, 0, 0);
assert_eq!(CommandReturn::is_success(&value), true);
assert_eq!(
CommandReturn::get_success_u32(&servo.command(SERVO_COUNT, 0, 0)),
CommandReturn::get_success_u32(&servo.command(1, 0, 0)),
Some(1)
);
assert_eq!(CommandReturn::is_success(&servo.command(2, 0, 90)), true);
assert_eq!(
CommandReturn::is_success(&servo.command(SET_ANGLE, 0, 90)),
true
);
assert_eq!(
CommandReturn::get_success_u32(&servo.command(GET_ANGLE, 0, 0)),
CommandReturn::get_success_u32(&servo.command(3, 0, 0)),
Some(90)
);
}
Expand All @@ -29,27 +26,27 @@ fn kernel_integration() {
let kernel = fake::Kernel::new();
let servo = Servo::<1>::new();
kernel.add_driver(&servo);
let value = fake::Syscalls::command(DRIVER_NUM, EXISTS, 0, 0);
let value = fake::Syscalls::command(DRIVER_NUM, 0, 0, 0);
assert_eq!(CommandReturn::is_success(&value), true);
assert_eq!(
CommandReturn::get_success_u32(&fake::Syscalls::command(DRIVER_NUM, SERVO_COUNT, 0, 0)),
CommandReturn::get_success_u32(&fake::Syscalls::command(DRIVER_NUM, 1, 0, 0)),
Some(1)
);
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, SET_ANGLE, 1, 90).get_failure(),
fake::Syscalls::command(DRIVER_NUM, 2, 1, 90).get_failure(),
Some(ErrorCode::NoDevice)
);
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, SET_ANGLE, 0, 181).get_failure(),
fake::Syscalls::command(DRIVER_NUM, 2, 0, 181).get_failure(),
Some(ErrorCode::Fail)
);
assert!(fake::Syscalls::command(DRIVER_NUM, SET_ANGLE, 0, 90).is_success());
assert!(fake::Syscalls::command(DRIVER_NUM, 2, 0, 90).is_success());
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, GET_ANGLE, 0, 0).get_success_u32(),
fake::Syscalls::command(DRIVER_NUM, 3, 0, 0).get_success_u32(),
Some(90)
);
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, GET_ANGLE, 2, 0).get_failure(),
fake::Syscalls::command(DRIVER_NUM, 3, 2, 0).get_failure(),
Some(ErrorCode::NoDevice)
);
}