From f76ced4cd9e913f03b9935f9fdf87628a1832166 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 18 Apr 2016 00:52:09 +0300 Subject: [PATCH] test/tensor: add specific test for new sync/access API [SKIP_CHANGELOG] REFERENCE: #37 --- src/device.rs | 2 +- src/frameworks/cuda/api/driver/error.rs | 2 +- src/frameworks/native/error.rs | 2 +- src/frameworks/opencl/api/error.rs | 2 +- src/tensor.rs | 2 +- tests/shared_memory_specs.rs | 19 +++++++++++++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/device.rs b/src/device.rs index 69b0b760..af65d090 100644 --- a/src/device.rs +++ b/src/device.rs @@ -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. diff --git a/src/frameworks/cuda/api/driver/error.rs b/src/frameworks/cuda/api/driver/error.rs index 239c3782..06f8a244 100644 --- a/src/frameworks/cuda/api/driver/error.rs +++ b/src/frameworks/cuda/api/driver/error.rs @@ -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. diff --git a/src/frameworks/native/error.rs b/src/frameworks/native/error.rs index b351f141..0d6f0693 100644 --- a/src/frameworks/native/error.rs +++ b/src/frameworks/native/error.rs @@ -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 diff --git a/src/frameworks/opencl/api/error.rs b/src/frameworks/opencl/api/error.rs index 621d7c55..70b10a7c 100644 --- a/src/frameworks/opencl/api/error.rs +++ b/src/frameworks/opencl/api/error.rs @@ -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. diff --git a/src/tensor.rs b/src/tensor.rs index 75792e2b..65dcbc74 100644 --- a/src/tensor.rs +++ b/src/tensor.rs @@ -493,7 +493,7 @@ impl SharedTensor { } /// Errors than can occur when synchronizing memory. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Error { /// No copy on source device. MissingSource(&'static str), diff --git a/tests/shared_memory_specs.rs b/tests/shared_memory_specs.rs index 23175bf0..23a89bb1 100644 --- a/tests/shared_memory_specs.rs +++ b/tests/shared_memory_specs.rs @@ -4,6 +4,7 @@ extern crate libc; #[cfg(test)] mod shared_memory_spec { use co::prelude::*; + use co::tensor::Error; fn write_to_memory(mem: &mut MemoryType, data: &[T]) { match mem { @@ -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::::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() {