Merge pull request #602 from tomaka/tests-on-travis

Tests on travis
This commit is contained in:
tomaka 2017-07-06 12:41:11 +02:00 committed by GitHub
commit 65d2319409
17 changed files with 181 additions and 123 deletions

View File

@ -22,15 +22,7 @@ addons:
- cmake-data
script:
- cargo test -v --manifest-path glsl-to-spirv/Cargo.toml
- cargo test -v --manifest-path vulkano-shaders/Cargo.toml
- cargo test -v --manifest-path vulkano-shader-derive/Cargo.toml
# We run the projects that depend on vulkano with `-j 1` or we have a
# chance to reach travis' memory limit
- cargo test -j 1 --manifest-path vulkano-win/Cargo.toml
- cargo test --no-run -j 1 -v --manifest-path vulkano/Cargo.toml
- cargo test --doc -j 1 -v --manifest-path vulkano/Cargo.toml
- cargo build -j 1 --manifest-path examples/Cargo.toml
- cargo test --all
after_success:
- |

View File

@ -508,7 +508,6 @@ mod tests {
}
#[test]
#[should_panic] // TODO: check Result error instead of panicking
fn writing_forbidden() {
let (device, queue) = gfx_dev_and_queue!();
@ -518,20 +517,21 @@ mod tests {
queue.clone())
.unwrap();
let _ = AutoCommandBufferBuilder::new(device.clone(), queue.family())
.unwrap()
.fill_buffer(buffer, 50)
.unwrap()
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.then_signal_fence_and_flush()
.unwrap();
assert_should_panic!({ // TODO: check Result error instead of panicking
let _ = AutoCommandBufferBuilder::new(device.clone(), queue.family())
.unwrap()
.fill_buffer(buffer, 50)
.unwrap()
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.then_signal_fence_and_flush()
.unwrap();
});
}
#[test]
#[should_panic] // TODO: check Result error instead of panicking
fn read_uninitialized_forbidden() {
let (device, queue) = gfx_dev_and_queue!();
@ -548,16 +548,18 @@ mod tests {
0)
.unwrap();
let _ = AutoCommandBufferBuilder::new(device.clone(), queue.family())
.unwrap()
.copy_buffer(source, buffer)
.unwrap()
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.then_signal_fence_and_flush()
.unwrap();
assert_should_panic!({ // TODO: check Result error instead of panicking
let _ = AutoCommandBufferBuilder::new(device.clone(), queue.family())
.unwrap()
.copy_buffer(source, buffer)
.unwrap()
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.then_signal_fence_and_flush()
.unwrap();
});
}
#[test]

View File

@ -416,8 +416,6 @@ mod tests {
}
#[test]
#[should_panic(expected = "Can't enable sparse residency without enabling sparse \
binding as well")]
fn panic_wrong_sparse_residency() {
let (device, _) = gfx_dev_and_queue!();
let sparse = SparseLevel {
@ -425,18 +423,20 @@ mod tests {
sparse_residency: true,
sparse_aliased: false,
};
let _ = unsafe {
UnsafeBuffer::new(device,
128,
BufferUsage::all(),
Sharing::Exclusive::<Empty<_>>,
sparse)
};
assert_should_panic!("Can't enable sparse residency without enabling sparse \
binding as well", {
let _ = unsafe {
UnsafeBuffer::new(device,
128,
BufferUsage::all(),
Sharing::Exclusive::<Empty<_>>,
sparse)
};
});
}
#[test]
#[should_panic(expected = "Can't enable sparse aliasing without enabling sparse \
binding as well")]
fn panic_wrong_sparse_aliased() {
let (device, _) = gfx_dev_and_queue!();
let sparse = SparseLevel {
@ -444,13 +444,17 @@ mod tests {
sparse_residency: false,
sparse_aliased: true,
};
let _ = unsafe {
UnsafeBuffer::new(device,
128,
BufferUsage::all(),
Sharing::Exclusive::<Empty<_>>,
sparse)
};
assert_should_panic!("Can't enable sparse aliasing without enabling sparse \
binding as well", {
let _ = unsafe {
UnsafeBuffer::new(device,
128,
BufferUsage::all(),
Sharing::Exclusive::<Empty<_>>,
sparse)
};
});
}
#[test]

View File

@ -332,11 +332,13 @@ mod tests {
}
#[test]
#[should_panic(expected = "Device doesn't match physical device when creating a command pool")]
fn panic_if_not_match_family() {
let (device, _) = gfx_dev_and_queue!();
let (_, queue) = gfx_dev_and_queue!();
let _ = UnsafeCommandPool::new(device, queue.family(), false, false);
assert_should_panic!("Device doesn't match physical device when creating a command pool", {
let _ = UnsafeCommandPool::new(device, queue.family(), false, false);
});
}
#[test]

View File

@ -189,9 +189,10 @@ mod tests {
use super::*;
#[test]
#[should_panic(expected = "Tried to submit a present command without any swapchain")]
fn no_swapchain_added() {
let (_, queue) = gfx_dev_and_queue!();
let _ = SubmitPresentBuilder::new().submit(&queue);
assert_should_panic!("Tried to submit a present command without any swapchain", {
let _ = SubmitPresentBuilder::new().submit(&queue);
});
}
}

View File

@ -341,7 +341,6 @@ mod tests {
}
#[test]
#[should_panic(expected = "Can't merge two queue submits that both have a fence")]
fn merge_both_have_fences() {
unsafe {
let (device, _) = gfx_dev_and_queue!();
@ -354,7 +353,9 @@ mod tests {
let mut builder2 = SubmitCommandBufferBuilder::new();
builder2.set_fence_signal(&fence2);
let _ = builder1.merge(builder2);
assert_should_panic!("Can't merge two queue submits that both have a fence", {
let _ = builder1.merge(builder2);
});
}
}
}

View File

@ -88,13 +88,14 @@ mod tests {
}
#[test]
#[should_panic]
fn wrong_device() {
let (dev1, queue) = gfx_dev_and_queue!();
let (dev2, _) = gfx_dev_and_queue!();
let buffer = CpuAccessibleBuffer::from_data(dev1, BufferUsage::all(),
iter::once(queue.family()), 0u32).unwrap();
let _ = check_fill_buffer(&dev2, &buffer);
assert_should_panic!({
let _ = check_fill_buffer(&dev2, &buffer);
});
}
}

View File

@ -123,14 +123,16 @@ mod tests {
}
#[test]
#[should_panic]
fn wrong_device() {
let (dev1, queue) = gfx_dev_and_queue!();
let (dev2, _) = gfx_dev_and_queue!();
let buffer = CpuAccessibleBuffer::from_iter(dev1, BufferUsage::all(),
iter::once(queue.family()),
0 .. 500u32).unwrap();
let _ = check_index_buffer(&dev2, &buffer);
assert_should_panic!({
let _ = check_index_buffer(&dev2, &buffer);
});
}
}

View File

@ -148,13 +148,14 @@ mod tests {
}
#[test]
#[should_panic]
fn wrong_device() {
let (dev1, queue) = gfx_dev_and_queue!();
let (dev2, _) = gfx_dev_and_queue!();
let buffer = CpuAccessibleBuffer::from_data(dev1, BufferUsage::all(),
iter::once(queue.family()), 0u32).unwrap();
let _ = check_update_buffer(&dev2, &buffer, &0);
assert_should_panic!({
let _ = check_update_buffer(&dev2, &buffer, &0);
});
}
}

View File

@ -992,7 +992,6 @@ mod tests {
}
#[test]
#[should_panic(expected = "The maximum number of sets can't be 0")]
fn zero_max_set() {
let (device, _) = gfx_dev_and_queue!();
let desc = DescriptorsCount {
@ -1000,14 +999,18 @@ mod tests {
..DescriptorsCount::zero()
};
let _ = UnsafeDescriptorPool::new(device, &desc, 0, false);
assert_should_panic!("The maximum number of sets can't be 0", {
let _ = UnsafeDescriptorPool::new(device, &desc, 0, false);
});
}
#[test]
#[should_panic(expected = "All the descriptors count of a pool are 0")]
fn zero_descriptors() {
let (device, _) = gfx_dev_and_queue!();
let _ = UnsafeDescriptorPool::new(device, &DescriptorsCount::zero(), 10, false);
assert_should_panic!("All the descriptors count of a pool are 0", {
let _ = UnsafeDescriptorPool::new(device, &DescriptorsCount::zero(), 10, false);
});
}
#[test]
@ -1041,7 +1044,6 @@ mod tests {
}
#[test]
#[should_panic(expected = "Tried to allocate from a pool with a set layout of a different device")]
fn alloc_diff_device() {
let (device1, _) = gfx_dev_and_queue!();
let (device2, _) = gfx_dev_and_queue!();
@ -1064,10 +1066,15 @@ mod tests {
..DescriptorsCount::zero()
};
let mut pool = UnsafeDescriptorPool::new(device2, &desc, 10, false).unwrap();
unsafe {
let _ = pool.alloc(iter::once(&set_layout));
}
assert_should_panic!("Tried to allocate from a pool with a set layout \
of a different device",
{
let mut pool = UnsafeDescriptorPool::new(device2, &desc, 10, false).unwrap();
unsafe {
let _ = pool.alloc(iter::once(&set_layout));
}
});
}
#[test]

View File

@ -365,7 +365,6 @@ mod tests {
}
#[test]
#[should_panic]
fn wrong_device_panic() {
let (device1, _) = gfx_dev_and_queue!();
let (device2, _) = gfx_dev_and_queue!();
@ -375,7 +374,9 @@ mod tests {
Err(_) => return
};
let _ = PipelineLayout::new(&device2, Some(&set), iter::empty());
assert_should_panic!({
let _ = PipelineLayout::new(&device2, Some(&set), iter::empty());
});
}
#[test]

View File

@ -229,14 +229,15 @@ mod tests {
}
#[test]
#[should_panic(expected = "Attachment num out of range")]
fn attachment_out_of_range() {
let (device, _) = gfx_dev_and_queue!();
let rp = EmptySinglePassRenderPassDesc;
let img = AttachmentImage::new(device, [128, 128], Format::R8G8B8A8Unorm).unwrap();
let _ = ensure_image_view_compatible(&rp, 0, &img);
assert_should_panic!("Attachment num out of range", {
let _ = ensure_image_view_compatible(&rp, 0, &img);
});
}
// TODO: more tests

View File

@ -405,11 +405,12 @@ mod tests {
}
#[test]
#[should_panic]
fn zero_size() {
let (device, _) = gfx_dev_and_queue!();
let mem_ty = device.physical_device().memory_types().next().unwrap();
let _ = DeviceMemory::alloc(device.clone(), mem_ty, 0);
assert_should_panic!({
let _ = DeviceMemory::alloc(device.clone(), mem_ty, 0);
});
}
#[test]

View File

@ -240,10 +240,11 @@ mod tests {
use pipeline::cache::PipelineCache;
#[test]
#[should_panic]
fn merge_self_forbidden() {
let (device, queue) = gfx_dev_and_queue!();
let pipeline = PipelineCache::empty(device).unwrap();
pipeline.merge(&[&pipeline]).unwrap();
assert_should_panic!({
pipeline.merge(&[&pipeline]).unwrap();
});
}
}

View File

@ -797,60 +797,63 @@ mod tests {
}
#[test]
#[should_panic]
fn min_lod_inferior() {
let (device, queue) = gfx_dev_and_queue!();
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
1.0,
1.0,
5.0,
2.0);
assert_should_panic!({
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
1.0,
1.0,
5.0,
2.0);
});
}
#[test]
#[should_panic]
fn max_anisotropy() {
let (device, queue) = gfx_dev_and_queue!();
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
1.0,
0.5,
0.0,
2.0);
assert_should_panic!({
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
sampler::SamplerAddressMode::Repeat,
1.0,
0.5,
0.0,
2.0);
});
}
#[test]
#[should_panic]
fn different_borders() {
let (device, queue) = gfx_dev_and_queue!();
let b1 = sampler::BorderColor::IntTransparentBlack;
let b2 = sampler::BorderColor::FloatOpaqueWhite;
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::ClampToBorder(b1),
sampler::SamplerAddressMode::ClampToBorder(b2),
sampler::SamplerAddressMode::Repeat,
1.0,
1.0,
5.0,
2.0);
assert_should_panic!({
let _ = sampler::Sampler::new(device,
sampler::Filter::Linear,
sampler::Filter::Linear,
sampler::MipmapMode::Nearest,
sampler::SamplerAddressMode::ClampToBorder(b1),
sampler::SamplerAddressMode::ClampToBorder(b2),
sampler::SamplerAddressMode::Repeat,
1.0,
1.0,
5.0,
2.0);
});
}
#[test]

View File

@ -379,29 +379,35 @@ mod tests {
}
#[test]
#[should_panic(expected = "Tried to wait for multiple fences that didn't belong to the same device")]
fn multiwait_different_devices() {
let (device1, _) = gfx_dev_and_queue!();
let (device2, _) = gfx_dev_and_queue!();
let fence1 = Fence::signaled(device1.clone()).unwrap();
let fence2 = Fence::signaled(device2.clone()).unwrap();
assert_should_panic!("Tried to wait for multiple fences that didn't belong \
to the same device",
{
let fence1 = Fence::signaled(device1.clone()).unwrap();
let fence2 = Fence::signaled(device2.clone()).unwrap();
let _ = Fence::multi_wait([&fence1, &fence2].iter().cloned(),
Some(Duration::new(0, 10)));
let _ = Fence::multi_wait([&fence1, &fence2].iter().cloned(),
Some(Duration::new(0, 10)));
});
}
#[test]
#[should_panic(expected = "Tried to reset multiple fences that didn't belong to the same device")]
fn multireset_different_devices() {
use std::iter::once;
let (device1, _) = gfx_dev_and_queue!();
let (device2, _) = gfx_dev_and_queue!();
let mut fence1 = Fence::signaled(device1.clone()).unwrap();
let mut fence2 = Fence::signaled(device2.clone()).unwrap();
assert_should_panic!("Tried to reset multiple fences that didn't belong \
to the same device",
{
let mut fence1 = Fence::signaled(device1.clone()).unwrap();
let mut fence2 = Fence::signaled(device2.clone()).unwrap();
let _ = Fence::multi_reset(once(&mut fence1).chain(once(&mut fence2)));
let _ = Fence::multi_reset(once(&mut fence1).chain(once(&mut fence2)));
});
}
}

View File

@ -65,3 +65,35 @@ macro_rules! gfx_dev_and_queue {
(device, queues.next().unwrap())
});
}
macro_rules! assert_should_panic {
($msg:expr, $code:block) => ({
let res = ::std::panic::catch_unwind(|| {
$code
});
match res {
Ok(_) => panic!("Test expected to panic but didn't"),
Err(err) => {
if let Some(msg) = err.downcast_ref::<String>() {
assert!(msg.contains($msg));
} else if let Some(&msg) = err.downcast_ref::<&str>() {
assert!(msg.contains($msg));
} else {
panic!("Couldn't decipher the panic message of the test")
}
}
}
});
($code:block) => ({
let res = ::std::panic::catch_unwind(|| {
$code
});
match res {
Ok(_) => panic!("Test expected to panic but didn't"),
Err(_) => {}
}
});
}