Bring tests from rpms/rust repo
This commit is contained in:
parent
f7c54f0ee5
commit
ca2e0129ee
14 changed files with 309 additions and 0 deletions
1
.fmf/version
Normal file
1
.fmf/version
Normal file
|
|
@ -0,0 +1 @@
|
|||
1
|
||||
5
tests/Sanity/basic-smoke/main.fmf
Normal file
5
tests/Sanity/basic-smoke/main.fmf
Normal file
|
|
@ -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
|
||||
55
tests/Sanity/basic-smoke/runtest.sh
Executable file
55
tests/Sanity/basic-smoke/runtest.sh
Executable file
|
|
@ -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 <mcermak@redhat.com>
|
||||
#
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# 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
|
||||
11
tests/Sanity/rpm-rebuild/librsvg2.fmf
Normal file
11
tests/Sanity/rpm-rebuild/librsvg2.fmf
Normal file
|
|
@ -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
|
||||
6
tests/Sanity/rpm-rebuild/main.fmf
Normal file
6
tests/Sanity/rpm-rebuild/main.fmf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
summary: rpmbuild package with rust
|
||||
description: 'Ensure that rust does not break rpmbuild'
|
||||
require+:
|
||||
- rpm-build
|
||||
- yum-utils
|
||||
duration: 1h
|
||||
11
tests/Sanity/rpm-rebuild/ripgrep.fmf
Normal file
11
tests/Sanity/rpm-rebuild/ripgrep.fmf
Normal file
|
|
@ -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
|
||||
11
tests/Sanity/rpm-rebuild/rpm-sequoia.fmf
Normal file
11
tests/Sanity/rpm-rebuild/rpm-sequoia.fmf
Normal file
|
|
@ -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"
|
||||
55
tests/Sanity/rpm-rebuild/runtest.sh
Executable file
55
tests/Sanity/rpm-rebuild/runtest.sh
Executable file
|
|
@ -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-<crate>, 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
|
||||
6
tests/Sanity/rpm-rebuild/stratisd.fmf
Normal file
6
tests/Sanity/rpm-rebuild/stratisd.fmf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
summary+: ": stratisd"
|
||||
require+:
|
||||
- stratisd
|
||||
environment+:
|
||||
PKG_TO_BUILD: "stratisd"
|
||||
duration: 1h
|
||||
12
tests/Sanity/rust-wasm-smoke-test/lib.rs
Normal file
12
tests/Sanity/rust-wasm-smoke-test/lib.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
9
tests/Sanity/rust-wasm-smoke-test/main.fmf
Normal file
9
tests/Sanity/rust-wasm-smoke-test/main.fmf
Normal file
|
|
@ -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
|
||||
52
tests/Sanity/rust-wasm-smoke-test/runtest.sh
Executable file
52
tests/Sanity/rust-wasm-smoke-test/runtest.sh
Executable file
|
|
@ -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 <jcheca@redhat.com>
|
||||
#
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# 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
|
||||
28
tests/Sanity/rust-wasm-smoke-test/test.js
Normal file
28
tests/Sanity/rust-wasm-smoke-test/test.js
Normal file
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
47
tests/main.fmf
Normal file
47
tests/main.fmf
Normal file
|
|
@ -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 <jchecahi@redhat.com>
|
||||
|
||||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue