1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-06-08 15:56:16 +02:00

integrate: Refactor a lifetime for rust 1.64.0

Signed-off-by: utam0k <k0ma@utam0k.jp>
This commit is contained in:
utam0k 2022-09-24 13:24:20 +09:00
parent 29faea1eda
commit 0be833abc0
No known key found for this signature in database
GPG Key ID: E9844426F4EA9E67
20 changed files with 79 additions and 79 deletions

View File

@ -89,25 +89,25 @@ fn main() -> Result<()> {
let seccomp_notify = get_seccomp_notify_test();
let ro_paths = get_ro_paths_test();
tm.add_test_group(&cl);
tm.add_test_group(&cc);
tm.add_test_group(&huge_tlb);
tm.add_test_group(&pidfile);
tm.add_test_group(&ns_itype);
tm.add_test_group(&hooks);
tm.add_test_group(&cgroup_v1_pids);
tm.add_test_group(&cgroup_v1_cpu);
tm.add_test_group(&cgroup_v2_cpu);
tm.add_test_group(&cgroup_v1_memory);
tm.add_test_group(&cgroup_v1_network);
tm.add_test_group(&cgroup_v1_blkio);
tm.add_test_group(&seccomp_notify);
tm.add_test_group(&ro_paths);
tm.add_test_group(Box::new(cl));
tm.add_test_group(Box::new(cc));
tm.add_test_group(Box::new(huge_tlb));
tm.add_test_group(Box::new(pidfile));
tm.add_test_group(Box::new(ns_itype));
tm.add_test_group(Box::new(hooks));
tm.add_test_group(Box::new(cgroup_v1_pids));
tm.add_test_group(Box::new(cgroup_v1_cpu));
tm.add_test_group(Box::new(cgroup_v2_cpu));
tm.add_test_group(Box::new(cgroup_v1_memory));
tm.add_test_group(Box::new(cgroup_v1_network));
tm.add_test_group(Box::new(cgroup_v1_blkio));
tm.add_test_group(Box::new(seccomp_notify));
tm.add_test_group(Box::new(ro_paths));
tm.add_cleanup(Box::new(cgroups::cleanup_v1));
tm.add_cleanup(Box::new(cgroups::cleanup_v2));
match &opts.command {
match opts.command {
SubCommand::Run(args) => run(args, &tm).context("run tests")?,
SubCommand::List => list(&tm).context("list tests")?,
}
@ -130,15 +130,15 @@ fn get_abs_path(rel_path: &Path) -> PathBuf {
}
}
fn run(opts: &Run, test_manager: &TestManager) -> Result<()> {
fn run(opts: Run, test_manager: &TestManager) -> Result<()> {
let runtime_path = get_abs_path(&opts.runtime);
set_runtime_path(&runtime_path);
let runtimetest_path = get_abs_path(&opts.runtimetest);
set_runtimetest_path(&runtimetest_path);
if let Some(tests) = &opts.tests {
let tests_to_run = parse_tests(tests);
if let Some(tests) = opts.tests {
let tests_to_run = parse_tests(&tests);
test_manager.run_selected(tests_to_run);
} else {
test_manager.run_all();

View File

@ -596,7 +596,7 @@ fn test_blkio(test_name: &str, rate: u64, empty: bool) -> TestResult {
})
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_blkio");
let non_empty_100kb = ConditionalTest::new(
"non_empty_100kb",

View File

@ -292,7 +292,7 @@ fn can_run_idle() -> bool {
can_run() && idle_path.exists()
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_cpu");
let linux_cgroups_cpus = ConditionalTest::new(
"test_linux_cgroups_cpus",

View File

@ -383,7 +383,7 @@ fn can_run_idle() -> bool {
can_run() && idle_path.exists()
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v2_cpu");
let test_cpu_weight_valid_set = ConditionalTest::new(
"test_cpu_weight_valid_set",

View File

@ -67,7 +67,7 @@ fn can_run() -> bool {
Path::new(CGROUP_MEMORY_LIMIT).exists() && Path::new(CGROUP_MEMORY_SWAPPINESS).exists()
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_memory");
let linux_cgroups_memory = ConditionalTest::new(
"test_linux_cgroups_memory",

View File

@ -143,7 +143,7 @@ fn can_run() -> bool {
iface_exists && cgroup_paths_exists
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_network");
let linux_cgroups_network = ConditionalTest::new(
"test_linux_cgroups_network",

View File

@ -150,7 +150,7 @@ fn can_run() -> bool {
Path::new("/sys/fs/cgroup/pids").exists()
}
pub fn get_test_group<'a>() -> TestGroup<'a> {
pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_pids");
let positive_limit = ConditionalTest::new(
"positive_pid_limit",

View File

@ -61,7 +61,7 @@ fn get_spec() -> Spec {
.unwrap()
}
fn get_test<'a>(test_name: &'static str) -> Test<'a> {
fn get_test(test_name: &'static str) -> Test {
Test::new(
test_name,
Box::new(move || {
@ -84,16 +84,16 @@ fn get_test<'a>(test_name: &'static str) -> Test<'a> {
};
delete_hook_output_file();
if log != "pre-start1 called\npre-start2 called\npost-start1 called\npost-start2 called\npost-stop1 called\npost-stop2 called\n" {
return TestResult::Failed(anyhow!(
"error : hooks must be called in the listed order"
));
}
return TestResult::Failed(anyhow!(
"error : hooks must be called in the listed order"
));
}
TestResult::Passed
}),
)
}
pub fn get_hooks_tests<'a>() -> TestGroup<'a> {
pub fn get_hooks_tests() -> TestGroup {
let mut tg = TestGroup::new("hooks");
tg.add(vec![Box::new(get_test("hooks"))]);
tg

View File

@ -63,12 +63,12 @@ impl ContainerCreate {
}
}
impl<'a> TestableGroup<'a> for ContainerCreate {
fn get_name(&self) -> &'a str {
impl TestableGroup for ContainerCreate {
fn get_name(&self) -> &'static str {
"create"
}
fn run_all(&self) -> Vec<(&'a str, TestResult)> {
fn run_all(&self) -> Vec<(&'static str, TestResult)> {
vec![
("empty_id", self.create_empty_id()),
("valid_id", self.create_valid_id()),
@ -76,7 +76,7 @@ impl<'a> TestableGroup<'a> for ContainerCreate {
]
}
fn run_selected(&self, selected: &[&str]) -> Vec<(&'a str, TestResult)> {
fn run_selected(&self, selected: &[&str]) -> Vec<(&'static str, TestResult)> {
let mut ret = Vec::new();
for name in selected {
match *name {

View File

@ -69,12 +69,12 @@ impl ContainerLifecycle {
}
}
impl<'a> TestableGroup<'a> for ContainerLifecycle {
fn get_name(&self) -> &'a str {
impl TestableGroup for ContainerLifecycle {
fn get_name(&self) -> &'static str {
"lifecycle"
}
fn run_all(&self) -> Vec<(&'a str, TestResult)> {
fn run_all(&self) -> Vec<(&'static str, TestResult)> {
vec![
("create", self.create()),
("start", self.start()),
@ -93,7 +93,7 @@ impl<'a> TestableGroup<'a> for ContainerLifecycle {
]
}
fn run_selected(&self, selected: &[&str]) -> Vec<(&'a str, TestResult)> {
fn run_selected(&self, selected: &[&str]) -> Vec<(&'static str, TestResult)> {
let mut ret = Vec::new();
for name in selected {
match *name {

View File

@ -29,7 +29,7 @@ fn get_spec() -> Spec {
r
}
fn get_test<'a>(test_name: &'static str) -> Test<'a> {
fn get_test(test_name: &'static str) -> Test {
Test::new(
test_name,
Box::new(move || {
@ -65,7 +65,7 @@ fn get_test<'a>(test_name: &'static str) -> Test<'a> {
)
}
pub fn get_ns_itype_tests<'a>() -> TestGroup<'a> {
pub fn get_ns_itype_tests() -> TestGroup {
let mut tg = TestGroup::new("ns_itype");
let tests: Vec<_> = vec![Box::new(get_test("ns_itype"))];
tg.add(tests);

View File

@ -94,7 +94,7 @@ fn test_pidfile() -> TestResult {
TestResult::Passed
}
pub fn get_pidfile_test<'a>() -> TestGroup<'a> {
pub fn get_pidfile_test() -> TestGroup {
let pidfile = Test::new("pidfile", Box::new(test_pidfile));
let mut tg = TestGroup::new("pidfile");
tg.add(vec![Box::new(pidfile)]);

View File

@ -236,7 +236,7 @@ fn check_readonly_device_nodes() -> TestResult {
TestResult::Passed
}
pub fn get_ro_paths_test<'a>() -> TestGroup<'a> {
pub fn get_ro_paths_test() -> TestGroup {
let ro_paths = Test::new("readonly_paths", Box::new(check_readonly_paths));
let ro_rel_paths = Test::new("readonly_rel_paths", Box::new(check_readonly_rel_path));
let ro_symlinks = Test::new("readonly_symlinks", Box::new(check_readonly_symlinks));

View File

@ -104,7 +104,7 @@ fn test_seccomp_notify() -> Result<()> {
Ok(())
}
pub fn get_seccomp_notify_test<'a>() -> TestGroup<'a> {
pub fn get_seccomp_notify_test() -> TestGroup {
let seccomp_notify_test = Test::new(
"seccomp_notify",
Box::new(|| {

View File

@ -134,7 +134,7 @@ fn test_valid_tlb() -> TestResult {
TestResult::Passed
}
pub fn get_tlb_test<'a>() -> TestGroup<'a> {
pub fn get_tlb_test() -> TestGroup {
let wrong_tlb = ConditionalTest::new(
"invalid_tlb",
Box::new(check_hugetlb),

View File

@ -7,18 +7,18 @@ type TestFn = dyn Fn() -> TestResult + Sync + Send;
type CheckFn = dyn Fn() -> bool + Sync + Send;
/// Basic Template structure for tests which need to be run conditionally
pub struct ConditionalTest<'a> {
pub struct ConditionalTest {
/// name of the test
name: &'a str,
name: &'static str,
/// actual test function
test_fn: Box<TestFn>,
/// function to check if a test can be run or not
check_fn: Box<CheckFn>,
}
impl<'a> ConditionalTest<'a> {
impl ConditionalTest {
/// Create a new condition test
pub fn new(name: &'a str, check_fn: Box<CheckFn>, test_fn: Box<TestFn>) -> Self {
pub fn new(name: &'static str, check_fn: Box<CheckFn>, test_fn: Box<TestFn>) -> Self {
ConditionalTest {
name,
check_fn,
@ -27,8 +27,8 @@ impl<'a> ConditionalTest<'a> {
}
}
impl<'a> Testable<'a> for ConditionalTest<'a> {
fn get_name(&self) -> &'a str {
impl Testable for ConditionalTest {
fn get_name(&self) -> &'static str {
self.name
}

View File

@ -5,22 +5,22 @@ use crate::testable::{TestResult, Testable};
type TestFn = dyn Sync + Send + Fn() -> TestResult;
/// Basic Template structure for a test
pub struct Test<'a> {
pub struct Test {
/// name of the test
name: &'a str,
name: &'static str,
/// Actual test function
test_fn: Box<TestFn>,
}
impl<'a> Test<'a> {
impl Test {
/// create new test
pub fn new(name: &'a str, test_fn: Box<TestFn>) -> Self {
pub fn new(name: &'static str, test_fn: Box<TestFn>) -> Self {
Test { name, test_fn }
}
}
impl<'a> Testable<'a> for Test<'a> {
fn get_name(&self) -> &'a str {
impl Testable for Test {
fn get_name(&self) -> &'static str {
self.name
}

View File

@ -4,16 +4,16 @@ use crossbeam::thread;
use std::collections::BTreeMap;
/// Stores tests belonging to a group
pub struct TestGroup<'a> {
pub struct TestGroup {
/// name of the test group
name: &'a str,
name: &'static str,
/// tests belonging to this group
tests: BTreeMap<&'a str, Box<dyn Testable<'a> + Sync + Send + 'a>>,
tests: BTreeMap<&'static str, Box<dyn Testable + Sync + Send>>,
}
impl<'a> TestGroup<'a> {
impl TestGroup {
/// create a new test group
pub fn new(name: &'a str) -> Self {
pub fn new(name: &'static str) -> Self {
TestGroup {
name,
tests: BTreeMap::new(),
@ -21,21 +21,21 @@ impl<'a> TestGroup<'a> {
}
/// add a test to the group
pub fn add(&mut self, tests: Vec<Box<impl Testable<'a> + Sync + Send + 'a>>) {
pub fn add(&mut self, tests: Vec<Box<impl Testable + Sync + Send + 'static>>) {
tests.into_iter().for_each(|t| {
self.tests.insert(t.get_name(), t);
});
}
}
impl<'a> TestableGroup<'a> for TestGroup<'a> {
impl TestableGroup for TestGroup {
/// get name of the test group
fn get_name(&self) -> &'a str {
fn get_name(&self) -> &'static str {
self.name
}
/// run all the test from the test group
fn run_all(&'a self) -> Vec<(&'a str, TestResult)> {
fn run_all(&self) -> Vec<(&'static str, TestResult)> {
let mut ret = Vec::with_capacity(self.tests.len());
thread::scope(|s| {
let mut collector = Vec::with_capacity(self.tests.len());
@ -58,7 +58,7 @@ impl<'a> TestableGroup<'a> for TestGroup<'a> {
}
/// run selected test from the group
fn run_selected(&'a self, selected: &[&str]) -> Vec<(&'a str, TestResult)> {
fn run_selected(&self, selected: &[&str]) -> Vec<(&'static str, TestResult)> {
let selected_tests = self
.tests
.iter()

View File

@ -4,21 +4,21 @@ use anyhow::Result;
use crossbeam::thread;
use std::collections::BTreeMap;
type TestableGroupType<'a> = dyn TestableGroup<'a> + Sync + Send + 'a;
type TestableGroupType = dyn TestableGroup + Sync + Send;
/// This manages all test groups, and thus the tests
pub struct TestManager<'a> {
test_groups: BTreeMap<&'a str, &'a TestableGroupType<'a>>,
pub struct TestManager {
test_groups: BTreeMap<&'static str, Box<TestableGroupType>>,
cleanup: Vec<Box<dyn Fn() -> Result<()>>>,
}
impl<'a> Default for TestManager<'a> {
impl Default for TestManager {
fn default() -> Self {
Self::new()
}
}
impl<'a> TestManager<'a> {
impl TestManager {
/// Create new TestManager
pub fn new() -> Self {
TestManager {
@ -28,7 +28,7 @@ impl<'a> TestManager<'a> {
}
/// add a test group to the test manager
pub fn add_test_group(&mut self, tg: &'a TestableGroupType<'a>) {
pub fn add_test_group(&mut self, tg: Box<TestableGroupType>) {
self.test_groups.insert(tg.get_name(), tg);
}
@ -38,7 +38,7 @@ impl<'a> TestManager<'a> {
/// Prints the given test results, usually used to print
/// results of a test group
fn print_test_result(&self, name: &str, res: &[(&'a str, TestResult)]) {
fn print_test_result(&self, name: &str, res: &[(&'static str, TestResult)]) {
println!("# Start group {}", name);
let len = res.len();
for (idx, (name, res)) in res.iter().enumerate() {

View File

@ -27,8 +27,8 @@ impl<T> From<Result<T>> for TestResult {
/// This trait indicates that something can be run as a test, or is 'testable'
/// This forms the basis of the framework, as all places where tests are done,
/// expect structs which implement this
pub trait Testable<'a> {
fn get_name(&self) -> &'a str;
pub trait Testable {
fn get_name(&self) -> &'static str;
fn can_run(&self) -> bool {
true
}
@ -37,10 +37,10 @@ pub trait Testable<'a> {
/// This trait indicates that something forms a group of tests.
/// Test groups are used to group tests in sensible manner as well as provide namespacing to tests
pub trait TestableGroup<'a> {
fn get_name(&self) -> &'a str;
fn run_all(&'a self) -> Vec<(&'a str, TestResult)>;
fn run_selected(&'a self, selected: &[&str]) -> Vec<(&'a str, TestResult)>;
pub trait TestableGroup {
fn get_name(&self) -> &'static str;
fn run_all(&self) -> Vec<(&'static str, TestResult)>;
fn run_selected(&self, selected: &[&str]) -> Vec<(&'static str, TestResult)>;
}
#[macro_export]