aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-09-27 13:35:02 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-09-27 13:35:02 +0400
commit31ea816d2b5cf9407f8291186e85060578251054 (patch)
tree824973f83bf2652a0af0003005052bb8a6af1600
parentf2e28f54d66bf9fff0690f366a0bbca14be6c182 (diff)
downloadniri-31ea816d2b5cf9407f8291186e85060578251054.tar.gz
niri-31ea816d2b5cf9407f8291186e85060578251054.tar.bz2
niri-31ea816d2b5cf9407f8291186e85060578251054.zip
layout: Add randomized test
-rw-r--r--.github/workflows/ci.yml3
-rw-r--r--Cargo.lock108
-rw-r--r--Cargo.toml4
-rw-r--r--src/layout.rs44
4 files changed, 146 insertions, 13 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 73af9f4e..df8403aa 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,6 +7,9 @@ on:
schedule:
- cron: '0 0 1 * *' # Monthly
+env:
+ RUN_SLOW_TESTS: 1
+
jobs:
build:
strategy:
diff --git a/Cargo.lock b/Cargo.lock
index 0b587ac3..bf278a7f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -333,6 +333,21 @@ dependencies = [
]
[[package]]
+name = "bit-set"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
+dependencies = [
+ "bit-vec",
+]
+
+[[package]]
+name = "bit-vec"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -882,6 +897,12 @@ dependencies = [
]
[[package]]
+name = "fnv"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+
+[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1545,6 +1566,8 @@ dependencies = [
"pipewire",
"portable-atomic",
"profiling",
+ "proptest",
+ "proptest-derive",
"sd-notify",
"serde",
"smithay",
@@ -1981,6 +2004,43 @@ dependencies = [
]
[[package]]
+name = "proptest"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65"
+dependencies = [
+ "bit-set",
+ "bitflags 1.3.2",
+ "byteorder",
+ "lazy_static",
+ "num-traits",
+ "rand",
+ "rand_chacha",
+ "rand_xorshift",
+ "regex-syntax 0.6.29",
+ "rusty-fork",
+ "tempfile",
+ "unarray",
+]
+
+[[package]]
+name = "proptest-derive"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "quick-error"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
+
+[[package]]
name = "quick-xml"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2029,6 +2089,15 @@ dependencies = [
]
[[package]]
+name = "rand_xorshift"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
+dependencies = [
+ "rand_core",
+]
+
+[[package]]
name = "raw-window-handle"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2153,6 +2222,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
+name = "rusty-fork"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
+dependencies = [
+ "fnv",
+ "quick-error",
+ "tempfile",
+ "wait-timeout",
+]
+
+[[package]]
name = "scan_fmt"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2284,7 +2365,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
[[package]]
name = "smithay"
version = "0.3.0"
-source = "git+https://github.com/Smithay/smithay.git#604c352305c209fa7b5c3ba69691cdc66949b0ec"
+source = "git+https://github.com/Smithay/smithay.git#509030a151ad440f8406229f32d674811efd9007"
dependencies = [
"appendlist",
"bitflags 2.4.0",
@@ -2347,7 +2428,7 @@ dependencies = [
[[package]]
name = "smithay-drm-extras"
version = "0.1.0"
-source = "git+https://github.com/Smithay/smithay.git#604c352305c209fa7b5c3ba69691cdc66949b0ec"
+source = "git+https://github.com/Smithay/smithay.git#509030a151ad440f8406229f32d674811efd9007"
dependencies = [
"drm",
"edid-rs",
@@ -2480,18 +2561,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.48"
+version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7"
+checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.48"
+version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35"
+checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
dependencies = [
"proc-macro2",
"quote",
@@ -2694,6 +2775,12 @@ dependencies = [
]
[[package]]
+name = "unarray"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
+
+[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2748,6 +2835,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
+name = "wait-timeout"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "waker-fn"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index acd3a225..ff5987ae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,6 +57,10 @@ features = [
git = "https://github.com/Smithay/smithay.git"
# path = "../smithay/smithay-drm-extras"
+[dev-dependencies]
+proptest = "1.2.0"
+proptest-derive = "0.4.0"
+
[features]
profile-with-tracy = ["profiling/profile-with-tracy", "tracy-client/default"]
diff --git a/src/layout.rs b/src/layout.rs
index 31a773f1..a501c401 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -2332,6 +2332,8 @@ mod tests {
use std::cell::Cell;
use std::rc::Rc;
+ use proptest::prelude::*;
+ use proptest_derive::Arbitrary;
use smithay::output::{Mode, PhysicalProperties, Subpixel};
use smithay::utils::IsAlive;
@@ -2422,17 +2424,27 @@ mod tests {
}
}
- #[derive(Debug, Clone, Copy)]
+ fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
+ any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| {
+ let loc: Point<i32, _> = Point::from((x.into(), y.into()));
+ let size: Size<i32, _> = Size::from((w.into(), h.into()));
+ Rectangle::from_loc_and_size(loc, size)
+ })
+ }
+
+ #[derive(Debug, Clone, Copy, Arbitrary)]
enum Op {
- AddOutput(usize),
- RemoveOutput(usize),
- FocusOutput(usize),
+ AddOutput(#[proptest(strategy = "1..=5usize")] usize),
+ RemoveOutput(#[proptest(strategy = "1..=5usize")] usize),
+ FocusOutput(#[proptest(strategy = "1..=5usize")] usize),
AddWindow {
+ #[proptest(strategy = "1..=5usize")]
id: usize,
+ #[proptest(strategy = "arbitrary_bbox()")]
bbox: Rectangle<i32, Logical>,
activate: bool,
},
- CloseWindow(usize),
+ CloseWindow(#[proptest(strategy = "1..=5usize")] usize),
FocusColumnLeft,
FocusColumnRight,
MoveColumnLeft,
@@ -2441,10 +2453,10 @@ mod tests {
ExpelWindowFromColumn,
FocusWorkspaceDown,
FocusWorkspaceUp,
- FocusWorkspace(u8),
+ FocusWorkspace(#[proptest(strategy = "1..=5u8")] u8),
MoveWindowToWorkspaceDown,
MoveWindowToWorkspaceUp,
- MoveWindowToWorkspace(u8),
+ MoveWindowToWorkspace(#[proptest(strategy = "1..=5u8")] u8),
}
impl Op {
@@ -2632,4 +2644,22 @@ mod tests {
check_ops(&ops);
}
+
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() {
+ eprintln!("ignoring slow test");
+ 0
+ } else {
+ ProptestConfig::default().cases
+ },
+ ..ProptestConfig::default()
+ })]
+
+ #[test]
+ fn random_operations_dont_panic(ops: Vec<Op>) {
+ // eprintln!("{ops:?}");
+ check_ops(&ops);
+ }
+ }
}