[svn-commits] mnicholson: testsuite/asterisk/trunk r439 - in /asterisk/trunk: asttest/self-...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 24 14:51:18 CDT 2010


Author: mnicholson
Date: Thu Jun 24 14:51:14 2010
New Revision: 439

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=439
Log:
Added a gettimeofday() function to luaposix and implemented the watcher lua lib's timeout in terms of it.  It now uses milliseconds as it's timeout value.  I also updated any tests using the watcherlib to use millisecond timeout values instead of seconds.

Modified:
    asterisk/trunk/asttest/self-tests/watcherlib/test.lua
    asterisk/trunk/asttest/tools/luaposix.diff
    asterisk/trunk/lib/lua/watcher.lua
    asterisk/trunk/tests/span-alarms/test.lua

Modified: asterisk/trunk/asttest/self-tests/watcherlib/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/self-tests/watcherlib/test.lua?view=diff&rev=439&r1=438&r2=439
==============================================================================
--- asterisk/trunk/asttest/self-tests/watcherlib/test.lua (original)
+++ asterisk/trunk/asttest/self-tests/watcherlib/test.lua Thu Jun 24 14:51:14 2010
@@ -91,7 +91,7 @@
 		etree = etree:add(watcher.event.new("Event" .. i))
 	end
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 function match_multiple_trees()
@@ -107,7 +107,7 @@
 		end
 	end
 
-	expect_success(watcher.watch(standard_dm(), {build_tree(5, 10), build_tree(1, 3)}, 2))
+	expect_success(watcher.watch(standard_dm(), {build_tree(5, 10), build_tree(1, 3)}, 100))
 end
 
 function match_branching_tree_1()
@@ -139,7 +139,7 @@
 	   :add(e("Event12"))
 	tree:add(e("Event23"))
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 
 	local tree = watcher.etree:new(watcher.event.new("Event1"))
 	local etree = tree
@@ -147,7 +147,7 @@
 		etree = etree:add(watcher.event.new("Event" .. i))
 	end
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 function match_out_of_order()
@@ -164,7 +164,7 @@
 	local tree = watcher.etree:new(events)
 	tree:add(watcher.event.new("Event10"))
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 
 	-- check and make sure every event was actually matched
 	for i=1,9 do
@@ -196,7 +196,7 @@
 	   :add(e("Event12"))
 	tree:add(e("Event23"))
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 function match_headers_1()
@@ -228,7 +228,7 @@
 	   :add(e("Event12"))
 	tree:add(e("Event23"))
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 function match_headers_2()
@@ -260,7 +260,7 @@
 	   :add(e("Event12"))
 	tree:add(e("Event23"))
 
-	expect_timeout(watcher.watch(standard_dm(), tree, 2))
+	expect_timeout(watcher.watch(standard_dm(), tree, 100))
 end
 
 function test_timeout_1()
@@ -275,7 +275,7 @@
 		etree = etree:add(watcher.event.new("Event" .. i))
 	end
 
-	expect_timeout(watcher.watch(standard_dm(), tree, 2))
+	expect_timeout(watcher.watch(standard_dm(), tree, 100))
 end
 
 function test_timeout_2()
@@ -289,7 +289,7 @@
 		etree = etree:add(watcher.event.new("Event" .. i))
 	end
 
-	expect_timeout(watcher.watch(empty_dm(), tree, 2))
+	expect_timeout(watcher.watch(empty_dm(), tree, 100))
 end
 
 function match_with_function_1()
@@ -299,7 +299,7 @@
 		return true
 	end)
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 function match_with_function_2()
@@ -312,7 +312,7 @@
 
 	local tree = watcher.etree:new(event)
 
-	expect_success(watcher.watch(standard_dm(), tree, 2))
+	expect_success(watcher.watch(standard_dm(), tree, 100))
 end
 
 match_single_tree()

Modified: asterisk/trunk/asttest/tools/luaposix.diff
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/tools/luaposix.diff?view=diff&rev=439&r1=438&r2=439
==============================================================================
--- asterisk/trunk/asttest/tools/luaposix.diff (original)
+++ asterisk/trunk/asttest/tools/luaposix.diff Thu Jun 24 14:51:14 2010
@@ -1,7 +1,15 @@
 diff -ruN a/lposix.c b/lposix.c
 --- a/lposix.c	2008-07-18 09:30:36.000000000 -0500
-+++ b/lposix.c	2010-06-24 12:49:23.000000000 -0500
-@@ -575,6 +575,12 @@
++++ b/lposix.c	2010-06-24 14:49:07.000000000 -0500
+@@ -9,6 +9,7 @@
+ */
+ 
+ #include <sys/stat.h>
++#include <sys/time.h>
+ #include <sys/times.h>
+ #include <sys/types.h>
+ #include <sys/utsname.h>
+@@ -575,6 +576,12 @@
  	return 1;
  }
  
@@ -14,7 +22,40 @@
  
  static int Psetenv(lua_State *L)		/** setenv(name,value,[over]) */
  {
-@@ -1069,6 +1075,7 @@
+@@ -701,6 +708,24 @@
+ 	return doselection(L, 1, SgetID, FgetID, NULL);
+ }
+ 
++static int Pgettimeofday(lua_State *L)		/** gettimeofday() */
++{
++	/* NOTE: the tz argument is not supported as the man page says it is
++	 * obsolete */
++	struct timeval tv;
++
++	if (gettimeofday(&tv, NULL)) {
++		return pusherror(L, NULL);
++	}
++
++	lua_createtable(L, 0, 2);
++	lua_pushnumber(L, tv.tv_sec);
++	lua_setfield(L, -2, "tv_sec");
++
++	lua_pushnumber(L, tv.tv_usec);
++	lua_setfield(L, -2, "tv_usec");
++	return 1;
++}
+ 
+ static int Phostid(lua_State *L)		/** hostid() */
+ {
+@@ -1055,6 +1080,7 @@
+ 	{"getlogin",		Pgetlogin},
+ 	{"getpasswd",		Pgetpasswd},
+ 	{"getpid",		Pgetpid},
++	{"gettimeofday",	Pgettimeofday},
+ 	{"glob",		Pglob},
+ 	{"hostid",		Phostid},
+ 	{"kill",		Pkill},
+@@ -1069,6 +1095,7 @@
  	{"setenv",		Psetenv},
  	{"setpid",		Psetpid},
  	{"sleep",		Psleep},
@@ -22,6 +63,7 @@
  	{"stat",		Pstat},
  	{"sysconf",		Psysconf},
  	{"times",		Ptimes},
+Binary files a/.lposix.c.swp and b/.lposix.c.swp differ
 diff -ruN a/lposix.h b/lposix.h
 --- a/lposix.h	1969-12-31 18:00:00.000000000 -0600
 +++ b/lposix.h	2010-06-22 15:29:02.000000000 -0500

Modified: asterisk/trunk/lib/lua/watcher.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/lua/watcher.lua?view=diff&rev=439&r1=438&r2=439
==============================================================================
--- asterisk/trunk/lib/lua/watcher.lua (original)
+++ asterisk/trunk/lib/lua/watcher.lua Thu Jun 24 14:51:14 2010
@@ -177,7 +177,9 @@
 -- @returns True on success and nil and an error message on failure.  Currently
 -- the only error message is "timeout".
 function watch(m, tree, timeout)
-	local rough_seconds = 0
+	function tv2ms(tv)
+		return tv.tv_sec * 1000 + tv.tv_usec / 1000
+	end
 
 	if getmetatable(tree) == watcher.etree then
 		tree = {tree}
@@ -200,9 +202,20 @@
 		end
 	end
 
+	local start, err = posix.gettimeofday()
+	if not start then return nil, err end
+	start = tv2ms(start)
+
 	m:register_event("", handle_events)
 	while not matched() do
-		if timeout ~= 0 and rough_seconds >= timeout then
+		local now, err = posix.gettimeofday()
+		if not now then
+			m:unregister_event("", handle_events)
+			return nil, err
+		end
+		now = tv2ms(now)
+
+		if timeout ~= 0 and timeout < now - start then
 			m:unregister_event("", handle_events)
 			return nil, "timeout"
 		end
@@ -216,12 +229,11 @@
 		m:process_events()
 
 		if timeout == 0 then
+			m:unregister_event("", handle_events)
 			return nil, "timeout"
 		end
 
-		posix.sleep(1)
-
-		rough_seconds = rough_seconds + 1
+		posix.usleep(1)
 	end
 
 	m:unregister_event("", handle_events)

Modified: asterisk/trunk/tests/span-alarms/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/span-alarms/test.lua?view=diff&rev=439&r1=438&r2=439
==============================================================================
--- asterisk/trunk/tests/span-alarms/test.lua (original)
+++ asterisk/trunk/tests/span-alarms/test.lua Thu Jun 24 14:51:14 2010
@@ -138,7 +138,7 @@
 
 print(tostring(etree))
 
-res, err = watcher.watch(m, etree, 120)
+res, err = watcher.watch(m, etree, 12000)
 
 r = m(logoff)
 




More information about the svn-commits mailing list