aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2018-03-16 19:19:57 -0300
committerLarry Jr <larry.olj@gmail.com>2018-04-12 17:21:09 -0300
commit041f0abe19807a2dee3454b75facad5c5e58874a (patch)
treec00914fa46ab0c79f5d7a4fc8f36e7c705da8e48
parenteolian: pyeolian automated testegenerator using list of eofiles (diff)
downloadefl-041f0abe19807a2dee3454b75facad5c5e58874a.tar.gz
eolian: testgenerator using pyolian WIP
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile_Automated.am49
-rwxr-xr-xsrc/scripts/pyolian/testgenerator.py143
-rw-r--r--src/scripts/pyolian/testgenerator_suite.template146
-rw-r--r--src/tests/automated/automated.template14
5 files changed, 286 insertions, 68 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2aebada36c..c9b6f0b41d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -86,6 +86,8 @@ include Makefile_Elua.am
include Makefile_Wayland_Protocols.am
+include Makefile_Automated.am
+
if HAVE_JS
AM_V_CP = $(am__v_CP_@AM_V@)
am__v_CP_ = $(am__v_CP_@AM_DEFAULT_V@)
diff --git a/src/Makefile_Automated.am b/src/Makefile_Automated.am
new file mode 100644
index 0000000000..c9bf148413
--- /dev/null
+++ b/src/Makefile_Automated.am
@@ -0,0 +1,49 @@
+if EFL_ENABLE_TESTS
+TEST_GEN=$(top_srcdir)/src/scripts/pyolian/testgenerator.py
+
+ecore_automated_suite = $(top_builddir)/src/tests/automated/ecore_suite_automated.c
+
+tests/automated/ecore_suite_automated.c:
+ $(TEST_GEN) automated ecore $(ecore_automated_suite) $(ecore_eolian_files)
+
+check_PROGRAMS += tests/automated/ecore_suite_automated
+TESTS += tests/automated/ecore_suite_automated
+
+tests_automated_ecore_suite_automated_SOURCE = tests/automated/ecore_suite_automated.c
+tests_automated_ecore_suite_automated_CPPFLAGS = $(tests_ecore_ecore_suite_CPPFLAGS)
+tests_automated_ecore_suite_automated_LDADD = tests_ecore_ecore_suite_LDADD
+
+endif
+
+# $(AUTOMATED_GEN) automated ecore_audio $(top_builddir) $(ecore_audio_eolian_files)
+# $(AUTOMATED_GEN) automated ecore_con $(top_builddir) $(ecore_con_eolian_files)
+# $(AUTOMATED_GEN) automated ector $(top_builddir) $(ector_eolian_files)
+# $(AUTOMATED_GEN) automated edje $(top_builddir) $(edje_eolian_files)
+# $(AUTOMATED_GEN) automated efl $(top_builddir) $(efl_eolian_files)
+# $(AUTOMATED_GEN) automated eio $(top_builddir) $(eio_eolian_files)
+# $(AUTOMATED_GEN) automated eldbus $(top_builddir) $(eldbus_eolian_files)
+# $(AUTOMATED_GEN) automated emotion $(top_builddir) $(emotion_eolian_files)
+# $(AUTOMATED_GEN) automated eo $(top_builddir) $(eo_eolian_files)
+# $(AUTOMATED_GEN) automated evas $(top_builddir) $(evas_eolian_files)
+#clean:
+# @echo "Cleaning up built objects..."
+#
+#
+#lib/tests/automated/ecore: $(ecore_eolian_pub_files)
+#
+### Tests for XXX
+#check_PROGRAMS += tests/automated/XXX_test
+#TESTS += tests/automated/XXX_test
+#
+#tests_automated_XXX_test_SOURCES = tests/automated/XXX_test.cc
+#tests_automated_XXX_test_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
+# -I$(top_builddir)/src/lib/efl/interfaces/ \
+# -I$(top_builddir)/src/lib/evas/canvas/ \
+# -I$(top_builddir)/src/lib/evas/gesture/ \
+# -I$(top_builddir)/src/lib/evas/include/ \
+# -DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/automated\" \
+# -DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/automated\" \
+# @CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ @EO_CXX_CFLAGS@ \
+# @ECORE_CFLAGS@ @EINA_CFLAGS@ @EVAS_CFLAGS@ @EO_CFLAGS@
+#tests_automated_XXX_test_LDADD = @CHECK_LIBS@ @USE_EVAS_LIBS@
+#tests_automated_XXX_test_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
diff --git a/src/scripts/pyolian/testgenerator.py b/src/scripts/pyolian/testgenerator.py
index 5831eb6994..af189bd1dc 100755
--- a/src/scripts/pyolian/testgenerator.py
+++ b/src/scripts/pyolian/testgenerator.py
@@ -35,10 +35,6 @@ def cleanup_db():
del eolian_db
atexit.register(cleanup_db)
-
-def zeronull_parameters_get(parameters, cparam=[]):
- return [ cparams[i] if i < len(cparams) else 'NULL' if param.type.is_ptr else "0" for i, param in enumerate(parameters) ]
-
def load_file(filename):
if os.path.isfile(filename):
with open(filename, "r") as f:
@@ -48,32 +44,6 @@ def load_file(filename):
"""
It will find methods and functions with owned return and without other params
"""
-def custom_loads(cls, filedir):
- cls.custom = load_file(os.path.join(filedir, "custom.c")) or ''
- cls.init = load_file(os.path.join(filedir, "init.c"))
- cls.shutdown = load_file(os.path.join(filedir, "shutdown.c"))
-
- for func in cls.methods:
- cls.custom += load_file(os.path.join(filedir, func.name, "custom.c")) or ''
- func.init = load_file(os.path.join(filedir, func.name, "init.c"))
- func.shutdown = load_file(os.path.join(filedir, func.name, "shutdown.c"))
- func.arg_init = load_file(os.path.join(filedir, func.name, "arg_init.c")) or "/* Zero/NULL args init */"
- func.arg_shutdown = load_file(os.path.join(filedir, func.name, "arg_shutdown.c")) or "/* Zero/NULL args shutdown */"
-
- for func in cls.properties:
- if func.getter_scope:
- cls.custom += load_file(os.path.join(filedir, '{}_get'.format(func.name), "custom.c")) or ""
- func.init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "init.c"))
- func.shutdown = load_file(os.path.join(filedir, '{}_get'.format(func.name), "shutdown.c"))
- func.arg_get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "arg_init.c")) or "/* Zero/NULL args getter init */"
- func.arg_get_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown.c")) or "/* Zero/NULL args getter shutdown */"
-
- if func.setter_scope:
- cls.custom += load_file(os.path.join(filedir, '{}_set'.format(func.name), "custom.c")) or ""
- func.init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "init.c"))
- func.shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "shutdown.c"))
- func.arg_set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_init.c")) or "/* Zero/NULL args setter init */"
- func.arg_set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown.c")) or "/* Zero/NULL args setter shutdown */"
class Template(pyratemp.Template):
@@ -98,55 +68,106 @@ class Template(pyratemp.Template):
renderer_class=renderer_class,
eval_class=eval_class)
- def render(self, cls, filename=None, verbose=True):
+ def render(self, suite, verbose=True):
+ #if verbose and filename:
+ # print("rendering: {} => {}".format(self.template_filename, filename))
+
# Build the context for the template
ctx = {}
- ctx['cls'] = cls
-
- if verbose and filename:
- print("rendering: {} => {}".format(
- self.template_filename, filename))
+ ctx['suite'] = suite
# render with the augmented context
output = self(**ctx)
- if filename is not None:
+ if suite.filename is not None:
# write to file
- with open(filename, "w") as f:
+ with open(suite.filename, "w") as f:
f.write(output)
else:
# or print to stdout
- print(output)
+ print("FILENAME IS NONE", output)
+
+
+class SuiteCase():
+ def __init__(self, name, testname, filename):
+ self.name = name
+ self.testname = testname
+ self.fullname = "{}_{}".format(name, testname)
+ self.filename = filename
+ self.template = os.path.join(script_path, "testgenerator_suite.template")
+ self.clslist = []
+
+ def __del__(self):
+ for cls in self.clslist:
+ cls.myname = None
+ cls.custom = None
+ cls.init = None
+ cls.mlist = None
+ cls.plist = None
+
+ self.clslist = None
+
+ def load(self, testdir, eofiles):
+ self.clslist = []
+ for eofile in eofiles:
+ cls = eolian_db.class_by_file_get(os.path.basename(eofile))
+ if not cls or cls.type != cls.type.REGULAR:
+ continue
+
+ if cls.file == "efl_promise.eo":
+ continue
+
+ self.clslist.append(cls)
+ cls.myname = os.path.splitext(cls.file)[0]
+ cls.myfullname = "{}_{}".format(self.fullname, cls.myname)
+ filedir = os.path.join(testdir, cls.myname)
+ cls.custom = load_file(os.path.join(filedir, "custom.c")) or ''
+ cls.init = load_file(os.path.join(filedir, "init.c"))
+ cls.shutdown = load_file(os.path.join(filedir, "shutdown.c"))
+
+ cls.mlist = list(cls.methods)
+ for func in cls.mlist:
+ cls.custom += load_file(os.path.join(filedir, func.name, "custom.c")) or ''
+ func.init = load_file(os.path.join(filedir, func.name, "init.c"))
+ func.shutdown = load_file(os.path.join(filedir, func.name, "shutdown.c"))
+ func.arg_init = load_file(os.path.join(filedir, func.name, "arg_init.c")) or "/* Zero/NULL args init */"
+ func.arg_shutdown = load_file(os.path.join(filedir, func.name, "arg_shutdown.c")) or "/* Zero/NULL args shutdown */"
+
+ cls.plist = [ p for p in cls.properties if p.getter_scope or p.setter_scope ]
+ for func in cls.plist:
+ if func.getter_scope:
+ cls.custom += load_file(os.path.join(filedir, '{}_get'.format(func.name), "custom.c")) or ""
+ func.get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "init.c"))
+ func.get_shutdown = load_file(os.path.join(filedir, '{}_get'.format(func.name), "shutdown.c"))
+ func.arg_get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "arg_init.c")) or "/* Zero/NULL args getter init */"
+ func.arg_get_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown.c")) or "/* Zero/NULL args getter shutdown */"
+
+ if func.setter_scope:
+ cls.custom += load_file(os.path.join(filedir, '{}_set'.format(func.name), "custom.c")) or ""
+ func.set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "init.c"))
+ func.set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "shutdown.c"))
+ func.arg_set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_init.c")) or "/* Zero/NULL args setter init */"
+ func.arg_set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown.c")) or "/* Zero/NULL args setter shutdown */"
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Pyolian search owned functions.')
- parser.add_argument('testcase', help='The TestCase Name to use. (REQUIRED)')
- parser.add_argument('-c', '--classname', help='The Class Name to use.')
- parser.add_argument('-e', '--eofiles', nargs='*', help='The Class Name to use.')
+ parser.add_argument('testname', help='The Test Name to use. (REQUIRED)')
+ parser.add_argument('suitename', help='The Suite Name to use. (REQUIRED)')
+ parser.add_argument('filename', help='Build file dest. (REQUIRED)')
+ parser.add_argument('eofiles', nargs='*', help='The Eolian File to use.')
args = parser.parse_args()
- testdir = os.path.join(root_path, 'src', 'tests', args.testcase)
- template = os.path.join(testdir, "{}.template".format(args.testcase))
- if not os.path.isfile(template):
- template = os.path.join(testdir, "automated.template")
-
- cls_list = [ eolian_db.class_by_file_get(os.path.basename(eofile)) for eofile in args.eofiles or [] ]
-
- if args.classname:
- cls = eolian_db.class_by_name_get(args.classname)
- if cls: cls_list.append(cls)
-
- print(cls_list)
-
- for cls in filter(None, cls_list):
- custom_loads(cls, os.path.join(testdir, cls.c_name.lower()))
- filename = os.path.join(testdir, "{}_test.c".format(cls.c_name.lower()))
-
- t = Template(template)
- t.render(cls, filename)
+ testdir = os.path.join(root_path, 'src', 'tests', args.testname)
+ suite = SuiteCase(args.suitename, args.testname, args.filename)
+ suite.load(testdir, args.eofiles)
+ t = Template(suite.template)
+ try:
+ t.render(suite)
+ except:
+ print("ERROR RENDERING - Cannot create file: {}".format(suite.filename))
diff --git a/src/scripts/pyolian/testgenerator_suite.template b/src/scripts/pyolian/testgenerator_suite.template
new file mode 100644
index 0000000000..d386803d75
--- /dev/null
+++ b/src/scripts/pyolian/testgenerator_suite.template
@@ -0,0 +1,146 @@
+<!--(macro init)-->
+ /** init **/
+ fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
+ fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
+ fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n");
+ fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
+
+ <!--(if exists("mfunc") and mfunc!= None)-->
+ ${mfunc}$
+ <!--(elif exists("mcls") and mcls!= None)-->
+ ${mcls}$
+ <!--(else)-->
+ Eo *obj = efl_add(${cls.c_name}$, NULL);
+ fail_if(!obj, "ERROR: Cannot init ${cls.name}$!\n");
+ <!--(end)-->
+<!--(end)-->
+<!--(macro shutdown)-->
+ /** shutdown **/
+ <!--(if exists("mfunc") and mfunc != None)-->
+ ${mfunc}$
+ <!--(elif exists("mcls") and mcls != None)-->
+ ${mcls}$
+ <!--(end)-->
+ efl_unref(obj);
+ eio_shutdown();
+ ecore_shutdown();
+ eina_shutdown();
+<!--(end)-->
+<!--(macro args_declaration)-->
+ <!--(for arg in args)-->
+ ${arg.type.c_type_return}$ arg_${arg.name}$ = <!--(if arg.type.is_ptr or arg.type.type == arg.type.type.CLASS or arg.type.builtin_type == arg.type.builtin_type.STRING)-->NULL<!--(elif arg.type.builtin_type == arg.type.builtin_type.ANY_VALUE)-->EINA_VALUE_EMPTY<!--(else)-->0<!--(end)-->;
+ <!--(end)-->
+<!--(end)-->
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <check.h>
+
+<!--(for cls in suite.clslist)-->
+void ${cls.myfullname}$_test(TCase *tc);
+<!--(end)-->
+
+static const Efl_Test_Case etc[] = {
+<!--(for cls in suite.clslist)-->
+ { "${suite.name.capitalize()}$ ${suite.testname.capitalize()}$ ${cls.myname.capitalize()}$", ${cls.myfullname}$_test },
+<!--(end)-->
+ { NULL, NULL }
+};
+
+<!--(for cls in suite.clslist)-->
+
+/**************** TEST CASE ${cls.c_name}$ ****************/
+
+ <!--(if cls.custom != None)-->
+${cls.custom}$
+ <!--(end)-->
+START_TEST(${cls.myfullname}$_smoke)
+{
+${init(mcls=cls.init)}$
+${shutdown(mcls=cls.shutdown)}$
+}
+END_TEST
+
+ <!--(for func in cls.mlist)-->
+START_TEST(${cls.myfullname}$_${func.full_c_method_name}$)
+{
+${args_declaration(args=func.parameters)}$${init(mcls=cls.init,mfunc=func.init)}$
+${func.arg_init}$
+ <!--(if func.method_return_type)-->${func.method_return_type.c_type_return}$ r = <!--(end)-->${func.full_c_method_name}$(obj<!--(for arg in func.parameters)-->, arg_${arg.name}$<!--(end)-->);
+${func.arg_shutdown}$
+${shutdown(mcls=cls.shutdown,mfunc=func.shutdown)}$
+}
+END_TEST
+
+ <!--(end)-->
+
+ <!--(for func in cls.plist)-->
+ <!--(if func.getter_scope)-->
+START_TEST(${cls.myfullname}$_${func.full_c_getter_name}$)
+{
+ <!--(if len(list(func.getter_values)) > 1)-->
+${args_declaration(args=func.getter_values)}$
+ <!--(end)-->
+${args_declaration(args=func.getter_keys)}$${init(mcls=cls.init,mfunc=func.get_init)}$
+${func.arg_get_init}$
+ <!--(if len(list(func.getter_values)) == 1)-->
+ ${list(func.getter_values)[0].type.c_type_return}$ r = ${func.full_c_getter_name}$(obj<!--(for arg in func.getter_keys)-->arg_${arg.name}$<!--(end)-->);
+ <!--(else)-->
+ ${func.full_c_getter_name}$(obj<!--(for arg in func.getter_values)-->, &arg_${arg.name}$<!--(end)--><!--(for arg in func.getter_keys)-->, arg_${arg.name}$<!--(end)-->);
+ <!--(end)-->
+${func.arg_get_shutdown}$
+${shutdown(mcustom=cls.shutdown,mfunc=func.get_shutdown)}$
+}
+END_TEST
+
+ <!--(end)-->
+ <!--(if func.setter_scope)-->
+START_TEST(${cls.myfullname}$_${func.full_c_setter_name}$)
+{
+${args_declaration(args=func.setter_keys)}$${args_declaration(args=func.setter_values)}$${init(mcls=cls.init,mfunc=func.set_init)}$
+${func.arg_set_init}$
+ ${func.full_c_getter_name}$(obj<!--(for arg in func.setter_values)-->, &arg_${arg.name}$<!--(end)--><!--(for arg in func.setter_keys)-->, arg_${arg.name}$<!--(end)-->);
+${func.arg_set_shutdown}$
+${shutdown(mcls=cls.shutdown,mfunc=func.set_shutdown)}$
+}
+END_TEST
+
+ <!--(end)-->
+ <!--(end)-->
+void ${cls.myfullname}$_test(TCase *tc)
+{
+ tcase_add_test(tc, ${cls.myfullname}$_smoke);
+
+ <!--(for func in cls.methods)-->
+ tcase_add_test(tc, ${cls.myfullname}$_${func.full_c_method_name}$);
+ <!--(end)-->
+ <!--(for func in cls.properties)-->
+ <!--(if func.getter_scope)-->
+ tcase_add_test(tc, ${cls.myfullname}$_${func.full_c_getter_name}$);
+ <!--(end)-->
+ <!--(if func.setter_scope)-->
+ tcase_add_test(tc, ${cls.myfullname}$_${func.full_c_setter_name}$);
+ <!--(end)-->
+ <!--(end)-->
+}
+<!--(end)-->
+
+int
+main(int argc, char **argv)
+{
+ int failed_count;
+
+ if (!_efl_test_option_disp(argc, argv, etc))
+ return 0;
+
+#ifdef NEED_RUN_IN_TREE
+ putenv("EFL_RUN_IN_TREE=1");
+#endif
+
+ failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1,
+ "${suite.fullname}$", etc);
+
+ return (failed_count == 0) ? 0 : 255;
+}
+
diff --git a/src/tests/automated/automated.template b/src/tests/automated/automated.template
index ef13addbdd..c342b56680 100644
--- a/src/tests/automated/automated.template
+++ b/src/tests/automated/automated.template
@@ -11,7 +11,7 @@
${mcls}$
<!--(else)-->
Eo *obj = efl_add(${cls.c_name}$, NULL);
- fail_if(!obj, "ERROR: Cannot init ${cls.full_name}$!\n");
+ fail_if(!obj, "ERROR: Cannot init ${cls.name}$!\n");
<!--(end)-->
<!--(end)-->
<!--(macro shutdown)-->
@@ -54,7 +54,7 @@ ${shutdown(mcls=cls.shutdown)}$
}
END_TEST
-<!--(for func in cls.methods)-->
+<!--(for func in cls.mlist)-->
START_TEST(automated_test_${func.full_c_method_name}$)
{
${args_declaration(args=func.parameters)}$${init(mcls=cls.init,mfunc=func.init)}$
@@ -67,14 +67,14 @@ END_TEST
<!--(end)-->
-<!--(for func in cls.properties)-->
+<!--(for func in cls.plist)-->
<!--(if func.getter_scope)-->
START_TEST(automated_test_${func.full_c_getter_name}$)
{
<!--(if len(list(func.getter_values)) > 1)-->
${args_declaration(args=func.getter_values)}$
<!--(end)-->
-${args_declaration(args=func.getter_keys)}$${init(mcls=cls.init,mfunc=func.init)}$
+${args_declaration(args=func.getter_keys)}$${init(mcls=cls.init,mfunc=func.get_init)}$
${func.arg_get_init}$
<!--(if len(list(func.getter_values)) == 1)-->
${list(func.getter_values)[0].type.c_type_return}$ r = ${func.full_c_getter_name}$(obj<!--(for arg in func.getter_keys)-->arg_${arg.name}$<!--(end)-->);
@@ -82,7 +82,7 @@ ${func.arg_get_init}$
${func.full_c_getter_name}$(obj<!--(for arg in func.getter_values)-->, &arg_${arg.name}$<!--(end)--><!--(for arg in func.getter_keys)-->, arg_${arg.name}$<!--(end)-->);
<!--(end)-->
${func.arg_get_shutdown}$
-${shutdown(mcustom=cls.shutdown,mfunc=func.shutdown)}$
+${shutdown(mcustom=cls.shutdown,mfunc=func.get_shutdown)}$
}
END_TEST
@@ -90,11 +90,11 @@ END_TEST
<!--(if func.setter_scope)-->
START_TEST(automated_test_${func.full_c_setter_name}$)
{
-${args_declaration(args=func.setter_keys)}$${args_declaration(args=func.setter_values)}$${init(mcls=cls.init,mfunc=func.init)}$
+${args_declaration(args=func.setter_keys)}$${args_declaration(args=func.setter_values)}$${init(mcls=cls.init,mfunc=func.set_init)}$
${func.arg_set_init}$
${func.full_c_getter_name}$(obj<!--(for arg in func.setter_values)-->, &arg_${arg.name}$<!--(end)--><!--(for arg in func.setter_keys)-->, arg_${arg.name}$<!--(end)-->);
${func.arg_set_shutdown}$
-${shutdown(mcls=cls.shutdown,mfunc=func.shutdown)}$
+${shutdown(mcls=cls.shutdown,mfunc=func.set_shutdown)}$
}
END_TEST