test_cmds.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 # -*- coding: utf-8 -*-
00004 
00005 '''rtshell
00006 
00007 Copyright (C) 2009-2010
00008     Geoffrey Biggs
00009     RT-Synthesis Research Group
00010     Intelligent Systems Research Institute,
00011     National Institute of Advanced Industrial Science and Technology (AIST),
00012     Japan
00013     All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016 
00017 Tests for the commands.
00018 
00019 '''
00020 
00021 
00022 import os
00023 import os.path
00024 import re
00025 import rtctree
00026 import rtctree.tree
00027 import rtsprofile.rts_profile
00028 import subprocess
00029 import sys
00030 import tempfile
00031 import time
00032 import unittest
00033 
00034 
00035 COMP_LIB_PATH='/usr/local/share/openrtm-1.1/example/rtcs'
00036 
00037 
00038 class RTCLaunchFailedError(Exception):
00039     pass
00040 
00041 
00042 def load_file(fn):
00043     with open(fn, 'r') as f:
00044         return f.read()
00045 
00046 def call_process(args):
00047     p = subprocess.Popen(args, stdout=subprocess.PIPE,
00048             stderr=subprocess.PIPE)
00049     output = p.communicate()
00050     output = (output[0].strip(), output[1].strip())
00051     return_code = p.returncode
00052     return output[0], output[1], return_code
00053 
00054 
00055 def start_process(args):
00056     return subprocess.Popen(args, stdout=subprocess.PIPE,
00057             stderr=subprocess.PIPE)
00058 
00059 
00060 def find_omninames():
00061     # If on Windows, ...
00062     # Else use ps
00063     procs, stderr, ret_code = call_process(['ps', '-e'])
00064     for p in procs.split('\n'):
00065         if 'omniNames' in p:
00066             return p.split()[0]
00067     return None
00068 
00069 
00070 def launch_comp(name):
00071     p = subprocess.Popen([os.path.join('./test', name),
00072         '-f', './test/rtc.conf'], stdout=subprocess.PIPE)
00073     p.poll()
00074     if p.returncode is not None:
00075         raise RTCLaunchFailedError
00076     return (p, name)
00077 
00078 
00079 def stop_comp(comp):
00080     comp[0].terminate()
00081     comp[0].wait()
00082     call_process(['killall', comp[1]])
00083 
00084 
00085 def start_ns():
00086     # Check if omniNames is running
00087     pid = find_omninames()
00088     if pid:
00089         # Kill the name server to get a clean one for the test
00090         call_process(['killall', 'omniNames'])
00091     # Start omniNames and return the PID
00092     return start_process('rtm-naming')
00093 
00094 
00095 def stop_ns(p):
00096     call_process(['killall', 'omniNames'])
00097 
00098 
00099 def wait_for_comp(comp, state='Inactive', tries=40, res=0.01):
00100     while tries > 0:
00101         stdout, stderr, ret = call_process(['./rtls', '-l',
00102             os.path.join('/localhost/local.host_cxt', comp)])
00103         if stdout != '':
00104             if stdout.split()[0] == state:
00105                 return
00106         tries -= 1
00107         time.sleep(res)
00108     raise RTCLaunchFailedError
00109 
00110 
00111 def make_zombie(comp='zombie_comp'):
00112     c = launch_comp(comp)
00113     wait_for_comp('Zombie0.rtc')
00114     c[0].kill()
00115     c[0].wait()
00116     call_process(['killall', c[1]])
00117 
00118 
00119 def clean_zombies():
00120     call_process(['./rtdel', '-z'])
00121 
00122 
00123 def launch_manager(tries=40, res=0.01):
00124     p = start_process(['rtcd', '-d', '-f', './test/rtc.conf'])
00125     while tries > 0:
00126         stdout, stderr, ret = call_process(['./rtls',
00127             '/localhost/local.host_cxt/manager.mgr'])
00128         if stdout == '' and stderr == '':
00129             return p
00130         tries -= 1
00131         time.sleep(res)
00132     raise RTCLaunchFailedError
00133 
00134 
00135 def stop_manager(mgr):
00136     mgr.terminate()
00137     mgr.wait()
00138     call_process(['killall', 'rtcd'])
00139 
00140 
00141 def add_obj_strs(args, obj1=None, obj2=None):
00142     if obj1 is not None:
00143         args.append('/localhost/local.host_cxt/{0}'.format(obj1))
00144     if obj2 is not None:
00145         args.append('/localhost/local.host_cxt/{0}'.format(obj2))
00146     return args
00147 
00148 
00149 def test_notacomp(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00150     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00151         obj1=obj1, obj2=obj2) + extra_opts)
00152     tester.assertEqual(stdout, '')
00153     tester.assertEqual(stderr,
00154         '{0}: Not a component: /localhost/local.host_cxt/{1}'.format(
00155             os.path.basename(cmd), obj1))
00156     tester.assertEqual(ret, 1)
00157 
00158 
00159 def test_notacomp2(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00160     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00161         obj1=obj1, obj2=obj2) + extra_opts)
00162     tester.assertEqual(stdout, '')
00163     tester.assertEqual(stderr,
00164         '{0}: Not a component: /localhost/local.host_cxt/{1}'.format(
00165             os.path.basename(cmd), obj2))
00166     tester.assertEqual(ret, 1)
00167 
00168 
00169 def test_noobject(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00170     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00171         obj1=obj1, obj2=obj2) + extra_opts)
00172     tester.assertEqual(stdout, '')
00173     tester.assertEqual(stderr,
00174         '{0}: No such object: /localhost/local.host_cxt/{1}'.format(
00175             os.path.basename(cmd), obj1))
00176     tester.assertEqual(ret, 1)
00177 
00178 
00179 def test_noobject2(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00180     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00181         obj1=obj1, obj2=obj2) + extra_opts)
00182     tester.assertEqual(stdout, '')
00183     tester.assertEqual(stderr,
00184         '{0}: No such object: /localhost/local.host_cxt/{1}'.format(
00185             os.path.basename(cmd), obj2))
00186     tester.assertEqual(ret, 1)
00187 
00188 
00189 def test_zombie(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00190     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00191         obj1=obj1, obj2=obj2) + extra_opts)
00192     tester.assertEqual(stdout, '')
00193     tester.assertEqual(stderr,
00194         '{0}: Zombie object: /localhost/local.host_cxt/{1}'.format(
00195             os.path.basename(cmd), obj1))
00196     tester.assertEqual(ret, 1)
00197 
00198 
00199 def test_portnotfound(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00200     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00201         obj1=obj1, obj2=obj2) + extra_opts)
00202     tester.assertEqual(stdout, '')
00203     tester.assertEqual(stderr,
00204         '{0}: Port not found: /localhost/local.host_cxt/{1}'.format(
00205             os.path.basename(cmd), obj1))
00206     tester.assertEqual(ret, 1)
00207 
00208 
00209 def test_port2notfound(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00210     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00211         obj1=obj1, obj2=obj2) + extra_opts)
00212     tester.assertEqual(stdout, '')
00213     tester.assertEqual(stderr,
00214         '{0}: Port not found: /localhost/local.host_cxt/{1}'.format(
00215             os.path.basename(cmd), obj2))
00216     tester.assertEqual(ret, 1)
00217 
00218 
00219 def test_sourceportnotfound(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00220     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00221         obj1=obj1, obj2=obj2) + extra_opts)
00222     tester.assertEqual(stdout, '')
00223     tester.assertEqual(stderr,
00224         '{0}: No source port specified.'.format(os.path.basename(cmd)))
00225     tester.assertEqual(ret, 1)
00226 
00227 
00228 def test_destportnotfound(tester, cmd, obj1=None, obj2=None, extra_opts=[]):
00229     stdout, stderr, ret = call_process(add_obj_strs(['./{0}'.format(cmd)],
00230         obj1=obj1, obj2=obj2) + extra_opts)
00231     tester.assertEqual(stdout, '')
00232     tester.assertEqual(stderr,
00233         '{0}: No destination port specified.'.format(os.path.basename(cmd)))
00234     tester.assertEqual(ret, 1)
00235 
00236 
00237 class rtactTests(unittest.TestCase):
00238     def setUp(self):
00239         self._ns = start_ns()
00240         self._std = launch_comp('std_comp')
00241         self._output = launch_comp('output_comp')
00242         make_zombie()
00243         self._mgr = launch_manager()
00244         wait_for_comp('Std0.rtc')
00245         wait_for_comp('Output0.rtc')
00246 
00247     def tearDown(self):
00248         stop_comp(self._std)
00249         stop_comp(self._output)
00250         clean_zombies()
00251         stop_manager(self._mgr)
00252         stop_ns(self._ns)
00253 
00254     def test_success(self):
00255         stdout, stderr, ret = call_process(['./rtact',
00256             '/localhost/local.host_cxt/Std0.rtc'])
00257         self.assertEqual(stdout, '')
00258         self.assertEqual(stderr, '')
00259         self.assertEqual(ret, 0)
00260         stdout, stderr, ret = call_process(['./rtcat',
00261             '/localhost/local.host_cxt/Std0.rtc'])
00262         self.assertEqual(stdout.split()[1], 'Active')
00263 
00264     def test_context(self):
00265         stdout, stderr, ret = call_process(['./rtact',
00266             '/localhost/local.host_cxt'])
00267         self.assertEqual(stdout, '')
00268         self.assertEqual(stderr,
00269             'rtact: Not a component: /localhost/local.host_cxt')
00270         self.assertEqual(ret, 1)
00271 
00272     def test_manager(self):
00273         test_notacomp(self, './rtact', obj1='manager.mgr')
00274 
00275     def test_port(self):
00276         test_notacomp(self, './rtact', obj1='Std0.rtc:in')
00277 
00278     def test_trailing_slash(self):
00279         test_notacomp(self, './rtact', obj1='Std0.rtc/')
00280         stdout, stderr, ret = call_process(['./rtcat',
00281             '/localhost/local.host_cxt/Std0.rtc'])
00282         self.assertEqual(stdout.split()[1], 'Inactive')
00283 
00284     def test_no_object(self):
00285         test_noobject(self, './rtact', obj1='NotAComp0.rtc')
00286 
00287     def test_zombie_object(self):
00288         test_zombie(self, './rtact', obj1='Zombie0.rtc')
00289 
00290     def test_no_arg(self):
00291         stdout, stderr, ret = call_process('./rtact')
00292         self.assertEqual(stdout, '')
00293         self.assertEqual(stderr, 'rtact: No components specified.')
00294         self.assertEqual(ret, 1)
00295 
00296     def test_multiple(self):
00297         stdout, stderr, ret = call_process(['./rtact',
00298             '/localhost/local.host_cxt/Std0.rtc',
00299             '/localhost/local.host_cxt/Output0.rtc'])
00300         self.assertEqual(stdout, '')
00301         self.assertEqual(stderr, '')
00302         self.assertEqual(ret, 0)
00303         stdout, stderr, ret = call_process(['./rtcat',
00304             '/localhost/local.host_cxt/Std0.rtc'])
00305         self.assertEqual(stdout.split()[1], 'Active')
00306         stdout, stderr, ret = call_process(['./rtcat',
00307             '/localhost/local.host_cxt/Output0.rtc'])
00308         self.assertEqual(stdout.split()[1], 'Active')
00309 
00310     def test_multiple_one_port(self):
00311         stdout, stderr, ret = call_process(['./rtact',
00312             '/localhost/local.host_cxt/Std0.rtc',
00313             '/localhost/local.host_cxt/Output0.rtc:in'])
00314         self.assertEqual(stdout, '')
00315         self.assertEqual(stderr, 'rtact: Not a component: '
00316             '/localhost/local.host_cxt/Output0.rtc:in')
00317         self.assertEqual(ret, 1)
00318         stdout, stderr, ret = call_process(['./rtcat',
00319             '/localhost/local.host_cxt/Std0.rtc'])
00320         self.assertEqual(stdout.split()[1], 'Inactive')
00321         stdout, stderr, ret = call_process(['./rtcat',
00322             '/localhost/local.host_cxt/Output0.rtc'])
00323         self.assertEqual(stdout.split()[1], 'Inactive')
00324 
00325 def rtact_suite():
00326     return unittest.TestLoader().loadTestsFromTestCase(rtactTests)
00327 
00328 
00329 class rtcatTests(unittest.TestCase):
00330     def setUp(self):
00331         self._ns = start_ns()
00332         self._std = launch_comp('std_comp')
00333         make_zombie()
00334         self._mgr = launch_manager()
00335         wait_for_comp('Std0.rtc')
00336 
00337     def tearDown(self):
00338         stop_comp(self._std)
00339         clean_zombies()
00340         stop_manager(self._mgr)
00341         stop_ns(self._ns)
00342 
00343     def test_context(self):
00344         stdout, stderr, ret = call_process(['./rtcat',
00345             '/localhost/local.host_cxt'])
00346         self.assertEqual(stdout, '')
00347         self.assertEqual(stderr, 'rtcat: No such object: '
00348             '/localhost/local.host_cxt')
00349         self.assertEqual(ret, 1)
00350 
00351     def test_no_object(self):
00352         test_noobject(self, './rtcat', obj1='NotAComp0.rtc')
00353 
00354     def test_no_object_port(self):
00355         test_noobject(self, './rtcat', obj1='NotAComp0.rtc:notaport')
00356 
00357     def test_no_arg(self):
00358         stdout, stderr, ret = call_process('./rtcat')
00359         self.assertEqual(stdout, '')
00360         self.assertEqual(stderr, 'rtcat: Cannot cat a directory.')
00361         self.assertEqual(ret, 1)
00362 
00363     def test_rtc(self):
00364         stdout, stderr, ret = call_process(['./rtcat',
00365             '/localhost/local.host_cxt/Std0.rtc'])
00366         self.assert_(stdout.startswith('Std0.rtc'))
00367         self.assert_('Inactive' in stdout)
00368         self.assert_('Category' in stdout)
00369         self.assert_('Execution Context' in stdout)
00370         self.assert_('DataInPort: in' in stdout)
00371         self.assertEqual(stderr, '')
00372         self.assertEqual(ret, 0)
00373 
00374     def test_manager(self):
00375         stdout, stderr, ret = call_process(['./rtcat',
00376             '/localhost/local.host_cxt/manager.mgr'])
00377         self.assert_(stdout.startswith('Name: manager'))
00378         self.assert_('Modules:' in stdout)
00379         self.assert_('Loaded modules:' in stdout)
00380         self.assertEqual(stderr, '')
00381         self.assertEqual(ret, 0)
00382 
00383     def test_port(self):
00384         stdout, stderr, ret = call_process(['./rtcat',
00385             '/localhost/local.host_cxt/Std0.rtc:in'])
00386         self.assertEqual(stdout, '+DataInPort: in')
00387         stdout, stderr, ret = call_process(['./rtcat', '-l',
00388             '/localhost/local.host_cxt/Std0.rtc:in'])
00389         self.assert_(stdout.startswith('-DataInPort: in'))
00390         self.assert_('dataport.data_type' in stdout)
00391         self.assert_('TimedLong' in stdout)
00392         self.assertEqual(stderr, '')
00393         self.assertEqual(ret, 0)
00394 
00395     def test_port_not_rtc(self):
00396         test_notacomp(self, './rtcat', obj1='manager.mgr:in')
00397 
00398     def test_port_trailing_slash(self):
00399         test_noobject(self, './rtcat', obj1='Std0.rtc:in/')
00400 
00401     def test_bad_port(self):
00402         test_portnotfound(self, './rtcat', obj1='Std0.rtc:out')
00403 
00404     def test_rtc_trailing_slash(self):
00405         test_noobject(self, './rtcat', obj1='Std0.rtc/')
00406 
00407     def test_zombie_object(self):
00408         test_zombie(self, './rtcat', obj1='Zombie0.rtc')
00409 
00410 
00411 def rtcat_suite():
00412     return unittest.TestLoader().loadTestsFromTestCase(rtcatTests)
00413 
00414 
00415 class rtcheckTests(unittest.TestCase):
00416     def setUp(self):
00417         self._ns = start_ns()
00418         self._std = launch_comp('std_comp')
00419         self._output = launch_comp('output_comp')
00420         wait_for_comp('Std0.rtc')
00421         wait_for_comp('Output0.rtc')
00422 
00423     def tearDown(self):
00424         stop_comp(self._std)
00425         stop_comp(self._output)
00426         stop_ns(self._ns)
00427 
00428     def test_noprobs(self):
00429         call_process(['./rtresurrect', './test/sys.rtsys'])
00430         call_process(['./rtstart', './test/sys.rtsys'])
00431         stdout, stderr, ret = call_process(['./rtcheck', './test/sys.rtsys'])
00432         self.assertEqual(stdout, '')
00433         self.assertEqual(stderr, '')
00434         self.assertEqual(ret, 0)
00435 
00436     def test_not_activated(self):
00437         call_process(['./rtresurrect', './test/sys.rtsys'])
00438         call_process(['./rtstart', './test/sys.rtsys'])
00439         call_process(['./rtdeact', '/localhost/local.host_cxt/Std0.rtc'])
00440         wait_for_comp('Std0.rtc', state='Inactive')
00441         stdout, stderr, ret = call_process(['./rtcheck', './test/sys.rtsys'])
00442         self.assertEqual(stdout, '')
00443         self.assertEqual(stderr,
00444                 'Component /localhost/local.host_cxt/Std0.rtc '\
00445                 'is in incorrect state Inactive')
00446         self.assertEqual(ret, 1)
00447 
00448     def test_not_connected(self):
00449         call_process(['./rtresurrect', './test/sys.rtsys'])
00450         call_process(['./rtstart', './test/sys.rtsys'])
00451         call_process(['./rtdis', '/localhost/local.host_cxt/Std0.rtc'])
00452         stdout, stderr, ret = call_process(['./rtcheck', './test/sys.rtsys'])
00453         self.assertEqual(stdout, '')
00454         self.assertEqual(stderr, 'No connection between '\
00455                 '/localhost/local.host_cxt/Output0.rtc:out and '\
00456                 '/localhost/local.host_cxt/Std0.rtc:in')
00457         self.assertEqual(ret, 1)
00458 
00459 
00460 def rtcheck_suite():
00461     return unittest.TestLoader().loadTestsFromTestCase(rtcheckTests)
00462 
00463 
00464 class rtcompTests(unittest.TestCase):
00465     def setUp(self):
00466         self._ns = start_ns()
00467         self._std = launch_comp('std_comp')
00468         self._mp = launch_comp('mp1_comp')
00469         self._mgr = launch_manager()
00470         wait_for_comp('Std0.rtc')
00471         wait_for_comp('MP0.rtc')
00472 
00473     def tearDown(self):
00474         stop_comp(self._std)
00475         stop_comp(self._mp)
00476         stop_manager(self._mgr)
00477         stop_ns(self._ns)
00478 
00479     def test_create(self):
00480         stdout, stderr, ret = call_process(['./rtcomp',
00481             '/localhost/local.host_cxt/manager.mgr',])
00482         self.assertEqual(stdout, '')
00483         self.assertEqual(stderr, '')
00484         self.assertEqual(ret, 0)
00485         self._assert_comp_exists('CompositeRTC.rtc')
00486         self._assert_comp_is_composite('CompositeRTC.rtc')
00487 
00488     def test_create_with_name(self):
00489         stdout, stderr, ret = call_process(['./rtcomp',
00490             '/localhost/local.host_cxt/manager.mgr:MrComponent',])
00491         self.assertEqual(stdout, '')
00492         self.assertEqual(stderr, '')
00493         self.assertEqual(ret, 0)
00494         self._assert_comp_exists('MrComponent.rtc')
00495         self._assert_comp_is_composite('MrComponent.rtc')
00496 
00497     def test_create_with_members(self):
00498         stdout, stderr, ret = call_process(['./rtcomp',
00499             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00500             '-a', '/localhost/local.host_cxt/MP0.rtc'])
00501         self.assertEqual(stdout, '')
00502         self.assertEqual(stderr, '')
00503         self.assertEqual(ret, 0)
00504         self._assert_comp_exists('MrComponent.rtc')
00505         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00506 
00507     def test_create_with_members_and_one_port(self):
00508         stdout, stderr, ret = call_process(['./rtcomp',
00509             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00510             '-a', '/localhost/local.host_cxt/MP0.rtc:in'])
00511         self.assertEqual(stdout, '')
00512         self.assertEqual(stderr, '')
00513         self.assertEqual(ret, 0)
00514         self._assert_comp_exists('MrComponent.rtc')
00515         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00516         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.in')
00517 
00518     def test_create_with_members_and_ports(self):
00519         stdout, stderr, ret = call_process(['./rtcomp',
00520             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00521             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out'])
00522         self.assertEqual(stdout, '')
00523         self.assertEqual(stderr, '')
00524         self.assertEqual(ret, 0)
00525         self._assert_comp_exists('MrComponent.rtc')
00526         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00527         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.in')
00528         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.out')
00529 
00530     def test_add_more_members(self):
00531         call_process(['./rtcomp',
00532             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00533             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out'])
00534         stdout, stderr, ret = call_process(['./rtcomp',
00535             '/localhost/local.host_cxt/MrComponent.rtc',
00536             '-a', '/localhost/local.host_cxt/Std0.rtc'])
00537         self.assertEqual(stdout, '')
00538         self.assertEqual(stderr, '')
00539         self.assertEqual(ret, 0)
00540         self._assert_comp_exists('MrComponent.rtc')
00541         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00542         self._assert_comp_has_member('MrComponent.rtc', 'Std0')
00543 
00544     def test_add_more_ports(self):
00545         call_process(['./rtcomp',
00546             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00547             '-a', '/localhost/local.host_cxt/MP0.rtc:in'])
00548         stdout, stderr, ret = call_process(['./rtcomp',
00549             '/localhost/local.host_cxt/MrComponent.rtc',
00550             '-a', '/localhost/local.host_cxt/MP0.rtc:out'])
00551         self.assertEqual(stdout, '')
00552         self.assertEqual(stderr, '')
00553         self.assertEqual(ret, 0)
00554         self._assert_comp_exists('MrComponent.rtc')
00555         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00556         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.in')
00557         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.out')
00558 
00559     def test_remove_ports(self):
00560         call_process(['./rtcomp',
00561             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00562             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out'])
00563         stdout, stderr, ret = call_process(['./rtcomp',
00564             '/localhost/local.host_cxt/MrComponent.rtc',
00565             '-r', '/localhost/local.host_cxt/MP0.rtc:out'])
00566         self.assertEqual(stdout, '')
00567         self.assertEqual(stderr, '')
00568         self.assertEqual(ret, 0)
00569         self._assert_comp_exists('MrComponent.rtc')
00570         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00571         self._assert_comp_exports_port('MrComponent.rtc', 'MP0.in')
00572         self._assert_comp_not_exports_port('MrComponent.rtc', 'MP0.out')
00573 
00574     def test_remove_all_ports(self):
00575         call_process(['./rtcomp',
00576             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00577             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out'])
00578         stdout, stderr, ret = call_process(['./rtcomp',
00579             '/localhost/local.host_cxt/MrComponent.rtc',
00580             '-r', '/localhost/local.host_cxt/MP0.rtc:in,out'])
00581         self.assertEqual(stdout, '')
00582         self.assertEqual(stderr, '')
00583         self.assertEqual(ret, 0)
00584         self._assert_comp_exists('MrComponent.rtc')
00585         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00586         self._assert_comp_not_exports_port('MrComponent.rtc', 'MP0.in')
00587         self._assert_comp_not_exports_port('MrComponent.rtc', 'MP0.out')
00588 
00589     def test_remove_members(self):
00590         call_process(['./rtcomp',
00591             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00592             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out',
00593             '-a', '/localhost/local.host_cxt/Std0.rtc'])
00594         stdout, stderr, ret = call_process(['./rtcomp',
00595             '/localhost/local.host_cxt/MrComponent.rtc',
00596             '-r', '/localhost/local.host_cxt/Std0.rtc'])
00597         self.assertEqual(stdout, '')
00598         self.assertEqual(stderr, '')
00599         self.assertEqual(ret, 0)
00600         self._assert_comp_exists('MrComponent.rtc')
00601         self._assert_comp_has_member('MrComponent.rtc', 'MP0')
00602         self._assert_comp_not_has_member('MrComponent.rtc', 'Std0')
00603 
00604     def test_remove_all_members(self):
00605         call_process(['./rtcomp',
00606             '/localhost/local.host_cxt/manager.mgr:MrComponent',
00607             '-a', '/localhost/local.host_cxt/MP0.rtc:in,out',
00608             '-a', '/localhost/local.host_cxt/Std0.rtc'])
00609         stdout, stderr, ret = call_process(['./rtcomp',
00610             '/localhost/local.host_cxt/MrComponent.rtc',
00611             '-r', '/localhost/local.host_cxt/MP0.rtc',
00612             '-r', '/localhost/local.host_cxt/Std0.rtc'])
00613         self.assertEqual(stdout, '')
00614         self.assertEqual(stderr, '')
00615         self.assertEqual(ret, 0)
00616         self._assert_comp_exists('MrComponent.rtc')
00617         self._assert_comp_not_has_member('MrComponent.rtc', 'MP0')
00618         self._assert_comp_not_has_member('MrComponent.rtc', 'Std0')
00619 
00620     def _assert_comp_exists(self, name):
00621         wait_for_comp(name)
00622         stdout, stderr, ret = call_process(['./rtls',
00623             '/localhost/local.host_cxt/{0}'.format(name)])
00624         self.assertEqual(stdout, name)
00625         self.assertEqual(stderr, '')
00626         self.assertEqual(ret, 0)
00627 
00628     def _assert_comp_is_composite(self, comp):
00629         p = ['/', 'localhost', 'local.host_cxt', comp]
00630         t = rtctree.tree.RTCTree(paths=p)
00631         c = t.get_node(p)
00632         self.assertNotEqual(c, None)
00633         self.assert_(c.is_composite)
00634 
00635     def _assert_comp_has_member(self, comp, member):
00636         p = ['/', 'localhost', 'local.host_cxt', comp]
00637         t = rtctree.tree.RTCTree(paths=p)
00638         c = t.get_node(p)
00639         self.assertNotEqual(c, None)
00640         has_member = False
00641         for m in c.members[c.organisations[0].org_id]:
00642             if m.get_component_profile().instance_name == member:
00643                 has_member = True
00644                 break
00645         self.assert_(has_member)
00646 
00647     def _assert_comp_not_has_member(self, comp, member):
00648         p = ['/', 'localhost', 'local.host_cxt', comp]
00649         t = rtctree.tree.RTCTree(paths=p)
00650         c = t.get_node(p)
00651         self.assertNotEqual(c, None)
00652         has_member = False
00653         for m in c.members[c.organisations[0].org_id]:
00654             if m.get_component_profile().instance_name == member:
00655                 has_member = True
00656                 break
00657         self.assert_(not has_member)
00658 
00659     def _assert_comp_exports_port(self, comp, port):
00660         p = ['/', 'localhost', 'local.host_cxt', comp]
00661         t = rtctree.tree.RTCTree(paths=p)
00662         c = t.get_node(p)
00663         self.assertNotEqual(c, None)
00664         ports = c.conf_sets['default'].data['exported_ports'].split(',')
00665         self.assert_(port in ports)
00666 
00667     def _assert_comp_not_exports_port(self, comp, port):
00668         p = ['/', 'localhost', 'local.host_cxt', comp]
00669         t = rtctree.tree.RTCTree(paths=p)
00670         c = t.get_node(p)
00671         self.assertNotEqual(c, None)
00672         ports = c.conf_sets['default'].data['exported_ports'].split(',')
00673         self.assert_(port not in ports)
00674 
00675 
00676 def rtcomp_suite():
00677     return unittest.TestLoader().loadTestsFromTestCase(rtcompTests)
00678 
00679 
00680 class rtconTests(unittest.TestCase):
00681     def setUp(self):
00682         self._ns = start_ns()
00683         self._std = launch_comp('std_comp')
00684         self._output = launch_comp('output_comp')
00685         self._err = launch_comp('err_comp')
00686         self._mgr = launch_manager()
00687         wait_for_comp('Std0.rtc')
00688         wait_for_comp('Output0.rtc')
00689         wait_for_comp('Err0.rtc')
00690 
00691     def tearDown(self):
00692         stop_comp(self._std)
00693         stop_comp(self._output)
00694         stop_comp(self._err)
00695         stop_manager(self._mgr)
00696         stop_ns(self._ns)
00697 
00698     def test_connect(self):
00699         stdout, stderr, ret = call_process(['./rtcon',
00700             '/localhost/local.host_cxt/Std0.rtc:in',
00701             '/localhost/local.host_cxt/Output0.rtc:out'])
00702         self.assertEqual(stdout, '')
00703         self.assertEqual(stderr, '')
00704         self.assertEqual(ret, 0)
00705         stdout, stderr, ret = call_process(['./rtcat', '-l',
00706             '/localhost/local.host_cxt/Std0.rtc:in'])
00707         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' in stdout)
00708         stdout, stderr, ret = call_process(['./rtcat', '-l',
00709             '/localhost/local.host_cxt/Output0.rtc:out'])
00710         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' in stdout)
00711 
00712     def test_set_props(self):
00713         stdout, stderr, ret = call_process(['./rtcon',
00714             '/localhost/local.host_cxt/Std0.rtc:in',
00715             '/localhost/local.host_cxt/Output0.rtc:out',
00716             '-p', 'dataport.subscription_type=new'])
00717         self.assertEqual(stdout, '')
00718         self.assertEqual(stderr, '')
00719         self.assertEqual(ret, 0)
00720         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00721             '/localhost/local.host_cxt/Std0.rtc:in'])
00722         self.assert_('dataport.subscription_type      new' in stdout)
00723         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00724             '/localhost/local.host_cxt/Output0.rtc:out'])
00725         self.assert_('dataport.subscription_type      new' in stdout)
00726 
00727     def test_bad_prop(self):
00728         stdout, stderr, ret = call_process(['./rtcon',
00729             '/localhost/local.host_cxt/Std0.rtc:in',
00730             '/localhost/local.host_cxt/Output0.rtc:out',
00731             '-p', 'dataport.subscription_type'])
00732         self.assertEqual(stdout, '')
00733         self.assert_(
00734             'Bad property format: dataport.subscription_type' in stderr)
00735         self.assertEqual(ret, 2)
00736         stdout, stderr, ret = call_process(['./rtcat', '-l',
00737             '/localhost/local.host_cxt/Std0.rtc:in'])
00738         self.assert_('Connected to: /localhost/local.host_cxt/Output0.rtc:out'\
00739                 not in stdout)
00740 
00741     def test_set_name(self):
00742         stdout, stderr, ret = call_process(['./rtcon',
00743             '/localhost/local.host_cxt/Std0.rtc:in',
00744             '/localhost/local.host_cxt/Output0.rtc:out',
00745             '-n', 'test_conn'])
00746         self.assertEqual(stdout, '')
00747         self.assertEqual(stderr, '')
00748         self.assertEqual(ret, 0)
00749         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00750             '/localhost/local.host_cxt/Std0.rtc:in'])
00751         self.assert_('test_conn' in stdout)
00752         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00753             '/localhost/local.host_cxt/Output0.rtc:out'])
00754         self.assert_('test_conn' in stdout)
00755 
00756     def test_set_id(self):
00757         stdout, stderr, ret = call_process(['./rtcon',
00758             '/localhost/local.host_cxt/Std0.rtc:in',
00759             '/localhost/local.host_cxt/Output0.rtc:out',
00760             '-i', 'conn_id'])
00761         self.assertEqual(stdout, '')
00762         self.assertEqual(stderr, '')
00763         self.assertEqual(ret, 0)
00764         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00765             '/localhost/local.host_cxt/Std0.rtc:in'])
00766         self.assert_('conn_id' in stdout)
00767         stdout, stderr, ret = call_process(['./rtcat', '-ll',
00768             '/localhost/local.host_cxt/Output0.rtc:out'])
00769         self.assert_('conn_id' in stdout)
00770 
00771     def test_no_source_port(self):
00772         test_sourceportnotfound(self, './rtcon', obj1='Std0.rtc',
00773                 obj2='Output0.rtc:out')
00774         test_sourceportnotfound(self, './rtcon', obj1='Output0.rtc',
00775                 obj2='Std0.rtc:in')
00776 
00777     def test_not_enough_targets(self):
00778         stdout, stderr, ret = call_process(['./rtcon', 'Std0.rtc:in'])
00779         self.assertEqual(stdout, '')
00780         self.assert_('Usage:' in stderr)
00781         self.assertEqual(ret, 1)
00782 
00783     def test_too_many_targets(self):
00784         stdout, stderr, ret = call_process(['./rtcon', 'Std0.rtc:in',
00785             'Output0.rtc:out', 'Err0.rtc:in'])
00786         self.assertEqual(stdout, '')
00787         self.assert_('Usage:' in stderr)
00788         self.assertEqual(ret, 1)
00789 
00790     def test_no_dest_port(self):
00791         test_destportnotfound(self, './rtcon', obj1='Std0.rtc:in',
00792                 obj2='Output0.rtc')
00793         test_destportnotfound(self, './rtcon', obj1='Output0.rtc:out',
00794                 obj2='Std0.rtc')
00795 
00796     def test_bad_source_port(self):
00797         test_portnotfound(self, './rtcon', obj1='Std0.rtc:noport',
00798                 obj2='Output0.rtc:out')
00799         test_portnotfound(self, './rtcon', obj1='Output0.rtc:noport',
00800                 obj2='Std0.rtc:in')
00801 
00802     def test_bad_source_rtc(self):
00803         test_noobject(self, './rtcon', obj1='NotAComp0.rtc:in',
00804                 obj2='Output0.rtc:out')
00805         test_noobject(self, './rtcon',
00806                 obj1='NotAComp0.rtc:out',
00807                 obj2='Std0.rtc:in')
00808 
00809     def test_bad_dest_port(self):
00810         test_port2notfound(self, './rtcon', obj1='Std0.rtc:in',
00811                 obj2='Output0.rtc:noport')
00812         test_port2notfound(self, './rtcon', obj1='Output0.rtc:out',
00813                 obj2='Std0.rtc:noport')
00814 
00815     def test_bad_dest_rtc(self):
00816         test_noobject2(self, './rtcon', obj1='Std0.rtc:in',
00817                 obj2='NotAComp0.rtc:out')
00818         test_noobject2(self, './rtcon', obj1='Output0.rtc:out',
00819                 obj2='NotAComp0.rtc:in')
00820 
00821     def test_bad_polarity(self):
00822         stdout, stderr, ret = call_process(['./rtcon',
00823             '/localhost/local.host_cxt/Std0.rtc:in',
00824             '/localhost/local.host_cxt/Err0.rtc:in'])
00825         self.assertEqual(stdout, '')
00826         self.assertEqual(stderr, 'rtcon: Wrong port type.')
00827         self.assertEqual(ret, 1)
00828 
00829     def test_context(self):
00830         stdout, stderr, ret = call_process(['./rtcon',
00831             '/localhost/local.host_cxt:port',
00832             '/localhost/local.host_cxt/Output0.rtc:out'])
00833         self.assertEqual(stdout, '')
00834         self.assertEqual(stderr,
00835             'rtcon: Not a component: /localhost/local.host_cxt:port')
00836         self.assertEqual(ret, 1)
00837         stdout, stderr, ret = call_process(['./rtcon',
00838             '/localhost/local.host_cxt/Output0.rtc:out',
00839             '/localhost/local.host_cxt:port'])
00840         self.assertEqual(stdout, '')
00841         self.assertEqual(stderr,
00842             'rtcon: Not a component: /localhost/local.host_cxt:port')
00843         self.assertEqual(ret, 1)
00844 
00845     def test_manager(self):
00846         test_sourceportnotfound(self, './rtcon', obj1='manager.mgr',
00847             obj2='Output0.rtc:out')
00848         test_destportnotfound(self, './rtcon', obj1='Std0.rtc:in', obj2='manager.mgr')
00849         test_notacomp(self, './rtcon', obj1='manager.mgr:port',
00850             obj2='Output0.rtc:out')
00851         test_notacomp2(self, './rtcon', obj1='Std0.rtc:in',
00852                 obj2='manager.mgr:port')
00853 
00854 
00855 def rtcon_suite():
00856     return unittest.TestLoader().loadTestsFromTestCase(rtconTests)
00857 
00858 
00859 class rtconfTests(unittest.TestCase):
00860     def setUp(self):
00861         self._ns = start_ns()
00862         self._std = launch_comp('std_comp')
00863         make_zombie()
00864         wait_for_comp('Std0.rtc')
00865 
00866     def tearDown(self):
00867         stop_comp(self._std)
00868         clean_zombies()
00869         stop_ns(self._ns)
00870 
00871     def test_list(self):
00872         stdout, stderr, ret = call_process(['./rtconf',
00873             '/localhost/local.host_cxt/Std0.rtc', 'list'])
00874         self.assert_('+default*' in stdout)
00875         self.assert_('+set1' in stdout)
00876         self.assert_('+set2' in stdout)
00877         self.assertEqual(stderr, '')
00878         self.assertEqual(ret, 0)
00879 
00880     def test_list_long(self):
00881         stdout, stderr, ret = call_process(['./rtconf',
00882             '/localhost/local.host_cxt/Std0.rtc', 'list', '-l'])
00883         self.assertEqual(stdout,
00884                 '-default*\n  param  0\n'\
00885                 '-set1\n  param  1\n'\
00886                 '-set2\n  param  2')
00887         self.assertEqual(stderr, '')
00888         self.assertEqual(ret, 0)
00889 
00890     def test_list_hidden_set_error(self):
00891         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
00892             '/localhost/local.host_cxt/Std0.rtc', 'list'])
00893         self.assertEqual(stdout, '')
00894         self.assertEqual(stderr, 'rtconf: No such configuration set: __hidden__')
00895         self.assertEqual(ret, 1)
00896 
00897     def test_list_hidden_set_ok(self):
00898         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
00899             '-a', '/localhost/local.host_cxt/Std0.rtc', 'list'])
00900         self.assertEqual(stdout, '+__hidden__')
00901         self.assertEqual(stderr, '')
00902         self.assertEqual(ret, 0)
00903 
00904     def test_list_bad_set(self):
00905         stdout, stderr, ret = call_process(['./rtconf', '-s', 'noset',
00906             '/localhost/local.host_cxt/Std0.rtc', 'list'])
00907         self.assertEqual(stdout, '')
00908         self.assertEqual(stderr, 'rtconf: No such configuration set: noset')
00909         self.assertEqual(ret, 1)
00910 
00911     def test_set_default(self):
00912         stdout, stderr, ret = call_process(['./rtconf',
00913             '/localhost/local.host_cxt/Std0.rtc', 'set', 'param', '42'])
00914         self.assertEqual(stdout, '')
00915         self.assertEqual(stderr, '')
00916         self.assertEqual(ret, 0)
00917         stdout, stderr, ret = call_process(['./rtconf',
00918             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00919         self.assertEqual(stdout, '42')
00920         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set1',
00921             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00922         self.assertEqual(stdout, '1')
00923         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
00924             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00925         self.assertEqual(stdout, '2')
00926 
00927     def test_set_other(self):
00928         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set1',
00929             '/localhost/local.host_cxt/Std0.rtc', 'set', 'param', '42'])
00930         self.assertEqual(stdout, '')
00931         self.assertEqual(stderr, '')
00932         self.assertEqual(ret, 0)
00933         stdout, stderr, ret = call_process(['./rtconf', '-s', 'default',
00934             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00935         self.assertEqual(stdout, '0')
00936         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set1',
00937             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00938         self.assertEqual(stdout, '42')
00939         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
00940             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00941         self.assertEqual(stdout, '2')
00942 
00943     def test_set_hidden_error(self):
00944         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
00945             '/localhost/local.host_cxt/Std0.rtc', 'set', 'param', '42'])
00946         self.assertEqual(stdout, '')
00947         self.assertEqual(stderr, 'rtconf: No such configuration set: __hidden__')
00948         self.assertEqual(ret, 1)
00949 
00950     def test_set_hidden_ok(self):
00951         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
00952             '-a', '/localhost/local.host_cxt/Std0.rtc', 'set', 'param', '42'])
00953         self.assertEqual(stdout, '')
00954         self.assertEqual(stderr, '')
00955         self.assertEqual(ret, 0)
00956         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
00957             '-a', '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00958         self.assertEqual(stdout, '42')
00959         stdout, stderr, ret = call_process(['./rtconf', '-s', 'default',
00960             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00961         self.assertEqual(stdout, '0')
00962         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set1',
00963             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00964         self.assertEqual(stdout, '1')
00965         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
00966             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00967         self.assertEqual(stdout, '2')
00968 
00969     def test_get_default(self):
00970         stdout, stderr, ret = call_process(['./rtconf',
00971             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00972         self.assertEqual(stdout, '0')
00973         self.assertEqual(stderr, '')
00974         self.assertEqual(ret, 0)
00975 
00976     def test_get_other(self):
00977         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
00978             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00979         self.assertEqual(stdout, '2')
00980         self.assertEqual(stderr, '')
00981         self.assertEqual(ret, 0)
00982 
00983     def test_get_bad_set(self):
00984         stdout, stderr, ret = call_process(['./rtconf', '-s', 'noset',
00985             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
00986         self.assertEqual(stdout, '')
00987         self.assertEqual(stderr, 'rtconf: No such configuration set: noset')
00988         self.assertEqual(ret, 1)
00989 
00990     def test_get_bad_param(self):
00991         stdout, stderr, ret = call_process(['./rtconf',
00992             '/localhost/local.host_cxt/Std0.rtc', 'get', 'noparam'])
00993         self.assertEqual(stdout, '')
00994         self.assertEqual(stderr,
00995                 'rtconf: No such configuration parameter: noparam')
00996         self.assertEqual(ret, 1)
00997 
00998     def test_get_hidden_error(self):
00999         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
01000             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
01001         self.assertEqual(stdout, '')
01002         self.assertEqual(stderr, 'rtconf: No such configuration set: __hidden__')
01003         self.assertEqual(ret, 1)
01004 
01005     def test_get_hidden_ok(self):
01006         stdout, stderr, ret = call_process(['./rtconf', '-s', '__hidden__',
01007             '-a', '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
01008         self.assertEqual(stdout, '3')
01009         self.assertEqual(stderr, '')
01010         self.assertEqual(ret, 0)
01011 
01012     def test_act(self):
01013         stdout, stderr, ret = call_process(['./rtconf',
01014             '/localhost/local.host_cxt/Std0.rtc', 'act', '-s', 'set1'])
01015         self.assertEqual(stdout, '')
01016         self.assertEqual(stderr, '')
01017         self.assertEqual(ret, 0)
01018         stdout, stderr, ret = call_process(['./rtconf',
01019             '/localhost/local.host_cxt/Std0.rtc', 'list'])
01020         self.assertEqual(stdout, '+default\n+set1*\n+set2')
01021 
01022     def test_act_bad_set(self):
01023         stdout, stderr, ret = call_process(['./rtconf',
01024             '/localhost/local.host_cxt/Std0.rtc', 'act', '-s', 'noset'])
01025         self.assertEqual(stdout, '')
01026         self.assertEqual(stderr, 'rtconf: No such configuration set: noset')
01027         self.assertEqual(ret, 1)
01028 
01029     def test_act_hidden_error(self):
01030         stdout, stderr, ret = call_process(['./rtconf',
01031             '/localhost/local.host_cxt/Std0.rtc', 'act', '-s', '__hidden__'])
01032         self.assertEqual(stdout, '')
01033         self.assertEqual(stderr, 'rtconf: No such configuration set: __hidden__')
01034         self.assertEqual(ret, 1)
01035 
01036     def test_act_hidden_ok(self):
01037         stdout, stderr, ret = call_process(['./rtconf', '-a',
01038             '/localhost/local.host_cxt/Std0.rtc', 'act', '-s', '__hidden__'])
01039         self.assertEqual(stdout, '')
01040         self.assert_('SDOPackage.InternalError' in stderr)
01041         self.assertEqual(ret, 1)
01042 
01043     def test_context(self):
01044         test_noobject(self, './rtconf', obj1='')
01045 
01046     def test_manager(self):
01047         test_noobject(self, './rtconf', obj1='manager.rtc',
01048                 extra_opts=['list'])
01049 
01050     def test_port(self):
01051         test_notacomp(self, './rtconf', obj1='Std0.rtc:in')
01052 
01053     def test_trailing_slash(self):
01054         test_noobject(self, './rtconf', obj1='Std0.rtc/')
01055 
01056     def test_bad_comp(self):
01057         test_noobject(self, './rtconf', obj1='NotAComp0.rtc')
01058 
01059     def test_zombie(self):
01060         test_zombie(self, './rtconf', obj1='Zombie0.rtc')
01061 
01062 
01063 def rtconf_suite():
01064     return unittest.TestLoader().loadTestsFromTestCase(rtconfTests)
01065 
01066 
01067 class rtcryoTests(unittest.TestCase):
01068     def setUp(self):
01069         self._ns = start_ns()
01070         self._std = launch_comp('std_comp')
01071         self._output = launch_comp('output_comp')
01072         wait_for_comp('Std0.rtc')
01073         wait_for_comp('Output0.rtc')
01074         stdout, stderr, ret = call_process(['./rtresurrect',
01075             './test/sys.rtsys'])
01076         self.assertEqual(stdout, '')
01077         self.assertEqual(stderr, '')
01078         self.assertEqual(ret, 0)
01079 
01080     def tearDown(self):
01081         stop_comp(self._std)
01082         stop_comp(self._output)
01083         stop_ns(self._ns)
01084 
01085     def _check_rtsys_xml(self, rtsys):
01086         self.assert_(rtsys.startswith('<?xml'))
01087         # Components
01088         self.assert_('rts:instanceName="Std0"' in rtsys)
01089         self.assert_('rts:instanceName="Output0"' in rtsys)
01090         # Configuration sets and parameters
01091         self.assert_('rts:ConfigurationSets rts:id="default"' in rtsys)
01092         self.assert_('rts:ConfigurationSets rts:id="__hidden__"' in rtsys)
01093         self.assert_('rts:ConfigurationSets rts:id="set1"' in rtsys)
01094         self.assert_('rts:ConfigurationSets rts:id="set2"' in rtsys)
01095         self.assert_('rts:name="param"' in rtsys)
01096         self.assert_('rts:data="0"' in rtsys)
01097         self.assert_('rts:data="1"' in rtsys)
01098         self.assert_('rts:data="42"' in rtsys)
01099         self.assert_('rts:data="3"' in rtsys)
01100         # Connections
01101         self.assert_('rts:DataPortConnectors' in rtsys)
01102         self.assert_('rts:name="in_out"' in rtsys)
01103         self.assert_('rts:sourceDataPort' in rtsys)
01104         self.assert_('rts:portName="Output0.out"' in rtsys)
01105         self.assert_('rts:targetDataPort' in rtsys)
01106         self.assert_('rts:portName="Std0.in"' in rtsys)
01107         # Can it be loaded?
01108         rtsprofile.rts_profile.RtsProfile(xml_spec=rtsys)
01109 
01110     def _check_rtsys_yaml(self, rtsys):
01111         self.assert_(rtsys.startswith('rtsProfile:'))
01112         # Components
01113         self.assert_('instanceName: Std0' in rtsys)
01114         self.assert_('instanceName: Output0' in rtsys)
01115         # Configuration sets and parameters
01116         self.assert_('id: default' in rtsys)
01117         self.assert_('id: __hidden__' in rtsys)
01118         self.assert_('id: set1' in rtsys)
01119         self.assert_('id: set2' in rtsys)
01120         self.assert_('name: param' in rtsys)
01121         self.assert_("data: '0'" in rtsys)
01122         self.assert_("data: '1'" in rtsys)
01123         self.assert_("data: '42'" in rtsys)
01124         self.assert_("data: '3'" in rtsys)
01125         # Connections
01126         self.assert_('dataPortConnectors' in rtsys)
01127         self.assert_('name: in_out' in rtsys)
01128         self.assert_('sourceDataPort' in rtsys)
01129         self.assert_('portName: Output0.out' in rtsys)
01130         self.assert_('targetDataPort' in rtsys)
01131         self.assert_('portName: Std0.in' in rtsys)
01132         # Can it be loaded?
01133         rtsprofile.rts_profile.RtsProfile(yaml_spec=rtsys)
01134 
01135     def test_freeze_to_stdout_xml(self):
01136         stdout, stderr, ret = call_process(['./rtcryo', '-x'])
01137         self.assertEqual(stderr, '')
01138         self.assertEqual(ret, 0)
01139         self._check_rtsys_xml(stdout)
01140 
01141     def test_freeze_to_file_xml(self):
01142         f, fn = tempfile.mkstemp(prefix='rtshell_test_')
01143         os.close(f)
01144         stdout, stderr, ret = call_process(['./rtcryo', '-x', '-o', fn])
01145         rtsys = load_file(fn)
01146         os.remove(fn)
01147         self.assertEqual(stdout, '')
01148         self.assertEqual(stderr, '')
01149         self.assertEqual(ret, 0)
01150         self._check_rtsys_xml(rtsys)
01151 
01152     def test_freeze_to_stdout_yaml(self):
01153         stdout, stderr, ret = call_process(['./rtcryo', '-y'])
01154         self.assertEqual(stderr, '')
01155         self.assertEqual(ret, 0)
01156         self._check_rtsys_yaml(stdout)
01157 
01158     def test_freeze_to_file_yaml(self):
01159         f, fn = tempfile.mkstemp(prefix='rtshell_test_')
01160         os.close(f)
01161         stdout, stderr, ret = call_process(['./rtcryo', '-y', '-o', fn])
01162         rtsys = load_file(fn)
01163         os.remove(fn)
01164         self.assertEqual(stdout, '')
01165         self.assertEqual(stderr, '')
01166         self.assertEqual(ret, 0)
01167         self._check_rtsys_yaml(rtsys)
01168 
01169     def test_freeze_abstract(self):
01170         stdout, stderr, ret = call_process(['./rtcryo', '-a',
01171             'This is an abstract'])
01172         self.assertEqual(stderr, '')
01173         self.assertEqual(ret, 0)
01174         orig = load_file('./test/sys.rtsys')
01175         self.assertNotEqual(stdout, orig)
01176         self.assert_('rts:abstract="This is an abstract"' in stdout)
01177 
01178     def test_freeze_sysname(self):
01179         stdout, stderr, ret = call_process(['./rtcryo', '-n',
01180             'system name'])
01181         self.assertEqual(stderr, '')
01182         self.assertEqual(ret, 0)
01183         orig = load_file('./test/sys.rtsys')
01184         self.assertNotEqual(stdout, orig)
01185         self.assert_('rts:id="RTSystem :Me.system name.0"' in stdout)
01186 
01187     def test_freeze_version(self):
01188         stdout, stderr, ret = call_process(['./rtcryo', '-v',
01189             '42'])
01190         self.assertEqual(stderr, '')
01191         self.assertEqual(ret, 0)
01192         orig = load_file('./test/sys.rtsys')
01193         self.assertNotEqual(stdout, orig)
01194         self.assert_('rts:id="RTSystem :Me.RTSystem.42"' in stdout)
01195 
01196     def test_freeze_vendor(self):
01197         stdout, stderr, ret = call_process(['./rtcryo', '-e',
01198             'UnitTest'])
01199         self.assertEqual(stderr, '')
01200         self.assertEqual(ret, 0)
01201         orig = load_file('./test/sys.rtsys')
01202         self.assertNotEqual(stdout, orig)
01203         self.assert_('rts:id="RTSystem :UnitTest.RTSystem.0"' in stdout)
01204 
01205 
01206 def rtcryo_suite():
01207     return unittest.TestLoader().loadTestsFromTestCase(rtcryoTests)
01208 
01209 
01210 class rtcwdTests(unittest.TestCase):
01211     def setUp(self):
01212         self._ns = start_ns()
01213         self._std = launch_comp('std_comp')
01214         self._mgr = launch_manager()
01215         wait_for_comp('Std0.rtc')
01216 
01217     def tearDown(self):
01218         stop_comp(self._std)
01219         stop_manager(self._mgr)
01220         stop_ns(self._ns)
01221 
01222     def test_cwd_nothing(self):
01223         stdout, stderr, ret = self._run_rtcwd('')
01224         self.assertEqual(stdout, 'export RTCSH_CWD="/"')
01225         self.assertEqual(stderr, '')
01226         self.assertEqual(ret, 0)
01227 
01228     def test_cwd_root(self):
01229         stdout, stderr, ret = self._run_rtcwd('/')
01230         self.assertEqual(stdout, 'export RTCSH_CWD="/"')
01231         self.assertEqual(stderr, '')
01232         self.assertEqual(ret, 0)
01233 
01234     def test_cwd_ns(self):
01235         stdout, stderr, ret = self._run_rtcwd('/localhost')
01236         self.assertEqual(stdout, 'export RTCSH_CWD="/localhost"')
01237         self.assertEqual(stderr, '')
01238         self.assertEqual(ret, 0)
01239         stdout, stderr, ret = self._run_rtcwd('/localhost/')
01240         self.assertEqual(stdout, 'export RTCSH_CWD="/localhost/"')
01241         self.assertEqual(stderr, '')
01242         self.assertEqual(ret, 0)
01243 
01244     def test_cwd_cxt(self):
01245         stdout, stderr, ret = self._run_rtcwd('/localhost/local.host_cxt')
01246         self.assertEqual(stdout, 'export RTCSH_CWD="/localhost/local.host_cxt"')
01247         self.assertEqual(stderr, '')
01248         self.assertEqual(ret, 0)
01249         stdout, stderr, ret = self._run_rtcwd('/localhost/local.host_cxt/')
01250         self.assertEqual(stdout, 'export RTCSH_CWD="/localhost/local.host_cxt/"')
01251         self.assertEqual(stderr, '')
01252         self.assertEqual(ret, 0)
01253 
01254     def test_cwd_comp(self):
01255         stdout, stderr, ret = self._run_rtcwd(
01256                 '/localhost/local.host_cxt/Std0.rtc')
01257         self.assertEqual(stdout, '')
01258         self.assertEqual(stderr, 'rtcwd: Not a directory: '\
01259                 '/localhost/local.host_cxt/Std0.rtc')
01260         self.assertEqual(ret, 1)
01261         stdout, stderr, ret = self._run_rtcwd(
01262                 '/localhost/local.host_cxt/Std0.rtc/')
01263         self.assertEqual(stdout, '')
01264         self.assertEqual(stderr, 'rtcwd: Not a directory: '\
01265                 '/localhost/local.host_cxt/Std0.rtc/')
01266         self.assertEqual(ret, 1)
01267 
01268     def test_cwd_mgr(self):
01269         stdout, stderr, ret = self._run_rtcwd(
01270                 '/localhost/local.host_cxt/manager.mgr')
01271         self.assertEqual(stdout,
01272                 'export RTCSH_CWD="/localhost/local.host_cxt/manager.mgr"')
01273         self.assertEqual(stderr, '')
01274         self.assertEqual(ret, 0)
01275         stdout, stderr, ret = self._run_rtcwd(
01276                 '/localhost/local.host_cxt/manager.mgr/')
01277         self.assertEqual(stdout,
01278                 'export RTCSH_CWD="/localhost/local.host_cxt/manager.mgr/"')
01279         self.assertEqual(stderr, '')
01280         self.assertEqual(ret, 0)
01281 
01282 
01283     def test_cwd_no_object(self):
01284         stdout, stderr, ret = self._run_rtcwd(
01285                 '/localhost/local.host_cxt/Nothing')
01286         self.assertEqual(stdout, '')
01287         self.assertEqual(stderr,
01288                 'rtcwd: Not a directory: /localhost/local.host_cxt/Nothing')
01289         self.assertEqual(ret, 1)
01290         stdout, stderr, ret = self._run_rtcwd(
01291                 '/localhost/local.host_cxt/Nothing/')
01292         self.assertEqual(stdout, '')
01293         self.assertEqual(stderr,
01294                 'rtcwd: Not a directory: /localhost/local.host_cxt/Nothing/')
01295         self.assertEqual(ret, 1)
01296 
01297 
01298     def _run_rtcwd(self, target):
01299         return call_process(['python', '-c',
01300             'import sys; import rtshell.rtcwd; sys.exit(rtshell.rtcwd.main('\
01301             '["{0}"]))'.format(target)])
01302 
01303 
01304 def rtcwd_suite():
01305     return unittest.TestLoader().loadTestsFromTestCase(rtcwdTests)
01306 
01307 
01308 class rtdeactTests(unittest.TestCase):
01309     def setUp(self):
01310         self._ns = start_ns()
01311         self._std = launch_comp('std_comp')
01312         self._output = launch_comp('output_comp')
01313         make_zombie()
01314         self._mgr = launch_manager()
01315         call_process(['./rtact', '/localhost/local.host_cxt/Std0.rtc'])
01316         wait_for_comp('Std0.rtc', state='Active')
01317         wait_for_comp('Output0.rtc', state='Active')
01318 
01319     def tearDown(self):
01320         stop_comp(self._std)
01321         stop_comp(self._output)
01322         clean_zombies()
01323         stop_manager(self._mgr)
01324         stop_ns(self._ns)
01325 
01326     def test_success(self):
01327         stdout, stderr, ret = call_process(['./rtdeact',
01328             '/localhost/local.host_cxt/Std0.rtc'])
01329         self.assertEqual(stdout, '')
01330         self.assertEqual(stderr, '')
01331         self.assertEqual(ret, 0)
01332         stdout, stderr, ret = call_process(['./rtcat',
01333             '/localhost/local.host_cxt/Std0.rtc'])
01334         self.assertEqual(stdout.split()[1], 'Inactive')
01335 
01336     def test_context(self):
01337         stdout, stderr, ret = call_process(['./rtdeact',
01338             '/localhost/local.host_cxt'])
01339         self.assertEqual(stdout, '')
01340         self.assertEqual(stderr,
01341             'rtdeact: Not a component: /localhost/local.host_cxt')
01342         self.assertEqual(ret, 1)
01343 
01344 
01345     def test_manager(self):
01346         test_notacomp(self, './rtdeact', obj1='manager.mgr')
01347 
01348     def test_port(self):
01349         test_notacomp(self, './rtdeact', obj1='Std0.rtc:in')
01350 
01351     def test_trailing_slash(self):
01352         test_notacomp(self, './rtdeact', obj1='Std0.rtc/')
01353         stdout, stderr, ret = call_process(['./rtcat',
01354             '/localhost/local.host_cxt/Std0.rtc'])
01355         self.assertEqual(stdout.split()[1], 'Active')
01356 
01357     def test_no_object(self):
01358         test_noobject(self, './rtdeact', obj1='NotAComp0.rtc')
01359 
01360     def test_zombie_object(self):
01361         test_zombie(self, './rtdeact', obj1='Zombie0.rtc')
01362 
01363     def test_no_arg(self):
01364         stdout, stderr, ret = call_process('./rtdeact')
01365         self.assertEqual(stdout, '')
01366         self.assertEqual(stderr, 'rtdeact: No components specified.')
01367         self.assertEqual(ret, 1)
01368 
01369     def test_multiple(self):
01370         stdout, stderr, ret = call_process(['./rtdeact',
01371             '/localhost/local.host_cxt/Std0.rtc',
01372             '/localhost/local.host_cxt/Output0.rtc'])
01373         self.assertEqual(stdout, '')
01374         self.assertEqual(stderr, '')
01375         self.assertEqual(ret, 0)
01376         stdout, stderr, ret = call_process(['./rtcat',
01377             '/localhost/local.host_cxt/Std0.rtc'])
01378         self.assertEqual(stdout.split()[1], 'Inactive')
01379         stdout, stderr, ret = call_process(['./rtcat',
01380             '/localhost/local.host_cxt/Output0.rtc'])
01381         self.assertEqual(stdout.split()[1], 'Inactive')
01382 
01383 
01384 def rtdeact_suite():
01385     return unittest.TestLoader().loadTestsFromTestCase(rtdeactTests)
01386 
01387 
01388 class rtdelTests(unittest.TestCase):
01389     def setUp(self):
01390         self._ns = start_ns()
01391         self._std = launch_comp('std_comp')
01392         make_zombie()
01393         self._mgr = launch_manager()
01394         self._load_mgr()
01395         wait_for_comp('Std0.rtc')
01396 
01397     def tearDown(self):
01398         stop_comp(self._std)
01399         clean_zombies()
01400         stop_manager(self._mgr)
01401         stop_ns(self._ns)
01402 
01403     def _load_mgr(self):
01404         stdout, stderr, ret = call_process(['./rtmgr',
01405             '/localhost/local.host_cxt/manager.mgr', '-l',
01406             os.path.join(COMP_LIB_PATH, 'Motor.so'), '-i',
01407             'MotorInit', '-c', 'Motor'])
01408         self.assertEqual(ret, 0)
01409 
01410     def test_rtc(self):
01411         stdout, stderr, ret = call_process(['./rtdel',
01412             '/localhost/local.host_cxt/Std0.rtc'])
01413         self.assertEqual(stdout, '')
01414         self.assertEqual(stderr, '')
01415         self.assertEqual(ret, 0)
01416         stdout, stderr, ret = call_process(['./rtls',
01417             '/localhost/local.host_cxt/Std0.rtc'])
01418         self.assertEqual(stdout, '')
01419 
01420     def test_context(self):
01421         stdout, stderr, ret = call_process(['./rtdel',
01422             '/localhost/local.host_cxt'])
01423         self.assertEqual(stdout, '')
01424         self.assertEqual(stderr, '')
01425         self.assertEqual(ret, 0)
01426         stdout, stderr, ret = call_process(['./rtls',
01427             '/localhost/local.host_cxt'])
01428         self.assertEqual(stdout, '')
01429 
01430     def test_manager(self):
01431         stdout, stderr, ret = call_process(['./rtdel',
01432             '/localhost/local.host_cxt/manager.mgr'])
01433         self.assertEqual(stdout, '')
01434         self.assertEqual(stderr, '')
01435         self.assertEqual(ret, 0)
01436         stdout, stderr, ret = call_process(['./rtls',
01437             '/localhost/local.host_cxt/manager.mgr'])
01438         self.assertEqual(stdout, '')
01439 
01440     def test_manager_child(self):
01441         stdout, stderr, ret = call_process(['./rtdel',
01442             '/localhost/local.host_cxt/manager.mgr/Motor0.rtc'])
01443         self.assertEqual(stdout, '')
01444         self.assertEqual(stderr, 'rtdel: Parent not a directory: '
01445             '/localhost/local.host_cxt/manager.mgr/Motor0.rtc')
01446         self.assertEqual(ret, 1)
01447         stdout, stderr, ret = call_process(['./rtls',
01448             '/localhost/local.host_cxt/manager.mgr/Motor0.rtc'])
01449         self.assertEqual(stdout, 'Motor0.rtc')
01450 
01451     def test_port(self):
01452         stdout, stderr, ret = call_process(['./rtdel',
01453             '/localhost/local.host_cxt/Std0.rtc:in'])
01454         self.assertEqual(stdout, '')
01455         self.assertEqual(stderr, 'rtdel: Undeletable object: '
01456             '/localhost/local.host_cxt/Std0.rtc:in')
01457         self.assertEqual(ret, 1)
01458 
01459     def test_ns(self):
01460         stdout, stderr, ret = call_process(['./rtdel',
01461             '/localhost'])
01462         self.assertEqual(stdout, '')
01463         self.assertEqual(stderr, 'rtdel: Undeletable object: /localhost')
01464         self.assertEqual(ret, 1)
01465 
01466     def test_trailing_slash(self):
01467         stdout, stderr, ret = call_process(['./rtdel',
01468             '/localhost/local.host_cxt/Std0.rtc/'])
01469         self.assertEqual(stdout, '')
01470         self.assertEqual(stderr, '')
01471         self.assertEqual(ret, 0)
01472         stdout, stderr, ret = call_process(['./rtls',
01473             '/localhost/local.host_cxt/Std0.rtc'])
01474         self.assertEqual(stdout, '')
01475 
01476     def test_zombie(self):
01477         stdout, stderr, ret = call_process(['./rtdel',
01478             '/localhost/local.host_cxt/Zombie0.rtc'])
01479         self.assertEqual(stdout, '')
01480         self.assertEqual(stderr, '')
01481         self.assertEqual(ret, 0)
01482         stdout, stderr, ret = call_process(['./rtls',
01483             '/localhost/local.host_cxt/Zombie0.rtc'])
01484         self.assertEqual(stdout, '')
01485 
01486     def test_notazombie(self):
01487         stdout, stderr, ret = call_process(['./rtdel', '-z',
01488             '/localhost/local.host_cxt/Std0.rtc'])
01489         self.assertEqual(stdout, '')
01490         self.assertEqual(stderr, 'rtdel: Not a zombie object: '
01491             '/localhost/local.host_cxt/Std0.rtc')
01492         self.assertEqual(ret, 1)
01493         stdout, stderr, ret = call_process(['./rtls',
01494             '/localhost/local.host_cxt/Std0.rtc'])
01495         self.assertEqual(stdout, 'Std0.rtc')
01496 
01497     def test_isazombie(self):
01498         stdout, stderr, ret = call_process(['./rtdel', '-z',
01499             '/localhost/local.host_cxt/Zombie0.rtc'])
01500         self.assertEqual(stdout, '')
01501         self.assertEqual(stderr, '')
01502         self.assertEqual(ret, 0)
01503         stdout, stderr, ret = call_process(['./rtls',
01504             '/localhost/local.host_cxt/Zombie0.rtc'])
01505         self.assertEqual(stdout, '')
01506 
01507     def test_all_zombies(self):
01508         stdout, stderr, ret = call_process(['./rtdel', '-z'])
01509         self.assertEqual(stdout, '')
01510         self.assertEqual(stderr, '')
01511         self.assertEqual(ret, 0)
01512         stdout, stderr, ret = call_process(['./rtls',
01513             '/localhost/local.host_cxt/Std0.rtc'])
01514         self.assertEqual(stdout, 'Std0.rtc')
01515         stdout, stderr, ret = call_process(['./rtls',
01516             '/localhost/local.host_cxt/Zombie0.rtc'])
01517         self.assertEqual(stdout, '')
01518 
01519 
01520 def rtdel_suite():
01521     return unittest.TestLoader().loadTestsFromTestCase(rtdelTests)
01522 
01523 
01524 class rtdisTests(unittest.TestCase):
01525     def setUp(self):
01526         self._ns = start_ns()
01527         self._std = launch_comp('std_comp')
01528         self._output = launch_comp('output_comp')
01529         self._err = launch_comp('err_comp')
01530         self._mgr = launch_manager()
01531         wait_for_comp('Std0.rtc')
01532         wait_for_comp('Output0.rtc')
01533         wait_for_comp('Err0.rtc')
01534         self._connect_comps()
01535 
01536     def tearDown(self):
01537         stop_comp(self._std)
01538         stop_comp(self._output)
01539         stop_comp(self._err)
01540         stop_manager(self._mgr)
01541         stop_ns(self._ns)
01542 
01543     def _connect_comps(self):
01544         stdout, stderr, ret = call_process(['./rtcon', '-i', 'con1',
01545             '/localhost/local.host_cxt/Std0.rtc:in',
01546             '/localhost/local.host_cxt/Output0.rtc:out'])
01547         self.assertEqual(ret, 0)
01548         stdout, stderr, ret = call_process(['./rtcon', '-i', 'con2',
01549             '/localhost/local.host_cxt/Output0.rtc:out',
01550             '/localhost/local.host_cxt/Err0.rtc:in'])
01551         self.assertEqual(ret, 0)
01552 
01553     def test_disconnect_all(self):
01554         stdout, stderr, ret = call_process(['./rtdis',
01555             '/localhost/local.host_cxt/Output0.rtc:out'])
01556         self.assertEqual(stdout, '')
01557         self.assertEqual(stderr, '')
01558         self.assertEqual(ret, 0)
01559         stdout, stderr, ret = call_process(['./rtcat', '-l',
01560             '/localhost/local.host_cxt/Output0.rtc:out'])
01561         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' not in stdout)
01562         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' not in stdout)
01563         stdout, stderr, ret = call_process(['./rtcat', '-l',
01564             '/localhost/local.host_cxt/Std0.rtc:in'])
01565         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01566         stdout, stderr, ret = call_process(['./rtcat', '-l',
01567             '/localhost/local.host_cxt/Err0.rtc:in'])
01568         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01569 
01570     def test_disconnect_one_from_many(self):
01571         stdout, stderr, ret = call_process(['./rtdis',
01572             '/localhost/local.host_cxt/Output0.rtc:out',
01573             '/localhost/local.host_cxt/Std0.rtc:in',])
01574         self.assertEqual(stdout, '')
01575         self.assertEqual(stderr, '')
01576         self.assertEqual(ret, 0)
01577         stdout, stderr, ret = call_process(['./rtcat', '-l',
01578             '/localhost/local.host_cxt/Output0.rtc:out'])
01579         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' not in stdout)
01580         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)
01581         stdout, stderr, ret = call_process(['./rtcat', '-l',
01582             '/localhost/local.host_cxt/Std0.rtc:in'])
01583         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01584         stdout, stderr, ret = call_process(['./rtcat', '-l',
01585             '/localhost/local.host_cxt/Err0.rtc:in'])
01586         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' in stdout)
01587 
01588     def test_disconnect_one_from_one(self):
01589         # Get rid of one connection to prepare for the test
01590         stdout, stderr, ret = call_process(['./rtdis',
01591             '/localhost/local.host_cxt/Output0.rtc:out',
01592             '/localhost/local.host_cxt/Std0.rtc:in',])
01593         self.assertEqual(ret, 0)
01594         # Now test
01595         stdout, stderr, ret = call_process(['./rtdis',
01596             '/localhost/local.host_cxt/Output0.rtc:out',
01597             '/localhost/local.host_cxt/Err0.rtc:in',])
01598         self.assertEqual(stdout, '')
01599         self.assertEqual(stderr, '')
01600         self.assertEqual(ret, 0)
01601         stdout, stderr, ret = call_process(['./rtcat', '-l',
01602             '/localhost/local.host_cxt/Output0.rtc:out'])
01603         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' not in stdout)
01604         stdout, stderr, ret = call_process(['./rtcat', '-l',
01605             '/localhost/local.host_cxt/Err0.rtc:in'])
01606         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01607 
01608     def test_disconnect_one_by_id(self):
01609         stdout, stderr, ret = call_process(['./rtdis', '-i', 'con1',
01610             '/localhost/local.host_cxt/Output0.rtc:out',
01611             '/localhost/local.host_cxt/Std0.rtc:in',])
01612         self.assertEqual(stdout, '')
01613         self.assertEqual(stderr, '')
01614         self.assertEqual(ret, 0)
01615         stdout, stderr, ret = call_process(['./rtcat', '-l',
01616             '/localhost/local.host_cxt/Output0.rtc:out'])
01617         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' not in stdout)
01618         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)
01619         stdout, stderr, ret = call_process(['./rtcat', '-l',
01620             '/localhost/local.host_cxt/Std0.rtc:in'])
01621         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01622         stdout, stderr, ret = call_process(['./rtcat', '-l',
01623             '/localhost/local.host_cxt/Err0.rtc:in'])
01624         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' in stdout)
01625 
01626     def test_disconnect_all_by_id(self):
01627         stdout, stderr, ret = call_process(['./rtdis', '-i', 'con1', '-v', 
01628             '/localhost/local.host_cxt/Output0.rtc:out'])
01629         self.assertEqual(stdout, '')
01630         self.assertEqual(stderr, '')
01631         self.assertEqual(ret, 0)
01632         stdout, stderr, ret = call_process(['./rtcat', '-l',
01633             '/localhost/local.host_cxt/Output0.rtc:out'])
01634         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' not in stdout)
01635         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)
01636         stdout, stderr, ret = call_process(['./rtcat', '-l',
01637             '/localhost/local.host_cxt/Std0.rtc:in'])
01638         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' not in stdout)
01639         stdout, stderr, ret = call_process(['./rtcat', '-l',
01640             '/localhost/local.host_cxt/Err0.rtc:in'])
01641         self.assert_('/localhost/local.host_cxt/Output0.rtc:out' in stdout)
01642 
01643     def test_disconnect_not_connected(self):
01644         # Get rid of one connection to prepare for the test
01645         stdout, stderr, ret = call_process(['./rtdis',
01646             '/localhost/local.host_cxt/Output0.rtc:out',
01647             '/localhost/local.host_cxt/Std0.rtc:in',])
01648         self.assertEqual(ret, 0)
01649         # Now test
01650         stdout, stderr, ret = call_process(['./rtdis',
01651             '/localhost/local.host_cxt/Output0.rtc:out',
01652             '/localhost/local.host_cxt/Std0.rtc:in',])
01653         self.assertEqual(stdout, '')
01654         self.assertEqual(stderr, 'rtdis: No connection from '
01655             '/localhost/local.host_cxt/Output0.rtc:out to '
01656             '/localhost/local.host_cxt/Std0.rtc:in')
01657         self.assertEqual(ret, 1)
01658         stdout, stderr, ret = call_process(['./rtcat', '-l',
01659             '/localhost/local.host_cxt/Output0.rtc:out'])
01660         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)
01661 
01662     def test_disconnect_bad_id(self):
01663         stdout, stderr, ret = call_process(['./rtdis', '-i', 'no_id',
01664             '/localhost/local.host_cxt/Output0.rtc:out',
01665             '/localhost/local.host_cxt/Std0.rtc:in',])
01666         self.assertEqual(stdout, '')
01667         self.assertEqual(stderr, 'rtdis: No connection from '
01668             '/localhost/local.host_cxt/Output0.rtc:out with ID no_id')
01669         self.assertEqual(ret, 1)
01670         stdout, stderr, ret = call_process(['./rtcat', '-l',
01671             '/localhost/local.host_cxt/Output0.rtc:out'])
01672         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' in stdout)
01673         self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)
01674 
01675     def test_no_source_port(self):
01676         test_sourceportnotfound(self, 'rtdis', obj1='Std0.rtc',
01677                 obj2='Output0.rtc:out')
01678         test_sourceportnotfound(self, 'rtdis', obj1='Output0.rtc',
01679                 obj2='Std0.rtc:in')
01680 
01681     def test_too_many_targets(self):
01682         stdout, stderr, ret = call_process(['./rtdis', 'Std0.rtc:in',
01683             'Output0.rtc:out', 'Err0.rtc:in'])
01684         self.assertEqual(stdout, '')
01685         self.assert_('Usage:' in stderr)
01686         self.assertEqual(ret, 1)
01687 
01688     def test_no_dest_port(self):
01689         test_destportnotfound(self, 'rtdis', obj1='Std0.rtc:in',
01690                 obj2='Output0.rtc')
01691         test_destportnotfound(self, 'rtdis', obj1='Output0.rtc:out',
01692                 obj2='Std0.rtc')
01693 
01694     def test_bad_source_port(self):
01695         test_portnotfound(self, 'rtdis', obj1='Std0.rtc:noport',
01696                 obj2='Output0.rtc:out')
01697         test_portnotfound(self, 'rtdis', obj1='Output0.rtc:noport',
01698                 obj2='Std0.rtc:in')
01699 
01700     def test_bad_source_rtc(self):
01701         test_sourceportnotfound(self, 'rtdis', obj1='',
01702                 obj2='Output0.rtc:out')
01703         test_noobject(self, 'rtdis', obj1='Std0.rtc/:in',
01704                 obj2='Output0.rtc:out')
01705         test_noobject(self, 'rtdis', obj1='NotAComp0.rtc:in',
01706                 obj2='Output0.rtc:out')
01707         test_noobject(self, 'rtdis',
01708                 obj1='NotAComp0.rtc:out',
01709                 obj2='Std0.rtc:in')
01710 
01711     def test_bad_dest_port(self):
01712         test_port2notfound(self, 'rtdis', obj1='Std0.rtc:in',
01713                 obj2='Output0.rtc:noport')
01714         test_port2notfound(self, 'rtdis', obj1='Output0.rtc:out',
01715                 obj2='Std0.rtc:noport')
01716 
01717     def test_bad_dest_rtc(self):
01718         test_noobject2(self, 'rtdis', obj1='Std0.rtc:in',
01719                 obj2='Output0.rtc/:out')
01720         test_noobject2(self, 'rtdis', obj1='Std0.rtc:in',
01721                 obj2='NotAComp0.rtc:out')
01722         test_noobject2(self, 'rtdis', obj1='Output0.rtc:out',
01723                 obj2='NotAComp0.rtc:in')
01724 
01725     def test_context(self):
01726         test_noobject(self, 'rtdis', obj1=':port', obj2='Output0.rtc:out')
01727         test_noobject2(self, 'rtdis', obj1='Std0.rtc:in', obj2=':port')
01728 
01729     def test_manager(self):
01730         test_notacomp(self, 'rtdis', obj1='manager.mgr:port',
01731             obj2='Output0.rtc:out')
01732         test_notacomp2(self, 'rtdis', obj1='Std0.rtc:in', obj2='manager.mgr:port')
01733 
01734 
01735 def rtdis_suite():
01736     return unittest.TestLoader().loadTestsFromTestCase(rtdisTests)
01737 
01738 
01739 class rtdocTests(unittest.TestCase):
01740     def setUp(self):
01741         self._ns = start_ns()
01742         self._std = launch_comp('std_comp')
01743         self._doc = launch_comp('doc_comp')
01744         self._doc2 = launch_comp('doc2_comp')
01745         make_zombie()
01746         self._mgr = launch_manager()
01747         wait_for_comp('Std0.rtc')
01748         wait_for_comp('Doc0.rtc')
01749         wait_for_comp('Doc20.rtc')
01750 
01751     def tearDown(self):
01752         stop_comp(self._std)
01753         stop_comp(self._doc)
01754         stop_comp(self._doc2)
01755         clean_zombies()
01756         stop_manager(self._mgr)
01757         stop_ns(self._ns)
01758 
01759     def _check_stdout(self, stdout, title):
01760         self.assert_(title in stdout)
01761         self.assert_('Documentation component' in stdout)
01762         self.assert_('Geoffrey Biggs' in stdout)
01763         self.assert_('test' in stdout)
01764         self.assert_('EPL' in stdout)
01765         self.assert_('example.com' in stdout)
01766         self.assert_('http://www.openrtm.org' in stdout)
01767         self.assert_('This is the introduction.' in stdout)
01768         self.assert_('This component requires nothing.' in stdout)
01769         self.assert_('You cannot install this component.' in stdout)
01770         self.assert_('You cannot use it, either.' in stdout)
01771         self.assert_('Miscellaneous is hard to spell.' in stdout)
01772         self.assert_('No changes.' in stdout)
01773         self.assert_('param' in stdout)
01774         self.assert_('This port receives stuff.' in stdout)
01775         self.assert_('Another section.' in stdout)
01776 
01777     def test_doc(self):
01778         stdout, stderr, ret = call_process(['./rtdoc',
01779             '/localhost/local.host_cxt/Doc0.rtc'])
01780         self.assertEqual(stderr, ''),
01781         self.assertEqual(ret, 0)
01782         self._check_stdout(stdout, 'Doc0.rtc')
01783 
01784     def test_doc_rst(self):
01785         stdout, stderr, ret = call_process(['./rtdoc',
01786             '/localhost/local.host_cxt/Doc0.rtc', '-f', 'rst'])
01787         self.assertEqual(stderr, ''),
01788         self.assertEqual(ret, 0)
01789         self._check_stdout(stdout, 'Doc0.rtc')
01790 
01791     def test_doc_html(self):
01792         stdout, stderr, ret = call_process(['./rtdoc',
01793             '/localhost/local.host_cxt/Doc0.rtc', '-f', 'html'])
01794         self.assertEqual(stderr, ''),
01795         self.assertEqual(ret, 0)
01796         self._check_stdout(stdout, 'Doc0.rtc')
01797 
01798     def test_doc_latex(self):
01799         stdout, stderr, ret = call_process(['./rtdoc',
01800             '/localhost/local.host_cxt/Doc0.rtc', '-f', 'latex'])
01801         self.assertEqual(stderr, ''),
01802         self.assertEqual(ret, 0)
01803         self._check_stdout(stdout, 'Doc0.rtc')
01804 
01805     def test_no_doc(self):
01806         stdout, stderr, ret = call_process(['./rtdoc',
01807             '/localhost/local.host_cxt/Std0.rtc', '-f', 'rst'])
01808         self.assert_(stdout.startswith('Std0.rtc\n'))
01809         self.assert_('Introduction' not in stdout)
01810         self.assert_('Requirements' not in stdout)
01811         self.assert_('Installation' not in stdout)
01812         self.assert_('Usage' not in stdout)
01813         self.assertEqual(stderr, ''),
01814         self.assertEqual(ret, 0)
01815 
01816     def test_no_ports_config(self):
01817         stdout, stderr, ret = call_process(['./rtdoc',
01818             '/localhost/local.host_cxt/Doc20.rtc', '-f', 'rst'])
01819         self.assert_(stdout.startswith('Doc20.rtc\n'))
01820         self.assert_('Ports' not in stdout)
01821         self.assert_('Configuration parameters' not in stdout)
01822         self.assertEqual(stderr, ''),
01823         self.assertEqual(ret, 0)
01824 
01825     def test_manager(self):
01826         test_notacomp(self, './rtdoc', obj1='manager.mgr')
01827 
01828     def test_port(self):
01829         test_notacomp(self, './rtdoc', obj1='Std0.rtc:in')
01830 
01831     def test_trailing_slash(self):
01832         test_notacomp(self, './rtdoc', obj1='Std0.rtc/')
01833 
01834     def test_no_object(self):
01835         test_noobject(self, './rtdoc', obj1='NotAComp0.rtc')
01836 
01837     def test_zombie_object(self):
01838         test_zombie(self, './rtdoc', obj1='Zombie0.rtc')
01839 
01840     def test_no_arg(self):
01841         stdout, stderr, ret = call_process('./rtdoc')
01842         self.assertEqual(stdout, '')
01843         self.assertEqual(stderr, 'rtdoc: No component specified.')
01844         self.assertEqual(ret, 1)
01845 
01846     def test_order(self):
01847         stdout, stderr, ret = call_process(['./rtdoc',
01848             '/localhost/local.host_cxt/Doc0.rtc', '-f', 'rst'])
01849         stdout = stdout.partition('Usage'),
01850         self.assert_('Installation' in stdout[0][0])
01851         self.assert_('Installation' not in stdout[0][2])
01852         self.assert_('Changelog' not in stdout[0][0])
01853         self.assert_('Changelog' in stdout[0][2])
01854         self.assert_('Another' not in stdout[0][0])
01855         self.assert_('Another' in stdout[0][2])
01856         self.assertEqual(stderr, ''),
01857         self.assertEqual(ret, 0)
01858         stdout, stderr, ret = call_process(['./rtconf', '-a', '-s', '__doc__',
01859             '/localhost/local.host_cxt/Doc0.rtc', 'set', '__order__',
01860             'intro,changelog,misc,usage,install,ports,config'])
01861         self.assertEqual(ret, 0)
01862         stdout, stderr, ret = call_process(['./rtdoc',
01863             '/localhost/local.host_cxt/Doc0.rtc', '-f', 'rst'])
01864         stdout = stdout.partition('Usage'),
01865         self.assert_('Installation' not in stdout[0][0])
01866         self.assert_('Installation' in stdout[0][2])
01867         self.assert_('Changelog' in stdout[0][0])
01868         self.assert_('Changelog' not in stdout[0][2])
01869         self.assert_('Another' not in stdout[0][0])
01870         self.assert_('Another' in stdout[0][2])
01871         self.assertEqual(stderr, ''),
01872         self.assertEqual(ret, 0)
01873 
01874 
01875 def rtdoc_suite():
01876     return unittest.TestLoader().loadTestsFromTestCase(rtdocTests)
01877 
01878 
01879 class rtexitTests(unittest.TestCase):
01880     def setUp(self):
01881         self._ns = start_ns()
01882         self._std = launch_comp('std_comp')
01883         make_zombie()
01884         self._mgr = launch_manager()
01885         wait_for_comp('Std0.rtc')
01886 
01887     def tearDown(self):
01888         stop_comp(self._std)
01889         clean_zombies()
01890         stop_manager(self._mgr)
01891         stop_ns(self._ns)
01892 
01893     def test_rtc(self):
01894         stdout, stderr, ret = call_process(['./rtexit',
01895             '/localhost/local.host_cxt/Std0.rtc'])
01896         self.assertEqual(stdout, '')
01897         self.assertEqual(stderr, '')
01898         self.assertEqual(ret, 0)
01899         stdout, stderr, ret = call_process(['./rtls',
01900             '/localhost/local.host_cxt/Std0.rtc'])
01901         self.assertEqual(stdout, '*Std0.rtc')
01902 
01903     def test_no_args(self):
01904         stdout, stderr, ret = call_process(['./rtexit'])
01905         self.assertEqual(stdout, '')
01906         self.assertEqual(stderr, 'rtexit: No component specified.')
01907         self.assertEqual(ret, 1)
01908 
01909     def test_context(self):
01910         test_notacomp(self, 'rtexit', '')
01911 
01912     def test_manager(self):
01913         test_notacomp(self, 'rtexit', obj1='manager.mgr')
01914 
01915     def test_port(self):
01916         test_notacomp(self, 'rtexit', obj1='Std0.rtc:in')
01917 
01918     def test_trailing_slash(self):
01919         test_notacomp(self, 'rtexit', obj1='Std0.rtc/')
01920         stdout, stderr, ret = call_process(['./rtls',
01921             '/localhost/local.host_cxt/Std0.rtc'])
01922         self.assertEqual(stdout, 'Std0.rtc')
01923 
01924     def test_no_object(self):
01925         test_noobject(self, 'rtexit', obj1='NotAComp0.rtc')
01926 
01927     def test_zombie_object(self):
01928         test_zombie(self, 'rtexit', obj1='Zombie0.rtc')
01929 
01930 
01931 def rtexit_suite():
01932     return unittest.TestLoader().loadTestsFromTestCase(rtexitTests)
01933 
01934 
01935 class rtfindTests(unittest.TestCase):
01936     def setUp(self):
01937         self._ns = start_ns()
01938         self._std = launch_comp('std_comp')
01939         self._output = launch_comp('output_comp')
01940         make_zombie()
01941         self._mgr = launch_manager()
01942         wait_for_comp('Std0.rtc')
01943         wait_for_comp('Output0.rtc')
01944 
01945     def tearDown(self):
01946         stop_comp(self._std)
01947         stop_comp(self._output)
01948         clean_zombies()
01949         stop_manager(self._mgr)
01950         stop_ns(self._ns)
01951 
01952     def test_find_by_exact_name(self):
01953         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'Std0.rtc'])
01954         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
01955         self.assertEqual(stderr, '')
01956         self.assertEqual(ret, 0)
01957         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'std0.rtc'])
01958         self.assertEqual(stdout, '')
01959         self.assertEqual(stderr, '')
01960         self.assertEqual(ret, 0)
01961 
01962     def test_find_by_type_c(self):
01963         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'c'])
01964         self.assert_('/localhost/local.host_cxt/Std0.rtc' in stdout)
01965         self.assert_('/localhost/local.host_cxt/Output0.rtc' in stdout)
01966         self.assertEqual(stderr, '')
01967         self.assertEqual(ret, 0)
01968 
01969     def test_find_by_type_d(self):
01970         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'd'])
01971         self.assert_('/localhost' in stdout)
01972         self.assert_('/localhost/local.host_cxt' in stdout)
01973         self.assert_('/localhost/local.host_cxt/manager.mgr' in stdout)
01974         self.assertEqual(stderr, '')
01975         self.assertEqual(ret, 0)
01976 
01977     def test_find_by_type_m(self):
01978         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'm'])
01979         self.assertEqual(stdout, '/localhost/local.host_cxt/manager.mgr')
01980         self.assertEqual(stderr, '')
01981         self.assertEqual(ret, 0)
01982 
01983     def test_find_by_type_n(self):
01984         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'n'])
01985         self.assertEqual(stdout, '/localhost')
01986         self.assertEqual(stderr, '')
01987         self.assertEqual(ret, 0)
01988 
01989     def test_find_by_type_z(self):
01990         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'z'])
01991         self.assertEqual(stdout, '/localhost/local.host_cxt/Zombie0.rtc')
01992         self.assertEqual(stderr, '')
01993         self.assertEqual(ret, 0)
01994 
01995     def test_find_by_type_multiple(self):
01996         stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'cm'])
01997         self.assert_('/localhost/local.host_cxt/Std0.rtc' in stdout)
01998         self.assert_('/localhost/local.host_cxt/Output0.rtc' in stdout)
01999         self.assert_('/localhost/local.host_cxt/manager.mgr' in stdout)
02000         self.assertEqual(stderr, '')
02001         self.assertEqual(ret, 0)
02002 
02003     def test_find_by_part_name(self):
02004         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'Std*'])
02005         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02006         self.assertEqual(stderr, '')
02007         self.assertEqual(ret, 0)
02008         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', '*d0.rtc'])
02009         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02010         self.assertEqual(stderr, '')
02011         self.assertEqual(ret, 0)
02012         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'Std?.rtc'])
02013         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02014         self.assertEqual(stderr, '')
02015         self.assertEqual(ret, 0)
02016 
02017     def test_find_by_exact_iname(self):
02018         stdout, stderr, ret = call_process(['./rtfind', '.', '-i', 'std0.rtc'])
02019         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02020         self.assertEqual(stderr, '')
02021         self.assertEqual(ret, 0)
02022         stdout, stderr, ret = call_process(['./rtfind', '.', '-i', 'std0.rtc'])
02023         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02024         self.assertEqual(stderr, '')
02025         self.assertEqual(ret, 0)
02026 
02027     def test_max_depth(self):
02028         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'Std0.rtc',
02029             '-m', '1'])
02030         self.assertEqual(stdout, '')
02031         self.assertEqual(stderr, '')
02032         self.assertEqual(ret, 0)
02033         stdout, stderr, ret = call_process(['./rtfind', '.', '-n', 'Std0.rtc',
02034             '-m', '3'])
02035         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02036         self.assertEqual(stderr, '')
02037         self.assertEqual(ret, 0)
02038 
02039     def test_prefix(self):
02040         stdout, stderr, ret = call_process(['./rtfind',
02041             '/localhost/local.host_cxt/', '-n', 'Std0.rtc'])
02042         self.assertEqual(stdout, '/localhost/local.host_cxt/Std0.rtc')
02043         self.assertEqual(stderr, '')
02044         self.assertEqual(ret, 0)
02045 
02046     def test_bad_prefix(self):
02047         stdout, stderr, ret = call_process(['./rtfind',
02048             '/localhost/local.host_cxt/Std0.rtc/', '-i', 'std0.rtc'])
02049         self.assertEqual(stdout, '')
02050         self.assertEqual(stderr, 'rtfind: Not a directory: '
02051             '/localhost/local.host_cxt/Std0.rtc/')
02052         self.assertEqual(ret, 1)
02053         stdout, stderr, ret = call_process(['./rtfind',
02054             '/localhost/local.host_cxt/Std0.rtc:in', '-i', 'std0.rtc'])
02055         self.assertEqual(stdout, '')
02056         self.assertEqual(stderr, 'rtfind: Not a directory: '
02057             '/localhost/local.host_cxt/Std0.rtc:in')
02058         self.assertEqual(ret, 1)
02059         stdout, stderr, ret = call_process(['./rtfind',
02060             '/localhost/not_a.host_cxt', '-i', 'std0.rtc'])
02061         self.assertEqual(stdout, '')
02062         self.assertEqual(stderr, 'rtfind: No such object: '
02063             '/localhost/not_a.host_cxt')
02064         self.assertEqual(ret, 1)
02065 
02066 
02067 def rtfind_suite():
02068     return unittest.TestLoader().loadTestsFromTestCase(rtfindTests)
02069 
02070 
02071 class rtinjectTests(unittest.TestCase):
02072     def setUp(self):
02073         self._clean_comp_output()
02074         self._ns = start_ns()
02075         self._std = launch_comp('std_comp')
02076         self._c2 = launch_comp('c2_comp')
02077         wait_for_comp('Std0.rtc')
02078         wait_for_comp('C20.rtc')
02079         call_process(['./rtact', '/localhost/local.host_cxt/Std0.rtc'])
02080         call_process(['./rtact', '/localhost/local.host_cxt/C20.rtc'])
02081         wait_for_comp('Std0.rtc', 'Active')
02082         wait_for_comp('C20.rtc', 'Active')
02083 
02084     def tearDown(self):
02085         stop_comp(self._std)
02086         stop_comp(self._c2)
02087         stop_ns(self._ns)
02088         self._clean_comp_output()
02089 
02090     def _get_comp_output(self, name):
02091         with open(os.path.join('./test', name + '_rcvd'), 'r') as f:
02092             return f.read()
02093 
02094     def _clean_comp_output(self):
02095         if os.path.exists('./test/std_rcvd'):
02096             os.remove('./test/std_rcvd')
02097         if os.path.exists('./test/c2_rcvd'):
02098             os.remove('./test/c2_rcvd')
02099 
02100     def test_stdin(self):
02101         p = subprocess.Popen(['./rtinject',
02102             '/localhost/local.host_cxt/Std0.rtc:in'], stdin=subprocess.PIPE,
02103             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
02104         stdout, stderr = p.communicate('RTC.TimedLong({time}, 42)')
02105         self.assertEqual(stdout, '')
02106         self.assertEqual(stderr, '')
02107         self.assertEqual(p.returncode, 0)
02108         self.assertEqual(self._get_comp_output('std'), '42\n')
02109 
02110     def test_option(self):
02111         stdout, stderr, ret = call_process(['./rtinject', '-c',
02112             'RTC.TimedLong({time}, 42)',
02113             '/localhost/local.host_cxt/Std0.rtc:in'])
02114         self.assertEqual(stdout, '')
02115         self.assertEqual(stderr, '')
02116         self.assertEqual(ret, 0)
02117         time.sleep(1)
02118         self.assertEqual(self._get_comp_output('std'), '42\n')
02119 
02120     def test_max(self):
02121         stdout, stderr, ret = call_process(['./rtinject', '-c',
02122             'RTC.TimedLong({time}, 42)', '-n', '3', '-r', '1000',
02123             '/localhost/local.host_cxt/Std0.rtc:in'])
02124         self.assertEqual(stdout, '')
02125         self.assertEqual(stderr, '')
02126         self.assertEqual(ret, 0)
02127         time.sleep(1.5)
02128         self.assertEqual(self._get_comp_output('std'), '42\n42\n42\n')
02129 
02130     def test_timeout(self):
02131         stdout, stderr, ret = call_process(['./rtinject', '-c',
02132             'RTC.TimedLong({time}, 42)', '-t', '2',
02133             '/localhost/local.host_cxt/Std0.rtc:in'])
02134         self.assertEqual(stdout, '')
02135         self.assertEqual(stderr, '')
02136         self.assertEqual(ret, 0)
02137         time.sleep(3)
02138         comp_out = self._get_comp_output('std')
02139         self.assertEqual(comp_out, '42\n')
02140 
02141     def test_rate(self):
02142         stdout, stderr, ret = call_process(['./rtinject', '-c',
02143             'RTC.TimedLong({time}, 42)', '-t', '1.5', '-r', '2',
02144             '/localhost/local.host_cxt/Std0.rtc:in'])
02145         self.assertEqual(stdout, '')
02146         self.assertEqual(stderr, '')
02147         self.assertEqual(ret, 0)
02148         time.sleep(3)
02149         comp_out = self._get_comp_output('std')
02150         self.assertEqual(comp_out, '42\n42\n')
02151 
02152     def test_mod(self):
02153         stdout, stderr, ret = call_process(['./rtinject', '-c',
02154             'MyData.Bleg(val1=4, val2=2)', '-m', 'MyData', '-p', './test',
02155             '/localhost/local.host_cxt/C20.rtc:input'])
02156         self.assertEqual(stdout, '')
02157         self.assertEqual(stderr, '')
02158         self.assertEqual(ret, 0)
02159         time.sleep(1)
02160         self.assertEqual(self._get_comp_output('c2'),
02161                 'MyData.Bleg(val1=4L, val2=2L)\n')
02162 
02163     def test_mod_no_path(self):
02164         stdout, stderr, ret = call_process(['./rtinject', '-c',
02165             'MyData.Bleg(val1=4, val2=2)', '-m', 'MyData',
02166             '/localhost/local.host_cxt/C20.rtc:input'])
02167         self.assertEqual(stdout, '')
02168         self.assertEqual(stderr, 'rtinject: No module named MyData')
02169         self.assertEqual(ret, 1)
02170 
02171     def test_bad_comp(self):
02172         stdout, stderr, ret = call_process(['./rtinject', '-c',
02173             'RTC.TimedLong({time}, 42)',
02174             '/localhost/local.host_cxt/NotAComp0.rtc:in'])
02175         self.assertEqual(stdout, '')
02176         self.assertEqual(stderr, 'rtinject: No such object: '
02177             '/localhost/local.host_cxt/NotAComp0.rtc')
02178         self.assertEqual(ret, 1)
02179 
02180     def test_bad_port(self):
02181         stdout, stderr, ret = call_process(['./rtinject', '-c',
02182             'RTC.TimedLong({time}, 42)',
02183             '/localhost/local.host_cxt/Std0.rtc:out'])
02184         self.assertEqual(stdout, '')
02185         self.assertEqual(stderr, 'rtinject: Port not found: '
02186             '/localhost/local.host_cxt/Std0.rtc:out')
02187         self.assertEqual(ret, 1)
02188 
02189 
02190 def rtinject_suite():
02191     return unittest.TestLoader().loadTestsFromTestCase(rtinjectTests)
02192 
02193 
02194 class rtlogTests(unittest.TestCase):
02195     # TODO: Add missing tests:
02196     # --absolute-times
02197     def setUp(self):
02198         self._clean_comp_output()
02199         self._ns = start_ns()
02200         self._std = launch_comp('std_comp')
02201         self._output = launch_comp('output_comp')
02202         self._c1 = launch_comp('c1_comp')
02203         self._c2 = launch_comp('c2_comp')
02204         wait_for_comp('Std0.rtc')
02205         wait_for_comp('Output0.rtc')
02206         wait_for_comp('C10.rtc')
02207         wait_for_comp('C20.rtc')
02208         call_process(['./rtact', '/localhost/local.host_cxt/Std0.rtc'])
02209         call_process(['./rtact', '/localhost/local.host_cxt/C20.rtc'])
02210         wait_for_comp('Std0.rtc', 'Active')
02211         wait_for_comp('C20.rtc', 'Active')
02212 
02213     def tearDown(self):
02214         stop_comp(self._std)
02215         stop_comp(self._output)
02216         stop_comp(self._c1)
02217         stop_comp(self._c2)
02218         stop_ns(self._ns)
02219 
02220     def _get_comp_output(self, name):
02221         with open(os.path.join('./test', name + '_rcvd'), 'r') as f:
02222             return f.read()
02223 
02224     def _clean_comp_output(self):
02225         if os.path.exists('./test/std_rcvd'):
02226             os.remove('./test/std_rcvd')
02227         if os.path.exists('./test/c2_rcvd'):
02228             os.remove('./test/c2_rcvd')
02229         if os.path.exists('./test/test.rtlog'):
02230             os.remove('./test/test.rtlog')
02231 
02232     def _num_recorded(self, text):
02233         return int(re.search(r'Number of entries: (\d+)\n', text).groups()[0])
02234 
02235     def _log_start(self, text):
02236         return float(re.search(r'Start time: \d{4}-\d{2}-\d{2} '
02237             '\d{2}:\d{2}:\d{2} \((\d+.\d+)\)\n', text).groups()[0])
02238 
02239     def _log_end(self, text):
02240         return float(re.search(r'End time: \d{4}-\d{2}-\d{2} '
02241             '\d{2}:\d{2}:\d{2} \((\d+.\d+)\)\n', text).groups()[0])
02242 
02243     def _test_playback(self):
02244         stdout, stderr, ret = call_process(['./rtlog',
02245             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02246             '-f', './test/output.rtlog', '-p'])
02247         self.assertEqual(stdout, '')
02248         self.assertEqual(stderr, 'rtlog: End of log reached.')
02249         self.assertEqual(ret, 0)
02250         self.assertEqual(self._get_comp_output('std'), '0\n1\n2\n3\n4\n')
02251 
02252     def _test_playback_from_middle_index(self):
02253         stdout, stderr, ret = call_process(['./rtlog',
02254             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02255             '-f', './test/output.rtlog', '-p', '-i', '-s', '2'])
02256         self.assertEqual(stdout, '')
02257         self.assertEqual(stderr, 'Playing from entry 2.\nrtlog: '
02258             'End of log reached.')
02259         self.assertEqual(ret, 0)
02260         time.sleep(0.5)
02261         self.assertEqual(self._get_comp_output('std'), '2\n3\n4\n')
02262 
02263     def _test_playback_to_middle_index(self):
02264         stdout, stderr, ret = call_process(['./rtlog',
02265             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02266             '-f', './test/output.rtlog', '-p', '-i', '-e', '3'])
02267         self.assertEqual(stdout, '')
02268         self.assertEqual(stderr, 'Playing 3 entries.')
02269         self.assertEqual(ret, 0)
02270         time.sleep(0.5)
02271         self.assertEqual(self._get_comp_output('std'), '0\n1\n2\n')
02272 
02273     def _test_playback_from_middle_to_middle_index(self):
02274         stdout, stderr, ret = call_process(['./rtlog',
02275             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02276             '-f', './test/output.rtlog', '-p', '-i', '-s', '2', '-e', '2'])
02277         self.assertEqual(stdout, '')
02278         self.assertEqual(stderr, 'Playing from entry 2 to entry 2.')
02279         self.assertEqual(ret, 0)
02280         time.sleep(0.5)
02281         self.assertEqual(self._get_comp_output('std'), '2\n')
02282 
02283     def _test_playback_from_middle_time(self):
02284         stdout, stderr, ret = call_process(['./rtlog',
02285             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02286             '-f', './test/output.rtlog', '-p', '-s', '1297156964'])
02287         self.assertEqual(stdout, '')
02288         self.assert_(re.match(r'Playing from \d{4}-\d{2}-\d{2} '
02289             '\d{2}:\d{2}:\d{2} \(\d+.\d+\)\.\nrtlog: End of log reached.',
02290             stderr) is not None)
02291         self.assertEqual(ret, 0)
02292         time.sleep(0.5)
02293         self.assertEqual(self._get_comp_output('std'), '1\n2\n3\n4\n')
02294 
02295     def _test_playback_to_middle_time(self):
02296         stdout, stderr, ret = call_process(['./rtlog',
02297             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02298             '-f', './test/output.rtlog', '-p', '-e', '1297156966'])
02299         self.assertEqual(stdout, '')
02300         self.assert_(re.match(r'Playing until \d{4}-\d{2}-\d{2} '
02301             '\d{2}:\d{2}:\d{2} \(\d+.\d+\)\.',
02302             stderr) is not None)
02303         self.assertEqual(ret, 0)
02304         time.sleep(0.5)
02305         self.assertEqual(self._get_comp_output('std'), '0\n1\n2\n')
02306 
02307     def _test_playback_from_middle_to_middle_time(self):
02308         stdout, stderr, ret = call_process(['./rtlog',
02309             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02310             '-f', './test/output.rtlog', '-p', '-s', '1297156964', '-e',
02311             '1297156966'])
02312         self.assertEqual(stdout, '')
02313         self.assert_(re.match(r'Playing from \d{4}-\d{2}-\d{2} '
02314             '\d{2}:\d{2}:\d{2} \(\d+.\d+\) until \d{4}-\d{2}-\d{2} '
02315             '\d{2}:\d{2}:\d{2} \(\d+.\d+\)\.', stderr) is not None)
02316         self.assertEqual(ret, 0)
02317         time.sleep(0.5)
02318         self.assertEqual(self._get_comp_output('std'), '1\n2\n')
02319 
02320     def _test_playback_rate(self):
02321         logger = start_process(['./rtlog',
02322             '/localhost/local.host_cxt/Std0.rtc:in.nums',
02323             '-f', './test/output.rtlog', '-p', '-r', '0.5'])
02324         time.sleep(3)
02325         logger.terminate()
02326         stdout, stderr = logger.communicate()
02327         self.assertEqual(stdout, '')
02328         self.assertEqual(stderr, '')
02329         self.assertEqual(logger.returncode, -15)
02330         time.sleep(0.5)
02331         self.assertEqual(self._get_comp_output('std'), '0\n')
02332 
02333     def _test_record(self):
02334         now = time.time()
02335         logger = start_process(['./rtlog',
02336             '/localhost/local.host_cxt/Output0.rtc:out',
02337             '-f', './test/test.rtlog', '-v'])
02338         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02339         wait_for_comp('Output0.rtc', 'Active')
02340         time.sleep(1)
02341         logger.terminate()
02342         stdout, stderr = logger.communicate()
02343         print stdout
02344         print stderr
02345         self.assertEqual(stdout, '')
02346         self.assertEqual(stderr, '')
02347         self.assertEqual(logger.returncode, -15)
02348         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02349             './test/test.rtlog'])
02350         self.assert_(self._num_recorded(stdout) > 0)
02351         self.assert_(self._log_start(stdout) > now)
02352 
02353     def _test_record_limit_index(self):
02354         logger = start_process(['./rtlog',
02355             '/localhost/local.host_cxt/Output0.rtc:out',
02356             '-f', './test/test.rtlog', '-i', '-e', '5'])
02357         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02358         wait_for_comp('Output0.rtc', 'Active')
02359         stdout, stderr = logger.communicate()
02360         self.assertEqual(stdout, '')
02361         self.assertEqual(stderr, 'Recording 5 entries.\n')
02362         self.assertEqual(logger.returncode, 0)
02363         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02364             './test/test.rtlog'])
02365         self.assert_(self._num_recorded(stdout) == 5)
02366 
02367     def _test_record_limit_time(self):
02368         limit = time.time() + 3
02369         logger = start_process(['./rtlog',
02370             '/localhost/local.host_cxt/Output0.rtc:out',
02371             '-f', './test/test.rtlog', '-e', '{0}'.format(limit)])
02372         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02373         wait_for_comp('Output0.rtc', 'Active')
02374         stdout, stderr = logger.communicate()
02375         self.assertEqual(stdout, '')
02376         m = re.match(r'Recording until \d{4}-\d{2}-\d{2} '
02377             '\d{2}:\d{2}:\d{2} \((\d+.\d+)\)\.', stderr)
02378         self.assert_(m is not None)
02379         self.assert_(abs(float(m.group(1)) - limit) < 0.01)
02380         self.assertEqual(logger.returncode, 0)
02381         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02382             './test/test.rtlog'])
02383         self.assert_(self._num_recorded(stdout) > 0)
02384 
02385     def _test_record_timeout(self):
02386         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02387         wait_for_comp('Output0.rtc', 'Active')
02388         stdout, stderr, ret = call_process(['./rtlog',
02389             '/localhost/local.host_cxt/Output0.rtc:out',
02390             '-f', './test/test.rtlog', '-t', '3'])
02391         self.assertEqual(stdout, '')
02392         self.assertEqual(stderr, 'Recording for 3.0s.')
02393         self.assertEqual(ret, 0)
02394         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02395             './test/test.rtlog'])
02396         self.assert_(self._num_recorded(stdout) > 0)
02397         log_length = self._log_end(stdout) - self._log_start(stdout)
02398         self.assert_(log_length < 3.5)
02399         self.assert_(log_length > 2.5)
02400 
02401     def _test_display_info(self):
02402         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02403             './test/output.rtlog'])
02404         self.assertEqual(stderr, '')
02405         self.assertEqual(ret, 0)
02406         self.assert_('Size: 1.41KiB (1446B)' in stdout)
02407         self.assert_('Start time: 2011-02-08 18:22:42 (1297156962.58)' in
02408                 stdout)
02409         self.assert_('First entry time: 2011-02-08 18:22:43 '
02410                 '(1297156963.450684160)' in stdout)
02411         self.assert_('End time: 2011-02-08 18:22:47 '
02412                 '(1297156967.592355840)' in stdout)
02413         self.assert_('Number of entries: 5' in stdout)
02414         self.assert_('Channel 1' in stdout)
02415         self.assert_('Name: nums' in stdout)
02416         self.assert_('Data type: TimedLong (RTC.TimedLong)' in stdout)
02417         self.assert_('/localhost/odyssey.host_cxt/ConsoleIn0.rtc:out.nums' in
02418                 stdout)
02419 
02420     def test_playback_usermod(self):
02421         stdout, stderr, ret = call_process(['./rtlog',
02422             '/localhost/local.host_cxt/C20.rtc:input.nums',
02423             '-f', './test/c1.rtlog', '-p', '--path=./test', '-m', 'MyData'])
02424         self.assertEqual(stdout, '')
02425         self.assertEqual(stderr, 'rtlog: End of log reached.')
02426         self.assertEqual(ret, 0)
02427         time.sleep(0.5)
02428         self.assertEqual(self._get_comp_output('c2'),
02429                 'MyData.Bleg(val1=1L, val2=0L)\n'
02430                 'MyData.Bleg(val1=1L, val2=1L)\n'
02431                 'MyData.Bleg(val1=1L, val2=2L)\n'
02432                 'MyData.Bleg(val1=1L, val2=3L)\n'
02433                 'MyData.Bleg(val1=1L, val2=4L)\n')
02434 
02435     def _test_record_usermod(self):
02436         call_process(['./rtact', '/localhost/local.host_cxt/C10.rtc'])
02437         wait_for_comp('C10.rtc', 'Active')
02438         stdout, stderr, ret = call_process(['./rtlog',
02439             '/localhost/local.host_cxt/C10.rtc:output',
02440             '-f', './test/test.rtlog', '-i', '-e', '5', '--path=./test', '-m',
02441             'MyData'])
02442         self.assertEqual(stdout, '')
02443         self.assertEqual(stderr, 'Recording 5 entries.')
02444         self.assertEqual(ret, 0)
02445         stdout, stderr, ret = call_process(['./rtlog', '-d', '-f',
02446             './test/test.rtlog', '--path=./test', '-m', 'MyData'])
02447         self.assert_(self._num_recorded(stdout) == 5)
02448 
02449     def _test_record_text(self):
02450         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02451         wait_for_comp('Output0.rtc', 'Active')
02452         stdout, stderr, ret = call_process(['./rtlog', '-l', 'text',
02453             '/localhost/local.host_cxt/Output0.rtc:out',
02454             '-f', './test/test.rtlog', '-i', '-e', '5'])
02455         self.assertEqual(stdout, '')
02456         self.assertEqual(stderr, 'Recording 5 entries.')
02457         self.assertEqual(ret, 0)
02458         self.assert_(re.match(r"\d+.\d+\s+\('input0', "
02459             "RTC\.TimedLong\(tm=RTC\.Time\(sec=0L, nsec=0L\), data=\d+\)\)\n",
02460             load_file('./test/test.rtlog')) is not None)
02461 
02462 
02463 def rtlog_suite():
02464     return unittest.TestLoader().loadTestsFromTestCase(rtlogTests)
02465 
02466 
02467 class rtlsTests(unittest.TestCase):
02468     def setUp(self):
02469         self._ns = start_ns()
02470         self._std = launch_comp('std_comp')
02471         self._output = launch_comp('output_comp')
02472         make_zombie()
02473         self._mgr = launch_manager()
02474         wait_for_comp('Std0.rtc')
02475         wait_for_comp('Output0.rtc')
02476         self._load_mgr()
02477 
02478     def tearDown(self):
02479         stop_comp(self._std)
02480         stop_comp(self._output)
02481         clean_zombies()
02482         stop_manager(self._mgr)
02483         stop_ns(self._ns)
02484 
02485     def _load_mgr(self):
02486         stdout, stderr, ret = call_process(['./rtmgr',
02487             '/localhost/local.host_cxt/manager.mgr', '-l',
02488             os.path.join(COMP_LIB_PATH, 'Controller.so'), '-i',
02489             'ControllerInit', '-c', 'Controller'])
02490         self.assertEqual(ret, 0)
02491         stdout, stderr, ret = call_process(['./rtmgr',
02492             '/localhost/local.host_cxt/manager.mgr', '-l',
02493             os.path.join(COMP_LIB_PATH, 'Sensor.so'), '-i',
02494             'SensorInit', '-c', 'Sensor'])
02495         self.assertEqual(ret, 0)
02496         stdout, stderr, ret = call_process(['./rtmgr',
02497             '/localhost/local.host_cxt/manager.mgr', '-l',
02498             os.path.join(COMP_LIB_PATH, 'Motor.so'), '-i',
02499             'MotorInit', '-c', 'Motor'])
02500         self.assertEqual(ret, 0)
02501 
02502     def test_ls_nothing(self):
02503         stdout, stderr, ret = call_process(['./rtls'])
02504         self.assertEqual(stdout, 'localhost/')
02505         self.assertEqual(stderr, '')
02506         self.assertEqual(ret, 0)
02507         stdout, stderr, ret = call_process(['./rtls', '/'])
02508         self.assertEqual(stdout, 'localhost/')
02509         self.assertEqual(stderr, '')
02510         self.assertEqual(ret, 0)
02511 
02512     def test_ls_ns(self):
02513         stdout, stderr, ret = call_process(['./rtls', 'localhost'])
02514         self.assertEqual(stdout, 'local.host_cxt/')
02515         self.assertEqual(stderr, '')
02516         self.assertEqual(ret, 0)
02517         stdout, stderr, ret = call_process(['./rtls', '/localhost'])
02518         self.assertEqual(stdout, 'local.host_cxt/')
02519         self.assertEqual(stderr, '')
02520         self.assertEqual(ret, 0)
02521 
02522     def test_ls_hc(self):
02523         stdout, stderr, ret = call_process(['./rtls',
02524             'localhost/local.host_cxt'])
02525         self.assert_('Std0.rtc' in stdout)
02526         self.assert_('Output0.rtc' in stdout)
02527         self.assert_('*Zombie0.rtc' in stdout)
02528         self.assert_('manager.mgr' in stdout)
02529         self.assertEqual(stderr, '')
02530         self.assertEqual(ret, 0)
02531         stdout, stderr, ret = call_process(['./rtls',
02532             '/localhost/local.host_cxt'])
02533         self.assert_('Std0.rtc' in stdout)
02534         self.assert_('Output0.rtc' in stdout)
02535         self.assert_('*Zombie0.rtc' in stdout)
02536         self.assert_('manager.mgr' in stdout)
02537         self.assertEqual(stderr, '')
02538         self.assertEqual(ret, 0)
02539 
02540     def test_ls_mgr_dir(self):
02541         stdout, stderr, ret = call_process(['./rtls',
02542             'localhost/local.host_cxt/manager.mgr'])
02543         self.assert_('Motor0.rtc' in stdout)
02544         self.assert_('Controller0.rtc' in stdout)
02545         self.assert_('Sensor0.rtc' in stdout)
02546         self.assertEqual(stderr, '')
02547         self.assertEqual(ret, 0)
02548         stdout, stderr, ret = call_process(['./rtls',
02549             '/localhost/local.host_cxt/manager.mgr'])
02550         self.assert_('Motor0.rtc' in stdout)
02551         self.assert_('Controller0.rtc' in stdout)
02552         self.assert_('Sensor0.rtc' in stdout)
02553         self.assertEqual(stderr, '')
02554         self.assertEqual(ret, 0)
02555 
02556     def test_ls_rtc(self):
02557         stdout, stderr, ret = call_process(['./rtls',
02558             'localhost/local.host_cxt/Std0.rtc'])
02559         self.assertEqual(stdout, 'Std0.rtc')
02560         self.assertEqual(stderr, '')
02561         self.assertEqual(ret, 0)
02562 
02563     def test_ls_zombie(self):
02564         stdout, stderr, ret = call_process(['./rtls',
02565             'localhost/local.host_cxt/Zombie0.rtc'])
02566         self.assertEqual(stdout, '*Zombie0.rtc')
02567         self.assertEqual(stderr, '')
02568         self.assertEqual(ret, 0)
02569 
02570     def test_ls_mgr_obj(self):
02571         stdout, stderr, ret = call_process(['./rtls',
02572             'localhost/local.host_cxt/manager.mgr'])
02573         self.assert_('Controller0.rtc' in stdout)
02574         self.assert_('Motor0.rtc' in stdout)
02575         self.assert_('Sensor0.rtc' in stdout)
02576         self.assertEqual(stderr, '')
02577         self.assertEqual(ret, 0)
02578 
02579     def test_ls_ns_long(self):
02580         stdout, stderr, ret = call_process(['./rtls', '-l',
02581             'localhost'])
02582         self.assertEqual(stdout, '-  -  -  -  -  local.host_cxt')
02583         self.assertEqual(stderr, '')
02584         self.assertEqual(ret, 0)
02585 
02586     def test_ls_hc_long(self):
02587         stdout, stderr, ret = call_process(['./rtls', '-l',
02588             'localhost/local.host_cxt'])
02589         self.assert_('Inactive  1/0  1/0  0/0  0/0  Std0.rtc' in stdout)
02590         self.assert_('Inactive  2/0  1/0  1/0  0/0  Motor0.rtc' in stdout)
02591         self.assert_('-         -    -    -    -    manager.mgr' in stdout)
02592         self.assertEqual(stderr, '')
02593         self.assertEqual(ret, 0)
02594 
02595     def test_ls_rtc_long(self):
02596         stdout, stderr, ret = call_process(['./rtls', '-l',
02597             'localhost/local.host_cxt/Std0.rtc'])
02598         self.assertEqual(stdout, 'Inactive  1/0  1/0  0/0  0/0  Std0.rtc')
02599         self.assertEqual(stderr, '')
02600         self.assertEqual(ret, 0)
02601 
02602     def test_ls_zombie_long(self):
02603         stdout, stderr, ret = call_process(['./rtls', '-l',
02604             'localhost/local.host_cxt/Zombie0.rtc'])
02605         self.assertEqual(stdout, '-  -  -  -  -  *Zombie0.rtc')
02606         self.assertEqual(stderr, '')
02607         self.assertEqual(ret, 0)
02608 
02609     def test_ls_recurse(self):
02610         stdout, stderr, ret = call_process(['./rtls', '-R'])
02611         self.assert_('/localhost' in stdout)
02612         self.assert_('/localhost/local.host_cxt' in stdout)
02613         self.assert_('Std0.rtc' in stdout)
02614         self.assert_('Motor0.rtc' in stdout)
02615         self.assert_('/localhost/local.host_cxt/manager.mgr' in stdout)
02616         self.assert_('manager.mgr' in stdout)
02617         self.assert_('*Zombie0.rtc' in stdout)
02618         self.assertEqual(stderr, '')
02619         self.assertEqual(ret, 0)
02620 
02621     def test_ls_recurse_long(self):
02622         stdout, stderr, ret = call_process(['./rtls', '-lR'])
02623         self.assert_('/localhost' in stdout)
02624         self.assert_('/localhost/local.host_cxt' in stdout)
02625         self.assert_('Inactive  1/0  1/0  0/0  0/0  Std0.rtc' in stdout)
02626         self.assert_('Inactive  2/0  1/0  1/0  0/0  Motor0.rtc' in stdout)
02627         self.assert_('/localhost/local.host_cxt/manager.mgr' in stdout)
02628         self.assert_('-         -    -    -    -    manager.mgr' in stdout)
02629         self.assert_('-         -    -    -    -    *Zombie0.rtc' in stdout)
02630         self.assertEqual(stderr, '')
02631         self.assertEqual(ret, 0)
02632 
02633     def test_ls_port(self):
02634         stdout, stderr, ret = call_process(['./rtls',
02635             'localhost/local.host_cxt/Std0.rtc:in'])
02636         self.assertEqual(stdout, '')
02637         self.assertEqual(stderr, 'rtls: Cannot list ports.')
02638         self.assertEqual(ret, 1)
02639 
02640     def test_ls_noobject(self):
02641         stdout, stderr, ret = call_process(['./rtls',
02642             '/localhost/local.host_cxt/NotAComp0.rtc'])
02643         self.assertEqual(stdout, '')
02644         self.assertEqual(stderr, 'rtls: No such object: '
02645             '/localhost/local.host_cxt/NotAComp0.rtc')
02646         self.assertEqual(ret, 1)
02647 
02648     def test_ls_notacomp(self):
02649         stdout, stderr, ret = call_process(['./rtls',
02650             '/localhost/local.host_cxt/Std0.rtc/'])
02651         self.assertEqual(stdout, '')
02652         self.assertEqual(stderr, 'rtls: No such object: '
02653             '/localhost/local.host_cxt/Std0.rtc/')
02654         self.assertEqual(ret, 1)
02655 
02656 
02657 def rtls_suite():
02658     return unittest.TestLoader().loadTestsFromTestCase(rtlsTests)
02659 
02660 
02661 class rtmgrTests(unittest.TestCase):
02662     def setUp(self):
02663         self._ns = start_ns()
02664         self._std = launch_comp('std_comp')
02665         self._mgr = launch_manager()
02666         wait_for_comp('Std0.rtc')
02667         self._load_mgr()
02668 
02669     def tearDown(self):
02670         stop_comp(self._std)
02671         stop_manager(self._mgr)
02672         stop_ns(self._ns)
02673 
02674     def _load_mgr(self):
02675         stdout, stderr, ret = call_process(['./rtmgr',
02676             '/localhost/local.host_cxt/manager.mgr', '-l',
02677             os.path.join(COMP_LIB_PATH, 'Controller.so') + ':ControllerInit'])
02678         self.assertEqual(ret, 0)
02679         stdout, stderr, ret = call_process(['./rtmgr',
02680             '/localhost/local.host_cxt/manager.mgr', '-l',
02681             os.path.join(COMP_LIB_PATH, 'Sensor.so') + ':SensorInit',
02682             '-c', 'Sensor'])
02683         self.assertEqual(ret, 0)
02684 
02685     def _grab_section(self, stdout, sec, next_sec=''):
02686         self.assert_(sec in stdout)
02687         if not next_sec:
02688             next_sec = '$'
02689         return re.match(r'.*?\n{0}\n(.*?){1}'.format(sec, next_sec), stdout,
02690             re.S).groups()[0]
02691 
02692     def test_load_mod(self):
02693         stdout, stderr, ret = call_process(['./rtmgr',
02694             '/localhost/local.host_cxt/manager.mgr', '-l',
02695             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit'])
02696         self.assertEqual(stdout, '')
02697         self.assertEqual(stderr, '')
02698         self.assertEqual(ret, 0)
02699         stdout, stderr, ret = call_process(['./rtcat',
02700             '/localhost/local.host_cxt/manager.mgr'])
02701         loaded = self._grab_section(stdout, 'Loaded modules:')
02702         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') in loaded)
02703 
02704     def test_load_mod_no_init(self):
02705         stdout, stderr, ret = call_process(['./rtmgr',
02706             '/localhost/local.host_cxt/manager.mgr', '-l',
02707             os.path.join(COMP_LIB_PATH, 'Motor.so')])
02708         self.assertEqual(stdout, '')
02709         self.assert_(stderr.endswith('rtmgr: error: No initialisation '
02710             'function specified.'))
02711         self.assertEqual(ret, 2)
02712         stdout, stderr, ret = call_process(['./rtcat',
02713             '/localhost/local.host_cxt/manager.mgr'])
02714         loaded = self._grab_section(stdout, 'Loaded modules:')
02715         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') not in loaded)
02716 
02717     def test_create_rtc(self):
02718         stdout, stderr, ret = call_process(['./rtmgr',
02719             '/localhost/local.host_cxt/manager.mgr', '-c', 'Controller'])
02720         self.assertEqual(stdout, '')
02721         self.assertEqual(stderr, '')
02722         self.assertEqual(ret, 0)
02723         stdout, stderr, ret = call_process(['./rtls',
02724             'localhost/local.host_cxt/manager.mgr'])
02725         self.assert_('Controller0.rtc' in stdout)
02726         stdout, stderr, ret = call_process(['./rtls',
02727             'localhost/local.host_cxt/'])
02728         self.assert_('Controller0.rtc' in stdout)
02729 
02730     def test_delete_rtc(self):
02731         stdout, stderr, ret = call_process(['./rtmgr',
02732             '/localhost/local.host_cxt/manager.mgr', '-d', 'Sensor0'])
02733         self.assertEqual(stdout, '')
02734         self.assertEqual(stderr, '')
02735         self.assertEqual(ret, 0)
02736         stdout, stderr, ret = call_process(['./rtls',
02737             'localhost/local.host_cxt/manager.mgr'])
02738         self.assert_('Sensor0.rtc' not in stdout)
02739         stdout, stderr, ret = call_process(['./rtls',
02740             'localhost/local.host_cxt/'])
02741         self.assert_('Sensor0.rtc' not in stdout)
02742 
02743     def test_unload_mod(self):
02744         stdout, stderr, ret = call_process(['./rtmgr',
02745             '/localhost/local.host_cxt/manager.mgr', '-u',
02746             os.path.join(COMP_LIB_PATH, 'Controller.so')])
02747         self.assertEqual(stdout, '')
02748         self.assertEqual(stderr, '')
02749         self.assertEqual(ret, 0)
02750         stdout, stderr, ret = call_process(['./rtcat',
02751             '/localhost/local.host_cxt/manager.mgr'])
02752         loaded = self._grab_section(stdout, 'Loaded modules:')
02753         self.assert_(os.path.join(COMP_LIB_PATH, 'Controller.so') not in loaded)
02754 
02755     def test_no_cmds(self):
02756         stdout, stderr, ret = call_process(['./rtmgr',
02757             '/localhost/local.host_cxt/manager.mgr'])
02758         self.assertEqual(stdout, '')
02759         self.assertEqual(stderr, 'rtmgr: No commands specified.')
02760         self.assertEqual(ret, 1)
02761 
02762     def test_multi_cmds(self):
02763         # Load a module, unload it, load it again, create a component from it,
02764         # load another module, create a component from it, delete the first
02765         # component, unload its module.
02766         stdout, stderr, ret = call_process(['./rtmgr',
02767             '/localhost/local.host_cxt/manager.mgr', '-l',
02768             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit',
02769             '-u', os.path.join(COMP_LIB_PATH, 'Motor.so'), '-l',
02770             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit',
02771             '-c', 'Motor', '-l',
02772             os.path.join(COMP_LIB_PATH, 'Controller.so') + ':ControllerInit',
02773             '-c', 'Controller', '-d', 'Motor0', '-u',
02774             os.path.join(COMP_LIB_PATH, 'Motor.so')])
02775         self.assertEqual(stdout, '')
02776         self.assertEqual(stderr, '')
02777         self.assertEqual(ret, 0)
02778         stdout, stderr, ret = call_process(['./rtcat',
02779             '/localhost/local.host_cxt/manager.mgr'])
02780         loaded = self._grab_section(stdout, 'Loaded modules:')
02781         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') not in loaded)
02782         self.assert_(os.path.join(COMP_LIB_PATH, 'Controller.so') in loaded)
02783         stdout, stderr, ret = call_process(['./rtls',
02784             'localhost/local.host_cxt/manager.mgr'])
02785         self.assert_('Controller0.rtc' in stdout)
02786         stdout, stderr, ret = call_process(['./rtls',
02787             'localhost/local.host_cxt/'])
02788         self.assert_('Controller0.rtc' in stdout)
02789 
02790     def test_port(self):
02791         stdout, stderr, ret = call_process(['./rtmgr',
02792             '/localhost/local.host_cxt/manager.mgr:port', '-c', 'Controller'])
02793         self.assertEqual(stdout, '')
02794         self.assertEqual(stderr, 'rtmgr: Not a manager: '
02795             '/localhost/local.host_cxt/manager.mgr:port')
02796         self.assertEqual(ret, 1)
02797 
02798     def test_rtc(self):
02799         stdout, stderr, ret = call_process(['./rtmgr',
02800             '/localhost/local.host_cxt/Std0.rtc', '-c', 'Controller'])
02801         self.assertEqual(stdout, '')
02802         self.assertEqual(stderr, 'rtmgr: Not a manager: '
02803             '/localhost/local.host_cxt/Std0.rtc')
02804         self.assertEqual(ret, 1)
02805 
02806     def test_context(self):
02807         stdout, stderr, ret = call_process(['./rtmgr',
02808             '/localhost/local.host_cxt', '-c', 'Controller'])
02809         self.assertEqual(stdout, '')
02810         self.assertEqual(stderr, 'rtmgr: Not a manager: '
02811             '/localhost/local.host_cxt')
02812         self.assertEqual(ret, 1)
02813 
02814     def test_ns(self):
02815         stdout, stderr, ret = call_process(['./rtmgr',
02816             '/localhost', '-c', 'Controller'])
02817         self.assertEqual(stdout, '')
02818         self.assertEqual(stderr, 'rtmgr: Not a manager: '
02819             '/localhost')
02820         self.assertEqual(ret, 1)
02821 
02822     def test_zombie(self):
02823         make_zombie()
02824         stdout, stderr, ret = call_process(['./rtmgr',
02825             '/localhost/local.host_cxt/Zombie0.rtc', '-c', 'Controller'])
02826         self.assertEqual(stdout, '')
02827         self.assertEqual(stderr, 'rtmgr: Zombie object: '
02828             '/localhost/local.host_cxt/Zombie0.rtc')
02829         self.assertEqual(ret, 1)
02830         clean_zombies()
02831 
02832     def test_noobject(self):
02833         stdout, stderr, ret = call_process(['./rtmgr',
02834             '/localhost/local.host_cxt/NotAComp.rtc', '-c', 'Controller'])
02835         self.assertEqual(stdout, '')
02836         self.assertEqual(stderr, 'rtmgr: No such object: '
02837             '/localhost/local.host_cxt/NotAComp.rtc')
02838         self.assertEqual(ret, 1)
02839 
02840     def test_load_mod_corbaloc(self):
02841         stdout, stderr, ret = call_process(['./rtmgr',
02842             'corbaloc::localhost:2810/manager', '-l',
02843             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit'])
02844         self.assertEqual(stdout, '')
02845         self.assertEqual(stderr, '')
02846         self.assertEqual(ret, 0)
02847         stdout, stderr, ret = call_process(['./rtcat',
02848             '/localhost/local.host_cxt/manager.mgr'])
02849         loaded = self._grab_section(stdout, 'Loaded modules:')
02850         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') in loaded)
02851 
02852     def test_create_rtc_corbaloc(self):
02853         stdout, stderr, ret = call_process(['./rtmgr',
02854             'corbaloc::localhost:2810/manager', '-c', 'Controller'])
02855         self.assertEqual(stdout, '')
02856         self.assertEqual(stderr, '')
02857         self.assertEqual(ret, 0)
02858         stdout, stderr, ret = call_process(['./rtls',
02859             'localhost/local.host_cxt/manager.mgr'])
02860         self.assert_('Controller0.rtc' in stdout)
02861         stdout, stderr, ret = call_process(['./rtls',
02862             'localhost/local.host_cxt/'])
02863         self.assert_('Controller0.rtc' in stdout)
02864 
02865     def test_delete_rtc_corbaloc(self):
02866         stdout, stderr, ret = call_process(['./rtmgr',
02867             'corbaloc::localhost:2810/manager', '-d', 'Sensor0'])
02868         self.assertEqual(stdout, '')
02869         self.assertEqual(stderr, '')
02870         self.assertEqual(ret, 0)
02871         stdout, stderr, ret = call_process(['./rtls',
02872             'localhost/local.host_cxt/manager.mgr'])
02873         self.assert_('Sensor0.rtc' not in stdout)
02874         stdout, stderr, ret = call_process(['./rtls',
02875             'localhost/local.host_cxt/'])
02876         self.assert_('Sensor0.rtc' not in stdout)
02877 
02878     def test_unload_mod_corbaloc(self):
02879         stdout, stderr, ret = call_process(['./rtmgr',
02880             'corbaloc::localhost:2810/manager', '-u',
02881             os.path.join(COMP_LIB_PATH, 'Controller.so')])
02882         self.assertEqual(stdout, '')
02883         self.assertEqual(stderr, '')
02884         self.assertEqual(ret, 0)
02885         stdout, stderr, ret = call_process(['./rtcat',
02886             '/localhost/local.host_cxt/manager.mgr'])
02887         loaded = self._grab_section(stdout, 'Loaded modules:')
02888         self.assert_(os.path.join(COMP_LIB_PATH, 'Controller.so') not in loaded)
02889 
02890     def test_load_mod_corbaloc_no_port(self):
02891         stdout, stderr, ret = call_process(['./rtmgr',
02892             'corbaloc::localhost/manager', '-l',
02893             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit'])
02894         self.assertEqual(stdout, '')
02895         self.assertEqual(stderr, '')
02896         self.assertEqual(ret, 0)
02897         stdout, stderr, ret = call_process(['./rtcat',
02898             '/localhost/local.host_cxt/manager.mgr'])
02899         loaded = self._grab_section(stdout, 'Loaded modules:')
02900         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') in loaded)
02901 
02902     def test_load_mod_corbaloc_no_id(self):
02903         stdout, stderr, ret = call_process(['./rtmgr',
02904             'corbaloc::localhost:2810', '-l',
02905             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit'])
02906         self.assertEqual(stdout, '')
02907         self.assertEqual(stderr, '')
02908         self.assertEqual(ret, 0)
02909         stdout, stderr, ret = call_process(['./rtcat',
02910             '/localhost/local.host_cxt/manager.mgr'])
02911         loaded = self._grab_section(stdout, 'Loaded modules:')
02912         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') in loaded)
02913 
02914     def test_load_mod_corbaloc_no_port_or_id(self):
02915         stdout, stderr, ret = call_process(['./rtmgr',
02916             'corbaloc::localhost', '-l',
02917             os.path.join(COMP_LIB_PATH, 'Motor.so') + ':MotorInit'])
02918         self.assertEqual(stdout, '')
02919         self.assertEqual(stderr, '')
02920         self.assertEqual(ret, 0)
02921         stdout, stderr, ret = call_process(['./rtcat',
02922             '/localhost/local.host_cxt/manager.mgr'])
02923         loaded = self._grab_section(stdout, 'Loaded modules:')
02924         self.assert_(os.path.join(COMP_LIB_PATH, 'Motor.so') in loaded)
02925 
02926 
02927 def rtmgr_suite():
02928     return unittest.TestLoader().loadTestsFromTestCase(rtmgrTests)
02929 
02930 
02931 class rtstodotTests(unittest.TestCase):
02932     def test_stdin(self):
02933         sys = load_file('./test/sys.rtsys')
02934         p = subprocess.Popen('./rtstodot', stdin=subprocess.PIPE,
02935             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
02936         stdout, stderr = p.communicate(sys)
02937         self.assertEqual(stderr, '')
02938         self.assertEqual(p.returncode, 0)
02939         sample = load_file('./test/sys.dot')
02940         self.assertEqual(sample, stdout)
02941 
02942     def test_file(self):
02943         stdout, stderr, ret = call_process(['./rtstodot', './test/sys.rtsys'])
02944         sample = load_file('./test/sys.dot')
02945         self.assertEqual(sample.rstrip(), stdout)
02946         self.assertEqual(stderr, '')
02947         self.assertEqual(ret, 0)
02948 
02949 
02950 def rtstodot_suite():
02951     return unittest.TestLoader().loadTestsFromTestCase(rtstodotests)
02952 
02953 
02954 class rtprintTests(unittest.TestCase):
02955     def setUp(self):
02956         self._ns = start_ns()
02957         self._output = launch_comp('output_comp')
02958         self._c1 = launch_comp('c1_comp')
02959         wait_for_comp('Output0.rtc')
02960         wait_for_comp('C10.rtc')
02961         call_process(['./rtact', '/localhost/local.host_cxt/Output0.rtc'])
02962         call_process(['./rtact', '/localhost/local.host_cxt/C10.rtc'])
02963         wait_for_comp('Output0.rtc', 'Active')
02964         wait_for_comp('C10.rtc', 'Active')
02965 
02966     def tearDown(self):
02967         stop_comp(self._output)
02968         stop_comp(self._c1)
02969         stop_ns(self._ns)
02970 
02971     def test_print(self):
02972         p = start_process(['./rtprint',
02973             '/localhost/local.host_cxt/Output0.rtc:out'])
02974         time.sleep(3)
02975         p.terminate()
02976         stdout, stderr = p.communicate()
02977         self.assert_(re.match(r'\[0\.0+\]\s\d+\n', stdout) is not None)
02978         self.assertEqual(stderr, '')
02979         self.assertEqual(p.returncode, -15)
02980 
02981     def test_print_count_limit(self):
02982         stdout, stderr, ret = call_process(['./rtprint',
02983             '/localhost/local.host_cxt/Output0.rtc:out', '-n', '2'])
02984         self.assert_(re.match(r'\[0\.0+\]\s\d+\n\[0\.0+\]\s\d+$', stdout) is not None)
02985         self.assertEqual(stderr, '')
02986         self.assertEqual(ret, 0)
02987 
02988     def test_print_time_limit(self):
02989         stdout, stderr, ret = call_process(['./rtprint',
02990             '/localhost/local.host_cxt/Output0.rtc:out', '-t', '1'])
02991         self.assert_(re.match(r'\[0\.0+\]\s\d+\n', stdout) is not None)
02992         self.assertEqual(stderr, '')
02993         self.assertEqual(ret, 0)
02994 
02995     def test_user_mod(self):
02996         stdout, stderr, ret = call_process(['./rtprint',
02997             '/localhost/local.host_cxt/C10.rtc:output', '-n', '1',
02998             '-p', './test', '-m', 'MyData'])
02999         self.assert_(re.match(r'MyData\.Bleg\(val1=1L, val2=\d+L\)', stdout) is not None)
03000         self.assertEqual(stderr, '')
03001         self.assertEqual(ret, 0)
03002 
03003     def test_mod_no_path(self):
03004         stdout, stderr, ret = call_process(['./rtprint',
03005             '/localhost/local.host_cxt/C10.rtc:output', '-n', '1',
03006             '-m', 'MyData'])
03007         self.assertEqual(stdout, '')
03008         self.assertEqual(stderr, 'rtprint: No module named MyData')
03009         self.assertEqual(ret, 1)
03010 
03011     def test_bad_comp(self):
03012         stdout, stderr, ret = call_process(['./rtprint',
03013             '/localhost/local.host_cxt/NotAComp0.rtc:out', '-n', '2'])
03014         self.assertEqual(stdout, '')
03015         self.assertEqual(stderr, 'rtprint: No such object: '
03016             '/localhost/local.host_cxt/NotAComp0.rtc')
03017         self.assertEqual(ret, 1)
03018 
03019     def test_bad_port(self):
03020         stdout, stderr, ret = call_process(['./rtprint',
03021             '/localhost/local.host_cxt/Output0.rtc:noport', '-n', '2'])
03022         self.assertEqual(stdout, '')
03023         self.assertEqual(stderr, 'rtprint: Port not found: '
03024             '/localhost/local.host_cxt/Output0.rtc:noport')
03025         self.assertEqual(ret, 1)
03026 
03027 
03028 def rtprint_suite():
03029     return unittest.TestLoader().loadTestsFromTestCase(rtprintTests)
03030 
03031 
03032 class rtresetTests(unittest.TestCase):
03033     def setUp(self):
03034         self._ns = start_ns()
03035         self._err = launch_comp('err_comp')
03036         make_zombie()
03037         self._mgr = launch_manager()
03038         call_process(['./rtact', '/localhost/local.host_cxt/Err0.rtc'])
03039         wait_for_comp('Err0.rtc', state='Error')
03040 
03041     def tearDown(self):
03042         stop_comp(self._err)
03043         clean_zombies()
03044         stop_manager(self._mgr)
03045         stop_ns(self._ns)
03046 
03047     def test_success(self):
03048         stdout, stderr, ret = call_process(['./rtreset',
03049             '/localhost/local.host_cxt/Err0.rtc'])
03050         self.assertEqual(stdout, '')
03051         self.assertEqual(stderr, '')
03052         self.assertEqual(ret, 0)
03053         stdout, stderr, ret = call_process(['./rtcat',
03054             '/localhost/local.host_cxt/Err0.rtc'])
03055         self.assertEqual(stdout.split()[1], 'Inactive')
03056 
03057     def test_context(self):
03058         stdout, stderr, ret = call_process(['./rtreset',
03059             '/localhost/local.host_cxt'])
03060         self.assertEqual(stdout, '')
03061         self.assertEqual(stderr,
03062             'rtreset: Not a component: /localhost/local.host_cxt')
03063         self.assertEqual(ret, 1)
03064 
03065 
03066     def test_manager(self):
03067         test_notacomp(self, './rtreset', obj1='manager.mgr')
03068 
03069     def test_port(self):
03070         test_notacomp(self, './rtreset', obj1='Err0.rtc:in')
03071 
03072     def test_trailing_slash(self):
03073         test_notacomp(self, './rtreset', obj1='Err0.rtc/')
03074         stdout, stderr, ret = call_process(['./rtcat',
03075             '/localhost/local.host_cxt/Err0.rtc'])
03076         self.assertEqual(stdout.split()[1], 'Error')
03077 
03078     def test_no_object(self):
03079         test_noobject(self, './rtreset', obj1='NotAComp0.rtc')
03080 
03081     def test_zombie_object(self):
03082         test_zombie(self, './rtreset', obj1='Zombie0.rtc')
03083 
03084     def test_no_arg(self):
03085         stdout, stderr, ret = call_process('./rtreset')
03086         self.assertEqual(stdout, '')
03087         self.assertEqual(stderr, 'rtreset: No components specified.')
03088         self.assertEqual(ret, 1)
03089 
03090 
03091 def rtreset_suite():
03092     return unittest.TestLoader().loadTestsFromTestCase(rtresetTests)
03093 
03094 
03095 class rtresurrectTests(unittest.TestCase):
03096     def setUp(self):
03097         self._ns = start_ns()
03098         self._std = launch_comp('std_comp')
03099         self._output = None
03100         wait_for_comp('Std0.rtc')
03101 
03102     def tearDown(self):
03103         stop_comp(self._std)
03104         if self._output:
03105             stop_comp(self._output)
03106         stop_ns(self._ns)
03107 
03108     def test_noprobs(self):
03109         self._output = launch_comp('output_comp')
03110         wait_for_comp('Output0.rtc')
03111         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
03112             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
03113         self.assertEqual(stdout, '2')
03114         stdout, stderr, ret = call_process(['./rtresurrect',
03115             './test/sys.rtsys'])
03116         self.assertEqual(stdout, '')
03117         self.assertEqual(stderr, '')
03118         self.assertEqual(ret, 0)
03119         stdout, stderr, ret = call_process(['./rtcat', '-l',
03120             '/localhost/local.host_cxt/Output0.rtc:out'])
03121         self.assert_('/localhost/local.host_cxt/Std0.rtc:in' in stdout)
03122         stdout, stderr, ret = call_process(['./rtconf', '-s', 'set2',
03123             '/localhost/local.host_cxt/Std0.rtc', 'get', 'param'])
03124         self.assertEqual(stdout, '42')
03125 
03126     def test_missing_comp(self):
03127         stdout, stderr, ret = call_process(['./rtresurrect',
03128             './test/sys.rtsys'])
03129         self.assertEqual(stdout, '')
03130         self.assertEqual(stderr, 'rtresurrect: Required action failed: '
03131             'Required component missing: '
03132             '/localhost/local.host_cxt/Output0.rtc')
03133         self.assertEqual(ret, 1)
03134 
03135     def test_missing_port(self):
03136         self._output = launch_comp('output_noport_comp')
03137         wait_for_comp('Output0.rtc')
03138         stdout, stderr, ret = call_process(['./rtresurrect',
03139             './test/sys.rtsys'])
03140         self.assertEqual(stdout, '')
03141         self.assertEqual(stderr, 'rtresurrect: Required action failed: '
03142                 'Required port not found: out')
03143         self.assertEqual(ret, 1)
03144 
03145     def test_dry_run(self):
03146         self._output = launch_comp('output_comp')
03147         wait_for_comp('Output0.rtc')
03148         stdout, stderr, ret = call_process(['./rtresurrect',
03149             './test/sys.rtsys', '--dry-run'])
03150         self.assertEqual(stderr, '')
03151         self.assertEqual(ret, 0)
03152         self.assert_('Check for required component "RTC:Geoffrey '
03153             'Biggs:test:Std:1.0", "Std0" at path '
03154             '/localhost/local.host_cxt/Std0.rtc (Required)' in stdout)
03155         self.assert_('Check for required component "RTC:Geoffrey '
03156             'Biggs:Test:Output:1.0", "Output0" at path '
03157             '/localhost/local.host_cxt/Output0.rtc (Required)' in stdout)
03158         self.assert_('Check for required port "in" on component at path '
03159             '/localhost/local.host_cxt/Std0.rtc (Required)' in stdout)
03160         self.assert_('Check for required port "out" on component at path '
03161             '/localhost/local.host_cxt/Output0.rtc (Required)' in stdout)
03162         self.assert_('Connect /localhost/local.host_cxt/Output0.rtc:out to '
03163             '/localhost/local.host_cxt/Std0.rtc:in with ID '
03164             'connection_id0 and properties' in stdout)
03165         self.assert_('Set parameter "param" in set "set2" on component at '
03166             'path /localhost/local.host_cxt/Std0.rtc to "42"' in stdout)
03167         self.assert_('Set configuration set "default" active on component at '
03168             'path /localhost/local.host_cxt/Std0.rtc' in stdout)
03169 
03170     def test_existing_con_diff_id(self):
03171         self._output = launch_comp('output_comp')
03172         wait_for_comp('Output0.rtc')
03173         stdout, stderr, ret = call_process(['./rtcon',
03174             '/localhost/local.host_cxt/Std0.rtc:in',
03175             '/localhost/local.host_cxt/Output0.rtc:out'])
03176         self.assertEqual(ret, 0)
03177         stdout, stderr, ret = call_process(['./rtresurrect',
03178             './test/sys.rtsys'])
03179         self.assertEqual(stdout, '')
03180         self.assertEqual(stderr, '')
03181         self.assertEqual(ret, 0)
03182         stdout, stderr, ret = call_process(['./rtcat', '-l',
03183             'localhost/local.host_cxt/Std0.rtc:in'])
03184         self.assertEqual(stdout.count('+Connected to  '
03185             '/localhost/local.host_cxt/Output0.rtc:out'), 2)
03186 
03187     def test_existing_con_same_id(self):
03188         self._output = launch_comp('output_comp')
03189         wait_for_comp('Output0.rtc')
03190         stdout, stderr, ret = call_process(['./rtcon',
03191             '/localhost/local.host_cxt/Std0.rtc:in',
03192             '/localhost/local.host_cxt/Output0.rtc:out',
03193             '-i', 'connection_id0'])
03194         self.assertEqual(ret, 0)
03195         stdout, stderr, ret = call_process(['./rtresurrect',
03196             './test/sys.rtsys'])
03197         self.assertEqual(stdout, '')
03198         self.assertEqual(stderr, '')
03199         self.assertEqual(ret, 0)
03200         stdout, stderr, ret = call_process(['./rtcat', '-l',
03201             'localhost/local.host_cxt/Std0.rtc:in'])
03202         self.assertEqual(stdout.count('+Connected to  '
03203             '/localhost/local.host_cxt/Output0.rtc:out'), 1)
03204 
03205 
03206 def rtresurrect_suite():
03207     return unittest.TestLoader().loadTestsFromTestCase(rtresurrectTests)
03208 
03209 
03210 class rtstartTests(unittest.TestCase):
03211     def setUp(self):
03212         self._ns = start_ns()
03213         self._std = launch_comp('std_comp')
03214         self._output = None
03215         wait_for_comp('Std0.rtc')
03216 
03217     def tearDown(self):
03218         stop_comp(self._std)
03219         if self._output:
03220             stop_comp(self._output)
03221         stop_ns(self._ns)
03222 
03223     def test_noprobs(self):
03224         self._output = launch_comp('output_comp')
03225         wait_for_comp('Output0.rtc')
03226         stdout, stderr, ret = call_process(['./rtcat',
03227             '/localhost/local.host_cxt/Std0.rtc'])
03228         self.assertEqual(stdout.split()[1], 'Inactive')
03229         stdout, stderr, ret = call_process(['./rtcat',
03230             '/localhost/local.host_cxt/Output0.rtc'])
03231         self.assertEqual(stdout.split()[1], 'Inactive')
03232         stdout, stderr, ret = call_process(['./rtstart', './test/sys.rtsys'])
03233         self.assertEqual(stdout, '')
03234         self.assertEqual(ret, 0)
03235         self.assert_('Activate /localhost/local.host_cxt/Std0.rtc in '
03236             'execution context 0 (Required)' in stderr)
03237         self.assert_('Activate /localhost/local.host_cxt/Output0.rtc in '
03238             'execution context 0 (Required)' in stderr)
03239         stdout, stderr, ret = call_process(['./rtcat',
03240             '/localhost/local.host_cxt/Std0.rtc'])
03241         self.assertEqual(stdout.split()[1], 'Active')
03242         stdout, stderr, ret = call_process(['./rtcat',
03243             '/localhost/local.host_cxt/Output0.rtc'])
03244         self.assertEqual(stdout.split()[1], 'Active')
03245 
03246     def test_missing_comp(self):
03247         stdout, stderr, ret = call_process(['./rtstart', './test/sys.rtsys'])
03248         self.assertEqual(stdout, '')
03249         self.assertEqual(stderr, 'rtstart: Required action failed: '
03250             'Required component missing: '
03251             '/localhost/local.host_cxt/Output0.rtc')
03252         self.assertEqual(ret, 1)
03253 
03254     def test_already_active(self):
03255         self._output = launch_comp('output_comp')
03256         wait_for_comp('Output0.rtc')
03257         stdout, stderr, ret = call_process(['./rtact',
03258             '/localhost/local.host_cxt/Std0.rtc'])
03259         stdout, stderr, ret = call_process(['./rtcat',
03260             '/localhost/local.host_cxt/Std0.rtc'])
03261         self.assertEqual(stdout.split()[1], 'Active')
03262         stdout, stderr, ret = call_process(['./rtcat',
03263             '/localhost/local.host_cxt/Output0.rtc'])
03264         self.assertEqual(stdout.split()[1], 'Inactive')
03265         stdout, stderr, ret = call_process(['./rtstart', './test/sys.rtsys'])
03266         self.assertEqual(stdout, '')
03267         self.assertEqual(ret, 0)
03268         self.assert_('Activate /localhost/local.host_cxt/Std0.rtc in '
03269             'execution context 0 (Required)' in stderr)
03270         self.assert_('Activate /localhost/local.host_cxt/Output0.rtc in '
03271             'execution context 0 (Required)' in stderr)
03272         stdout, stderr, ret = call_process(['./rtcat',
03273             '/localhost/local.host_cxt/Std0.rtc'])
03274         self.assertEqual(stdout.split()[1], 'Active')
03275         stdout, stderr, ret = call_process(['./rtcat',
03276             '/localhost/local.host_cxt/Output0.rtc'])
03277         self.assertEqual(stdout.split()[1], 'Active')
03278 
03279     def test_dry_run(self):
03280         self._output = launch_comp('output_comp')
03281         wait_for_comp('Output0.rtc')
03282         stdout, stderr, ret = call_process(['./rtstart',
03283             './test/sys.rtsys', '--dry-run'])
03284         self.assertEqual(stderr, '')
03285         self.assertEqual(ret, 0)
03286         self.assert_('Check for required component "RTC:Geoffrey '
03287             'Biggs:test:Std:1.0", "Std0" at path '
03288             '/localhost/local.host_cxt/Std0.rtc (Required)' in stdout)
03289         self.assert_('Check for required component "RTC:Geoffrey '
03290             'Biggs:Test:Output:1.0", "Output0" at path '
03291             '/localhost/local.host_cxt/Output0.rtc (Required)' in stdout)
03292         self.assert_('Activate /localhost/local.host_cxt/Std0.rtc in '
03293             'execution context 0 (Required)' in stdout)
03294         self.assert_('Activate /localhost/local.host_cxt/Output0.rtc in '
03295             'execution context 0 (Required)' in stdout)
03296 
03297 
03298 def rtstart_suite():
03299     return unittest.TestLoader().loadTestsFromTestCase(rtstartTests)
03300 
03301 
03302 class rtstopTests(unittest.TestCase):
03303     def setUp(self):
03304         self._ns = start_ns()
03305         self._std = launch_comp('std_comp')
03306         self._output = None
03307         wait_for_comp('Std0.rtc')
03308 
03309     def tearDown(self):
03310         stop_comp(self._std)
03311         if self._output:
03312             stop_comp(self._output)
03313         stop_ns(self._ns)
03314 
03315     def test_noprobs(self):
03316         self._output = launch_comp('output_comp')
03317         wait_for_comp('Output0.rtc')
03318         stdout, stderr, ret = call_process(['./rtact',
03319             '/localhost/local.host_cxt/Std0.rtc'])
03320         stdout, stderr, ret = call_process(['./rtact',
03321             '/localhost/local.host_cxt/Output0.rtc'])
03322         stdout, stderr, ret = call_process(['./rtcat',
03323             '/localhost/local.host_cxt/Std0.rtc'])
03324         self.assertEqual(stdout.split()[1], 'Active')
03325         stdout, stderr, ret = call_process(['./rtcat',
03326             '/localhost/local.host_cxt/Output0.rtc'])
03327         self.assertEqual(stdout.split()[1], 'Active')
03328         stdout, stderr, ret = call_process(['./rtstop', './test/sys.rtsys'])
03329         self.assertEqual(stdout, '')
03330         self.assertEqual(ret, 0)
03331         self.assert_('Deactivate /localhost/local.host_cxt/Std0.rtc in '
03332             'execution context 0' in stderr)
03333         self.assert_('Deactivate /localhost/local.host_cxt/Output0.rtc in '
03334             'execution context 0' in stderr)
03335         stdout, stderr, ret = call_process(['./rtcat',
03336             '/localhost/local.host_cxt/Std0.rtc'])
03337         self.assertEqual(stdout.split()[1], 'Inactive')
03338         stdout, stderr, ret = call_process(['./rtcat',
03339             '/localhost/local.host_cxt/Output0.rtc'])
03340         self.assertEqual(stdout.split()[1], 'Inactive')
03341 
03342     def test_missing_comp(self):
03343         stdout, stderr, ret = call_process(['./rtstop', './test/sys.rtsys'])
03344         self.assertEqual(stdout, '')
03345         self.assert_('Action failed: Component missing: '
03346             '/localhost/local.host_cxt/Output0.rtc' in stderr)
03347         self.assertEqual(ret, 0)
03348 
03349     def test_already_inactive(self):
03350         self._output = launch_comp('output_comp')
03351         wait_for_comp('Output0.rtc')
03352         stdout, stderr, ret = call_process(['./rtact',
03353             '/localhost/local.host_cxt/Std0.rtc'])
03354         stdout, stderr, ret = call_process(['./rtcat',
03355             '/localhost/local.host_cxt/Std0.rtc'])
03356         self.assertEqual(stdout.split()[1], 'Active')
03357         stdout, stderr, ret = call_process(['./rtcat',
03358             '/localhost/local.host_cxt/Output0.rtc'])
03359         self.assertEqual(stdout.split()[1], 'Inactive')
03360         stdout, stderr, ret = call_process(['./rtstop', './test/sys.rtsys'])
03361         self.assertEqual(stdout, '')
03362         self.assertEqual(ret, 0)
03363         self.assert_('Deactivate /localhost/local.host_cxt/Std0.rtc in '
03364             'execution context 0' in stderr)
03365         self.assert_('Deactivate /localhost/local.host_cxt/Output0.rtc in '
03366             'execution context 0' in stderr)
03367         stdout, stderr, ret = call_process(['./rtcat',
03368             '/localhost/local.host_cxt/Std0.rtc'])
03369         self.assertEqual(stdout.split()[1], 'Inactive')
03370         stdout, stderr, ret = call_process(['./rtcat',
03371             '/localhost/local.host_cxt/Output0.rtc'])
03372         self.assertEqual(stdout.split()[1], 'Inactive')
03373 
03374     def test_dry_run(self):
03375         self._output = launch_comp('output_comp')
03376         wait_for_comp('Output0.rtc')
03377         stdout, stderr, ret = call_process(['./rtstop',
03378             './test/sys.rtsys', '--dry-run'])
03379         self.assertEqual(stderr, '')
03380         self.assertEqual(ret, 0)
03381         self.assert_('Deactivate /localhost/local.host_cxt/Std0.rtc in '
03382             'execution context 0' in stdout)
03383         self.assert_('Deactivate /localhost/local.host_cxt/Output0.rtc in '
03384             'execution context 0' in stdout)
03385 
03386 
03387 def rtstop_suite():
03388     return unittest.TestLoader().loadTestsFromTestCase(rtstopTests)
03389 
03390 
03391 class rtteardownTests(unittest.TestCase):
03392     def setUp(self):
03393         self._ns = start_ns()
03394         self._std = launch_comp('std_comp')
03395         self._output = None
03396         wait_for_comp('Std0.rtc')
03397 
03398     def tearDown(self):
03399         stop_comp(self._std)
03400         if self._output:
03401             stop_comp(self._output)
03402         stop_ns(self._ns)
03403 
03404     def _setup_comp(self, id=''):
03405         self._output = launch_comp('output_comp')
03406         wait_for_comp('Output0.rtc')
03407         args = ['./rtcon',
03408             '/localhost/local.host_cxt/Std0.rtc:in',
03409             '/localhost/local.host_cxt/Output0.rtc:out']
03410         if id:
03411             args += ['-i', id]
03412         stdout, stderr, ret = call_process(args)
03413 
03414     def test_noprobs(self):
03415         self._setup_comp('connection_id0')
03416         stdout, stderr, ret = call_process(['./rtteardown',
03417             './test/sys.rtsys'])
03418         self.assertEqual(stdout, '')
03419         self.assertEqual(stderr, '')
03420         self.assertEqual(ret, 0)
03421         stdout, stderr, ret = call_process(['./rtcat', '-l',
03422             '/localhost/local.host_cxt/Std0.rtc:in'])
03423         self.assert_('Connected to' not in stdout)
03424 
03425     def test_missing_comp(self):
03426         stdout, stderr, ret = call_process(['./rtteardown',
03427             './test/sys.rtsys'])
03428         self.assertEqual(stdout, '')
03429         self.assertEqual(stderr, 'Action failed: Source component missing: '
03430             '/localhost/local.host_cxt/Output0.rtc')
03431         self.assertEqual(ret, 0)
03432 
03433     def test_missing_port(self):
03434         self._output = launch_comp('output_noport_comp')
03435         wait_for_comp('Output0.rtc')
03436         stdout, stderr, ret = call_process(['./rtteardown',
03437             './test/sys.rtsys'])
03438         self.assertEqual(stdout, '')
03439         self.assertEqual(stderr, 'Action failed: Source port missing: '
03440             '/localhost/local.host_cxt/Output0.rtc:out')
03441         self.assertEqual(ret, 0)
03442 
03443     def test_wrong_id(self):
03444         self._setup_comp('other_id')
03445         stdout, stderr, ret = call_process(['./rtteardown',
03446             './test/sys.rtsys'])
03447         self.assertEqual(stdout, '')
03448         self.assertEqual(stderr, 'Action failed: No connection from '
03449             '/localhost/local.host_cxt/Output0.rtc:out with ID connection_id0')
03450         self.assertEqual(ret, 0)
03451 
03452     def test_dry_run(self):
03453         self._setup_comp('connection_id0')
03454         stdout, stderr, ret = call_process(['./rtteardown',
03455             './test/sys.rtsys', '--dry-run'])
03456         self.assertEqual(stderr, '')
03457         self.assertEqual(ret, 0)
03458         self.assertEqual(stdout, 'Disconnect '
03459             '/localhost/local.host_cxt/Output0.rtc:out from '
03460             '/localhost/local.host_cxt/Std0.rtc:in with ID connection_id0')
03461 
03462 
03463 def rtteardown_suite():
03464     return unittest.TestLoader().loadTestsFromTestCase(rtteardownTests)
03465 
03466 
03467 def suite():
03468     return unittest.TestSuite([rtact_suite(), rtdeact_suite(), rtreset_suite(),
03469         rtcat_suite(), rtcheck_suite(), rtcomp_suite(), rtcon_suite(),
03470         rtconf_suite(), rtcryo_suite(), rtcwd_suite(), rtdel_suite(),
03471         rtdis_suite(), rtdoc_suite(), rtexit_suite(), rtfind_suite(),
03472         rtinject_suite(), rtlog_suite(), rtls_suite(), rtmgr_suite(),
03473         rtprint_suite(), rtresurrect_suite(), rtstart_suite(),
03474         rtstodot_suite(), rtstop_suite(), rtteardown_suite()])
03475 
03476 
03477 if __name__ == '__main__':
03478     if len(sys.argv) >= 2:
03479         COMP_LIB_PATH = sys.argv[1]
03480         sys.argv = [sys.argv[0]] + sys.argv[2:]
03481     unittest.main()
03482     #unittest.TextTestRunner().run(rtcomp_suite())
03483 


rtshell
Author(s): Geoffrey Biggs
autogenerated on Fri Aug 28 2015 12:55:12