test-pkgconfig.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 PKG = 'hrpsys'
4 NAME = 'test-pkgconfig'
5 
6 code = """
7 #include <sys/types.h> /* iob.h need this */
8 #include "hrpsys/io/iob.h"
9 int main (int argc, char** argv)
10 {
11  open_iob();
12  close_iob();
13  return 0;
14 }
15 """
16 import unittest, os, sys
17 from subprocess import call, check_output, Popen, PIPE, STDOUT
18 
19 class TestHrpsysPkgconfig(unittest.TestCase):
20  PKG_CONFIG_PATH = ''
21 
22  def setUp(self):
23  # if rosbuild environment
24  hrpsys_path = check_output(['rospack','find','hrpsys']).rstrip()
25  openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip()
26  if os.path.exists(os.path.join(hrpsys_path, "bin")) :
27  self.PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(hrpsys_path, openhrp3_path)
28 
29  def pkg_config_variable(self, var):
30  return check_output("%s pkg-config hrpsys-base --variable=%s"%(self.PKG_CONFIG_PATH, var), shell=True).rstrip()
31 
32  def check_if_file_exists(self, var, fname):
33  pkg_var = var
34  pkg_dname = self.pkg_config_variable(pkg_var)
35  pkg_path = os.path.join(pkg_dname, fname)
36  pkg_ret = os.path.exists(pkg_path)
37  self.assertTrue(pkg_ret, "pkg-config hrpsys --variable=%s`/%s (%s) returns %r"%(pkg_var, fname, pkg_path, pkg_ret))
38 
39 
41  pkg_dname = check_output(['rospack','find','hrpsys']).rstrip()
42  pkg_path = os.path.join(pkg_dname, fname)
43  pkg_ret = os.path.exists(pkg_path)
44  self.assertTrue(pkg_ret, "`rospack find hrpsys`(%s) returns %r"%(pkg_path, pkg_ret))
45 
47  # https://github.com/start-jsk/hrpsys/blob/master/test/test-pa10.test#L13
48  self.check_if_file_exists_from_rospack("samples/PA10/")
49  self.check_if_file_exists_from_rospack("samples/PA10/rtc.conf")
50  self.check_if_file_exists_from_rospack("samples/PA10/RobotHardware.conf")
51  self.check_if_file_exists_from_rospack("samples/PA10/PA10.conf")
52 
54  # https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/catkin.cmake#L50
55  self.check_if_file_exists("idldir", "HRPDataTypes.idl")
56 
57  def test_compile_iob(self):
58  global PID
59  cmd = "%s pkg-config hrpsys-base --cflags --libs"%(self.PKG_CONFIG_PATH)
60  print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT)
61  ret = call("gcc -o hrpsys-sample-pkg-config /tmp/%d-hrpsys-sample.cpp `%s` -lhrpIo"%(PID,cmd), shell=True)
62  self.assertTrue(ret==0)
63 
64  def test_idlfile(self):
65  cmd = "%s pkg-config hrpsys-base --variable=idldir"%(self.PKG_CONFIG_PATH)
66  print "`"+cmd+"`/RobotHardwareService.idl = ",os.path.join(check_output(cmd, shell=True, stderr=STDOUT).rstrip(), "RobotHardwareService.idl")
67  self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), "RobotHardwareService.idl")))
68 
69 #unittest.main()
70 if __name__ == '__main__':
71  import rostest
72  global PID
73  PID = os.getpid()
74  f = open("/tmp/%d-hrpsys-sample.cpp"%(PID),'w')
75  f.write(code)
76  f.close()
77  rostest.run(PKG, NAME, TestHrpsysPkgconfig, sys.argv)
def check_if_file_exists(self, var, fname)
def check_if_file_exists_from_rospack(self, fname)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51