[asterisk-commits] dvossel: branch dvossel/test_api r234006 - in /team/dvossel/test_api: include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 9 16:40:57 CST 2009


Author: dvossel
Date: Wed Dec  9 16:40:54 2009
New Revision: 234006

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234006
Log:
test.c and test.h

Added:
    team/dvossel/test_api/include/asterisk/test.h   (with props)
    team/dvossel/test_api/main/test.c   (with props)
Modified:
    team/dvossel/test_api/main/asterisk.c

Added: team/dvossel/test_api/include/asterisk/test.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/include/asterisk/test.h?view=auto&rev=234006
==============================================================================
--- team/dvossel/test_api/include/asterisk/test.h (added)
+++ team/dvossel/test_api/include/asterisk/test.h Wed Dec  9 16:40:54 2009
@@ -1,0 +1,107 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007 - 2009, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \author David Vossel <dvossel at digium.com>
+ * \brief Test Framework api
+ */
+
+
+#define AST_TEST_FRAMEWORK //todohere move to a better place
+
+
+/* Macros used for for test API */
+#ifdef AST_TEST_FRAMEWORK
+#define AST_TEST_DEFINE(hdr, body) hdr body
+#define AST_TEST_REGISTER(name, cat, sum, des, cb) ast_test_register(name, cat, sum, des, cb)
+#define AST_TEST_UNREGISTER(cb) ast_test_unregister(cb)
+#else /* else no-op */
+#define AST_TEST_DEFINE(hdr, body)
+#define AST_TEST_REGISTER(name, cat, sum, des, cb)
+#define AST_TEST_UNREGISTER(cb)
+#endif
+
+
+#ifdef AST_TEST_FRAMEWORK
+
+/*!
+ * \brief Generic test callback function
+ *
+ * \param error buffer on failure
+ * \param length of error buffer
+ *
+ * \return 0 for pass, 1 for failure
+ */
+typedef int (ast_test_cb_t)(char *errbuf, int len);
+
+/*!
+ * \brief Initializes test framework.
+ *
+ * \return 0 on success, 1 on failure.
+ */
+int ast_test_init(void);
+
+int ast_test_register(const char *name, const char *catagory, const char *summary, const char *description, ast_test_cb_t *cb);
+
+int ast_test_unregister(ast_test_cb_t *cb);
+
+/*!
+ * \brief Runs test suit
+ * 
+ * \param name of test to run (optional)
+ * \param test catagory to run (optional)
+ *
+ * \return 0 if test(s) ran, 1 if error finding registered test(s)  
+ *
+ * \note This function has three modes of operation
+ * 1. When given a name and catagory that individual test will execute if found.
+ * 2. When given only a catagory all tests within that catagory will execute.
+ * 3. If given no name or catagory all registered tests will execute.
+ */
+int ast_test_execute(const char *name, const char *catagory);
+
+/*!
+ * \brief Generate test results.
+ * 
+ * \param name of test result to generate (optional)
+ * \param test catagory to generate (optional)
+ * \param path to xml file to generate, default if NULL (optional)
+ *
+ * \return 0 if results were generated, 1 if error  
+ *
+ * \note This function has three modes of operation.
+ * 1. Given both a name and catagory results will be generated for that single test. 
+ * 2. Given only a catagory results for every test within the catagory will be generated
+ * 3. If given no name or catagory results for every registered test will be generated.
+ * 
+ */
+int ast_test_results(const char *name, const char *catagory, const char *xml_path);
+
+#endif
+
+
+
+
+
+
+
+
+
+
+

Propchange: team/dvossel/test_api/include/asterisk/test.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/test_api/include/asterisk/test.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/test_api/include/asterisk/test.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/dvossel/test_api/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/asterisk.c?view=diff&rev=234006&r1=234005&r2=234006
==============================================================================
--- team/dvossel/test_api/main/asterisk.c (original)
+++ team/dvossel/test_api/main/asterisk.c Wed Dec  9 16:40:54 2009
@@ -140,6 +140,9 @@
 #include "asterisk/buildinfo.h"
 #include "asterisk/xmldoc.h"
 #include "asterisk/poll-compat.h"
+
+//todohere add an ifdef for flag
+#include "asterisk/test.h"
 
 #include "../defaults.h"
 
@@ -3547,6 +3550,11 @@
 		exit(1);
 	}
 
+	if (ast_test_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	ast_makesocket();
 	sigemptyset(&sigs);
 	sigaddset(&sigs, SIGHUP);

Added: team/dvossel/test_api/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/test.c?view=auto&rev=234006
==============================================================================
--- team/dvossel/test_api/main/test.c (added)
+++ team/dvossel/test_api/main/test.c Wed Dec  9 16:40:54 2009
@@ -1,0 +1,213 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007 - 2009, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Internal test framework
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#include "asterisk.h"
+
+#include "asterisk/_private.h"
+
+#include "asterisk/test.h"
+#include "asterisk/logger.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/utils.h"
+
+
+enum ast_test_result_state {
+	AST_TEST_NOT_RUN = 0,
+	AST_TEST_PASS = 1,
+	AST_TEST_FAIL = 2,
+};
+
+struct ast_test_result {
+	/*! current test result state */
+	enum ast_test_result_state state;
+	/*! optional error buf to describe error results */
+	char error[64];
+};
+
+struct ast_test {
+	char *name;
+	char *catagory;
+	char *summary;
+	char *description;
+	ast_test_cb_t *cb;
+
+	/*! stores the last ran result */
+	struct ast_test_result result;
+	AST_LIST_ENTRY(ast_test) entry;
+};
+
+#ifdef AST_TEST_FRAMEWORK
+/*! List of registered test definitions */
+static AST_LIST_HEAD_STATIC(tests, ast_test);
+#endif
+
+
+/*! static function prototypes */
+static struct ast_test *test_alloc(const char *name, const char *catagory, const char *summary, const char *description, ast_test_cb_t *cb);
+static struct ast_test *test_free(struct ast_test *test);
+static int test_insert(struct ast_test *test);
+static struct ast_test *test_remove(ast_test_cb_t *cb);
+
+int ast_test_init()
+{
+	return 0;
+}
+
+int ast_test_register(const char *name, const char *catagory, const char *summary, const char *description, ast_test_cb_t *cb)
+{
+	struct ast_test *test;
+
+	/* verify data.  Name, Catagory, and cb _MUST_ be present to register a test */
+	if (ast_strlen_zero(name) || ast_strlen_zero(catagory) || !cb) {
+		return -1;
+	}
+
+	/* create test object */
+	if (!(test = test_alloc(name, catagory, summary, description, cb))) {
+		return -1;
+	}
+
+	/* insert into list */
+	if (test_insert(test)) {
+		test_free(test);
+		return -1;
+	}
+
+	return 0;
+}
+
+int ast_test_unregister(ast_test_cb_t *cb)
+{
+	struct ast_test *test;
+
+	/* find test and remove */
+	if (!(test = test_remove(cb))) {
+		return -1; /* not found */
+	}
+
+	/* free test object */
+	test_free(test);
+
+	return 0;
+}
+
+int ast_test_execute(const char *name, const char *catagory)
+{
+	//todohere
+	return 0;
+}
+
+int ast_test_results(const char *name, const char *catagory, const char *xml_path)
+{
+	//todohere
+	return 0;
+}
+
+
+/*!
+ * \brief adds test to container sorted first by catagory then by name
+ *
+ * \return 0 on success, -1 on failure
+ */
+static int test_insert(struct ast_test *test)
+{
+	struct ast_test *cur = NULL;
+	int res = 0;
+
+	AST_LIST_LOCK(&tests);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
+		//todohere compare test to cur and see what's up.  
+		//todohere if dup, res = -1 and break
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	AST_LIST_UNLOCK(&tests);
+
+	return res;
+}
+
+/*!
+ * \brief removes test from container
+ *
+ * \return ast_test removed from list on success, or NULL on failure
+ */
+static struct ast_test *test_remove(ast_test_cb_t *cb)
+{
+	struct ast_test *cur = NULL, *test = NULL;
+
+	AST_LIST_LOCK(&tests);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
+		if (cur->cb == cb) {
+			test = cur;
+			AST_LIST_REMOVE_CURRENT(entry);
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	AST_LIST_UNLOCK(&tests);
+
+	return test;
+}
+
+/*!
+ * \brief frees a ast_test object and all it's data members
+ */
+static struct ast_test *test_free(struct ast_test *test)
+{
+	if (!test) {
+		return NULL;
+	}
+
+	ast_free(test->name);
+	ast_free(test->catagory);
+	ast_free(test->summary);
+	ast_free(test->description);
+	ast_free(test);
+
+	return NULL;
+}
+
+/*!
+ * \brief allocates a ast_test object.
+ */
+static struct ast_test *test_alloc(const char *name, const char *catagory, const char *summary, const char *description, ast_test_cb_t *cb)
+{
+	struct ast_test *test;
+
+	if (!(test = ast_calloc(sizeof(*test), 1))) {
+		return NULL;
+	}
+
+	if (!(test->name = ast_strdup(name)) ||
+		 !(test->catagory = ast_strdup(catagory)) ||
+		 !(test->summary = ast_strdup(summary)) ||
+		 !(test->description = ast_strdup(description))) {
+
+		return test_free(test);
+	}
+
+	test->cb = cb;
+
+	return test;
+}

Propchange: team/dvossel/test_api/main/test.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/test_api/main/test.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/test_api/main/test.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list