From 18f581f2c47d3ba81ce753334830ac8ecd5e5a5c Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 22 Dec 2016 01:32:02 +0530 Subject: [PATCH] Add an installed soname unit test We also need to test that the sonames are correct after installation. --- run_unittests.py | 58 ++++++++++++++++++++++++++-- test cases/unit/1 soname/meson.build | 8 +++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/run_unittests.py b/run_unittests.py index d11c3f3bc..d85711b94 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -57,6 +57,9 @@ class LinuxlikeTests(unittest.TestCase): src_root = os.path.dirname(__file__) src_root = os.path.join(os.getcwd(), src_root) self.builddir = tempfile.mkdtemp() + self.prefix = '/usr' + self.libdir = os.path.join(self.prefix, 'lib') + self.installdir = os.path.join(self.builddir, 'install') self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py')] self.mconf_command = [sys.executable, os.path.join(src_root, 'mesonconf.py')] self.mintro_command = [sys.executable, os.path.join(src_root, 'mesonintrospect.py')] @@ -77,11 +80,18 @@ class LinuxlikeTests(unittest.TestCase): self.output += subprocess.check_output(command, env=os.environ.copy()) def init(self, srcdir): - self._run(self.meson_command + [srcdir, self.builddir]) + args = [srcdir, self.builddir, + '--prefix', self.prefix, + '--libdir', self.libdir] + self._run(self.meson_command + args) def build(self): self._run(self.ninja_command) + def install(self): + os.environ['DESTDIR'] = self.installdir + self._run(self.ninja_command + ['install']) + def run_target(self, target): self.output += subprocess.check_output(self.ninja_command + [target]) @@ -236,8 +246,8 @@ class LinuxlikeTests(unittest.TestCase): intro = self.introspect('--targets') if intro[0]['type'] == 'executable': intro = intro[::-1] - self.assertEqual(intro[0]['install_filename'], '/usr/local/libtest/libstat.a') - self.assertEqual(intro[1]['install_filename'], '/usr/local/bin/prog') + self.assertEqual(intro[0]['install_filename'], '/usr/lib/libstat.a') + self.assertEqual(intro[1]['install_filename'], '/usr/bin/prog') def test_run_target_files_path(self): ''' @@ -323,6 +333,48 @@ class LinuxlikeTests(unittest.TestCase): self.assertEqual(self.get_soname(bothset), 'libbothset.so.1.2.3') self.assertEqual(len(glob(bothset[:-3] + '*')), 3) + def test_installed_soname(self): + testdir = os.path.join(self.unit_test_dir, '1 soname') + self.init(testdir) + self.build() + self.install() + + # File without aliases set. + nover = self.installdir + os.path.join(self.libdir, 'libnover.so') + self.assertTrue(os.path.exists(nover)) + self.assertFalse(os.path.islink(nover)) + self.assertEqual(self.get_soname(nover), 'libnover.so') + self.assertEqual(len(glob(nover[:-3] + '*')), 1) + + # File with version set + verset = self.installdir + os.path.join(self.libdir, 'libverset.so') + self.assertTrue(os.path.exists(verset + '.4.5.6')) + self.assertEqual(os.readlink(verset), 'libverset.so.4') + self.assertEqual(self.get_soname(verset), 'libverset.so.4') + self.assertEqual(len(glob(verset[:-3] + '*')), 3) + + # File with soversion set + soverset = self.installdir + os.path.join(self.libdir, 'libsoverset.so') + self.assertTrue(os.path.exists(soverset + '.1.2.3')) + self.assertEqual(os.readlink(soverset), 'libsoverset.so.1.2.3') + self.assertEqual(self.get_soname(soverset), 'libsoverset.so.1.2.3') + self.assertEqual(len(glob(soverset[:-3] + '*')), 2) + + # File with version and soversion set to same values + settosame = self.installdir + os.path.join(self.libdir, 'libsettosame.so') + self.assertTrue(os.path.exists(settosame + '.7.8.9')) + self.assertEqual(os.readlink(settosame), 'libsettosame.so.7.8.9') + self.assertEqual(self.get_soname(settosame), 'libsettosame.so.7.8.9') + self.assertEqual(len(glob(settosame[:-3] + '*')), 2) + + # File with version and soversion set to different values + bothset = self.installdir + os.path.join(self.libdir, 'libbothset.so') + self.assertTrue(os.path.exists(bothset + '.1.2.3')) + self.assertEqual(os.readlink(bothset), 'libbothset.so.1.2.3') + self.assertEqual(os.readlink(bothset + '.1.2.3'), 'libbothset.so.4.5.6') + self.assertEqual(self.get_soname(bothset), 'libbothset.so.1.2.3') + self.assertEqual(len(glob(bothset[:-3] + '*')), 3) + def test_compiler_check_flags_order(self): ''' Test that compiler check flags override all other flags. This can't be diff --git a/test cases/unit/1 soname/meson.build b/test cases/unit/1 soname/meson.build index d956afed9..950dadc5d 100644 --- a/test cases/unit/1 soname/meson.build +++ b/test cases/unit/1 soname/meson.build @@ -1,18 +1,22 @@ project('vertest', 'c') -shared_library('nover', 'versioned.c') +shared_library('nover', 'versioned.c', + install : true) shared_library('verset', 'versioned.c', + install : true, version : '4.5.6') shared_library('soverset', 'versioned.c', + install : true, soversion : '1.2.3') shared_library('bothset', 'versioned.c', + install : true, soversion : '1.2.3', version : '4.5.6') shared_library('settosame', 'versioned.c', + install : true, soversion : '7.8.9', version : '7.8.9') -