Skip to content

Commit a122e42

Browse files
committed
pixelbender: Add pbasm integration tests
1 parent a6ad19d commit a122e42

File tree

30 files changed

+563
-0
lines changed

30 files changed

+563
-0
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ members = [
2020
"render/canvas",
2121
"render/naga-agal",
2222
"render/pbasm",
23+
"render/pbasm/integration_tests",
2324
"render/wgpu",
2425
"render/webgl",
2526

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "pbasm_integration_tests"
3+
authors.workspace = true
4+
edition.workspace = true
5+
homepage.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
version.workspace = true
9+
10+
[lints]
11+
workspace = true
12+
13+
[dev-dependencies]
14+
pbasm = { path = ".." }
15+
ruffle_fs_tests_runner = { path = "../../../tests/fs-tests-runner" }
16+
libtest-mimic = { workspace = true }
17+
serde = { workspace = true, features = ["derive"] }
18+
toml = { workspace = true }
19+
anyhow = { workspace = true }
20+
clap = { workspace = true }
21+
vfs = { workspace = true }
22+
23+
[[test]]
24+
name = "integration_tests"
25+
harness = false
26+
path = "src/runner.rs"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pbasm Integration Tests
2+
3+
This directory contains integration tests for `pbasm`.
4+
Each directory with `test.toml` contains one integration test.
5+
6+
## `test.toml`
7+
8+
```toml
9+
# Type of the test, either 'assembly', 'disassembly', or 'roundtrip'.
10+
type = "roundtrip"
11+
# If set to true, the test will be ignored.
12+
ignore = false
13+
```
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//! Integration tests runner for pbasm.
2+
3+
use anyhow::{anyhow, Context, Result};
4+
use libtest_mimic::Trial;
5+
use pbasm::{run_main, Opt};
6+
use ruffle_fs_tests_runner::{FsTestsRunner, TestLoaderParams};
7+
use serde::Deserialize;
8+
use std::path::Path;
9+
use std::{borrow::Cow, path::PathBuf};
10+
use vfs::VfsPath;
11+
12+
const TEST_TOML_NAME: &str = "test.toml";
13+
14+
#[derive(Clone, Copy, Deserialize)]
15+
enum TestType {
16+
Roundtrip,
17+
Assemble,
18+
Dissassemble,
19+
}
20+
21+
impl TestType {
22+
fn perform_assembly(self) -> bool {
23+
matches!(self, TestType::Assemble | TestType::Roundtrip)
24+
}
25+
26+
fn perform_disassembly(self) -> bool {
27+
matches!(self, TestType::Dissassemble | TestType::Roundtrip)
28+
}
29+
}
30+
31+
#[derive(Clone, Deserialize)]
32+
#[serde(default, deny_unknown_fields)]
33+
struct TestOptions {
34+
pub r#type: TestType,
35+
pub ignore: bool,
36+
pub pbj_path: String,
37+
pub pbasm_path: String,
38+
}
39+
40+
impl Default for TestOptions {
41+
fn default() -> Self {
42+
Self {
43+
r#type: TestType::Roundtrip,
44+
ignore: false,
45+
pbj_path: "test.pbj".to_owned(),
46+
pbasm_path: "test.pbasm".to_owned(),
47+
}
48+
}
49+
}
50+
51+
impl TestOptions {
52+
fn read(path: &VfsPath) -> Result<Self> {
53+
let result = toml::from_str(&path.read_to_string()?)?;
54+
Ok(result)
55+
}
56+
57+
fn pbj_path(&self, test_dir: &VfsPath) -> Result<VfsPath> {
58+
test_dir
59+
.join(&self.pbj_path)
60+
.context("Failed to get pbj path")
61+
}
62+
63+
fn pbasm_path(&self, test_dir: &VfsPath) -> Result<VfsPath> {
64+
test_dir
65+
.join(&self.pbasm_path)
66+
.context("Failed to get pbasm path")
67+
}
68+
}
69+
70+
fn main() {
71+
let mut runner = FsTestsRunner::new();
72+
73+
runner
74+
.with_descriptor_name(Cow::Borrowed(TEST_TOML_NAME))
75+
.with_test_loader(Box::new(|params| Some(load_test(params))));
76+
77+
runner.run()
78+
}
79+
80+
fn load_test(params: TestLoaderParams) -> Trial {
81+
let test_dir = params.test_dir.clone();
82+
let test_dir_real = params.test_dir_real.into_owned();
83+
let name = params.test_name;
84+
85+
let descriptor_path = test_dir.join("test.toml").unwrap();
86+
87+
let options = TestOptions::read(&descriptor_path)
88+
.map_err(|e| anyhow!("Failed to parse {}: {e}", descriptor_path.as_str()))
89+
.expect("Failed to parse test descriptor");
90+
let ignore = options.ignore;
91+
92+
let mut trial = Trial::test(name.to_string(), move || {
93+
let pbj_path = options.pbj_path(&test_dir)?;
94+
let pbj_path_real = to_real_path(&test_dir_real, &pbj_path);
95+
let pbasm_path = options.pbasm_path(&test_dir)?;
96+
let pbasm_path_real = to_real_path(&test_dir_real, &pbasm_path);
97+
98+
let pbj_actual_path = test_dir_real.join("actual.pbj");
99+
let pbasm_actual_path = test_dir_real.join("actual.pbasm");
100+
101+
if options.r#type.perform_assembly() {
102+
let opt = Opt {
103+
source: pbasm_path_real.to_str().unwrap().to_string(),
104+
disassemble: false,
105+
output: Some(pbj_actual_path.to_str().unwrap().to_string()),
106+
};
107+
run_test(opt, &pbj_path_real)?;
108+
}
109+
110+
if options.r#type.perform_disassembly() {
111+
let opt = Opt {
112+
source: pbj_path_real.to_str().unwrap().to_string(),
113+
disassemble: true,
114+
output: Some(pbasm_actual_path.to_str().unwrap().to_string()),
115+
};
116+
run_test(opt, &pbasm_path_real)?;
117+
}
118+
119+
Ok(())
120+
});
121+
if ignore {
122+
trial = trial.with_ignored_flag(true);
123+
}
124+
trial
125+
}
126+
127+
fn to_real_path(real_dir: &Path, file: &VfsPath) -> PathBuf {
128+
real_dir.join(file.as_str().strip_prefix('/').unwrap())
129+
}
130+
131+
fn run_test(opt: Opt, expected_path: &Path) -> Result<()> {
132+
let actual_path = opt.output.clone().unwrap();
133+
run_main(opt).map_err(|e: anyhow::Error| anyhow!("Failed to execute pbasm: {e}"))?;
134+
135+
let actual = std::fs::read(&actual_path)?;
136+
let expected = std::fs::read(expected_path).map_err(|e| {
137+
anyhow!(
138+
"Error reading test file {}: {e}",
139+
expected_path.to_string_lossy()
140+
)
141+
})?;
142+
143+
if actual != expected {
144+
return Err(anyhow!(
145+
"Test failed: Output doesn't match: {}",
146+
actual_path.to_string()
147+
));
148+
}
149+
150+
let _ = std::fs::remove_file(actual_path);
151+
Ok(())
152+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
actual.pbj
2+
actual.pbasm
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version 1i
2+
name "Test"
3+
4+
mov i1.rgba, i0.rgba
5+
mov i1.rgb, i0.rgb
6+
mov i1.rga, i0.rgb
7+
mov i1.rba, i0.rgb
8+
mov i1.gba, i0.rgb
9+
mov i1.rg, i0.rg
10+
mov i1.rb, i0.rg
11+
mov i1.ra, i0.rg
12+
mov i1.gb, i0.rg
13+
mov i1.ga, i0.rg
14+
mov i1.ba, i0.rg
15+
mov i1.r, i0.r
16+
mov i1.g, i0.r
17+
mov i1.b, i0.r
18+
mov i1.a, i0.r
19+
mov i1.rgb, i0.rgba
20+
mov i1.rgb, i0.rg
21+
mov i1.rgb, i0.r
22+
mov i1.rg, i0.rgba
23+
mov i1.rg, i0.rgb
24+
mov i1.rg, i0.r
25+
mov i1.r, i0.rgba
26+
mov i1.r, i0.rgb
27+
mov i1.r, i0.rg
Binary file not shown.

render/pbasm/integration_tests/tests/dst_channels/test.toml

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version 1i
2+
name "Test"
3+
4+
param.in "param1", float2x2, f1.m2
5+
6+
param.in "param2", float3x3, f1.m3
7+
8+
param.in "param2", float4x4, f1.m4
9+
10+
mov f1.m2, f0.m2
11+
mov f1.m3, f0.m3
12+
mov f1.m4, f0.m4
13+
mov f1.rgba, f0.m2
14+
mov f1.rgb, f0.m2
15+
mov f1.rba, f0.m2
16+
mov f1.rga, f0.m2
17+
mov f1.rgb, f0.m2
18+
mov f1.rg, f0.m2
19+
mov f1.rb, f0.m2
20+
mov f1.ra, f0.m2
21+
mov f1.gb, f0.m2
22+
mov f1.ga, f0.m2
23+
mov f1.ba, f0.m2
24+
mov f1.r, f0.m2
25+
mov f1.g, f0.m2
26+
mov f1.b, f0.m2
27+
mov f1.a, f0.m2
28+
mov f1.rgba, f0.m3
29+
mov f1.rgb, f0.m3
30+
mov f1.rba, f0.m3
31+
mov f1.rga, f0.m3
32+
mov f1.rgb, f0.m3
33+
mov f1.rg, f0.m3
34+
mov f1.rb, f0.m3
35+
mov f1.ra, f0.m3
36+
mov f1.gb, f0.m3
37+
mov f1.ga, f0.m3
38+
mov f1.ba, f0.m3
39+
mov f1.r, f0.m3
40+
mov f1.g, f0.m3
41+
mov f1.b, f0.m3
42+
mov f1.a, f0.m3
43+
mov f1.rgba, f0.m4
44+
mov f1.rgb, f0.m4
45+
mov f1.rba, f0.m4
46+
mov f1.rga, f0.m4
47+
mov f1.rgb, f0.m4
48+
mov f1.rg, f0.m4
49+
mov f1.rb, f0.m4
50+
mov f1.ra, f0.m4
51+
mov f1.gb, f0.m4
52+
mov f1.ga, f0.m4
53+
mov f1.ba, f0.m4
54+
mov f1.r, f0.m4
55+
mov f1.g, f0.m4
56+
mov f1.b, f0.m4
57+
mov f1.a, f0.m4

0 commit comments

Comments
 (0)