00001
00002
00003 PKG = 'openhrp3'
00004 import roslib; roslib.load_manifest(PKG)
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
00022 class TestCompile(unittest.TestCase):
00023 PKG_CONFIG_PATH = ''
00024
00025 def setUp(self):
00026
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
00043
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_exists_from_prefix(self, fname):
00053 self.check_if_file_exists("prefix", fname)
00054
00055 def test_files_for_hrpsys(self):
00056
00057
00058 self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/project")
00059
00060
00061 self.check_if_file_exists("idl_dir", "OpenHRP/OpenHRPCommon.idl")
00062
00063
00064
00065 def test_files_for_hrpsys_ros_bridge(self):
00066
00067
00068 self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
00069
00070
00071 self.check_if_file_exists("idl_dir", "../sample/model/PA10/pa10.main.wrl")
00072 self.check_if_file_exists("idl_dir", "../sample/model/sample1.wrl")
00073 self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
00074 self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/sample1.wrl")
00075
00076
00077
00078
00079 def test_compile_pkg_config(self):
00080 global PID
00081 cmd = "%s pkg-config openhrp3.1 --cflags --libs"%(self.PKG_CONFIG_PATH)
00082 print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT)
00083 ret = call("g++ -o openhrp3-sample-pkg-config /tmp/%d-openhrp3-sample.cpp `%s`"%(PID,cmd), shell=True)
00084 self.assertTrue(ret==0)
00085
00086 def _test_compile_move_ankle(self):
00087 cmd1 = "pkg-config openhrp3.1 --cflags --libs"
00088 cmd2 = "pkg-config openhrp3.1 --variable=idl_dir"
00089 print "`"+cmd1+"` =",check_output(cmd1, shell=True, stderr=STDOUT)
00090 print "`"+cmd2+"` =",check_output(cmd2, shell=True, stderr=STDOUT)
00091 ret = call("g++ -o move_ankle `%s`/../sample/example/move_ankle/move_ankle.cpp `%s`"%(cmd2,cmd1), shell=True)
00092 self.assertTrue(ret==0)
00093
00094 def test_idl_dir(self):
00095 cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00096 fname = "OpenHRP/OpenHRPCommon.idl"
00097
00098 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00099 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
00100
00101 def test_sample_pa10(self):
00102 cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00103 fname = "../sample/model/PA10/pa10.main.wrl"
00104
00105 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00106 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
00107
00108 cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
00109 fname = "share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl"
00110
00111 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00112 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
00113
00114 def test_sample_samplerobot(self):
00115 cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
00116 fname = "../sample/model/sample1.wrl"
00117
00118 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00119 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00120
00121
00122 fname = "../sample/controller/SampleController/etc/Sample.pos"
00123 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00124 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00125
00126 cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
00127 fname = "share/OpenHRP-3.1/sample/model/sample1.wrl"
00128
00129 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00130 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00131
00132
00133 fname = "share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos"
00134 print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
00135 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
00136
00137
00138 if __name__ == '__main__':
00139 import rostest
00140 global PID
00141 PID = os.getpid()
00142 f = open("/tmp/%d-openhrp3-sample.cpp"%(PID),'w')
00143 f.write(code)
00144 f.close()
00145 rostest.rosrun(PKG, 'test_openhrp3', TestCompile)
00146
00147
00148