test_openhrp3.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 PKG = 'openhrp3'
4 import roslib; roslib.load_manifest(PKG) # This line is not needed with Catkin.
5 
6 import os
7 import sys
8 import unittest
9 
10 code = """
11 #include <hrpModel/Body.h>
12 
13 int main (int argc, char** argv)
14 {
15  hrp::BodyPtr body(new hrp::Body());
16  return 0;
17 }
18 """
19 from subprocess import call, check_output, Popen, PIPE, STDOUT
20 
21 ## A sample python unit test
22 class TestCompile(unittest.TestCase):
23  PKG_CONFIG_PATH = ''
24 
25  def setUp(self):
26  # if rosbuild environment
27  openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip()
28  if os.path.exists(os.path.join(openhrp3_path, "bin")) :
29  self.PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(openhrp3_path)
30 
31  def pkg_config_variable(self, var):
32  return check_output("%s pkg-config openhrp3.1 --variable=%s"%(self.PKG_CONFIG_PATH, var), shell=True).rstrip()
33 
34  def check_if_file_exists(self, var, fname):
35  pkg_var = var
36  pkg_dname = self.pkg_config_variable(pkg_var)
37  pkg_path = os.path.join(pkg_dname, fname)
38  pkg_ret = os.path.exists(pkg_path)
39  self.assertTrue(pkg_ret, "pkg-config openhrp3.1 --variable=%s`/%s (%s) returns %r"%(pkg_var, fname, pkg_path, pkg_ret))
40 
42  # self.check_if_file_exists("prefix", "") # not defined
43  # self.check_if_file_exists("exec_prefix", "") # not defined
44  self.check_if_file_exists("idl_dir", "OpenHRP/OpenHRPCommon.idl")
45 
47  pkg_dname = check_output(['rospack','find','openhrp3']).rstrip()
48  pkg_path = os.path.join(pkg_dname, fname)
49  pkg_ret = os.path.exists(pkg_path)
50  self.assertTrue(pkg_ret, "`rospack find openhrp3`(%s) returns %r"%(pkg_path, pkg_ret))
51 
53  self.check_if_file_exists("prefix", fname)
54 
56  # https://github.com/start-jsk/hrpsys/blob/master/catkin.cmake#L125
57  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/project")
58  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/project")
59 
60  # https://code.google.com/p/hrpsys-base/source/browse/trunk/idl/CMakeLists.txt#118
61  self.check_if_file_exists("idl_dir", "OpenHRP/OpenHRPCommon.idl")
62  # https://code.google.com/p/hrpsys-base/source/browse/trunk/sample/PA10/PA10.conf.in#1
63  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
64 
66  # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/test/test-samplerobot.py#L63
67  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
68  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
69 
70  # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/catkin.cmake#L141
71  self.check_if_file_exists("idl_dir", "../sample/model/PA10/pa10.main.wrl")
72  self.check_if_file_exists("idl_dir", "../sample/model/sample1.wrl")
73  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
74  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/sample1.wrl")
75  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
76  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/sample1.wrl")
77 
78  ## test 1 == 1
80  global PID
81  cmd = "%s pkg-config openhrp3.1 --cflags --libs"%(self.PKG_CONFIG_PATH)
82  print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT)
83  ret = call("g++ -o openhrp3-sample-pkg-config /tmp/%d-openhrp3-sample.cpp `%s`"%(PID,cmd), shell=True)
84  self.assertTrue(ret==0)
85 
87  cmd1 = "pkg-config openhrp3.1 --cflags --libs"
88  cmd2 = "pkg-config openhrp3.1 --variable=idl_dir"
89  print "`"+cmd1+"` =",check_output(cmd1, shell=True, stderr=STDOUT)
90  print "`"+cmd2+"` =",check_output(cmd2, shell=True, stderr=STDOUT)
91  ret = call("g++ -o move_ankle `%s`/../sample/example/move_ankle/move_ankle.cpp `%s`"%(cmd2,cmd1), shell=True)
92  self.assertTrue(ret==0)
93 
94  def test_idl_dir(self):
95  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
96  fname = "OpenHRP/OpenHRPCommon.idl"
97  # check if idl file exists
98  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
99  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
100 
101  def test_sample_pa10(self):
102  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
103  fname = "../sample/model/PA10/pa10.main.wrl"
104  # check if model file exists
105  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
106  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
107 
108  cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
109  fname = "share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl"
110  # check if model file exists
111  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
112  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
113 
115  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
116  fname = "../sample/model/sample1.wrl"
117  # check if model file exists
118  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
119  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
120  #
121  # check if walk data file exists
122  fname = "../sample/controller/SampleController/etc/Sample.pos"
123  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
124  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
125 
126  cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
127  fname = "share/OpenHRP-3.1/sample/model/sample1.wrl"
128  # check if model file exists
129  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
130  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
131  #
132  # check if walk data file exists
133  fname = "share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos"
134  print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname)
135  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
136 
137 #unittest.main()
138 if __name__ == '__main__':
139  import rostest
140  global PID
141  PID = os.getpid()
142  f = open("/tmp/%d-openhrp3-sample.cpp"%(PID),'w')
143  f.write(code)
144  f.close()
145  rostest.rosrun(PKG, 'test_openhrp3', TestCompile)
146 
147 
148 
def check_if_file_exists_from_prefix(self, fname)
A sample python unit test.
def test_compile_pkg_config(self)
test 1 == 1
def test_files_for_hrpsys_ros_bridge(self)
def check_if_file_exists(self, var, fname)
def _test_compile_move_ankle(self)
def check_if_file_exists_from_rospack(self, fname)
def pkg_config_variable(self, var)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:25