Add support for running tests in no_std mode.
This commit is contained in:
10
README.rst
10
README.rst
@@ -74,11 +74,13 @@ Or, when using `cretonne` as a dependency (in Cargo.toml):
|
||||
path = "..."
|
||||
features = ["no_std"]
|
||||
|
||||
Currently, tests don't test the `no_std` feature:
|
||||
`no_std` is currently "best effort". We won't try to break it, and we'll
|
||||
accept patches fixing problems, however we don't expect all developers to
|
||||
build and test with `no_std` when submitting patches. Accordingly, the
|
||||
`./test-all.sh` script does not test `no_std`.
|
||||
|
||||
1. `cargo test --features no_std` won't compile.
|
||||
|
||||
2. `./test-all.sh` doesn't test the `no_std` feature.
|
||||
There is a separate `./test-no_std.sh` script that tests the `no_std`
|
||||
feature in packages which support it.
|
||||
|
||||
It's important to note that cretonne still needs liballoc to compile.
|
||||
Thus, whatever environment is used must implement an allocator.
|
||||
|
||||
28
cranelift/test-no_std.sh
Executable file
28
cranelift/test-no_std.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is the test script for testing the no_std configuration of
|
||||
# packages which support it.
|
||||
|
||||
# Exit immediately on errors.
|
||||
set -e
|
||||
|
||||
# Repository top-level directory.
|
||||
cd $(dirname "$0")
|
||||
topdir=$(pwd)
|
||||
|
||||
function banner() {
|
||||
echo "====== $@ ======"
|
||||
}
|
||||
|
||||
# Test those packages which have no_std support.
|
||||
LIBS="cretonne frontend wasm native"
|
||||
cd "$topdir"
|
||||
for LIB in $LIBS
|
||||
do
|
||||
banner "Rust unit tests in $LIB"
|
||||
cd "lib/$LIB"
|
||||
cargo test --features no_std
|
||||
cd "$topdir"
|
||||
done
|
||||
|
||||
banner "OK"
|
||||
@@ -222,7 +222,8 @@ where
|
||||
}
|
||||
|
||||
/// Get a text version of the path to `key`.
|
||||
fn tpath(&self, key: K, forest: &MapForest<K, V, C>, comp: &C) -> String {
|
||||
fn tpath(&self, key: K, forest: &MapForest<K, V, C>, comp: &C) -> ::std::string::String {
|
||||
use std::string::ToString;
|
||||
match self.root.expand() {
|
||||
None => "map(empty)".to_string(),
|
||||
Some(root) => {
|
||||
@@ -415,7 +416,8 @@ where
|
||||
}
|
||||
|
||||
/// Get a text version of the path to the current position.
|
||||
fn tpath(&self) -> String {
|
||||
fn tpath(&self) -> ::std::string::String {
|
||||
use std::string::ToString;
|
||||
self.path.to_string()
|
||||
}
|
||||
}
|
||||
@@ -423,6 +425,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::mem;
|
||||
use std::vec::Vec;
|
||||
use super::*;
|
||||
use super::super::NodeData;
|
||||
|
||||
|
||||
@@ -580,6 +580,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::mem;
|
||||
use std::string::ToString;
|
||||
use super::*;
|
||||
|
||||
// Forest impl for a set implementation.
|
||||
|
||||
@@ -78,6 +78,7 @@ impl<F: Forest> NodePool<F> {
|
||||
{
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
use super::Comparator;
|
||||
use entity::SparseSet;
|
||||
|
||||
|
||||
@@ -314,7 +314,8 @@ where
|
||||
}
|
||||
|
||||
/// Get a text version of the path to the current position.
|
||||
fn tpath(&self) -> String {
|
||||
fn tpath(&self) -> ::std::string::String {
|
||||
use std::string::ToString;
|
||||
self.path.to_string()
|
||||
}
|
||||
}
|
||||
@@ -351,6 +352,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::mem;
|
||||
use std::vec::Vec;
|
||||
use super::*;
|
||||
use super::super::NodeData;
|
||||
|
||||
|
||||
@@ -19,10 +19,12 @@ use std::fmt;
|
||||
use std::fs::File;
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use std::io::{self, Write};
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use std::sync::atomic;
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use std::thread;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT;
|
||||
|
||||
/// Is debug tracing enabled?
|
||||
|
||||
@@ -204,6 +204,7 @@ mod tests {
|
||||
use super::*;
|
||||
use cursor::{Cursor, FuncCursor};
|
||||
use ir::{Function, InstBuilder, types};
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
|
||||
@@ -266,6 +266,7 @@ impl FromStr for FloatCC {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
static INT_ALL: [IntCC; 10] = [
|
||||
IntCC::Equal,
|
||||
|
||||
@@ -944,6 +944,7 @@ mod tests {
|
||||
use cursor::{Cursor, FuncCursor};
|
||||
use ir::types;
|
||||
use ir::{Function, Opcode, InstructionData, TrapCode};
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn make_inst() {
|
||||
|
||||
@@ -262,6 +262,7 @@ impl From<Heap> for AnyEntity {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::u32;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn value_with_number() {
|
||||
|
||||
@@ -379,6 +379,7 @@ impl FromStr for CallConv {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ir::types::{I32, F32, B8};
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn argument_type() {
|
||||
|
||||
@@ -122,6 +122,7 @@ impl FromStr for ExternalName {
|
||||
mod tests {
|
||||
use super::ExternalName;
|
||||
use ir::LibCall;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display_testcase() {
|
||||
|
||||
@@ -630,6 +630,7 @@ mod tests {
|
||||
use std::{f32, f64};
|
||||
use std::str::FromStr;
|
||||
use std::fmt::Display;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn format_imm64() {
|
||||
|
||||
@@ -724,6 +724,7 @@ pub enum ResolvedConstraint {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn opcodes() {
|
||||
|
||||
@@ -142,6 +142,8 @@ mod tests {
|
||||
use super::JumpTableData;
|
||||
use ir::Ebb;
|
||||
use entity::EntityRef;
|
||||
use std::vec::Vec;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
|
||||
@@ -743,6 +743,7 @@ mod tests {
|
||||
use entity::EntityRef;
|
||||
use ir::{Ebb, Inst, ProgramOrder, SourceLoc};
|
||||
use std::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
struct LayoutCursor<'f> {
|
||||
/// Borrowed function layout. Public so it can be re-borrowed from this cursor.
|
||||
|
||||
@@ -100,6 +100,7 @@ impl LibCall {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display() {
|
||||
|
||||
@@ -148,6 +148,7 @@ mod tests {
|
||||
use super::*;
|
||||
use entity::EntityRef;
|
||||
use ir::{Inst, Ebb};
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn convert() {
|
||||
|
||||
@@ -51,6 +51,7 @@ impl fmt::Display for SourceLoc {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ir::SourceLoc;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display() {
|
||||
|
||||
@@ -320,6 +320,7 @@ mod tests {
|
||||
use ir::Function;
|
||||
use ir::types;
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn stack_slot() {
|
||||
|
||||
@@ -83,6 +83,7 @@ impl FromStr for TrapCode {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
// Everything but user-defined codes.
|
||||
const CODES: [TrapCode; 8] = [
|
||||
|
||||
@@ -324,6 +324,7 @@ impl Default for Type {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn basic_scalars() {
|
||||
|
||||
@@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-arm32.rs"));
|
||||
mod tests {
|
||||
use super::{INFO, GPR, S, D};
|
||||
use isa::RegUnit;
|
||||
use std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn unit_encodings() {
|
||||
|
||||
@@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-arm64.rs"));
|
||||
mod tests {
|
||||
use super::INFO;
|
||||
use isa::RegUnit;
|
||||
use std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn unit_encodings() {
|
||||
|
||||
@@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-intel.rs"));
|
||||
mod tests {
|
||||
use super::*;
|
||||
use isa::RegUnit;
|
||||
use std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn unit_encodings() {
|
||||
|
||||
@@ -117,6 +117,7 @@ mod tests {
|
||||
use isa;
|
||||
use ir::{DataFlowGraph, InstructionData, Opcode};
|
||||
use ir::{types, immediates};
|
||||
use std::string::{String, ToString};
|
||||
|
||||
fn encstr(isa: &isa::TargetIsa, enc: Result<isa::Encoding, isa::Legalize>) -> String {
|
||||
match enc {
|
||||
|
||||
@@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-riscv.rs"));
|
||||
mod tests {
|
||||
use super::{INFO, GPR, FPR};
|
||||
use isa::RegUnit;
|
||||
use std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn unit_encodings() {
|
||||
|
||||
@@ -12,6 +12,7 @@ include!(concat!(env!("OUT_DIR"), "/settings-riscv.rs"));
|
||||
mod tests {
|
||||
use super::{builder, Flags};
|
||||
use settings::{self, Configurable};
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display_default() {
|
||||
|
||||
@@ -48,6 +48,8 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn adjpairs() {
|
||||
use super::IteratorExtras;
|
||||
|
||||
@@ -63,7 +63,6 @@ mod write;
|
||||
#[cfg(feature = "no_std")]
|
||||
mod std {
|
||||
pub use core::*;
|
||||
#[macro_use]
|
||||
pub use alloc::{boxed, vec, string};
|
||||
pub mod collections {
|
||||
pub use hashmap_core::{HashMap, HashSet};
|
||||
|
||||
@@ -231,6 +231,7 @@ mod test {
|
||||
use loop_analysis::{Loop, LoopAnalysis};
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use dominator_tree::DominatorTree;
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn nested_loops_detection() {
|
||||
|
||||
@@ -33,6 +33,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::partition_slice;
|
||||
use std::vec::Vec;
|
||||
|
||||
fn check(x: &[u32], want: &[u32]) {
|
||||
assert_eq!(x.len(), want.len());
|
||||
|
||||
@@ -221,6 +221,7 @@ impl fmt::Display for AllocatableSet {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use isa::registers::{RegClass, RegClassData};
|
||||
use std::vec::Vec;
|
||||
|
||||
// Register classes for testing.
|
||||
const GPR: RegClass = &RegClassData {
|
||||
|
||||
@@ -18,8 +18,6 @@ use std::cmp;
|
||||
use std::iter;
|
||||
use std::fmt;
|
||||
use std::slice;
|
||||
use std::iter::Peekable;
|
||||
use std::mem;
|
||||
use std::vec::Vec;
|
||||
use isa::{TargetIsa, EncInfo};
|
||||
use timing;
|
||||
|
||||
@@ -463,6 +463,7 @@ mod tests {
|
||||
use entity::EntityRef;
|
||||
use ir::{ProgramOrder, ExpandedProgramPoint};
|
||||
use std::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
// Dummy program order which simply compares indexes.
|
||||
// It is assumed that EBBs have indexes that are multiples of 10, and instructions have indexes
|
||||
|
||||
@@ -273,6 +273,7 @@ mod tests {
|
||||
use regalloc::AllocatableSet;
|
||||
use std::borrow::Borrow;
|
||||
use super::Pressure;
|
||||
use std::boxed::Box;
|
||||
|
||||
// Make an arm32 `TargetIsa`, if possible.
|
||||
fn arm32() -> Option<Box<TargetIsa>> {
|
||||
|
||||
@@ -1163,6 +1163,7 @@ mod tests {
|
||||
use isa::{TargetIsa, RegClass, RegUnit, RegInfo};
|
||||
use regalloc::AllocatableSet;
|
||||
use super::{Solver, Move};
|
||||
use std::boxed::Box;
|
||||
|
||||
// Make an arm32 `TargetIsa`, if possible.
|
||||
fn arm32() -> Option<Box<TargetIsa>> {
|
||||
|
||||
@@ -348,6 +348,7 @@ mod tests {
|
||||
use super::{builder, Flags};
|
||||
use super::Error::*;
|
||||
use super::Configurable;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display_default() {
|
||||
|
||||
@@ -238,6 +238,7 @@ mod details {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn display() {
|
||||
|
||||
@@ -1132,7 +1132,10 @@ mod tests {
|
||||
Ok(_) => { panic!("Expected an error!") },
|
||||
Err(Error { message, .. } ) => {
|
||||
if !message.contains($msg) {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
panic!(format!("'{}' did not contain the substring '{}'", message, $msg));
|
||||
#[cfg(feature = "no_std")]
|
||||
panic!("error message did not contain the expected substring");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,6 +467,7 @@ impl<'a> fmt::Display for DisplayValues<'a> {
|
||||
mod tests {
|
||||
use ir::{Function, ExternalName, StackSlotData, StackSlotKind};
|
||||
use ir::types;
|
||||
use std::string::ToString;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
|
||||
@@ -1039,7 +1039,12 @@ mod tests {
|
||||
let flags = settings::Flags::new(&settings::builder());
|
||||
match verify_function(&func, &flags) {
|
||||
Ok(()) => {}
|
||||
Err(err) => panic!(err.message),
|
||||
Err(err) => {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
panic!(err.message);
|
||||
#[cfg(feature = "no_std")]
|
||||
panic!("function failed to verify");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1213,7 +1218,12 @@ mod tests {
|
||||
let flags = settings::Flags::new(&settings::builder());
|
||||
match verify_function(&func, &flags) {
|
||||
Ok(()) => {}
|
||||
Err(err) => panic!(err.message),
|
||||
Err(err) => {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
panic!(err.message);
|
||||
#[cfg(feature = "no_std")]
|
||||
panic!("function failed to verify");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1259,7 +1269,12 @@ mod tests {
|
||||
let flags = settings::Flags::new(&settings::builder());
|
||||
match verify_function(&func, &flags) {
|
||||
Ok(()) => {}
|
||||
Err(err) => panic!(err.message),
|
||||
Err(err) => {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
panic!(err.message);
|
||||
#[cfg(feature = "no_std")]
|
||||
panic!("function failed to verify");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user