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, Popen, PIPE, STDOUT
20 
21 from subprocess import check_output as _check_output
22 def check_output(*args, **kwargs): return _check_output(*args, **kwargs).decode('ascii')
23 
24 
25 class TestCompile(unittest.TestCase):
26  PKG_CONFIG_PATH = ''
27 
28  def setUp(self):
29  # if rosbuild environment
30  openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip()
31  if os.path.exists(os.path.join(openhrp3_path, "bin")) :
32  self.PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(openhrp3_path)
33 
34  def pkg_config_variable(self, var):
35  return check_output("%s pkg-config openhrp3.1 --variable=%s"%(self.PKG_CONFIG_PATH, var), shell=True).rstrip()
36 
37  def check_if_file_exists(self, var, fname):
38  pkg_var = var
39  pkg_dname = self.pkg_config_variable(pkg_var)
40  pkg_path = os.path.join(pkg_dname, fname)
41  pkg_ret = os.path.exists(pkg_path)
42  self.assertTrue(pkg_ret, "pkg-config openhrp3.1 --variable=%s`/%s (%s) returns %r"%(pkg_var, fname, pkg_path, pkg_ret))
43 
45  # self.check_if_file_exists("prefix", "") # not defined
46  # self.check_if_file_exists("exec_prefix", "") # not defined
47  self.check_if_file_exists("idl_dir", "OpenHRP/OpenHRPCommon.idl")
48 
50  pkg_dname = check_output(['rospack','find','openhrp3']).rstrip()
51  pkg_path = os.path.join(pkg_dname, fname)
52  pkg_ret = os.path.exists(pkg_path)
53  self.assertTrue(pkg_ret, "`rospack find openhrp3`(%s) returns %r"%(pkg_path, pkg_ret))
54 
56  self.check_if_file_exists("prefix", fname)
57 
59  # https://github.com/start-jsk/hrpsys/blob/master/catkin.cmake#L125
60  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/project")
61  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/project")
62 
63  # https://code.google.com/p/hrpsys-base/source/browse/trunk/idl/CMakeLists.txt#118
64  self.check_if_file_exists("idl_dir", "OpenHRP/OpenHRPCommon.idl")
65  # https://code.google.com/p/hrpsys-base/source/browse/trunk/sample/PA10/PA10.conf.in#1
66  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
67 
69  # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/test/test-samplerobot.py#L63
70  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
71  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos")
72 
73  # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/catkin.cmake#L141
74  self.check_if_file_exists("idl_dir", "../sample/model/PA10/pa10.main.wrl")
75  self.check_if_file_exists("idl_dir", "../sample/model/sample1.wrl")
76  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
77  self.check_if_file_exists_from_prefix("share/OpenHRP-3.1/sample/model/sample1.wrl")
78  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl")
79  # self.check_if_file_exists_from_rospack("share/OpenHRP-3.1/sample/model/sample1.wrl")
80 
81 
83  global PID
84  cmd = "%s pkg-config openhrp3.1 --cflags --libs"%(self.PKG_CONFIG_PATH)
85  print("`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT))
86  ret = call("g++ -o openhrp3-sample-pkg-config /tmp/%d-openhrp3-sample.cpp `%s`"%(PID,cmd), shell=True)
87  self.assertTrue(ret==0)
88 
90  cmd1 = "pkg-config openhrp3.1 --cflags --libs"
91  cmd2 = "pkg-config openhrp3.1 --variable=idl_dir"
92  print("`"+cmd1+"` =",check_output(cmd1, shell=True, stderr=STDOUT))
93  print("`"+cmd2+"` =",check_output(cmd2, shell=True, stderr=STDOUT))
94  ret = call("g++ -o move_ankle `%s`/../sample/example/move_ankle/move_ankle.cpp `%s`"%(cmd2,cmd1), shell=True)
95  self.assertTrue(ret==0)
96 
97  def test_idl_dir(self):
98  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
99  fname = "OpenHRP/OpenHRPCommon.idl"
100  # check if idl file exists
101  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
102  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
103 
104  def test_sample_pa10(self):
105  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
106  fname = "../sample/model/PA10/pa10.main.wrl"
107  # check if model file exists
108  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
109  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
110 
111  cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
112  fname = "share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl"
113  # check if model file exists
114  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
115  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)))
116 
118  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(self.PKG_CONFIG_PATH)
119  fname = "../sample/model/sample1.wrl"
120  # check if model file exists
121  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
122  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
123  #
124  # check if walk data file exists
125  fname = "../sample/controller/SampleController/etc/Sample.pos"
126  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
127  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
128 
129  cmd = "%s pkg-config openhrp3.1 --variable=prefix"%(self.PKG_CONFIG_PATH)
130  fname = "share/OpenHRP-3.1/sample/model/sample1.wrl"
131  # check if model file exists
132  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
133  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
134  #
135  # check if walk data file exists
136  fname = "share/OpenHRP-3.1/sample/controller/SampleController/etc/Sample.pos"
137  print("`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname))
138  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname)), "cmd = %r, fname = %r"%(cmd, fname))
139 
140 #unittest.main()
141 if __name__ == '__main__':
142  import rostest
143  global PID
144  PID = os.getpid()
145  f = open("/tmp/%d-openhrp3-sample.cpp"%(PID),'w')
146  f.write(code)
147  f.close()
148  rostest.rosrun(PKG, 'test_openhrp3', TestCompile)
149 
150 
151 
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)
def check_output(args, kwargs)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:05