Skip to content

Commit

Permalink
Add a tool to automatically download and test a byond version for mis…
Browse files Browse the repository at this point in the history
…sing signatures
  • Loading branch information
Absolucy committed Jan 23, 2025
1 parent 73690f1 commit 2cc5e0e
Show file tree
Hide file tree
Showing 10 changed files with 593 additions and 795 deletions.
1,140 changes: 426 additions & 714 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["auxcov", "auxtools", "auxtools-impl", "debug_server", "instruction_hooking", "tests/auxtest", "tests/byond_get", "tests/test_runner"]
members = ["auxcov", "auxtools", "auxtools-impl", "debug_server", "instruction_hooking", "tests/auxsigcheck", "tests/auxtest", "tests/test_runner"]
default-members = ["auxtools", "auxtools-impl", "debug_server", "instruction_hooking"]
resolver = "2"

[workspace.package]
Expand Down
18 changes: 18 additions & 0 deletions tests/auxsigcheck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "auxsigcheck"
rust-version = "1.79"
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
byond-get = { git = "https://github.com/absolucy/byond-get" }
cfg-if = "1"
clap = { version = "4", features = ["derive"] }
color-eyre = "0.6"
tempdir = "0.3"

[lints]
workspace = true
Empty file added tests/auxsigcheck/src/args.rs
Empty file.
22 changes: 22 additions & 0 deletions tests/auxsigcheck/src/dm/auxsigcheck.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if DM_VERSION >= 515
#define LIBCALL call_ext
#else
#define LIBCALL call
#endif

/world/New()
. = ..()
var/result = run_tests()
if(!result)
world.log << "FAILED (unknown, likely runtime)"
else
world.log << "[result]"
del(src)

/proc/run_tests()
var/dll = world.GetConfig("env", "AUXTOOLS_DLL")
if(!dll)
return "FAILED (AUXTOOLS_DLL not set)"
if(!fexists(dll))
return "FAILED (AUXTOOLS_DLL path doesn't exist)"
return LIBCALL(dll, "auxtools_check_signatures")()
19 changes: 19 additions & 0 deletions tests/auxsigcheck/src/dm/auxsigcheck.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// DM Environment file for auxsigcheck.dme.
// All manual changes should be made outside the BEGIN_ and END_ blocks.
// New source code should be placed in .dm files: choose File/New --> Code File.

// BEGIN_INTERNALS
// END_INTERNALS

// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR

// BEGIN_PREFERENCES
#define DEBUG
// END_PREFERENCES

// BEGIN_INCLUDE
#include "auxsigcheck.dm"
// END_INCLUDE

85 changes: 85 additions & 0 deletions tests/auxsigcheck/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
mod result;

use byond_get::OsType;
use cfg_if::cfg_if;
use clap::Parser;
use color_eyre::eyre::{Result, WrapErr};
use result::TestResult;
use std::{path::PathBuf, process::Command};
use tempdir::TempDir;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
/// Path to the auxtools DLL to use.
#[arg(short, long)]
pub auxtools_path: PathBuf,

/// Version of BYOND to use.
pub version: u16,

/// Build of BYOND to use.
pub build: u16
}

static TEST_DM: &[u8] = include_bytes!("dm/auxsigcheck.dm");
static TEST_DME: &[u8] = include_bytes!("dm/auxsigcheck.dme");

cfg_if! {
if #[cfg(windows)] {
const OS: OsType = OsType::Windows;
const DREAMMAKER_EXE: &str = "dm.exe";
const DREAMDAEMON_EXE: &str = "dd.exe";
} else {
const OS: OsType = OsType::Linux;
const DREAMMAKER_EXE: &str = "DreamMaker";
const DREAMDAEMON_EXE: &str = "DreamDaemon";
}
}

fn main() -> Result<()> {
color_eyre::install()?;
let args = Args::parse();
let auxtools_path = std::path::absolute(args.auxtools_path).wrap_err("failed to get absolute auxtools path")?;
let tmpdir = TempDir::new("auxsigcheck").wrap_err("failed to crate tempdir")?;
let base_path = tmpdir.path();

let byond_path = base_path.join("byond");
byond_get::download_bin(args.version, args.build, OS, &byond_path).wrap_err("failed to download byond")?;

std::fs::write(base_path.join("auxsigcheck.dm"), TEST_DM).wrap_err("failed to write auxsigcheck.dm")?;
std::fs::write(base_path.join("auxsigcheck.dme"), TEST_DME).wrap_err("failed to write auxsigcheck.dme")?;

let status = Command::new(byond_path.join(DREAMMAKER_EXE))
.arg(base_path.join("auxsigcheck.dme"))
.output()
.wrap_err("failed to run DreamMaker")?
.status;
if !status.success() {
panic!("Failed to compile auxsigcheck.dme, DreamMaker exited with code {status}")
}

std::env::set_var("LD_LIBRARY_PATH", byond_path.to_str().unwrap());
std::env::set_var("AUXTOOLS_DLL", auxtools_path);

let test_run = Command::new(byond_path.join(DREAMDAEMON_EXE))
.arg(base_path.join("auxsigcheck.dmb"))
.args(["-trusted", "-invisible"])
.output()
.wrap_err("failed to run DreamDaemon")?;

// cleanup env variables
std::env::remove_var("AUXTOOLS_DLL");
if !test_run.status.success() {
panic!("Failed to run auxsigcheck.dmb, DreamDaemon exited with code {status}")
}

let stderr = String::from_utf8_lossy(&test_run.stderr).into_owned();
match result::extract_test_result(&stderr) {
TestResult::Success => println!("success"),
TestResult::Failed(reason) => println!("failed: {reason}"),
TestResult::Missing(sigs) => println!("missing: {sigs}")
}

Ok(())
}
21 changes: 21 additions & 0 deletions tests/auxsigcheck/src/result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub enum TestResult {
Success,
Failed(String),
Missing(String)
}

pub fn extract_test_result(s: &str) -> TestResult {
for line in s.lines() {
let trimmed = line.trim();
if trimmed.is_empty() {
continue;
} else if trimmed.starts_with("SUCCESS") {
return TestResult::Success;
} else if trimmed.starts_with("FAILED") {
return TestResult::Failed(trimmed.split('(').nth(1).unwrap().replace(")", "").trim().to_owned());
} else if trimmed.starts_with("MISSING") {
return TestResult::Missing(trimmed.split(':').nth(1).unwrap().trim().to_owned());
}
}
panic!("No test result found")
}
11 changes: 0 additions & 11 deletions tests/byond_get/Cargo.toml

This file was deleted.

69 changes: 0 additions & 69 deletions tests/byond_get/src/main.rs

This file was deleted.

0 comments on commit 2cc5e0e

Please sign in to comment.