From 3f29806bc260dffbd5001680ee9d08ce9085ea90 Mon Sep 17 00:00:00 2001 From: Edjunior Machado Date: Tue, 15 Aug 2023 12:32:27 +0200 Subject: [PATCH] Add plans/ci.fmf and testcase Sanity/basic-smoke --- .fmf/version | 1 + Sanity/basic-smoke/Makefile | 64 ++++++++++++++++++ Sanity/basic-smoke/PURPOSE | 3 + Sanity/basic-smoke/hello.go | 13 ++++ Sanity/basic-smoke/init.txt | 9 +++ Sanity/basic-smoke/main.fmf | 34 ++++++++++ Sanity/basic-smoke/runtest.sh | 120 ++++++++++++++++++++++++++++++++++ Sanity/basic-smoke/script.exp | 81 +++++++++++++++++++++++ plans/ci.fmf | 5 ++ 9 files changed, 330 insertions(+) create mode 100644 .fmf/version create mode 100644 Sanity/basic-smoke/Makefile create mode 100644 Sanity/basic-smoke/PURPOSE create mode 100644 Sanity/basic-smoke/hello.go create mode 100644 Sanity/basic-smoke/init.txt create mode 100644 Sanity/basic-smoke/main.fmf create mode 100755 Sanity/basic-smoke/runtest.sh create mode 100644 Sanity/basic-smoke/script.exp create mode 100644 plans/ci.fmf 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/Sanity/basic-smoke/Makefile b/Sanity/basic-smoke/Makefile new file mode 100644 index 0000000..fc95ece --- /dev/null +++ b/Sanity/basic-smoke/Makefile @@ -0,0 +1,64 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/delve/Sanity/basic-smoke +# Description: basic smoke test +# Author: Edjunior Machado +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2019 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/delve/Sanity/basic-smoke +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE hello.go init.txt script.exp + +.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: basic smoke test" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: delve" >> $(METADATA) + @echo "Requires: delve golang expect" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -RHEL4 -RHELClient5 -RHELServer5" >> $(METADATA) + @echo "Architectures: x86_64 aarch64" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/Sanity/basic-smoke/PURPOSE b/Sanity/basic-smoke/PURPOSE new file mode 100644 index 0000000..fbd311c --- /dev/null +++ b/Sanity/basic-smoke/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /tools/delve/Sanity/basic-smoke +Description: basic smoke test +Author: Edjunior Machado diff --git a/Sanity/basic-smoke/hello.go b/Sanity/basic-smoke/hello.go new file mode 100644 index 0000000..1aca341 --- /dev/null +++ b/Sanity/basic-smoke/hello.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func hello_world() { + fmt.Println("Hello World") +} + +func main() { + i := 10 + hello_world() + i-- +} diff --git a/Sanity/basic-smoke/init.txt b/Sanity/basic-smoke/init.txt new file mode 100644 index 0000000..3674e26 --- /dev/null +++ b/Sanity/basic-smoke/init.txt @@ -0,0 +1,9 @@ +break main.main +continue +next +break hello_world +continue +next 4 +locals +continue +exit diff --git a/Sanity/basic-smoke/main.fmf b/Sanity/basic-smoke/main.fmf new file mode 100644 index 0000000..6a4cfd2 --- /dev/null +++ b/Sanity/basic-smoke/main.fmf @@ -0,0 +1,34 @@ +summary: basic smoke test +description: '' +enabled: true +link: + - relates: https://bugzilla.redhat.com/show_bug.cgi?id=2098063 + - relates: https://bugzilla.redhat.com/show_bug.cgi?id=2078639 + - relates: https://bugzilla.redhat.com/show_bug.cgi?id=2076501 +tag: + - CI-Tier-1 + - NoRHEL4 + - NoRHEL5 + - TIPfail_Apps + - rhel8-gating +adjust: + - enabled: false + when: arch == aarch64, arm, armhfp, i386, ia64, ppc, ppc64, ppc64le, s390, s390x + continue: false + - enabled: false + when: distro == rhel-4, rhel-5 + continue: false +contact: Edjunior Machado +component: + - delve + - golang +test: ./runtest.sh +framework: beakerlib +recommend: + - delve + - golang + - expect +duration: 10m +extra-nitrate: TC#0605108 +extra-summary: /tools/delve/Sanity/basic-smoke +extra-task: /tools/delve/Sanity/basic-smoke diff --git a/Sanity/basic-smoke/runtest.sh b/Sanity/basic-smoke/runtest.sh new file mode 100755 index 0000000..e38def0 --- /dev/null +++ b/Sanity/basic-smoke/runtest.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/delve/Sanity/basic-smoke +# Description: basic smoke test +# Author: Edjunior Machado +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2019 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 dlv))" + +GO_PACKAGE="$(rpm -qf $(which go))" + +rlJournalStart + rlPhaseStartSetup + if ! rlCheckRpm $PACKAGE; then + if rlIsRHEL && [ "$(arch)" != "x86_64" ]; then + rlLogInfo "RHEL delve currently is only supported on x86_64" + skip_test=1 + else + rlRun go_version=$(go version | sed -e 's/go version go\(.*\) .*/\1/') + if rlTestVersion $go_version '<' 1.13; then + rlLogInfo "delve is not supported before go1.13" + skip_test=1 + else + rlDie "delve is missing. Aborting testcase..." + fi + fi + else + rlAssertRpm $GO_PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp hello.go init.txt script.exp $TmpDir" + rlRun "pushd $TmpDir" + fi + rlPhaseEnd + +if [ ! $skip_test ]; then + rlPhaseStartTest + rlRun "set -o pipefail" + + rlRun -l "dlv" 0 + + rlRun -l "dlv version |& tee version.out" 0 + rlAssertGrep "^Delve Debugger$" version.out + + rlPhaseEnd + + rlPhaseStartTest "Init file test" + rlRun "cat hello.go" + rlRun "go mod init main" + rlRun "cat init.txt" + + rlRun "delve_version=$(dlv version | awk '/Version:/{ print $2}')" + # --allow-non-terminal-interactive=true is needed on delve 1.6.0 (rhel-8.5) + if rlTestVersion $delve_version '>=' 1.6; then + rlRun "DELVE_INIT_ARGS='--allow-non-terminal-interactive=true'" + else + rlRun "DELVE_INIT_ARGS=''" + fi + # delve should exit with 0 now, since rhbz#1780554 was fixed + rlRun "dlv debug $DELVE_INIT_ARGS --init ./init.txt |& tee debug.out" 0 + + if grep 'Version of Delve is too old' debug.out; then + rlFail "'Delve is too old' warning message" + rlLogInfo "Rerunning with --check-go-version=false" + rlRun "DELVE_IGNORE_GO_VERSION='--check-go-version=false'" + rlRun "dlv debug $DELVE_INIT_ARGS $DELVE_IGNORE_GO_VERSION --init ./init.txt |& tee debug.out" 0 + fi + + rlAssertGrep "^Breakpoint 1 set at .* for main.main() ./hello.go:9$" debug.out + rlAssertGrep "^Hello World$" debug.out + rlAssertGrep "^i = 9$" debug.out + rlAssertGrep "Process .* has exited with status 0$" debug.out + rlAssertNotGrep "failed" debug.out + + rlFileSubmit debug.out + rlPhaseEnd + + rlPhaseStartTest "Prompt test" + rlRun "expect -- script.exp $DELVE_IGNORE_GO_VERSION |& tee expect.log" + rlAssertGrep "PASS: break main.main" expect.log + rlAssertGrep "PASS: continue" expect.log + rlAssertGrep "PASS: next" expect.log + rlAssertGrep "PASS: break hello_world" expect.log + rlAssertGrep "PASS: c" expect.log + rlAssertGrep "PASS: next 4" expect.log + rlAssertGrep "PASS: locals" expect.log + rlAssertGrep "PASS: c (exit)" expect.log + rlAssertGrep "PASS: exit" expect.log + rlFileSubmit expect.log + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +fi +rlJournalPrintText +rlJournalEnd diff --git a/Sanity/basic-smoke/script.exp b/Sanity/basic-smoke/script.exp new file mode 100644 index 0000000..7280d75 --- /dev/null +++ b/Sanity/basic-smoke/script.exp @@ -0,0 +1,81 @@ +#!/usr/bin/expect -f + +set param [lindex $argv 0]; + +spawn dlv debug "$param" +match_max 100000 + +expect -exact "Type 'help' for list of commands.\r +(dlv) " +send -- "break main.main\r" +expect "break main.main\r +Breakpoint 1 set at * for main.main() ./hello.go:9\r +(dlv) " { + puts "PASS: break main.main" +} + +send -- "continue\r" +expect "continue\r +> main.main() ./hello.go:9 (hits goroutine(1):1 total:1) (PC: 0x*)\r +* +*=>* 9:*func*main() {\r +* +(dlv) " { + puts "PASS: continue" +} + +send -- "next\r" +expect "next\r +> main.main() ./hello.go:10 (PC: 0x*)\r +* +*=>* 10:*i := *10*\r +* +(dlv) " { + puts "PASS: next" +} + +send -- "break hello_world\r" +expect "break hello_world\r +Breakpoint 2 set at 0x* for main.hello_world() ./hello.go:5\r +(dlv) " { + puts "PASS: break hello_world" +} + +send -- "c\r" +expect "c\r +> main.hello_world() ./hello.go:5 (hits goroutine(1):1 total:1) (PC: 0x*)\r +* +*=>* 5:*func* hello_world() {\r +* +(dlv) " { + puts "PASS: c" +} + +send -- "next 4\r" +expect "next 4\r +Hello World\r +> main.main() ./hello.go:13 (PC: 0x*)\r +* +*=>* 13:*}\r +(dlv) " { + puts "PASS: next 4" +} + +send -- "locals\r" +expect -exact "locals\r +i = 9\r +(dlv) " { + puts "PASS: locals" +} + +send -- "c\r" +expect "c\r +Process * has exited with status 0\r +(dlv) " { + puts "PASS: c (exit)" +} + +send -- "exit\r" +expect eof { + puts "PASS: exit" +} diff --git a/plans/ci.fmf b/plans/ci.fmf new file mode 100644 index 0000000..3fd3ab7 --- /dev/null +++ b/plans/ci.fmf @@ -0,0 +1,5 @@ +summary: CI Gating Plan +discover: + how: fmf +execute: + how: tmt