summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYevhenii Shapovalov <yshapova@redhat.com>2017-11-09 13:39:24 +0200
committerYevhenii Shapovalov <yshapova@redhat.com>2017-11-09 13:39:24 +0200
commit7b824e0268575e4c13c624b54b2a1280aa295f7f (patch)
tree4ae2e36e9e6b708845fb15fdd002f0e20c384421
parent8a0d5153089bcc081fd088027b52b4c90c76b769 (diff)
downloadlua-add_test.tar.gz
lua-add_test.tar.xz
lua-add_test.zip
add testsHEADadd_test
-rw-r--r--tests/README.md3
-rw-r--r--tests/Smoke/Makefile63
-rw-r--r--tests/Smoke/PURPOSE3
-rw-r--r--tests/Smoke/account.lua35
-rw-r--r--tests/Smoke/bisect.lua28
-rw-r--r--tests/Smoke/globals.lua23
-rw-r--r--tests/Smoke/hello.lua4
-rwxr-xr-xtests/Smoke/runtest.sh70
-rw-r--r--tests/Smoke/sieve.lua28
-rw-r--r--tests/tests.yml14
10 files changed, 271 insertions, 0 deletions
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..5683070
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,3 @@
+# lua
+
+lua tests \ No newline at end of file
diff --git a/tests/Smoke/Makefile b/tests/Smoke/Makefile
new file mode 100644
index 0000000..cc6503b
--- /dev/null
+++ b/tests/Smoke/Makefile
@@ -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)
diff --git a/tests/Smoke/PURPOSE b/tests/Smoke/PURPOSE
new file mode 100644
index 0000000..fc1a3f3
--- /dev/null
+++ b/tests/Smoke/PURPOSE
@@ -0,0 +1,3 @@
+PURPOSE of /CoreOS/lua/Sanity/Smoke
+Description: Basic smoke for lua component
+Author: Stepan Sigut <ssigut@redhat.com>
diff --git a/tests/Smoke/account.lua b/tests/Smoke/account.lua
new file mode 100644
index 0000000..e783c01
--- /dev/null
+++ b/tests/Smoke/account.lua
@@ -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)
diff --git a/tests/Smoke/bisect.lua b/tests/Smoke/bisect.lua
new file mode 100644
index 0000000..77ac36c
--- /dev/null
+++ b/tests/Smoke/bisect.lua
@@ -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)
diff --git a/tests/Smoke/globals.lua b/tests/Smoke/globals.lua
new file mode 100644
index 0000000..e053f36
--- /dev/null
+++ b/tests/Smoke/globals.lua
@@ -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,"")
diff --git a/tests/Smoke/hello.lua b/tests/Smoke/hello.lua
new file mode 100644
index 0000000..0768a9d
--- /dev/null
+++ b/tests/Smoke/hello.lua
@@ -0,0 +1,4 @@
+-- hello.lua
+-- the first program in every language
+
+io.write("Hello world, from ",_VERSION,"!\n")
diff --git a/tests/Smoke/runtest.sh b/tests/Smoke/runtest.sh
new file mode 100755
index 0000000..d6c6545
--- /dev/null
+++ b/tests/Smoke/runtest.sh
@@ -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
diff --git a/tests/Smoke/sieve.lua b/tests/Smoke/sieve.lua
new file mode 100644
index 0000000..4ce8456
--- /dev/null
+++ b/tests/Smoke/sieve.lua
@@ -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
diff --git a/tests/tests.yml b/tests/tests.yml
new file mode 100644
index 0000000..2613885
--- /dev/null
+++ b/tests/tests.yml
@@ -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