Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sui-framework test added to CI #75

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
062824-add-sui-framework-tests: ini
jcivlin committed Jun 28, 2024
commit 006c0161094b455dc8a67502c865943567849c24
4 changes: 4 additions & 0 deletions external-crates/move/solana/move-mv-llvm-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -88,4 +88,8 @@ harness = false

[[test]]
name = "failure-tests"
harness = false

[[test]]
name = "sui-framework-tests"
harness = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Copyright (c) The Diem Core Contributors
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

//! Run tests for known and fixed failures.
//!
//! # Usage
//!
//! These tests require `move-compiler` to be pre-built:
//!
//! ```
//! cargo build -p move-compiler
//! ```
//!
//! Running the tests:
//!
//! ```
//! cargo test -p move-mv-llvm-compiler --test sui-framework-tests
//! ```
//!
//! Running a specific test:
//!
//! ```
//! cargo test -p move-mv-llvm-compiler --test sui-framework-tests -- hash_tests.move
//! ```
//!
//! Promoting all results to expected results:
//!
//! ```
//! PROMOTE_LLVM_IR=1 cargo test -p move-mv-llvm-compiler --test sui-framework-tests
//! ```
//!
//! # Details
//!
//! They do the following:
//!
//! - Create a test for every .move file in sui-framework-tests/
//! - Run `move-mv-llvm-compiler` to compile Move source to LLVM IR.
//! - Compare the actual IR to an existing expected IR.
//!
//! If the `PROMOTE_LLVM_IR` env var is set, the actual IR is promoted to the
//! expected IR.
//!
//! MVIR files may contain "test directives" instructing the harness
//! how to behave. These are specially-interpreted comments of the form
//!
//! - `// ignore` - don't run the test

use anyhow::{anyhow, bail};
use log::debug;
use std::{env, fs, io, path::{Path, PathBuf}};

mod test_common;
use test_common as tc;

pub const TEST_DIR: &str = "tests/sui-framework-tests";

datatest_stable::harness!(run_test, TEST_DIR, r".*\.move$");

fn run_test(test_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
tc::setup_logging_for_test();
dbg!(test_path);
Ok(run_test_inner(test_path)?)
}

fn run_test_inner(test_path: &Path) -> anyhow::Result<()> {
let harness_paths = tc::get_harness_paths("move-compiler")?;
let test_plan = tc::get_test_plan(test_path)?;

if test_plan.should_ignore() {
eprintln!("ignoring {}", test_plan.name);
return Ok(());
}

let current_dir = env::current_dir()
.or_else(|err| bail!("Cannot get currecnt directory. Got error: {}", err))
.unwrap();

let test_name = &test_plan.name;
debug!(target: "debug", "test_name {:#?}", &test_name);

let toml_dir: String;
if let Some(pos) = test_name.rfind('/') {
toml_dir = test_name[..pos].to_string();
} else {
bail!("No extension found in the filename {}", test_name);
}

let p_absolute_path = current_dir.join(&toml_dir).to_str().unwrap().to_owned();
debug!(target: "debug", "p_absolute_path {}", &p_absolute_path);


debug!(target: "debug", "current_dir {:#?}", &current_dir);
debug!(target: "debug", "toml_dir {:#?}", &toml_dir);
debug!(target: "debug", "p_absolute_path {:#?}", &p_absolute_path);

let dependency = find_move_toml(&p_absolute_path);
debug!(target: "debug", "dependency {:#?}", &dependency);

let mut extra_param = if let Some(lib_dep) = dependency {
let p = "-p".to_string().to_owned();
let lib_dep_str = lib_dep.to_str().unwrap().to_string();
vec![p, lib_dep_str]
} else {
let stdlib = "--stdlib".to_string().to_owned();
vec![stdlib]
};
extra_param.push("--test".to_string());
extra_param.push("--skip-undefined-entries".to_string());

let src = &test_plan.build_dir;
let dst = &src.join("stored_results");

tc::clean_results(src)?;
std::fs::remove_dir_all(dst).ok();



debug!("harness_paths {:#?} &test_plan {:#?}", &harness_paths, &test_plan);
tc::run_move_to_llvm_build(
&harness_paths,
&test_plan,
extra_param.iter().collect()
)?;

tc::compare_results(&test_plan)?;

Ok(())
}

fn check_files_with_extensions(dir: &PathBuf, ext1: &str, ext2: &str) -> Result<Vec<String>, io::Error> {
let mut missing_files = Vec::new();

// Read the contents of the directory
let entries = fs::read_dir(dir)?;

for entry in entries {
let entry = entry?;
let path = entry.path();
// Check if the entry is a file with the specified ext1 extension
if path.is_file() && path.extension().and_then(|e| e.to_str()) == Some(ext1) {
debug!("Found {}-file {}", ext1, &path.to_string_lossy());
// Construct the corresponding file path with ext2 extension
let mut new_path = path.clone();
new_path.set_extension(ext2);
debug!("Checking for correspondin {}-file {}", ext2, &new_path.to_string_lossy());
// Check if the corresponding file exists
if !new_path.exists() {
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
let missed = format!("{}.{}", stem.to_string(), ext2);
// missing_files.push(stem.to_string());
missing_files.push(missed);
}
}
}
}
Ok(missing_files)
}

fn find_move_toml(dir: &str) -> Option<PathBuf> {
let path = Path::new(dir);
let move_toml = path.join("Move.toml");

if move_toml.exists() {
Some(move_toml)
} else {
None
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "Dynamic-field-tests"
version = "0.0.1"
# published-at = "0x2"

[dependencies]
# MoveStdlib = { local = "../move-stdlib" }
# MoveStdlib = { local = "../../../../../../../crates/sui-framework/packages/sui-framework/../move-stdlib" }
# Sui = { local = "../../../../../../../crates/sui-framework/packages/sui-framework", address = "0x2", package = "Sui" }

Sui = { local = "/home/sol/work/git/sui-solana-032024/crates/sui-framework/packages/sui-framework" }

[addresses]
sui = "0x2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; ModuleID = '0x1__address'
source_filename = "../../../../../../crates/sui-framework/packages/move-stdlib/sources/address.move"
target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128"
target triple = "sbf-solana-solana"

%__move_rt_type = type { { ptr, i64 }, i64, ptr }

@__move_rttydesc_signer = private unnamed_addr constant %__move_rt_type { { ptr, i64 } { ptr @__move_rttydesc_signer_name, i64 6 }, i64 9, ptr @__move_rttydesc_NOTHING_info }
@__move_rttydesc_signer_name = private unnamed_addr constant [6 x i8] c"signer"
@__move_rttydesc_NOTHING_info = private unnamed_addr constant i8 -1

declare i32 @memcmp(ptr, ptr, i64)

define void @"0000000000000001_address_unit_test_poiso_2F27Z5dFXYpcdW"() {
entry:
%local_0 = alloca i64, align 8
%local_1 = alloca { ptr, i64, i64 }, align 8
store i64 0, ptr %local_0, align 8
%loaded_alloca = load i64, ptr %local_0, align 8
%retval = call { ptr, i64, i64 } @move_native_unit_test_create_signers_for_testing(i64 %loaded_alloca)
store { ptr, i64, i64 } %retval, ptr %local_1, align 8
call void @move_rt_vec_destroy(ptr @__move_rttydesc_signer, ptr %local_1)
ret void
}

declare { ptr, i64, i64 } @move_native_unit_test_create_signers_for_testing(i64)

define i64 @"0000000000000001_address_length_BCf655p6LX13Y5"() {
entry:
%local_0 = alloca i64, align 8
store i64 32, ptr %local_0, align 8
%retval = load i64, ptr %local_0, align 8
ret i64 %retval
}

declare void @move_rt_vec_destroy(ptr nonnull readonly dereferenceable(32), ptr)
Loading