Skip to content

Commit

Permalink
Fetch test roms from build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
joajfreitas committed Jul 8, 2024
1 parent d9efcb3 commit ed1af53
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 73 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ jobs:
with:
submodules: 'true'
- uses: Swatinem/rust-cache@v2
- name: Fetch mooneye-test-suite
run: >
wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz;
tar -xvf mts-20240127-1204-74ae166.tar.xz;
mkdir -p third_party/mooneye-test-suite;
mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build;
- name: Version
run: rustc --version
- name: Run rustfmt
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "third_party/mooneye-test-suite"]
path = third_party/mooneye-test-suite
url = [email protected]:Gekkio/mooneye-test-suite.git
33 changes: 29 additions & 4 deletions fpt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::path::Path;

use serde::{Deserialize, Serialize};

use std::process::Command;

#[derive(Serialize, Deserialize)]
struct Suite {
tests: Vec<Test>,
Expand All @@ -19,18 +21,17 @@ struct Test {
enabled: Option<bool>,
}

// build script's entry point
fn main() {
fn generate_rom_tests() {
let out_dir = env::var("OUT_DIR").unwrap();
let destination = dbg!(Path::new(&out_dir).join("tests.rs"));
let destination = Path::new(&out_dir).join("tests.rs");
let mut test_file = File::create(destination).unwrap();

write_header(&mut test_file);
write_test(&mut test_file, "tests/rom_tests.json");
}

fn write_test(test_file: &mut File, directory: &str) {
let source = dbg!(std::fs::read_to_string(directory).unwrap());
let source = std::fs::read_to_string(directory).unwrap();
let suite: Suite = serde_json::from_str(&source).unwrap();

for test in suite.tests {
Expand All @@ -53,3 +54,27 @@ fn write_test(test_file: &mut File, directory: &str) {
fn write_header(test_file: &mut File) {
write!(test_file, include_str!("./tests/templates/header")).unwrap();
}

fn run_cmd(cmd: &str) -> String {
let output = Command::new("sh")
.arg("-c")
.arg(cmd)
.output()
.expect("failed to execute process");

String::from_utf8(output.stdout).expect("Failed to convert output to string")
}

fn fetch_mooneye_test_roms() {
run_cmd("wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz");
run_cmd("tar -xvf mts-20240127-1204-74ae166.tar.xz");
run_cmd("mkdir -p third_party/mooneye-test-suite");
run_cmd("mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build");
run_cmd("tree .");
}

fn main() {
generate_rom_tests();
fetch_mooneye_test_roms();
}

Loading

0 comments on commit ed1af53

Please sign in to comment.