[svn-commits] mnicholson: testsuite/asterisk/trunk r146 - in /asterisk/trunk/asttest: lib/l...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 25 12:36:11 CDT 2010


Author: mnicholson
Date: Thu Mar 25 12:36:08 2010
New Revision: 146

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=146
Log:
Added proc.perror() to print useful error messages from the return values of p:wait(), p:term(), p:kill(), and p:term_or_kill().

Added:
    asterisk/trunk/asttest/self-tests/proclib_perror/
    asterisk/trunk/asttest/self-tests/proclib_perror/test.lua   (with props)
Modified:
    asterisk/trunk/asttest/lib/lua/proclib.lua

Modified: asterisk/trunk/asttest/lib/lua/proclib.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/proclib.lua?view=diff&rev=146&r1=145&r2=146
==============================================================================
--- asterisk/trunk/asttest/lib/lua/proclib.lua (original)
+++ asterisk/trunk/asttest/lib/lua/proclib.lua Thu Mar 25 12:36:08 2010
@@ -34,3 +34,30 @@
 	return res, err
 end
 
+--- Print an appropriate error message for the given error.
+-- @usage <code>res, err = proc.perror(p:wait())</code>
+-- @usage <code>res, err = proc.perror(p:term())</code>
+-- @usage <code>res, err = proc.perror(p:kill())</code>
+-- @return This function returns its parameters.
+function perror(res, err, strerror, errno)
+	if res == nil then
+		if err == "core" then
+			print("process crashed (core dumped)")
+		elseif err == "timeout" then
+			return res, err
+		elseif err == "error" then
+			if strerror and errno then
+				print("error running process (" .. strerror .. ")")
+			else
+				print("error running process")
+			end
+		elseif type(err) == "number" then
+			print("process terminated by signal " .. err)
+		else
+			print("error running process (" .. err .. ")")
+		end
+	end
+
+	return res, err, strerror, errno
+end
+

Added: asterisk/trunk/asttest/self-tests/proclib_perror/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/self-tests/proclib_perror/test.lua?view=auto&rev=146
==============================================================================
--- asterisk/trunk/asttest/self-tests/proclib_perror/test.lua (added)
+++ asterisk/trunk/asttest/self-tests/proclib_perror/test.lua Thu Mar 25 12:36:08 2010
@@ -1,0 +1,90 @@
+-- test proclib's ablity to detect missing and non-executable files
+
+real_print = print
+function print(msg)
+	printed = true
+	if msg ~= expected_msg then
+		print = real_print
+		fail("expected perror to print '" .. tostring(expected_msg) .. "' but got '" .. msg .. "' instead")
+	end
+end
+
+function expect(msg)
+	printed = false
+	expected_msg = msg
+end
+
+function check()
+	if not printed then
+		print = real_print
+		fail("expected perror to print '" .. tostring(expected_msg) .. "' but got nothing instead")
+	end
+
+	expected_msg = nil
+	printed = false
+end
+
+function test_crash()
+	real_print("testing crash")
+
+	expect("process crashed (core dumped)")
+	proc.perror(nil, "core")
+	check()
+end
+
+function test_timeout()
+	real_print("testing a timeout")
+	expect(nil)
+	local p = proc.exec("sleep", "1")
+	proc.perror(p:wait(1))
+end
+
+
+function test_error_1()
+	real_print("testing an error (1)")
+	expect("error running process")
+	proc.perror(nil, "error")
+	check()
+end
+
+function test_error_2()
+	real_print("testing an error (2)")
+	expect("error running process (error)")
+	proc.perror(nil, "error", "error", 1)
+	check()
+end
+
+function test_signal_1()
+	real_print("testing a signal (1)")
+	expect("process terminated by signal 0")
+	proc.perror(nil, 0)
+	check()
+end
+
+function test_signal_2()
+	real_print("testing a signal (2)")
+	expect("process terminated by signal 15")
+	local p = proc.exec("sleep", "1")
+	proc.perror(p:term())
+	check()
+end
+
+function test_unknown()
+	real_print("testing an unknown error (2)")
+	expect("error running process (unknown)")
+	proc.perror(nil, "unknown")
+	check()
+end
+
+
+test_crash()
+test_timeout()
+
+test_error_1()
+test_error_2()
+
+test_signal_1()
+test_signal_2()
+
+test_unknown()
+

Propchange: asterisk/trunk/asttest/self-tests/proclib_perror/test.lua
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/asttest/self-tests/proclib_perror/test.lua
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/asttest/self-tests/proclib_perror/test.lua
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list