Fixed pipeline and comparator for ordering tests

Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
diff --git a/tests/test_v2x.py b/tests/test_v2x.py
index 1a99ab2..478b82b 100644
--- a/tests/test_v2x.py
+++ b/tests/test_v2x.py
@@ -34,17 +34,21 @@
             name_inputs='L,F'
             )
 def order_based_on_deps(left, right):
+    # TODO: this is overly simplified sorting over files with dependencies
+    # normally it should be solved with use of topological sort
     with open(left, 'r') as leftfile:
         relhref = xmlinc.make_relhref(left, right)
         leftcontent = leftfile.read()
         if relhref in leftcontent:
             return 1
+        leftinccount = leftcontent.count('`include')
     with open(right, 'r') as rightfile:
         relhref = xmlinc.make_relhref(right, left)
         rightcontent = rightfile.read()
         if relhref in rightcontent:
             return -1
-    return 0
+        rightinccount = rightcontent.count('`include')
+    return leftinccount - rightinccount
 
 
 def find_files(pattern, rootdir):
@@ -55,24 +59,34 @@
     simfiles = sorted(
         sorted(convert.get_filenames_containing('*.sim.v', testfile)),
         key=cmp_to_key(order_based_on_deps))
+    goldens = []
     for sim in simfiles:
         res = find_files('golden.' + goldentype, os.path.dirname(sim))
         if len(res) == 1:
-            yield res[0]
+            goldens.append(res[0])
+    return goldens
 
 
-@pytest.mark.parametrize("testdatafile",
-                         get_test_goldens('model.xml', __file__))
-def test_model_generation_with_vlog_to_model(testdatafile):
+def pytest_generate_tests(metafunc):
+    if "modelcase" in metafunc.fixturenames:
+        models = get_test_goldens('model.xml', __file__)
+        metafunc.parametrize("modelcase", models)
+    if "pbtypecase" in metafunc.fixturenames:
+        models = get_test_goldens('pb_type.xml', __file__)
+        metafunc.parametrize("pbtypecase", models)
+
+
+def test_model_generation_with_vlog_to_model(modelcase):
     """Parametrized test that checks  if the model.xml files produced by the
     vlog_to_model function are valid
     Parameters
     ----------
-    testdatafile : str
+    modelcase : str
         The filename of the model.xml file that should be produced by the
         corresponding sim.v file
     """
-    testdatadir = os.path.dirname(testdatafile) + '/'
+    modelfile = modelcase
+    testdatadir = os.path.dirname(modelfile) + '/'
     vlog_filenames = find_files('*.sim.v', testdatadir)
     assert len(vlog_filenames) == 1
     vlog_filename = vlog_filenames[0]
@@ -83,7 +97,7 @@
     with open(generatedmodelfile, 'w') as model:
         model.write(modelout)
 
-    convertedgolden = convert.vtr_stylize_xml(testdatafile)
+    convertedgolden = convert.vtr_stylize_xml(modelfile)
     convertedmodel = convert.vtr_stylize_xml(generatedmodelfile)
 
     assert convertedmodel == convertedgolden
@@ -92,18 +106,17 @@
         model.write(convertedmodel)
 
 
-@pytest.mark.parametrize("testdatafile",
-                         get_test_goldens('pb_type.xml', __file__))
-def test_pbtype_generation_with_vlog_to_pbtype(testdatafile):
+def test_pbtype_generation_with_vlog_to_pbtype(pbtypecase):
     """Parametrized test that checks  if the pb_type.xml files produced by the
     vlog_to_pbtype function are valid
     Parameters
     ----------
-    testdatafile : str
+    pbtypecase : str
         The filename of the pb_type.xml file that should be produced by the
         corresponding sim.v file
     """
-    testdatadir = os.path.dirname(testdatafile)
+    testdatafile = pbtypecase
+    testdatadir = os.path.dirname(testdatafile) + '/'
     vlog_filenames = find_files('*.sim.v', testdatadir)
     assert len(vlog_filenames) == 1
     vlog_filename = vlog_filenames[0]