From 53016a005bd95c8bcba08544faecd9a6208534b3 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Sun, 16 Oct 2022 20:40:44 +0200 Subject: [PATCH] add test for many features and fix issue compiling tor-rtcompat with on ssl runtime --- .gitlab-ci.yml | 2 + crates/tor-rtcompat/src/lib.rs | 4 +- maint/matrix_test | 98 ++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100755 maint/matrix_test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 57b3930bc..710acde29 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,6 +42,7 @@ rust-checks: stage: build image: rust:latest script: + - apt-get update && apt-get install -y python3-toml python-is-python3 - rustup show - rustup component add rustfmt - ./maint/via-cargo-install-in-ci cargo-audit cargo-sort cargo-license @@ -50,6 +51,7 @@ rust-checks: - ./maint/cargo_audit - ./maint/cargo_sort - ./maint/check_tree + - ./maint/matrix_test cache: paths: - cargo-audit diff --git a/crates/tor-rtcompat/src/lib.rs b/crates/tor-rtcompat/src/lib.rs index f30d2a9eb..35347eabc 100644 --- a/crates/tor-rtcompat/src/lib.rs +++ b/crates/tor-rtcompat/src/lib.rs @@ -63,9 +63,9 @@ pub use timer::{SleepProviderExt, Timeout, TimeoutError}; pub mod tls { pub use crate::traits::{CertifiedConn, TlsConnector}; - #[cfg(feature = "native-tls")] + #[cfg(all(feature = "native-tls", any(feature = "tokio", feature = "async-std")))] pub use crate::impls::native_tls::NativeTlsProvider; - #[cfg(feature = "rustls")] + #[cfg(all(feature = "rustls", any(feature = "tokio", feature = "async-std")))] pub use crate::impls::rustls::RustlsProvider; } diff --git a/maint/matrix_test b/maint/matrix_test new file mode 100755 index 000000000..2dd1aa5e5 --- /dev/null +++ b/maint/matrix_test @@ -0,0 +1,98 @@ +#!/usr/bin/python3 + +import toml.decoder +import sys +import os.path +import os +import list_crates +from subprocess import run + +TOPDIR = os.path.split(os.path.dirname(sys.argv[0]))[0] +os.chdir(TOPDIR) +CRATEDIR = os.path.join(TOPDIR, 'crates') + +# some tests don't compile on every combination 😐 +# also test is way slower than check +KEYWORD = "check" + +supplementary_targets = dict() + +def combination(*args): + res = None + for featureset in args: + powerset = [[]] + for feature in featureset: + powerset.extend([combination + [feature] for combination in powerset]) + # remove empty set + powerset.pop(0) + if res is None: + res = powerset + else: + new_res = [] + for prev_feat in res: + for new_feat in powerset: + new_res.append(prev_feat + new_feat) + res = new_res + return res + +supplementary_targets["tor-rtcompat"] = combination(["async-std", "tokio", "native-tls", "rustls"]) +supplementary_targets["arti-client"] = combination(["async-std", "tokio", "native-tls", "rustls"]) +supplementary_targets["arti"] = combination(["async-std", "tokio"], ["native-tls", "rustls"]) + +def take(dic, key): + if key in dic: + res = dic.get(key) + del(dic[key]) + return res + return None + +def test_crate_config(crate, features, allow_empty=False): + if features is None: + return + if len(features) == 0 and not allow_empty: + return + features = ",".join(features) + args = ["cargo", KEYWORD, "-p", crate, "--no-default-features", "--features", features] + p = run(args) + if p.returncode != 0: + raise Exception("Failed to test '" + crate + "' with features '" + features + "'") + +def test_crate(crate): + if crate in ['fs-mistrust', 'tor-config']: + # these tests do not pass as of now. Skipping them. + return + + crate_path = os.path.join(CRATEDIR, crate) + toml_path = os.path.join(crate_path, 'Cargo.toml') + t = toml.decoder.load(toml_path) + features = t.get('features') or {} + + # remove testing features, it makes little sens to test them + take(features, 'testing') + + default = sorted(take(features, 'default') or []) + full = sorted(take(features, 'full') or []) + all_features = sorted([feat for feat in features.keys()]) + + # no features; don't test if it would already be tested by normal tests + if len(features) != 0: + # arti does not work: it requires an executor + if not crate in ['arti']: + test_crate_config(crate, [], True) + # default + test_crate_config(crate, default) + # full + test_crate_config(crate, full) + # all + test_crate_config(crate, all_features) + + for combination in supplementary_targets.get(crate, []): + test_crate_config(crate, combination) + # TODO test random combination? + +def main(): + for crate in list_crates.crate_list(): + test_crate(crate) + +if __name__ == '__main__': + main()