Skip to content

Commit

Permalink
test/tensor: add specific test for sync/access API (autumnai#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermorozov committed Apr 17, 2016
1 parent 728603e commit ce927ef
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum DeviceType {
Cuda(CudaContext),
}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines a generic set of Memory Errors.
pub enum Error {
/// Failures related to the Native framework implementation.
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/cuda/api/driver/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines OpenCL errors.
pub enum Error {
/// Failure with provided value.
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/native/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines the Native Error.
pub enum Error {
/// Failure related to allocation, syncing memory
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/opencl/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines OpenCL errors.
pub enum Error {
/// Failure with provided platform.
Expand Down
19 changes: 19 additions & 0 deletions tests/shared_memory_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate libc;
#[cfg(test)]
mod shared_memory_spec {
use co::prelude::*;
use co::tensor::Error;

fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
match mem {
Expand Down Expand Up @@ -59,6 +60,24 @@ mod shared_memory_spec {
}
}

#[test]
#[cfg(feature = "native")]
fn it_fails_on_initialized_memory_read() {
let ntv = Native::new();
let cpu = ntv.new_device(ntv.hardwares()).unwrap();
let shared_data = &mut SharedTensor::<f32>::new(&10).unwrap();
assert_eq!(shared_data.read(&cpu).unwrap_err(),
Error::UninitializedMemory);
assert_eq!(shared_data.read_write(&cpu).unwrap_err(),
Error::UninitializedMemory);

shared_data.write_only(&cpu).unwrap();
shared_data.drop_device(&cpu).unwrap();

assert_eq!(shared_data.read(&cpu).unwrap_err(),
Error::UninitializedMemory);
}

#[test]
#[cfg(feature = "cuda")]
fn it_syncs_from_native_to_cuda_and_back() {
Expand Down

0 comments on commit ce927ef

Please sign in to comment.