diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/Sanity/basic-smoke/main.fmf b/tests/Sanity/basic-smoke/main.fmf new file mode 100644 index 0000000..571d093 --- /dev/null +++ b/tests/Sanity/basic-smoke/main.fmf @@ -0,0 +1,5 @@ +summary: basic-smoke +description: 'Compile a basic rust program with rustc and check it runs' +duration: 10m +extra-summary: /tools/rust/Sanity/basic-smoke +extra-task: /tools/rust/Sanity/basic-smoke diff --git a/tests/Sanity/basic-smoke/runtest.sh b/tests/Sanity/basic-smoke/runtest.sh new file mode 100755 index 0000000..ed25e86 --- /dev/null +++ b/tests/Sanity/basic-smoke/runtest.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/rust/Sanity/basic-smoke +# Description: basic-smoke +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="$(rpm -qf $(which rustc))" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + HELLO_SRC=$( mktemp ) + HELLO_BIN=$( mktemp ) + echo 'fn main() { println!("hello"); }' > $HELLO_SRC + rlRun "which rustc" + rlRun "rustc -V" + rlRun "rustc -o $HELLO_BIN $HELLO_SRC" + rlRun "$HELLO_BIN" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Sanity/rpm-rebuild/librsvg2.fmf b/tests/Sanity/rpm-rebuild/librsvg2.fmf new file mode 100644 index 0000000..35e4df4 --- /dev/null +++ b/tests/Sanity/rpm-rebuild/librsvg2.fmf @@ -0,0 +1,11 @@ +summary+: ": librsvg2" +require+: + - librsvg2 +environment+: + PKG_TO_BUILD: "librsvg2" +duration: 20m + +adjust+: + # building librsvg2 in Fedora is very flaky. Do not run it there + - when: distro == fedora + enabled: false diff --git a/tests/Sanity/rpm-rebuild/main.fmf b/tests/Sanity/rpm-rebuild/main.fmf new file mode 100644 index 0000000..47b7a61 --- /dev/null +++ b/tests/Sanity/rpm-rebuild/main.fmf @@ -0,0 +1,6 @@ +summary: rpmbuild package with rust +description: 'Ensure that rust does not break rpmbuild' +require+: + - rpm-build + - yum-utils +duration: 1h diff --git a/tests/Sanity/rpm-rebuild/ripgrep.fmf b/tests/Sanity/rpm-rebuild/ripgrep.fmf new file mode 100644 index 0000000..9cb533c --- /dev/null +++ b/tests/Sanity/rpm-rebuild/ripgrep.fmf @@ -0,0 +1,11 @@ +summary+: ": ripgrep" +require+: + - ripgrep +environment+: + PKG_TO_BUILD: "ripgrep" +duration: 15m + +adjust+: + # ripgrep is not part of RHEL + - when: distro != fedora + enabled: false diff --git a/tests/Sanity/rpm-rebuild/rpm-sequoia.fmf b/tests/Sanity/rpm-rebuild/rpm-sequoia.fmf new file mode 100644 index 0000000..c70d7a8 --- /dev/null +++ b/tests/Sanity/rpm-rebuild/rpm-sequoia.fmf @@ -0,0 +1,11 @@ +summary+: ": rpm-sequoia" +require+: + - rpm-sequoia +environment+: + PKG_TO_BUILD: "rpm-sequoia" +duration: 90m + +adjust+: + - when: distro < rhel-10, centos-stream-10 + enabled: false + because: "rpm-sequoia is available only in RHEL >= 10" diff --git a/tests/Sanity/rpm-rebuild/runtest.sh b/tests/Sanity/rpm-rebuild/runtest.sh new file mode 100755 index 0000000..475d2f9 --- /dev/null +++ b/tests/Sanity/rpm-rebuild/runtest.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="$(rpm -qf $(which rustc))" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE || rlDie "rustc not found. Aborting testcase..." + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + + if [[ "x" == "x${PKG_TO_BUILD}" ]]; then + rlLogError "No package was configured to build." + rlDie "The package must be passed over PKG_TO_BUILD environment variable." + fi + + rlPhaseEnd + + rlPhaseStart FAIL ${PKG_TO_BUILD}FetchSrcAndInstallBuildDeps + if ! rlCheckRpm $PKG_TO_BUILD; then + rlRun "yum install -y $PKG_TO_BUILD ${YUM_SWITCHES}" + rlAssertRpm $PKG_TO_BUILD + fi + rlFetchSrcForInstalled $PKG_TO_BUILD + rlRun SRPM=$(ls -1 *.src.rpm) + rlRun "rpm -ivh $SRPM" + rlRun SPECDIR="$(rpm -E '%{_specdir}')" + # Note about the spec file name: When packaging rust crates, the package + # is named rust-, as well as the spec file, but the rpm package + # (the one we use in dnf to install and query) is named as the crate, + # (without the "rust-" prefix). We have to take that into account to + # find the spec: + # https://docs.fedoraproject.org/en-US/packaging-guidelines/Rust/#_package_naming + rlRun "SPECNAME=$(rpm -ql $SRPM | grep .spec)" + + # Packages built with rust usually contains dynamic dependencies. + # builddep needs to be run from the srpm, not the spec file, to be able + # to generate them: + # https://fedoraproject.org/wiki/Changes/DynamicBuildRequires#rpmbuild + rlRun "yum-builddep -y ${SRPM} ${YUM_SWITCHES}" + rlPhaseEnd + + rlPhaseStartTest + set -o pipefail + rlRun "rpmbuild -bb ${SPECDIR}/${SPECNAME} |& tee ${SRPM}_rpmbuild.log" + rlFileSubmit "${SRPM}_rpmbuild.log" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Sanity/rpm-rebuild/stratisd.fmf b/tests/Sanity/rpm-rebuild/stratisd.fmf new file mode 100644 index 0000000..64cce60 --- /dev/null +++ b/tests/Sanity/rpm-rebuild/stratisd.fmf @@ -0,0 +1,6 @@ +summary+: ": stratisd" +require+: + - stratisd +environment+: + PKG_TO_BUILD: "stratisd" +duration: 1h diff --git a/tests/Sanity/rust-wasm-smoke-test/lib.rs b/tests/Sanity/rust-wasm-smoke-test/lib.rs new file mode 100644 index 0000000..36e7457 --- /dev/null +++ b/tests/Sanity/rust-wasm-smoke-test/lib.rs @@ -0,0 +1,12 @@ +#[no_mangle] +pub fn fib(index: u32) -> u32 { + let mut nminus2; + let mut nminus1 = 1; + let mut n = 0; + for _ in 0..index { + nminus2 = nminus1; + nminus1 = n; + n = nminus2 + nminus1; + } + n +} diff --git a/tests/Sanity/rust-wasm-smoke-test/main.fmf b/tests/Sanity/rust-wasm-smoke-test/main.fmf new file mode 100644 index 0000000..47ca3f1 --- /dev/null +++ b/tests/Sanity/rust-wasm-smoke-test/main.fmf @@ -0,0 +1,9 @@ +summary: Test that the rust wasm target is enabled and can compile correctly +description: '' +require+: + - rust + - rust-std-static-wasm32-unknown-unknown + - nodejs +duration: 5m +extra-summary: /tools/rust/Sanity/rust-wasm-smoke-test +extra-task: /tools/rust/Sanity/rust-wasm-smoke-test diff --git a/tests/Sanity/rust-wasm-smoke-test/runtest.sh b/tests/Sanity/rust-wasm-smoke-test/runtest.sh new file mode 100755 index 0000000..7f325c2 --- /dev/null +++ b/tests/Sanity/rust-wasm-smoke-test/runtest.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/rust/Sanity/rust-wasm-smoke-test +# Description: Test that the rust wasm target is enabled and can compile correctly +# Author: Jesus Checa +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2021 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGES="$(rpm -qf $(which rustc)) rust-std-static-wasm32-unknown-unknown" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm --all + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp lib.rs $TmpDir" + rlRun "cp test.js $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "rustc --target wasm32-unknown-unknown --crate-type=cdylib lib.rs -o fib.wasm" 0 "Building WASM binary" + rlRun "node test.js" 0 "Testing WASM binary" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Sanity/rust-wasm-smoke-test/test.js b/tests/Sanity/rust-wasm-smoke-test/test.js new file mode 100644 index 0000000..921df38 --- /dev/null +++ b/tests/Sanity/rust-wasm-smoke-test/test.js @@ -0,0 +1,28 @@ +function js_fibonacci(index) { + let nminus2 = 0; + let nminus1 = 1; + let n = 0; + for(let i = 0; i < index; ++i) { + nminus2 = nminus1; + nminus1 = n; + n = nminus1 + nminus2; + } + return n; +} + +const fs = require('fs'); +const buf = fs.readFileSync('./fib.wasm'); +const lib = WebAssembly.instantiate(new Uint8Array(buf)). + then(res => { + var fib = res.instance.exports.fib; + for (var i=1; i<=10; i++) { + if(fib(i) != js_fibonacci(i)){ + console.log("Mismatch between wasm and JS functions"); + process.exit(1); + } + } + }).catch(e => { + console.log(e); + process.exit(1); + } +); diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..402232a --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,47 @@ +# Common configuration for all the tests in this repo +component: + - rust +# Default contact. If more are relevant use contact+: in each test metadata. +contact: + - Jesus Checa Hidalgo + +# All tests use beakerlib by default. If a shell test is needed for some reason +# this key can be overriden in the specific test metadata. +framework: beakerlib + +# Always define test key and override in adjust or in each specific test +# metadata if needed. +test: ./runtest.sh +adjust+: + # Non-SCL requirements + - require+: + - rust + - cargo + environment+: + PACKAGES: 'rust cargo' + when: collection is not defined + + # DevTools SCL requirements + - when: collection is defined and collection = rust-toolset-1.58 + require+: + - rust-toolset-1.58-rust + - rust-toolset-1.58-cargo + environment+: + PACKAGES: rust-toolset-1.58-rust rust-toolset-1.58-cargo + test: scl enable rust-toolset-1.58 -- ./runtest.sh + + - when: collection = rust-toolset-1.62 + require+: + - rust-toolset-1.62-rust + - rust-toolset-1.62-cargo + environment+: + PACKAGES: rust-toolset-1.62-rust rust-toolset-1.62-cargo + test: scl enable rust-toolset-1.62 -- ./runtest.sh + + - when: collection is defined and collection = rust-toolset-1.66 + require+: + - rust-toolset-1.66-rust + - rust-toolset-1.66-cargo + environment+: + PACKAGES: rust-toolset-1.66-rust rust-toolset-1.66-cargo + test: scl enable rust-toolset-1.66 -- ./runtest.sh