Commit 56ede834 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

ptest: Use github workflow instead of travis



Now that the travis description is empty, ptest no longer runs any
tests.  Change it to use the github workflow description.  It is still
fairly specific to our particular workflow, and will need to be updated
if the form of what is there changes.

The workflow description is quite a bit simpler, so a bunch of code has
been removed.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 94c177da
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -235,7 +235,6 @@ dependencies = [
 "failure",
 "log",
 "num_cpus",
 "regex",
 "std-semaphore",
 "yaml-rust",
]
+0 −1
Original line number Diff line number Diff line
@@ -10,6 +10,5 @@ env_logger = "0.6.0"
failure = "0.1.5"
log = "0.4.6"
num_cpus = "1.9"
regex = "1.1"
std-semaphore = "0.1"
yaml-rust = "0.4"
+58 −74
Original line number Diff line number Diff line
@@ -3,14 +3,15 @@
//! mcuboot simulator is strictly single threaded, as there is a lock around running the C startup
//! code, because it contains numerous global variables.
//!
//! To help speed up testing, the Travis configuration defines all of the configurations that can
//! To help speed up testing, the Workflow configuration defines all of the configurations that can
//! be run in parallel.  Fortunately, cargo works well this way, and these can be run by simply
//! using subprocess for each particular thread.
//!
//! For now, we assume all of the features are listed under
//! jobs->environment->strategy->matric->features

use chrono::Local;
use failure::format_err;
use log::{debug, error, warn};
use regex::Regex;
use std::{
    collections::HashSet,
    fs::{self, OpenOptions},
@@ -35,13 +36,13 @@ type Result<T> = result::Result<T, failure::Error>;
fn main() -> Result<()> {
    env_logger::init();

    let travis_text = fs::read_to_string("../.travis.yml")?;
    let travis = YamlLoader::load_from_str(&travis_text)?;
    let workflow_text = fs::read_to_string("../.github/workflows/sim.yaml")?;
    let workflow = YamlLoader::load_from_str(&workflow_text)?;

    let ncpus = num_cpus::get();
    let limiter = Arc::new(Semaphore::new(ncpus as isize));

    let matrix = Matrix::from_yaml(&travis)?;
    let matrix = Matrix::from_yaml(&workflow)?;

    let mut children = vec![];
    let state = State::new(matrix.envs.len());
@@ -153,7 +154,7 @@ impl State {
    }
}

/// The extracted configurations from the travis config
/// The extracted configurations from the workflow config
#[derive(Debug)]
struct Matrix {
    envs: Vec<FeatureSet>,
@@ -179,25 +180,23 @@ impl Matrix {
                None => continue,
            };
            for elt in m {
                if lookup_os(elt) == Some("linux") {
                    debug!("yaml: {:?}", lookup_env(elt));
                    let env = match lookup_env(elt) {
                        Some (env) => env,
                        None => continue,
                let elt = match elt.as_str() {
                    None => {
                        warn!("Unexpected yaml: {:?}", elt);
                        continue;
                    }
                    Some(e) => e,
                };

                    // Skip features not targeted to this build.
                    let fset = match FeatureSet::decode(env) {
                let fset = match FeatureSet::decode(elt) {
                    Ok(fset) => fset,
                    Err(err) => {
                        warn!("Skipping: {:?}", err);
                        continue;
                    }
                };
                    debug!("fset: {:?}", fset);

                if false {
                        // Respect the groupings in the `.travis.yml` file.
                    // Respect the groupings in the `.workflow.yml` file.
                    envs.push(fset);
                } else {
                    // Break each test up so we can run more in
@@ -217,7 +216,6 @@ impl Matrix {
                }
            }
        }
        }

        Ok(Matrix {
            envs: envs,
@@ -227,27 +225,16 @@ impl Matrix {

impl FeatureSet {
    fn decode(text: &str) -> Result<FeatureSet> {
        // This is not general environment settings, but specific to the
        // travis file.
        let re = Regex::new(r#"^([A-Z_]+)="(.*)" TEST=sim$"#)?;

        match re.captures(text) {
            None => Err(format_err!("Invalid line: {:?}", text)),
            Some(cap) => {
                let ename = &cap[1];
                let sep = if ename == "SINGLE_FEATURES" { ' ' } else { ',' };
                let values: Vec<_> = cap[2]
                    .split(sep)
        // The github workflow is just a space separated set of values.
        let values: Vec<_> = text
            .split(',')
            .map(|s| s.to_string())
            .collect();
                debug!("name={:?} values={:?}", ename, values);
        Ok(FeatureSet {
                    env: ename.to_string(),
            env: "MULTI_FEATURES".to_string(),
            values: values,
        })
    }
        }
    }

    /// Run a test for this given feature set.  Output is captured and will be returned if there is
    /// an error.  Each will be run successively, and the first failure will be returned.
@@ -282,19 +269,16 @@ impl FeatureSet {
}

fn lookup_matrix(y: &Yaml) -> Option<&Vec<Yaml>> {
    let jobs = Yaml::String("jobs".to_string());
    let environment = Yaml::String("environment".to_string());
    let strategy = Yaml::String("strategy".to_string());
    let matrix = Yaml::String("matrix".to_string());
    let include = Yaml::String("include".to_string());
    y.as_hash()?.get(&matrix)?.as_hash()?.get(&include)?.as_vec()
}

fn lookup_os(y: &Yaml) -> Option<&str> {
    let os = Yaml::String("os".to_string());

    y.as_hash()?.get(&os)?.as_str()
}

fn lookup_env(y: &Yaml) -> Option<&str> {
    let env = Yaml::String("env".to_string());

    y.as_hash()?.get(&env)?.as_str()
    let features = Yaml::String("features".to_string());
    y
        .as_hash()?.get(&jobs)?
        .as_hash()?.get(&environment)?
        .as_hash()?.get(&strategy)?
        .as_hash()?.get(&matrix)?
        .as_hash()?.get(&features)?
        .as_vec()
}