From a024dea3e514b73863d4e89a303c4f60aeeb104f Mon Sep 17 00:00:00 2001 From: Edjunior Machado Date: Mon, 4 Oct 2021 14:38:18 +0200 Subject: [PATCH] Introduce CI gating #2 --- .fmf/version | 1 + gating.yaml | 19 ++++++ plans/ci.fmf | 6 ++ tests/Sanity/basic-test/Makefile | 63 ++++++++++++++++++++ tests/Sanity/basic-test/PURPOSE | 3 + tests/Sanity/basic-test/hello.cpp | 92 ++++++++++++++++++++++++++++++ tests/Sanity/basic-test/main.fmf | 14 +++++ tests/Sanity/basic-test/runtest.sh | 56 ++++++++++++++++++ 8 files changed, 254 insertions(+) create mode 100644 .fmf/version create mode 100644 gating.yaml create mode 100644 plans/ci.fmf create mode 100644 tests/Sanity/basic-test/Makefile create mode 100644 tests/Sanity/basic-test/PURPOSE create mode 100644 tests/Sanity/basic-test/hello.cpp create mode 100644 tests/Sanity/basic-test/main.fmf create mode 100755 tests/Sanity/basic-test/runtest.sh 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/gating.yaml b/gating.yaml new file mode 100644 index 0000000..ce3cdc1 --- /dev/null +++ b/gating.yaml @@ -0,0 +1,19 @@ +--- !Policy +product_versions: + - fedora-* +decision_context: bodhi_update_push_stable +subject_type: koji_build +rules: + - !PassingTestCaseRule {test_case_name: fedora-ci.koji-build.tier0.functional} +--- !Policy +product_versions: + - rhel-8 +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: baseos-ci.brew-build.tier1.functional} +--- !Policy +product_versions: + - rhel-9 +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: baseos-ci.brew-build.tier1.functional} diff --git a/plans/ci.fmf b/plans/ci.fmf new file mode 100644 index 0000000..1ad2c12 --- /dev/null +++ b/plans/ci.fmf @@ -0,0 +1,6 @@ +summary: CI Gating Plan +discover: + how: fmf + directory: tests +execute: + how: beakerlib diff --git a/tests/Sanity/basic-test/Makefile b/tests/Sanity/basic-test/Makefile new file mode 100644 index 0000000..7575c1a --- /dev/null +++ b/tests/Sanity/basic-test/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/cppunit/Sanity/basic-test +# Description: cppunit basic test +# Author: Edjunior Machado +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/tools/cppunit/Sanity/basic-test +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE hello.cpp + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Edjunior Machado " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: cppunit basic test" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 1h" >> $(METADATA) + @echo "RunFor: cppunit" >> $(METADATA) + @echo "Requires: gcc-c++ cppunit cppunit-devel" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -RHEL4 -RHELClient5 -RHELServer5" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Sanity/basic-test/PURPOSE b/tests/Sanity/basic-test/PURPOSE new file mode 100644 index 0000000..82f79dd --- /dev/null +++ b/tests/Sanity/basic-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /tools/cppunit/Sanity/basic-test +Description: cppunit basic test +Author: Edjunior Machado diff --git a/tests/Sanity/basic-test/hello.cpp b/tests/Sanity/basic-test/hello.cpp new file mode 100644 index 0000000..51fdecd --- /dev/null +++ b/tests/Sanity/basic-test/hello.cpp @@ -0,0 +1,92 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Math +{ +public: + int Addition (int x, int y); +}; + +int +Math::Addition (int x, int y) +{ + return (x + y); +} + +class Test:public + CPPUNIT_NS::TestCase +{ + CPPUNIT_TEST_SUITE (Test); + CPPUNIT_TEST (testAddition); + CPPUNIT_TEST_SUITE_END (); + +public: + void + setUp (void); + void + tearDown (void); + +protected: + void + testAddition (void); + +private: + Math * + mTestObj; +}; + +void +Test::testAddition (void) +{ + CPPUNIT_ASSERT (5 == mTestObj->Addition (2, 3)); +} + +void +Test::setUp (void) +{ + mTestObj = new Math (); +} + +void +Test::tearDown (void) +{ + delete mTestObj; +} + +CPPUNIT_TEST_SUITE_REGISTRATION (Test); + +int +main (int ac, char **av) +{ + CPPUNIT_NS::TestResult controller; + + CPPUNIT_NS::TestResultCollector result; + controller.addListener (&result); + + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener (&progress); + + CPPUNIT_NS::TestRunner runner; + runner. + addTest (CPPUNIT_NS::TestFactoryRegistry::getRegistry ().makeTest ()); + runner.run (controller); + + CPPUNIT_NS::CompilerOutputter compileroutputter (&result, std::cerr); + compileroutputter.write (); + + ofstream xmlFileOut ("output.xml"); + CPPUNIT_NS::XmlOutputter xmlOut (&result, xmlFileOut); + xmlOut.write (); + + return result.wasSuccessful ()? 0 : 1; +} diff --git a/tests/Sanity/basic-test/main.fmf b/tests/Sanity/basic-test/main.fmf new file mode 100644 index 0000000..0c92a73 --- /dev/null +++ b/tests/Sanity/basic-test/main.fmf @@ -0,0 +1,14 @@ +summary: cppunit basic test +description: '' +contact: Edjunior Machado +component: + - cppunit +test: ./runtest.sh +framework: beakerlib +recommend: + - gcc-c++ + - cppunit + - cppunit-devel +duration: 1h +extra-summary: /tools/cppunit/Sanity/basic-test +extra-task: /tools/cppunit/Sanity/basic-test diff --git a/tests/Sanity/basic-test/runtest.sh b/tests/Sanity/basic-test/runtest.sh new file mode 100755 index 0000000..4d9e0aa --- /dev/null +++ b/tests/Sanity/basic-test/runtest.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/cppunit/Sanity/basic-test +# Description: cppunit basic test +# Author: Edjunior Machado +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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 + +PACKAGE="cppunit" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp hello.cpp $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "g++ -Wall -o hello hello.cpp -lcppunit" + rlAssertExists "hello" + rlRun "./hello > hello.log" + rlRun "cat hello.log" + rlAssertGrep 'Test::testAddition : OK' hello.log + rlRun "cat output.xml" + rlAssertGrep 'Test::testAddition' output.xml + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd