def test_find_two_files_at_a_time(self): """Starts with one include, finds it, then two more includes, finish when all are found. Found items are taken into account in FindRequest.existing """ NUM_FILES = 10 brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka')) names_a = [ BlockCellName(self.user + "/blocka/a%d.h" % i) for i in range(NUM_FILES) ] resources_info = {"a%d.h" % i: ("a", []) for i in range(NUM_FILES)} publisher = TestPublisher(self.user, self.store) publisher.publish(brl_a, resources_info) # Use the same request object, to accumulate existing (already found) files request = FinderRequest() request.policy = Policy.default() version = BlockVersion(brl_a, 0) # The version is always the same for i in range(0, NUM_FILES, 2): declaration1 = CPPDeclaration(names_a[i]) declaration2 = CPPDeclaration(names_a[i + 1]) request.unresolved = {declaration1, declaration2} result = self.service.find(request, BiiResponse()) self.check_result(result, resolved=[(brl_a, 0, {names_a[i], names_a[i + 1]})]) # The found one is added to the existing, for next iteration request.existing[version][declaration1] = {names_a[i]} request.existing[version][declaration2] = {names_a[i + 1]} self.assertEqual(len(request.existing[version]), i + 2)
def simple_dependencies_cpp_test(self): block_holder = self._cells_setup( 'dummy/geom', ['sphere.h', 'sphere.cpp', 'main.cpp'], CPP) # Parse processor setup block_holder['main.cpp'].cell.dependencies.unresolved = { CPPDeclaration('iostream'), CPPDeclaration('sphere.h') } block_holder['sphere.cpp'].cell.dependencies.unresolved = { CPPDeclaration('math.h'), CPPDeclaration('iostream'), CPPDeclaration('sphere.h') } changes, _ = process_holder(block_holder, DependenciesProcessor()) # Checks self.assert_bii_equal(changes, ProcessorChanges()) mainR = block_holder['main.cpp'].cell self.check_dependency_set(mainR.dependencies, resolved=['sphere.h', 'iostream'], explicit=['dummy/geom/sphere.h'], system=['iostream']) sphereR = block_holder['sphere.cpp'].cell self.check_dependency_set(sphereR.dependencies, resolved=['sphere.h', 'iostream', 'math.h'], explicit=['dummy/geom/sphere.h'], system=['iostream', 'math.h'])
def test_include_partial(self): brls = { 'main': 'dummy/block/main.cpp', 'astar': 'dummy/block/algorithms/astar.h', 'solver_h': 'dummy/block/solver/solver.h', 'solver_cpp': 'dummy/block/solver/solver.cpp' } cells = {x: SimpleCell(x) for x in brls.values()} cells_names = [x.name.cell_name for x in cells.itervalues()] block_holder = self._cells_setup('dummy/block', cells_names, CPP) main = block_holder['main.cpp'].cell main.dependencies.unresolved = {CPPDeclaration('solver/solver.h')} solver_h = block_holder['solver/solver.h'].cell solver_h.dependencies.unresolved = { CPPDeclaration('../algorithms/astar.h') } solver_cpp = block_holder['solver/solver.cpp'].cell solver_cpp.dependencies.unresolved = {CPPDeclaration('solver.h')} process_holder(block_holder, DependenciesProcessor()) # Checks self.assertEquals(set(), cells[brls['main']].dependencies.unresolved) self.assertEquals(set(), cells[brls['solver_h']].dependencies.unresolved) self.assertEquals(set(), cells[brls['solver_cpp']].dependencies.unresolved)
def test_similar_includes(self): brls = { 'smpso_cpp': 'dummy/jmetal/algorithms/smpso/smpso.cpp', 'smpso_h': 'dummy/jmetal/algorithms/smpso/smpso.h', 'pso_settings_cpp': 'dummy/jmetal/settings/pso_settings.cpp', 'pso_settings_h': 'dummy/jmetal/settings/pso_settings.h', 'pso_cpp': 'dummy/jmetal/algorithms/pso/pso.cpp', 'pso_h': 'dummy/jmetal/algorithms/pso/pso.h', 'pso_main': 'dummy/jmetal/main/pso_main.cpp', } cells = {x: SimpleCell(x) for x in brls.values()} cells_names = [x.name.cell_name for x in cells.itervalues()] block_holder = self._cells_setup('dummy/jmetal', cells_names, CPP) smpso_cpp = block_holder['algorithms/smpso/smpso.cpp'].cell pso_cpp = block_holder['algorithms/pso/pso.cpp'].cell pso_settings_h = block_holder['settings/pso_settings.h'].cell pso_main = block_holder['main/pso_main.cpp'].cell smpso_cpp.dependencies.unresolved = {CPPDeclaration('smpso.h')} pso_cpp.dependencies.unresolved = {CPPDeclaration('pso.h')} pso_settings_h.dependencies.unresolved = { CPPDeclaration('../algorithms/pso/pso.h') } pso_main.dependencies.unresolved = { CPPDeclaration('../algorithms/pso/pso.h') } process_holder(block_holder, DependenciesProcessor()) # Checks self.assertEquals(set(), pso_cpp.dependencies.unresolved) self.assertEquals(set(), smpso_cpp.dependencies.unresolved) self.assertEquals(set(), pso_settings_h.dependencies.unresolved) self.assertEquals(set(), pso_main.dependencies.unresolved)
def virtual_dependencies_test(self): sphereh = 'dummy/geom/sphere.h' sphereh_test = 'dummy/geom/test/sphere.h' sphereh_dev = 'dummy/geom/develop/sphere.h' block_holder = self._cells_setup( 'dummy/geom', ['main.cpp', 'test/sphere.h', 'main2.cpp', 'develop/sphere.h'], CPP) block_holder._resources['sphere.h'] = Resource(VirtualCell(sphereh), None) block_holder['test/sphere.h'].cell.container = BlockCellName(sphereh) block_holder['develop/sphere.h'].cell.container = BlockCellName( sphereh) block_holder['main.cpp'].cell.dependencies.unresolved = { CPPDeclaration(sphereh_test) } block_holder['main2.cpp'].cell.dependencies.unresolved = { CPPDeclaration(sphereh_dev) } _, outputstream = process_holder(block_holder, DependenciesProcessor()) warn = 'Block dummy/geom has absolute paths, like: #include "dummy/geom/develop/sphere.h"' self.assertIn(warn, str(outputstream)) # Checks main_cell = block_holder['main.cpp'].cell self.check_dependency_set(main_cell.dependencies, resolved=[sphereh_test], explicit=[sphereh]) main_cell = block_holder['main2.cpp'].cell self.check_dependency_set(main_cell.dependencies, resolved=[sphereh_dev], explicit=[sphereh])
def test_duplicated_n_level(self): brls = { 'gtest1': 'dummy/block/a1/b/c/gtest/gtest.h', 'getest2': 'dummy/block/a2/gtest/gtest.h', 'getest-all1': 'dummy/block/a1/gtest-all.cc', 'getest-all2': 'dummy/block/a3/gtest-all.cc', 'getest-all3': 'dummy/block/a1/b2/gtest-all.cc', } cells = {x: SimpleCell(x) for x in brls.values()} cells_names = [x.name.cell_name for x in cells.itervalues()] block_holder = self._cells_setup('dummy/block', cells_names, CPP) getest_all1 = block_holder['a1/gtest-all.cc'].cell getest_all1.dependencies.unresolved = { CPPDeclaration('b/c/gtest/gtest.h') } getest_all2 = block_holder['a3/gtest-all.cc'].cell getest_all2.dependencies.unresolved = {CPPDeclaration('gtest.h')} getest_all3 = block_holder['a1/b2/gtest-all.cc'].cell getest_all3.dependencies.unresolved = { CPPDeclaration('../b/c/gtest/gtest.h') } process_holder(block_holder, DependenciesProcessor()) # Checks self.assertEquals(0, len(getest_all1.dependencies.unresolved)) self.assertEquals(1, len(getest_all2.dependencies.unresolved)) self.assertEquals(0, len(getest_all3.dependencies.unresolved))
def test_finder_request_unresolved(self): f = FinderRequest() f.unresolved = set( [CPPDeclaration("iostream.h"), CPPDeclaration("math.h")]) f.policy = Policy.default() s = f.serialize() f2 = FinderRequest.deserialize(s) self.assertEqual(f, f2)
def test_declarations(self): d1 = CPPDeclaration('path/to/file.h') s = d1.serialize() d2 = CPPDeclaration.deserialize(s) self.assertEqual(d1, d2) d1 = PythonDeclaration("import sys") s = d1.serialize() d2 = PythonDeclaration.deserialize(s) self.assertEqual(d1, d2)
def test_relative_composed_block_match(self): # Given cut = CPPDeclaration("algs/astar.h") from_block_cell_name = BlockCellName("fran/test/main.cpp") block_cell_names = [BlockCellName("fran/test/algs/astar.h"), BlockCellName("fran/test/main.cpp")] # When result = cut.match(block_cell_names, from_block_cell_name) # Then expected = set([BlockCellName("fran/test/algs/astar.h")]) self.assertEquals(result, expected)
def not_delete_dependant_test(self): """ A resolved dependency in the same block must NOT be removed if that exist """ sphereh = 'dummy/geom/sphere.h' block_holder = self._cells_setup('dummy/geom', ['main.cpp', 'sphere.h'], CPP) main_cell = block_holder['main.cpp'].cell main_cell.dependencies.explicit = {BlockCellName(sphereh)} main_cell.dependencies.system = {SystemCellName('iostream')} main_cell.dependencies.resolved = {CPPDeclaration('sphere.h'), CPPDeclaration('iostream')} process_holder(block_holder, DependenciesProcessor()) # Checks self.check_dependency_set(main_cell.dependencies, resolved=['sphere.h', 'iostream'], explicit=[sphereh], system=['iostream'])
def test_relative_composed_block_match(self): #Given cut = CPPDeclaration("algs/astar.h") from_block_cell_name = BlockCellName('fran/test/main.cpp') block_cell_names = [ BlockCellName("fran/test/algs/astar.h"), BlockCellName("fran/test/main.cpp") ] #When result = cut.match(block_cell_names, from_block_cell_name) #Then expected = set([BlockCellName('fran/test/algs/astar.h')]) self.assertEquals(result, expected)
def test_deps_block_match(self): #Given cut = CPPDeclaration("../../deps/akka/math/sphere.h") from_block_cell_name = BlockCellName('fran/test/main.cpp') block_cell_names = [ BlockCellName("akka/math/sphere.h"), BlockCellName("fran/test/other/jarl.cpp"), BlockCellName("fran/test/main.cpp") ] #When result = cut.match(block_cell_names, from_block_cell_name) #Then expected = set([BlockCellName('akka/math/sphere.h')]) self.assertEquals(result, expected)
def test_deps_block_match(self): # Given cut = CPPDeclaration("../../deps/akka/math/sphere.h") from_block_cell_name = BlockCellName("fran/test/main.cpp") block_cell_names = [ BlockCellName("akka/math/sphere.h"), BlockCellName("fran/test/other/jarl.cpp"), BlockCellName("fran/test/main.cpp"), ] # When result = cut.match(block_cell_names, from_block_cell_name) # Then expected = set([BlockCellName("akka/math/sphere.h")]) self.assertEquals(result, expected)
def test_performance_breadth(self): store = MongoServerStore(self.conn, self.__class__.__name__) store.create_user(User("user2")) publisher = TestPublisher("user2", store) brl_block = BRLBlock('user2/user2/block/master') count = 1000 resource_info = {} for i in xrange(count): deps = DependencySet() if i > 0: deps = DependencySet() for j in range(max(0, i - 25), i): deps.explicit.add(BlockCellName('user2/block/cell%d.h' % j)) deps.resolved.add( CPPDeclaration('user2/block/cell%d.h' % j)) deps.unresolved.add(CPPDeclaration('path/to/file.h')) deps.implicit.add(BlockCellName('user2/block/cell%d.h' % j)) resource_info['cell%d.h' % i] = 'content %d' % i, deps publisher.publish(brl_block, resource_info) timer = self.get_timer() start_time = timer() store = MemServerStore(store) #print 'MEMSTORE SIZE 0', asizeof(store) / 1000000.0 translator = ReferenceTranslatorService(store, "user2") version = BlockVersion(brl_block, 0) missing = References() missing[version].add('cell%d.h' % (count - 1)) closure = CompatibilityClosure(missing) full_graph = BlockVersionGraph() full_graph.add_nodes([version]) build_compatibility_closure(translator, closure, [version], full_graph) elapsed_time = timer() - start_time #print 'Closure time', elapsed_time #print 'CLOSURE SIZE ', asizeof(closure) / 1000000.0 #print 'MEMSTORE SIZE ', asizeof(store) / 1000000.0 # print 'MINCELLS SIZE ', asizeof(store.min_cells)/1000000.0 self.assertEqual({brl_block.block_name + c for c in resource_info}, closure.block_cell_names) self.assertLess(elapsed_time, 7)
def _unresolvedDependencyRequest(self, unresolved_deps): request = FinderRequest() unresolved = set() for dep in unresolved_deps: unresolved.add(CPPDeclaration(dep)) request.unresolved = unresolved request.policy = Policy.default() return request
def build_update_request(self, block_version, block_cell_name): request = FinderRequest() existing = ReferencedDependencies() existing[block_version][CPPDeclaration(block_cell_name)].add( block_cell_name) request.existing = existing request.policy = Policy.default() request.find = False request.update = True return request
def build_unresolved_request(self, unresolved_deps): if isinstance(unresolved_deps, basestring): unresolved_deps = [unresolved_deps] request = FinderRequest() unresolved = set() for dep in unresolved_deps: unresolved.add(CPPDeclaration(dep)) request.unresolved = unresolved request.policy = Policy.default() return request
def test_python_c_include(self): code = r''' import biipyc import my_block lib = link_clib("user/block/test.h") some_var = test("user/block/cosa.h") value = 3 libd = biipyc.link_clib("user/block/test2.h")''' py = PythonParser() py.parse(code) obtained_explicit_decs = py.explicit_declarations expected_explicit_decs = [CPPDeclaration("user/block/test.h"), CPPDeclaration("user/block/test2.h"), PythonDeclaration("import my_block"), PythonDeclaration("import biipyc")] self.assertItemsEqual(expected_explicit_decs, obtained_explicit_decs) self.assertTrue(py.has_main_function())
def test_no_unresolved_to_local(self): files = { self.block_name + 'main.cpp': '#include "dummy/myblock/sphere.h"' } self.hive_manager.process(None, files) find_request, unresolved = self.hive_manager.hive_holder.find_request( Policy.default()) self.assertEqual(set(), find_request.unresolved) self.assertEqual(unresolved, {CPPDeclaration("dummy/myblock/sphere.h")})
def test_compute_request(self): files = { self.block_name + 'main.cpp': '#include "user2/block/sphere.h"' } self.hive_manager.process(None, files) find_request, unresolved = self.hive_manager.hive_holder.find_request( Policy.default()) self.assertIn(CPPDeclaration('user2/block/sphere.h'), find_request.unresolved) self.assertEqual(unresolved, set())
def test_dependency_set(self): d1 = DependencySet() d1.add_implicit(BlockCellName("user/block/path/file2.h")) d1.add_implicit(BlockCellName("user/block/path/file3.h")) d1.add_implicit(BlockCellName("user/block/path/file4.h")) names = set() names.add(CPPDeclaration("iostream.h")) d1.update_declarations(names) s = d1.serialize() d2 = DependencySet.deserialize(s) self.assert_bii_equal(d1, d2)
def test_replace_includes(self): text = r'''# include "file.h" //My comment # include "file2.h" # include "path/to/file.h" //My comment # include "file3.h" //bii://biicode.txt ''' parser = DRLCPPParser() parser.parse(text) d1 = CPPDeclaration('file.h') d2 = CPPDeclaration('user/block/file.h') text = parser.updateDeclaration(text, d1, d2) d1 = CPPDeclaration('file3.h') d2 = CPPDeclaration('user/block2/file3.h') text = parser.updateDeclaration(text, d1, d2) d1 = CPPDeclaration('file2.h') d2 = CPPDeclaration('user/block2/file2.h') text = parser.updateDeclaration(text, d1, d2) d1 = DataDeclaration('biicode.txt') d2 = DataDeclaration('user/block/biicode.txt') text = parser.updateDeclaration(text, d1, d2) expected = '''# include "user/block/file.h" //My comment # include "user/block2/file2.h" # include "path/to/file.h" //My comment # include "user/block2/file3.h" //bii://user/block/biicode.txt ''' self.assertEqual(expected, text)
def test_duplicated_first_level(self): brls = {'gtest1': 'dummy/block/include/gtest/gtest.h', 'getest2': 'dummy/block/fused-src/gtest/gtest.h', 'getest-all1': 'dummy/block/fused-src/gtest/gtest-all.cc', 'getest-all2': 'dummy/block/src/gtest-all.cc', 'sample': 'dummy/block/samples/sample_unittest.cc' } cells = {x: SimpleCell(x) for x in brls.values()} cells_names = [x.name.cell_name for x in cells.itervalues()] block_holder = self._cells_setup('dummy/block', cells_names, CPP) getest_all1 = block_holder['fused-src/gtest/gtest-all.cc'].cell getest_all1.dependencies.unresolved = {CPPDeclaration('gtest.h')} getest_all2 = block_holder['src/gtest-all.cc'].cell getest_all2.dependencies.unresolved = {CPPDeclaration('gtest.h')} sample = block_holder['samples/sample_unittest.cc'].cell sample.dependencies.unresolved = {CPPDeclaration('gtest.h')} process_holder(block_holder, DependenciesProcessor()) # Checks self.assertEquals(0, len(getest_all1.dependencies.unresolved)) self.assertEquals(1, len(getest_all2.dependencies.unresolved)) self.assertEquals(1, len(sample.dependencies.unresolved))
def update_test(self): deps = DependencySet() brl1 = BlockCellName("user/module/mytest.h") dec = CPPDeclaration("name1") deps.unresolved.add(brl1) deps.explicit.add(brl1) deps.resolved.add(dec) deps2 = DependencySet() brl2 = BlockCellName("user/module/mytest2.h") dec2 = CPPDeclaration("name2") deps2.unresolved.add(brl2) deps2.explicit.add(brl2) deps2.resolved.add(dec2) deps.update(deps2) self.assertIn(brl1, deps.unresolved) self.assertIn(brl1, deps.explicit) self.assertIn(dec, deps.resolved) self.assertIn(brl2, deps.unresolved) self.assertIn(brl2, deps.explicit) self.assertIn(dec2, deps.resolved)
def check_result(self, result, resolved=None, unresolved=None, updated=None): unresolved = unresolved or [] unresolved = {CPPDeclaration(str(u)) for u in unresolved} self.assertEqual(result.unresolved, unresolved) resolved = resolved or [] refs = ReferencedDependencies() for brl, time, block_cell_names in resolved: for name in block_cell_names: refs[BlockVersion( brl, time)][CPPDeclaration(name)] = {BlockCellName(name)} self.assertEqual(result.resolved, refs) updated = updated or [] refs = ReferencedDependencies() for brl, time, block_cell_names in updated: for name in block_cell_names: refs[BlockVersion( brl, time)][CPPDeclaration(name)] = {BlockCellName(name)} self.assertEqual(result.updated, refs)
def test_declarations(self): d1 = CPPDeclaration('path/to/file.h') s = d1.serialize() d2 = CPPDeclaration.deserialize(s) self.assertEqual(d1, d2) d1 = PythonDeclaration("import sys") s = d1.serialize() d2 = PythonDeclaration.deserialize(s) self.assertEqual(d1, d2)
def test_fiunder_request_existing(self): f = FinderRequest() self.assertFalse(f) existing = ReferencedDependencies() version = BlockVersion('user/user/block/master', 1) existing[version][CPPDeclaration("file.h")].add(CellName("file.h")) f.existing = existing f.update = True f.policy = Policy.default() #print f s = f.serialize() #print s f2 = FinderRequest.deserialize(s) self.assertEquals(f, f2) self.assertTrue(f2)
def test_apply_result(self): # TODO: this is actually a test of find result, move away files = { self.block_name + 'main.cpp': '#include "user2/block/sphere.h"' } self.hive_manager.process(None, files) find_result = FinderResult() version = BRLBlock('user2/user2/block/branch') + 3 d = ReferencedDependencies() decl = CPPDeclaration('user2/block/sphere.h') d[version][decl].add(BlockCellName('user2/block/sphere.h')) find_result.resolved = d hive_holder = self.hive_manager.hive_holder update_hive_with_find_result(hive_holder, find_result) self.assertEqual(2, len(hive_holder.resources)) self.assertEqual(BlockVersionTable([version]), hive_holder[self.block_name].requirements)
def testNormalizeWithWrongInput(self): d = CPPDeclaration("sphere.h") self.assertRaises(BiiException, d.normalize, ["sphere.h", "gtest.g"])
def testNormalize(self): d = CPPDeclaration("sphere.h") d2 = CPPDeclaration("sphere2.h") self.assertEquals(d.normalize(["sphere.h"]), None) self.assertEquals(d.normalize(["sphere2.h"]), d2)
def testBasic(self): d = CPPDeclaration("sphere.h") d2 = CPPDeclaration("sphere.h") d3 = CPPDeclaration("sphere2.h") self.assertEquals(d, d2) self.assertNotEqual(d, d3)
def testNormalize(self): d = CPPDeclaration("sphere.h") d2 = CPPDeclaration("sphere2.h") self.assertEquals(d.normalize(["sphere.h"]), None) self.assertEquals(d.normalize(["sphere2.h"]), d2)
def explicit_declarations(self): result = set() result |= (set([PythonDeclaration(x.name) for x in self.imports])) result |= (set([CPPDeclaration(x) for x in self.c_includes])) result |= (set([DataDeclaration(x.name) for x in self.references])) return result
def test_find_gtest_implementations(self): text = testfileutils.load('gtest/src/gtest-death-test.cc') parser = DRLCPPParser() parser.parse(text) self.assertIn(CPPDeclaration('../include/gtest/internal/gtest-port.h'), parser.explicit_declarations)