From 8a8070ad74c0fa674f7f2b20a782284f6b69e752 Mon Sep 17 00:00:00 2001 From: Edjunior Machado Date: Mon, 18 Jan 2021 22:11:55 +0100 Subject: [PATCH] Introduce CI gating --- .fmf/version | 1 + gating.yaml | 19 +++++ plans/ci.fmf | 6 ++ tests/Sanity/smoke-check-flex-runs/Makefile | 63 +++++++++++++++ tests/Sanity/smoke-check-flex-runs/PURPOSE | 3 + .../smoke-check-flex-runs/calc-grammar.y | 36 +++++++++ .../Sanity/smoke-check-flex-runs/calc-lexer.l | 15 ++++ .../count_chars_and_lines.l | 21 +++++ .../expected_calc_output.txt | 3 + tests/Sanity/smoke-check-flex-runs/main.fmf | 15 ++++ tests/Sanity/smoke-check-flex-runs/runtest.sh | 78 +++++++++++++++++++ 11 files changed, 260 insertions(+) create mode 100644 .fmf/version create mode 100644 gating.yaml create mode 100644 plans/ci.fmf create mode 100644 tests/Sanity/smoke-check-flex-runs/Makefile create mode 100644 tests/Sanity/smoke-check-flex-runs/PURPOSE create mode 100644 tests/Sanity/smoke-check-flex-runs/calc-grammar.y create mode 100644 tests/Sanity/smoke-check-flex-runs/calc-lexer.l create mode 100644 tests/Sanity/smoke-check-flex-runs/count_chars_and_lines.l create mode 100644 tests/Sanity/smoke-check-flex-runs/expected_calc_output.txt create mode 100644 tests/Sanity/smoke-check-flex-runs/main.fmf create mode 100755 tests/Sanity/smoke-check-flex-runs/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/smoke-check-flex-runs/Makefile b/tests/Sanity/smoke-check-flex-runs/Makefile new file mode 100644 index 0000000..3abe871 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/flex/Sanity/smoke-check-flex-runs +# Description: Show your version. Build a one-file project. +# Author: Vaclav Kadlcik +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 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/flex/Sanity/smoke-check-flex-runs +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE count_chars_and_lines.l calc-lexer.l calc-grammar.y expected_calc_output.txt + +.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: Vaclav Kadlcik " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Show your version. Build a one-file project." >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: flex" >> $(METADATA) + @echo "Requires: flex bison gcc" >> $(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/smoke-check-flex-runs/PURPOSE b/tests/Sanity/smoke-check-flex-runs/PURPOSE new file mode 100644 index 0000000..ed0f21f --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /tools/flex/Sanity/smoke-check-flex-runs +Description: Show your version. Build a one-file project. +Author: Vaclav Kadlcik diff --git a/tests/Sanity/smoke-check-flex-runs/calc-grammar.y b/tests/Sanity/smoke-check-flex-runs/calc-grammar.y new file mode 100644 index 0000000..53d4a85 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/calc-grammar.y @@ -0,0 +1,36 @@ +%{ +#include +%} + +%token NUMBER +%token ADD SUB MUL DIV +%token EOL + +%% + +input: + | input EOL { } + | input expression EOL { printf("%d\n", $2); } + ; + +expression: + factor + | expression ADD factor { $$ = $1 + $3; } + | expression SUB factor { $$ = $1 - $3; } + ; + +factor: + NUMBER + | factor MUL NUMBER { $$ = $1 * $3; } + | factor DIV NUMBER { $$ = $1 / $3; } + ; + +%% + +int main(int argc, char ** argv) { + yyparse(); +} + +yyerror(char *s) { + fprintf(stderr, "ERROR: %s\n", s); +} diff --git a/tests/Sanity/smoke-check-flex-runs/calc-lexer.l b/tests/Sanity/smoke-check-flex-runs/calc-lexer.l new file mode 100644 index 0000000..fa9ac41 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/calc-lexer.l @@ -0,0 +1,15 @@ +%option noyywrap +%{ +#include "calc-grammar.tab.h" +%} + +%% +"+" { return ADD; } +"-" { return SUB; } +"*" { return MUL; } +"/" { return DIV; } +[0-9]+ { yylval = atoi(yytext); return NUMBER; } +\n { return EOL; } +[ \t] { /* ignore whitespaces */ } +. { yyerror("unexpected character %c", *yytext); } +%% diff --git a/tests/Sanity/smoke-check-flex-runs/count_chars_and_lines.l b/tests/Sanity/smoke-check-flex-runs/count_chars_and_lines.l new file mode 100644 index 0000000..7b90045 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/count_chars_and_lines.l @@ -0,0 +1,21 @@ +%option noyywrap +%{ +#include + +int chars = 0; +int lines = 0; +%} + +%% + +\n { lines++; chars++; } +. { chars++; } + +%% + +int main(int argc, char ** argv) { + yylex(); + printf("chars: %d\n", chars); + printf("lines: %d\n", lines); + return 0; +} diff --git a/tests/Sanity/smoke-check-flex-runs/expected_calc_output.txt b/tests/Sanity/smoke-check-flex-runs/expected_calc_output.txt new file mode 100644 index 0000000..7baa841 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/expected_calc_output.txt @@ -0,0 +1,3 @@ +STDOUT: 7 +STDOUT: -221 +STDOUT: 42 diff --git a/tests/Sanity/smoke-check-flex-runs/main.fmf b/tests/Sanity/smoke-check-flex-runs/main.fmf new file mode 100644 index 0000000..2b25e69 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/main.fmf @@ -0,0 +1,15 @@ +summary: Show your version. Build a one-file project. +description: '' +contact: +- Vaclav Kadlcik +component: +- flex +test: ./runtest.sh +framework: beakerlib +recommend: +- flex +- bison +- gcc +duration: 15m +extra-summary: /tools/flex/Sanity/smoke-check-flex-runs +extra-task: /tools/flex/Sanity/smoke-check-flex-runs diff --git a/tests/Sanity/smoke-check-flex-runs/runtest.sh b/tests/Sanity/smoke-check-flex-runs/runtest.sh new file mode 100755 index 0000000..68ee8a3 --- /dev/null +++ b/tests/Sanity/smoke-check-flex-runs/runtest.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/flex/Sanity/smoke-check-flex-runs +# Description: Show your version. Build a one-file project. +# Author: Vaclav Kadlcik +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 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="flex" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + yum -y install bison gcc + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp count_chars_and_lines.l calc-lexer.l calc-grammar.y expected_calc_output.txt $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest 'Show version' + + rlRun -t -s 'flex -V' + rlAssertNotGrep '^STDERR:' $rlRun_LOG + rlAssertGrep '^STDOUT: flex [0-9]' $rlRun_LOG + + rlPhaseEnd + + rlPhaseStartTest 'Flex works standalone' + + rlRun 'flex -o count_chars_and_lines.c count_chars_and_lines.l' + rlRun 'gcc -o count_chars_and_lines count_chars_and_lines.c' + rlAssertExists 'count_chars_and_lines' + rlRun -t -s 'echo -e "nazdar\nbazar" | ./count_chars_and_lines' + rlAssertNotGrep '^STDERR:' $rlRun_LOG + rlAssertGrep '^STDOUT: chars: 13$' $rlRun_LOG + rlAssertGrep '^STDOUT: lines: 2$' $rlRun_LOG + + rlPhaseEnd + + rlPhaseStartTest 'Flex works with Bison' + + rlRun 'bison -d calc-grammar.y' + rlRun 'flex calc-lexer.l' + rlRun 'gcc -o calc calc-grammar.tab.c lex.yy.c' + rlAssertExists 'calc' + rlRun -t -s 'echo -e "1 + 2 * 3\n1 - 666 / 3\n42" | ./calc' + rlAssertNotDiffer expected_calc_output.txt $rlRun_LOG + + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd