test_openhrp3.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 PKG = 'openhrp3'
00004 import roslib; roslib.load_manifest(PKG)  # This line is not needed with Catkin.
00005 
00006 import os
00007 import sys
00008 import unittest
00009 
00010 code = """
00011 #include <hrpModel/Body.h>
00012 
00013 int main (int argc, char** argv)
00014 {
00015   hrp::BodyPtr body(new hrp::Body());
00016   return 0;
00017 }
00018 """
00019 from subprocess import call, check_output, Popen, PIPE, STDOUT
00020 
00021 ## A sample python unit test
00022 class TestCompile(unittest.TestCase):
00023     PKG_CONFIG_PATH = ''
00024 
00025     def setUp(self):
00026         # if rosbuild environment
00027         openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip()
00028         if os.path.exists(os.path.join(openhrp3_path, "bin")) :
00029             self.PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(openhrp3_path)
00030 
00031     def pkg_config_variable(self, var):
00032         return check_output("%s pkg-config openhrp3.1 --variable=%s"%(self.PKG_CONFIG_PATH, var), shell=True).rstrip()
00033 
00034     def check_if_file_exists(self, var, fname):
00035         pkg_var = var
00036         pkg_dname = self.pkg_config_variable(pkg_var)
00037         pkg_path = os.path.join(pkg_dname, fname)
00038         pkg_ret = os.path.exists(pkg_path)
00039         self.assertTrue(pkg_ret, "pkg-config openhrp3.1 --variable=%s`/%s (%s) returns %r"%(pkg_var, fname, pkg_path, pkg_ret))
00040 
00041     def test_config_variables(self):
00042         # self.check_if_file_exists("prefix",             "") # not defined
00043         # self.check_if_file_exists("exec_prefix",        "") # not defined
00044         self.check_if_file_exists("idl_dir",            "OpenHRP/OpenHRPCommon.idl")
00045 
00046     def check_if_file_exists_from_rospack(self, fname):
00047         pkg_dname = check_output(['rospack','find','openhrp3']).rstrip()
00048         pkg_path = os.path.join(pkg_dname, fname)
00049         pkg_ret = os.path.exists(pkg_path)
00050         self.assertTrue(pkg_ret, "`rospack find openhrp3`(%s) returns %r"%(pkg_path, pkg_ret))
00051 
00052     def check_if_file_exites_from_prefix(self, fname):
00053         self.check_if_file_exists("prefix", fname)
00054 
00055     def test_files_for_hrpsys(self):
00056         # https://github.com/start-jsk/hrpsys/blob/master/catkin.cmake#L125
00057         self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/project")
00058         # self.check_if_file_exites_from_prefix("share/openhrp3/share/OpenHRP-3.1/sample/project")
00059 
00060         # https://code.google.com/p/hrpsys-base/source/browse/trunk/idl/CMakeLists.txt#118
00061         self.check_if_file_exists("idl_dir",            "OpenHRP/OpenHRPCommon.idl")
00062         # https://code.google.com/p/hrpsys-base/source/browse/trunk/sample/PA10/PA10.conf.in#1
00063         self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
00064 
00065     def test_files_for_hrpsys_ros_bridge(self):
00066         # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/test/test-samplerobot.py#L63
00067         self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
00068 
00069         # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/catkin.cmake#L141
00070         self.check_if_file_exists("idl_dir",            "../sample/model/PA10/pa10.main.wrl")
00071         self.check_if_file_exists("idl_dir",            "../sample/model/sample1.wrl")
00072         self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
00073         self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/sample1.wrl")
00074 
00075     ## test 1 == 1
00076     def test_compile_pkg_config(self):
00077         global PID
00078         cmd = "%s pkg-config openhrp3.1 --cflags --libs"%(self.PKG_CONFIG_PATH)
00079         print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT)
00080         ret = call("gcc -o openhrp3-sample-pkg-config /tmp/%d-openhrp3-sample.cpp `%s`"%(PID,cmd), shell=True)
00081         self.assertTrue(ret==0)
00082 
00083     def _test_compile_move_ankle(self):
00084         cmd1 = "pkg-config openhrp3.1 --cflags --libs"
00085         cmd2 = "pkg-config openhrp3.1 --variable=idl_dir"
00086         print "`"+cmd1+"` =",check_output(cmd1, shell=True, stderr=STDOUT)
00087         print "`"+cmd2+"` =",check_output(cmd2, shell=True, stderr=STDOUT)
00088         ret = call("gcc -o move_ankle `%s`/../sample/example/move_ankle/move_ankle.cpp `%s`"%(cmd2,cmd1), shell=True)
00089         self.assertTrue(ret==0)
00090 
00091     def test_idl_dir(self):
00092         cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00093         fname = "OpenHRP/OpenHRPCommon.idl"
00094         # check if idl file exists
00095         print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00096         self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
00097 
00098     def test_sample_pa10(self):
00099         cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00100         fname = "../sample/model/PA10/pa10.main.wrl"
00101         # check if model file exists
00102         print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00103         self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
00104 
00105     def test_sample_samplerobot(self):
00106         cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00107         fname = "../sample/model/sample1.wrl"
00108         # check if model file exists
00109         print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00110         self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00111         #
00112         # check if walk data file exists
00113         fname = "../sample/controller/SampleController/etc/Sample.pos"
00114         print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00115         self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00116 
00117 #unittest.main()
00118 if __name__ == '__main__':
00119     import rostest
00120     global PID
00121     PID = os.getpid()
00122     f = open("/tmp/%d-openhrp3-sample.cpp"%(PID),'w')
00123     f.write(code)
00124     f.close()
00125     rostest.rosrun(PKG, 'test_openhrp3', TestCompile) 
00126 
00127 
00128 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Fri Aug 28 2015 11:53:39