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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 9 17:03:29 CDT 2010


Author: mnicholson
Date: Wed Jun  9 17:03:25 2010
New Revision: 384

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=384
Log:
Added support for the -v flag in asttest.  This allows the version of asterisk to be passed to asttest.  If the -v flag is not specified, the version will be determined from the version.h file.  Code was also added to astlib to parse and compare version numbers.

Added:
    asterisk/trunk/asttest/self-tests/asterisk_version/
    asterisk/trunk/asttest/self-tests/asterisk_version/test.lua   (with props)
Modified:
    asterisk/trunk/asttest/README
    asterisk/trunk/asttest/asttest.c
    asterisk/trunk/asttest/include/asttest/asttest.h
    asterisk/trunk/asttest/include/asttest/testsuite.h
    asterisk/trunk/asttest/lib/lua.c
    asterisk/trunk/asttest/lib/lua/astlib.c
    asterisk/trunk/asttest/lib/lua/astlib.lua
    asterisk/trunk/asttest/lib/testsuite.c

Modified: asterisk/trunk/asttest/README
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/README?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/README (original)
+++ asterisk/trunk/asttest/README Wed Jun  9 17:03:25 2010
@@ -63,7 +63,7 @@
 #!/bin/bash -e
 export LUA_PATH=../../lib/lua/?.lua\;\;
 export LUA_CPATH=../../lib/lua/?.so\;\;
-asttest -a / -s tests/my-test
+asttest -a / -s tests/my-test $@
 
 The -a option indicates the location of the asterisk installation to use for 
 the test and the -s option turns on single test mode and indicates the 

Modified: asterisk/trunk/asttest/asttest.c
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/asttest.c?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/asttest.c (original)
+++ asterisk/trunk/asttest/asttest.c Wed Jun  9 17:03:25 2010
@@ -29,7 +29,8 @@
 void usage(const char *prog_name) {
 	fprintf(stderr,
 		"Usage:\n"
-		"  %s [-whs] [-l <filename>] [-a <directory>] <test_dir> [test_dir...]\n"
+		"  %s [-wh] [-v <version>] [-l <filename>] [-a <directory>] <test_dir> [test_dir...]\n"
+		"  %s [-wh] [-v <version>] [-l <filename>] [-a <directory>] -s <test_dir>\n"
 		"\n"
 		"Options:\n"
 		"  -l <filename>  Specify the name of the log file.  One log file will be\n"
@@ -51,8 +52,11 @@
 		"                 output to be sent to stdout instead of a log file and will\n"
 		"                 cause the program to exit with a non zero return code in if\n"
 		"                 the test fails.\n"
+		"  -v <version>   Specify the version of asterisk we are testing against.  If\n"
+		"                 not specified, the version.h file from the specified asterisk\n"
+		"                 path will be usedi to determine the version number.\n"
 		"\n"
-		, prog_name);
+		, prog_name, prog_name);
 }
 
 /*
@@ -78,7 +82,7 @@
 	opts->asterisk_path = "asterisk";
 
 	/* parse options */	
-	while ((c = getopt(argc, argv, "l:a:s:wh")) != -1) {
+	while ((c = getopt(argc, argv, "l:a:s:v:wh")) != -1) {
 		switch (c) {
 		case 'l':
 			opts->log_filename = optarg;
@@ -91,6 +95,9 @@
 			break;
 		case 's':
 			opts->single_test_mode = optarg;
+			break;
+		case 'v':
+			opts->asterisk_version = optarg;
 			break;
 		case 'h':
 			return 1;

Modified: asterisk/trunk/asttest/include/asttest/asttest.h
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/include/asttest/asttest.h?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/include/asttest/asttest.h (original)
+++ asterisk/trunk/asttest/include/asttest/asttest.h Wed Jun  9 17:03:25 2010
@@ -25,6 +25,7 @@
 	unsigned int warn_on_error:1;
 	const char *log_filename;
 	const char *asterisk_path;
+	const char *asterisk_version;
 	const char *single_test_mode;
 };
 

Modified: asterisk/trunk/asttest/include/asttest/testsuite.h
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/include/asttest/testsuite.h?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/include/asttest/testsuite.h (original)
+++ asterisk/trunk/asttest/include/asttest/testsuite.h Wed Jun  9 17:03:25 2010
@@ -31,6 +31,7 @@
 	unsigned int total;
 	FILE *log;
 	char asterisk_path[PATH_MAX];
+	const char *asterisk_version;
 	unsigned int single_test_mode:1;
 };
 

Modified: asterisk/trunk/asttest/lib/lua.c
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua.c?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/lib/lua.c (original)
+++ asterisk/trunk/asttest/lib/lua.c Wed Jun  9 17:03:25 2010
@@ -74,7 +74,11 @@
 	/* load the asterisk lib */
 	lua_pushcfunction(L, luaopen_astlib);
 	lua_pushstring(L, ts->asterisk_path);
-	if (lua_pcall(L, 1, 0, 0)) {
+	if (ts->asterisk_version)
+		lua_pushstring(L, ts->asterisk_version);
+	else
+		lua_pushnil(L);
+	if (lua_pcall(L, 2, 0, 0)) {
 		goto e_print_error;
 	}
 

Modified: asterisk/trunk/asttest/lib/lua/astlib.c
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/astlib.c?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/lib/lua/astlib.c (original)
+++ asterisk/trunk/asttest/lib/lua/astlib.c Wed Jun  9 17:03:25 2010
@@ -317,6 +317,15 @@
 }
 
 /*!
+ * \brief [lua_CFunction asterisk:_version] get the version of this asterisk instance
+ * \return the version string for this version of asterisk
+ */
+static int get_asterisk_version(lua_State *L) {
+	lua_getfield(L, LUA_REGISTRYINDEX, "astlib_version");
+	return 1;
+}
+
+/*!
  * \brief [lua_CFunction asterisk:clean_work_area] Clean up the work area for
  * this instance.
  * \param L the lua state to use
@@ -463,6 +472,7 @@
 
 static luaL_Reg astlib[] = {
 	{"unlink", unlink_file},
+	{"_version", get_asterisk_version},
 	{NULL, NULL},
 };
 
@@ -475,10 +485,14 @@
 
 int luaopen_astlib(lua_State *L) {
 	const char *asterisk_path = luaL_checkstring(L, 1);
+	const char *asterisk_version = luaL_optstring(L, 2, "unknown");
 
 	/* set up some registry values */
 	lua_pushstring(L, asterisk_path);
 	lua_setfield(L, LUA_REGISTRYINDEX, "astlib_path");
+
+	lua_pushstring(L, asterisk_version);
+	lua_setfield(L, LUA_REGISTRYINDEX, "astlib_version");
 
 	lua_pushinteger(L, 1);
 	lua_setfield(L, LUA_REGISTRYINDEX, "astlib_count");

Modified: asterisk/trunk/asttest/lib/lua/astlib.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/astlib.lua?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/lib/lua/astlib.lua (original)
+++ asterisk/trunk/asttest/lib/lua/astlib.lua Wed Jun  9 17:03:25 2010
@@ -24,6 +24,51 @@
 
 function new()
 	return asterisk:new()
+end
+
+function version(ver)
+	local version = ver or _version()
+	if version == "unknown" then
+		-- read version from path .. /usr/include/asterisk/version.h
+		local f, err = io.open(path .. "/usr/include/asterisk/version.h")
+		if not f then
+			error("error determining asterisk verison; unable to open version.h: " .. err)
+		end
+
+		for line in f:lines() do
+			version = line:match('ASTERISK_VERSION%s"([^"]+)"')
+			if version then
+				break
+			end
+		end
+		f:close()
+
+		if not version then
+			error("error determining asterisk version; version not found in version.h")
+		end
+	end
+	return asterisk_version:new(version)
+end
+
+function has_major_version(v)
+	if v == "trunk" then
+		v = "SVN-trunk-r00000"
+	end
+
+	local v1 = version(v)
+	local v2 = version()
+
+	if v1.svn and v2.svn and v1.branch == v2.branch then return true end
+	if v2.svn then
+		v1 = version("SVN-branch-" .. v .. "-r00000")
+		if v1.branch == v2.branch then return true end
+	end
+	if not v2.svn and not v1.svn and v1.concept == v2.concept and v1.major == v2.major then
+		if not v1.minor then return true end
+		if v1.minor == v2.minor then return true end
+	end
+
+	return false
 end
 
 -- asterisk table is created in astlib.c
@@ -274,6 +319,79 @@
 	log:close()
 end
 
+asterisk_version = {}
+function asterisk_version:new(version)
+	local v = {
+		version = version,
+	}
+	setmetatable(v, self)
+	self.__index = self
+
+	v:_parse()
+	return v
+end
+
+function asterisk_version:_parse()
+	if self.version:sub(1,3) == "SVN" then
+		self.svn = true
+		self.branch, self.revision, self.parent = self.version:match("SVN%-(.*)%-r(%d+M?)%-(.*)")
+		if not self.branch then
+			self.branch, self.revision = self.version:match("SVN%-(.*)%-r(%d+M?)")
+		end
+	else
+		self.concept, self.major, self.minor, self.patch = self.version:match("(%d+).(%d+).(%d+).(%d+)")
+		if not self.concept then
+			self.concept, self.major, self.minor = self.version:match("(%d+).(%d+).(%d+)")
+		end
+		if not self.concept then
+			self.concept, self.major, self.minor = self.version:match("(%d+).(%d+)")
+		end
+	end
+end
+
+function asterisk_version:__tostring()
+	return self.version
+end
+
+function asterisk_version:__lt(other)
+	if self.svn and other.svn then
+		-- for svn versions, just compare revisions
+		local v1 = tonumber(self.revision:match("(%d)M?"))
+		local v2 = tonumber(other.revision:match("(%d)M?"))
+		return v1 < v2
+	elseif not self.svn and not other.svn then
+		if tonumber(self.concept) < tonumber(other.concept) then
+			return true
+		elseif self.concept == other.concept then
+			if tonumber(self.major) < tonumber(other.major) then
+				return true
+			elseif self.major == other.major then
+				if (self.minor or other.minor) and tonumber(self.minor or 0) < tonumber(other.minor or 0) then
+					return true
+				elseif (self.minor or other.minor) and (self.minor or "0") == (other.minor or "0") then
+					if (self.patch or other.patch) and tonumber(self.patch or 0) < tonumber(other.patch or 0) then
+						return true
+					else
+						return false
+					end
+				else
+					return false
+				end
+
+			else
+				return false
+			end
+		else
+			return false
+		end
+	end
+	error("cannot compare svn version number with non svn version number")
+end
+
+function asterisk_version:__eq(other)
+	return self.version == other.version
+end
+
 config = {}
 function config:from_file(name, src_filename, dst_filename)
 	local ac = config:new(name, dst_filename)

Modified: asterisk/trunk/asttest/lib/testsuite.c
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/testsuite.c?view=diff&rev=384&r1=383&r2=384
==============================================================================
--- asterisk/trunk/asttest/lib/testsuite.c (original)
+++ asterisk/trunk/asttest/lib/testsuite.c Wed Jun  9 17:03:25 2010
@@ -32,6 +32,8 @@
 	
 	memset(ts, 0, sizeof(struct testsuite));
 	
+	ts->asterisk_version = opts->asterisk_version;
+
 	snprintf(log_path, sizeof(log_path), "%s/%s", path, opts->log_filename);
 
 	ts->log = fopen(log_path, "w");
@@ -68,6 +70,7 @@
 
 	ts->log = stdout;
 	ts->single_test_mode = 1;
+	ts->asterisk_version = opts->asterisk_version;
 
 	/* make asterisk_path absolute */
 	if (opts->asterisk_path[0] == '/') {

Added: asterisk/trunk/asttest/self-tests/asterisk_version/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/self-tests/asterisk_version/test.lua?view=auto&rev=384
==============================================================================
--- asterisk/trunk/asttest/self-tests/asterisk_version/test.lua (added)
+++ asterisk/trunk/asttest/self-tests/asterisk_version/test.lua Wed Jun  9 17:03:25 2010
@@ -1,0 +1,79 @@
+-- test asterisk version string parsing
+
+function normal_version(version, concept, major, minor, patch)
+	print("testing " .. version)
+	local v = ast.version(version)
+	fail_if(v.svn, version .. " was detected as an svn version")
+	fail_if(tostring(v) ~= version, string.format("tostring(v) for %s ~= %s", version, version))
+	fail_if(v.concept ~= concept, string.format("v.concept ~= concept (%s ~= %s)", v.concept or "nil", concept or "nil"))
+	fail_if(v.major ~= major, string.format("v.major ~= major (%s ~= %s)", v.major or "nil", major or "nil"))
+	fail_if(v.minor ~= minor, string.format("v.minor ~= minor (%s ~= %s)", v.minor or "nil", minor or "nil"))
+	fail_if(v.patch ~= patch, string.format("v.patch ~= patch (%s ~= %s)", v.patch or "nil", patch or "nil"))
+end
+
+function svn_version(version, branch, revision, parent)
+	print("testing svn " .. version)
+	local v = ast.version(version)
+	fail_if(not v.svn, version .. " was NOT detected as an svn version")
+	fail_if(tostring(v) ~= version, string.format("tostring(v) for %s ~= %s", version, version))
+	fail_if(v.branch ~= branch, string.format("v.branch ~= branch (%s ~= %s)", v.branch or "nil", branch or "nil"))
+	fail_if(v.revision ~= revision, string.format("v.revision ~= revision (%s ~= %s)", v.revision or "nil", revision or "nil"))
+	fail_if(v.parent ~= parent, string.format("v.parent ~= parent (%s ~= %s)", v.parent or "nil", parent or "nil"))
+end
+
+function major_version(v1, v2)
+	print(string.format("testing major version %s matches %s", v1, v2))
+	local old_version = ast._version
+	ast._version = function()
+		return v2
+	end
+
+	fail_if(not ast.has_major_version(v1), string.format("ast.has_major_version(%s) failed for %s", v1, v2))
+
+	ast._version = old_version
+end
+
+function not_major_version(v1, v2)
+	print(string.format("testing major version %s does not match %s", v1, v2))
+	local old_version = ast._version
+	ast._version = function()
+		return v2
+	end
+
+	fail_if(ast.has_major_version(v1), string.format("ast.has_major_version(%s) matched for %s", v1, v2))
+
+	ast._version = old_version
+end
+
+normal_version("1.4.30", "1", "4", "30")
+normal_version("1.4.30.1", "1", "4", "30", "1")
+normal_version("1.4", "1", "4")
+svn_version("SVN-trunk-r252849", "trunk", "252849")
+svn_version("SVN-branch-1.6.2-r245581M", "branch-1.6.2", "245581M")
+svn_version("SVN-russell-cdr-q-r249059M-/trunk", "russell-cdr-q", "249059M", "/trunk")
+svn_version("SVN-russell-rest-r1234", "russell-rest", "1234")
+
+major_version("1.4", "1.4.30")
+major_version("1.4", "1.4.30.1")
+major_version("trunk", "SVN-trunk-r224353")
+major_version("1.4", "SVN-branch-1.4-r224353")
+major_version("1.6.2", "SVN-branch-1.6.2-r224353")
+major_version("1.6.2", "1.6.2.0")
+
+not_major_version("1.4", "1.6.2")
+not_major_version("1.4", "1.8")
+not_major_version("1.6", "SVN-trunk-r224353")
+not_major_version("1.6.1", "1.6.2")
+
+fail_if(ast.version("1.6") > ast.version("1.6.2"), "1.6 > 1.6.2 failed")
+fail_if(ast.version("1.6.2") < ast.version("1.6.2"), "1.6.2 < 1.6.2 failed")
+fail_if(ast.version("1.6.2") ~= ast.version("1.6.2"), "1.6.2 ~= 1.6.2 failed")
+fail_if(not (ast.version("1.6.2") <= ast.version("1.6.2")), "1.6.2 <= 1.6.2 failed")
+fail_if(not (ast.version("1.4") < ast.version("1.6.2")), "1.4 < 1.6.2 failed")
+fail_if(not (ast.version("1.4") < ast.version("1.4.2")), "1.4 < 1.4.2 failed")
+fail_if(not (ast.version("1.4.30") < ast.version("1.6")), "1.4.30 < 1.6 failed")
+
+if ast.exists() then
+	print(ast.version())
+end
+

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

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

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




More information about the svn-commits mailing list