Skip to content

Commit

Permalink
tests/inst: Add destructive test framework
Browse files Browse the repository at this point in the history
This adds infrastructure to the Rust test suite for destructive
tests, and adds a new `transactionality` test which runs
rpm-ostree in a loop (along with `ostree-finalize-staged`) and
repeatedly uses either `kill -9`, `reboot` and  `reboot -ff`.

The main goal here is to flush out any "logic errors".

So far I've validated that this passes a lot of cycles
using
```
$ kola run --qemu-image=fastbuild-fedora-coreos-ostree-qemu.qcow2 ext.ostree.destructive-rs.transactionality --debug --multiply 8 --parallel 4
```
a number of times.
  • Loading branch information
cgwalters committed Aug 16, 2020
1 parent ab95c02 commit 43a46b8
Show file tree
Hide file tree
Showing 15 changed files with 1,039 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .cci.jenkinsfile
Expand Up @@ -81,6 +81,8 @@ parallel fcos: {
coreos-assembler buildextend-metal4k
coreos-assembler buildextend-live --fast
# Install the tests
# Build and install the tests
make -C tests/kolainst
make -C tests/kolainst install
""")
}
Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Expand Up @@ -43,6 +43,9 @@ AM_DISTCHECK_CONFIGURE_FLAGS += \

GITIGNOREFILES = aclocal.m4 build-aux/ buildutil/*.m4 config.h.in gtk-doc.make

# Generated by coreos-assembler build-fast and kola
GITIGNOREFILES += fastbuild-*.qcow2 _kola_temp/

SUBDIRS += .

if ENABLE_GTK_DOC
Expand Down
30 changes: 19 additions & 11 deletions tests/inst/Cargo.toml
Expand Up @@ -6,17 +6,21 @@ edition = "2018"

[[bin]]
name = "ostree-test"
path = "src/insttest.rs"
path = "src/insttestmain.rs"

[dependencies]
clap = "2.32.0"
structopt = "0.2"
structopt = "0.3"
serde = "1.0.111"
serde_derive = "1.0.111"
serde_json = "1.0"
commandspec = "0.12.2"
anyhow = "1.0"
tempfile = "3.1.0"
glib = "0.9.1"
gio = "0.8"
ostree = { version = "0.7.1", features = ["v2020_1"] }
libtest-mimic = "0.2.0"
libtest-mimic = "0.3.0"
twoway = "0.2.1"
hyper = "0.13"
futures = "0.3.4"
Expand All @@ -26,17 +30,21 @@ tokio = { version = "0.2", features = ["full"] }
futures-util = "0.3.1"
base64 = "0.12.0"
procspawn = "0.8"
proc-macro2 = "0.4"
quote = "0.6"
syn = "0.15"
rand = "0.7.3"
linkme = "0.2"
strum = "0.18.0"
strum_macros = "0.18.0"
openat = "0.1.19"
openat-ext = "0.1.4"
nix = "0.17.0"

itest-macro = { path = "itest-macro" }

# This one I might publish to crates.io, not sure yet
with-procspawn-tempdir = { git = "https://github.com/cgwalters/with-procspawn-tempdir" }
#with-procspawn-tempdir = { path = "/var/srv/walters/src/github/cgwalters/with-procspawn-tempdir" }

# See https://github.com/tcr/commandspec/pulls?q=is%3Apr+author%3Acgwalters+
# Internal crate for the test macro
itest-macro = { path = "itest-macro" }

[patch.crates-io]
# See https://github.com/tcr/commandspec/pulls?q=is%3Apr+author%3Acgwalters+
# If patches don't get reviewed I'll probably fork it.
commandspec = { git = "https://github.com/cgwalters/commandspec", branch = 'walters-master' }
#commandspec = { path = "/var/srv/walters/src/github/tcr/commandspec" }
45 changes: 42 additions & 3 deletions tests/inst/itest-macro/src/itest-macro.rs
Expand Up @@ -9,18 +9,57 @@ use quote::quote;
#[proc_macro_attribute]
pub fn itest(attrs: TokenStream, input: TokenStream) -> TokenStream {
let attrs = syn::parse_macro_input!(attrs as syn::AttributeArgs);
if attrs.len() > 0 {
return syn::Error::new_spanned(&attrs[0], "itest takes no attributes")
if attrs.len() > 1 {
return syn::Error::new_spanned(&attrs[1], "itest takes 0 or 1 attributes")
.to_compile_error()
.into();
}
let destructive = match attrs.get(0) {
Some(syn::NestedMeta::Meta(syn::Meta::NameValue(namevalue))) => {
if let Some(name) = namevalue.path.get_ident().map(|i| i.to_string()) {
if name == "destructive" {
match &namevalue.lit {
syn::Lit::Bool(v) => v.value,
_ => {
return syn::Error::new_spanned(
&attrs[1],
format!("destructive must be bool {}", name),
)
.to_compile_error()
.into();
}
}
} else {
return syn::Error::new_spanned(
&attrs[1],
format!("Unknown argument {}", name),
)
.to_compile_error()
.into();
}
} else {
false
}
}
Some(v) => {
return syn::Error::new_spanned(&v, "Unexpected argument")
.to_compile_error()
.into()
}
None => false,
};
let func = syn::parse_macro_input!(input as syn::ItemFn);
let fident = func.sig.ident.clone();
let varident = quote::format_ident!("ITEST_{}", fident);
let fidentstrbuf = format!(r#"{}"#, fident);
let fidentstr = syn::LitStr::new(&fidentstrbuf, Span::call_site());
let testident = if destructive {
quote::format_ident!("{}", "DESTRUCTIVE_TESTS")
} else {
quote::format_ident!("{}", "NONDESTRUCTIVE_TESTS")
};
let output = quote! {
#[linkme::distributed_slice(TESTS)]
#[linkme::distributed_slice(#testident)]
#[allow(non_upper_case_globals)]
static #varident : Test = Test {
name: #fidentstr,
Expand Down

0 comments on commit 43a46b8

Please sign in to comment.