#1 Add CI tests using the standard test interface
Merged 5 years ago by spot. Opened 5 years ago by yshapovalov.
git://fedorapeople.org/~yshapovalov/lua add_test  into  master

add tests
Yevhenii Shapovalov • 5 years ago  
tests/README.md
file added
+3
@@ -0,0 +1,3 @@

+ # lua

+ 

+ lua tests 

\ No newline at end of file

tests/Smoke/Makefile
file added
+63
@@ -0,0 +1,63 @@

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/lua/Sanity/Smoke

+ #   Description: Basic smoke for lua component

+ #   Author: Stepan Sigut <ssigut@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2016 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=/CoreOS/lua/Sanity/Smoke

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE *.lua

+ 

+ .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:           Stepan Sigut <ssigut@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     Basic smoke for lua component" >> $(METADATA)

+ 	@echo "Type:            Sanity" >> $(METADATA)

+ 	@echo "TestTime:        5m" >> $(METADATA)

+ 	@echo "RunFor:          lua" >> $(METADATA)

+ 	@echo "Requires:        lua" >> $(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)

tests/Smoke/PURPOSE
file added
+3
@@ -0,0 +1,3 @@

+ PURPOSE of /CoreOS/lua/Sanity/Smoke

+ Description: Basic smoke for lua component

+ Author: Stepan Sigut <ssigut@redhat.com>

tests/Smoke/account.lua
file added
+35
@@ -0,0 +1,35 @@

+ -- account.lua

+ -- from PiL 1, Chapter 16

+ 

+ Account = {balance = 0}

+ 

+ function Account:new (o, name)

+   o = o or {name=name}

+   setmetatable(o, self)

+   self.__index = self

+   return o

+ end

+ 

+ function Account:deposit (v)

+   self.balance = self.balance + v

+ end

+ 

+ function Account:withdraw (v)

+   if v > self.balance then error("insufficient funds on account "..self.name) end

+   self.balance = self.balance - v

+ end

+ 

+ function Account:show (title)

+   print(title or "", self.name, self.balance)

+ end

+ 

+ a = Account:new(nil,"demo")

+ a:show("after creation")

+ a:deposit(1000.00)

+ a:show("after deposit")

+ a:withdraw(100.00)

+ a:show("after withdraw")

+ 

+ -- this would raise an error

+ b = Account:new(nil,"DEMO")

+ b:withdraw(100.00)

tests/Smoke/bisect.lua
file added
+28
@@ -0,0 +1,28 @@

+ -- bisect.lua

+ -- bisection method for solving non-linear equations

+ 

+ delta=1e-6  -- tolerance

+ 

+ function bisect(f,a,b,fa,fb)

+  local c=(a+b)/2

+  io.write(n," c=",c," a=",a," b=",b,"\n")

+  if c==a or c==b or math.abs(a-b)<delta then return c,b-a end

+  n=n+1

+  local fc=f(c)

+  if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end

+ end

+ 

+ -- find root of f in the inverval [a,b]. needs f(a)*f(b)<0

+ function solve(f,a,b)

+  n=0

+  local z,e=bisect(f,a,b,f(a),f(b))

+  io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))

+ end

+ 

+ -- our function

+ function f(x)

+  return x*x*x-x-1

+ end

+ 

+ -- find zero in [1,2]

+ solve(f,1,2)

tests/Smoke/globals.lua
file added
+23
@@ -0,0 +1,23 @@

+ -- globals.lua

+ -- show all global variables

+ 

+ local seen={}

+ 

+ function dump(t,i)

+     seen[t]=true

+     local s={}

+     local n=0

+     for k in pairs(t) do

+         n=n+1 s[n]=k

+     end

+     table.sort(s)

+     for k,v in ipairs(s) do

+         print(i,v)

+         v=t[v]

+         if type(v)=="table" and not seen[v] then

+             dump(v,i.."\t")

+         end

+     end

+ end

+ 

+ dump(_G,"")

tests/Smoke/hello.lua
file added
+4
@@ -0,0 +1,4 @@

+ -- hello.lua

+ -- the first program in every language

+ 

+ io.write("Hello world, from ",_VERSION,"!\n")

tests/Smoke/runtest.sh
file added
+70
@@ -0,0 +1,70 @@

+ #!/bin/bash

+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/lua/Sanity/Smoke

+ #   Description: Basic smoke for lua component

+ #   Author: Stepan Sigut <ssigut@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2016 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/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGES=${PACKAGES:-"lua"}

+ LUA=${LUA:-"lua"}

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm --all

+         rlAssertBinaryOrigin $LUA

+         set -o pipefail

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "cp *.lua $TmpDir"

+         rlRun "pushd $TmpDir"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlRun "$LUA hello.lua 2>&1 | tee dump.log" 0

+         rlAssertGrep "Hello world, from Lua" "dump.log"

+     rlPhaseEnd

+     rlPhaseStartTest

+         rlRun "$LUA bisect.lua 2>&1 | tee dump.log" 0

+         rlAssertGrep "after 20 steps, root is 1.3247179985046387 with error 9.5e-07, f=1.8e-07" "dump.log"

+     rlPhaseEnd

+     rlPhaseStartTest

+         rlRun "$LUA globals.lua &>/dev/null" 0

+     rlPhaseEnd

+     rlPhaseStartTest

+         rlRun "$LUA account.lua 2>&1 | tee dump.log" 1

+         rlAssertGrep "after creation" "dump.log"

+         rlAssertGrep "lua: account.lua:18: insufficient funds on account DEMO" "dump.log"

+     rlPhaseEnd

+     rlPhaseStartTest

+         rlRun "$LUA sieve.lua &>/dev/null" 0

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "popd"

+         rlRun "rm -r $TmpDir" 0 "Removing tmp directory"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

tests/Smoke/sieve.lua
file added
+28
@@ -0,0 +1,28 @@

+ -- sieve.lua

+ -- the sieve of Eratosthenes programmed with coroutines

+ -- typical usage: lua -e N=500 sieve.lua | column

+ 

+ -- generate all the numbers from 2 to n

+ function gen (n)

+   return coroutine.wrap(function ()

+     for i=2,n do coroutine.yield(i) end

+   end)

+ end

+ 

+ -- filter the numbers generated by `g', removing multiples of `p'

+ function filter (p, g)

+   return coroutine.wrap(function ()

+     for n in g do

+       if n%p ~= 0 then coroutine.yield(n) end

+     end

+   end)

+ end

+ 

+ N=N or 500      -- from command line

+ x = gen(N)      -- generate primes up to N

+ while 1 do

+   local n = x()     -- pick a number until done

+   if n == nil then break end

+   print(n)      -- must be a prime number

+   x = filter(n, x)  -- now remove its multiples

+ end

tests/tests.yml
file added
+14
@@ -0,0 +1,14 @@

+ ---

+ # This first play always runs on the local staging system

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - classic

+     - container

+     - atomic

+     tests:

+     - Smoke

+     required_packages:

+     - lua     # Required for smoke test

+     - which   # Required for smoke test

no initial comment

Justification

Adds tests according to the CI wiki specifically the standard test interface in the spec.

The playbook includes Tier1 level test cases that have been tested in the following contexts and is passing reliably: Classic and Container. Test logs are stored in the artifacts directory.

The following steps are used to execute the tests using the standard test interface:

Test enveronment

Make sure you have installed packages from the spec

# rpm -q ansible python2-dnf libselinux-python standard-test-roles \
ansible-2.3.2.0-1.fc26.noarch \
python2-dnf-2.6.3-11.fc26.noarch \
libselinux-python-2.6-7.fc26.x86_64 \
standard-test-roles-2.4-1.fc26.noarch

Run tests for Classic

# export TEST_SUBJECTS=
# sudo ansible-playbook --tags classic tests.yml

Snip of the example test run for Classic tests:

TASK [standard-test-beakerlib : Check the results] ****************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=15   changed=9    unreachable=0    failed=0   

Run tests for Container

# export ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory)
# export TEST_SUBJECTS=docker:docker.io/library/fedora:26
# sudo ansible-playbook --tags=container tests.yml

Snip of the example test run for Container tests:

TASK [standard-test-beakerlib : Check the results] ****************************************************************************************************************************************************************
changed: [883b695c1d6b0e091ae8ee3d27838e0c2f28a51344469e2f573c36c290cb1c5a]

PLAY RECAP ********************************************************************************************************************************************************************************************************
883b695c1d6b0e091ae8ee3d27838e0c2f28a51344469e2f573c36c290cb1c5a : ok=15   changed=11   unreachable=0    failed=0   

Notes

Tests will be enabled in CI, yet gating is currently disabled, so nothing will change. Tests will run on each dist-git commit, they are not triggered on koji builds and if you are using FMN, it should notify you of failures normally.

The RH QE maintainer contact in case you have questions: yshapova@redhat.com
The idea is that these tests become yours just as you're maintaining the package, there will of course be people around if you have questions or troubles.

Pull-Request has been merged by spot

5 years ago