tests/common/141: Also test C + asm targets

Ensure that they are all built with and linked with the C compiler
pull/1505/head
Nirbheek Chauhan 8 years ago
parent fa09b122b0
commit 9261243834
  1. 20
      run_unittests.py
  2. 8
      test cases/common/141 c cpp and asm/main.c
  3. 1
      test cases/common/141 c cpp and asm/meson.build

@ -886,7 +886,7 @@ class AllPlatformTests(BasePlatformTests):
if env.detect_c_compiler(False).get_id() == 'msvc':
raise unittest.SkipTest('MSVC can\'t compile assembly')
self.init(testdir)
commands = {'cpp-asm': {}, 'cpp-c-asm': {}, 'c-cpp-asm': {}}
commands = {'c-asm': {}, 'cpp-asm': {}, 'cpp-c-asm': {}, 'c-cpp-asm': {}}
for cmd in self.get_compdb():
# Get compiler
split = shlex.split(cmd['command'])
@ -895,7 +895,14 @@ class AllPlatformTests(BasePlatformTests):
else:
compiler = split[0]
# Classify commands
if 'Icpp-asm' in cmd['command']:
if 'Ic-asm' in cmd['command']:
if cmd['file'].endswith('.S'):
commands['c-asm']['asm'] = compiler
elif cmd['file'].endswith('.c'):
commands['c-asm']['c'] = compiler
else:
raise AssertionError('{!r} found in cpp-asm?'.format(cmd['command']))
elif 'Icpp-asm' in cmd['command']:
if cmd['file'].endswith('.S'):
commands['cpp-asm']['asm'] = compiler
elif cmd['file'].endswith('.cpp'):
@ -922,12 +929,21 @@ class AllPlatformTests(BasePlatformTests):
raise AssertionError('{!r} found in cpp-c-asm?'.format(cmd['command']))
else:
raise AssertionError('Unknown command {!r} found'.format(cmd['command']))
# Check that .S files are always built with the C compiler
self.assertEqual(commands['c-asm']['asm'], commands['c-asm']['c'])
self.assertEqual(commands['c-asm']['asm'], commands['cpp-asm']['asm'])
self.assertEqual(commands['cpp-asm']['asm'], commands['c-cpp-asm']['c'])
self.assertEqual(commands['c-cpp-asm']['asm'], commands['c-cpp-asm']['c'])
self.assertEqual(commands['cpp-c-asm']['asm'], commands['cpp-c-asm']['c'])
self.assertNotEqual(commands['cpp-asm']['asm'], commands['cpp-asm']['cpp'])
self.assertNotEqual(commands['c-cpp-asm']['c'], commands['c-cpp-asm']['cpp'])
self.assertNotEqual(commands['cpp-c-asm']['c'], commands['cpp-c-asm']['cpp'])
# Check that the c-asm target is always linked with the C linker
build_ninja = os.path.join(self.builddir, 'build.ninja')
with open(build_ninja, 'r', encoding='utf-8') as f:
contents = f.read()
m = re.search('build c-asm.*: c_LINKER', contents)
self.assertIsNotNone(m, msg=contents)
class WindowsTests(BasePlatformTests):

@ -0,0 +1,8 @@
#include <stdio.h>
int get_retval(void);
int main(int argc, char **argv) {
printf("C seems to be working.\n");
return get_retval();
}

@ -12,6 +12,7 @@ if meson.get_compiler('c').get_id() == 'msvc'
error('MESON_SKIP_TEST MSVC can\'t compile assembly')
endif
test('test-c-asm', executable('c-asm', ['main.c', 'retval-' + cpu + '.S']))
test('test-cpp-asm', executable('cpp-asm', ['main.cpp', 'retval-' + cpu + '.S']))
test('test-c-cpp-asm', executable('c-cpp-asm', ['somelib.c', 'main.cpp', 'retval-' + cpu + '.S']))
test('test-cpp-c-asm', executable('cpp-c-asm', ['main.cpp', 'somelib.c', 'retval-' + cpu + '.S']))

Loading…
Cancel
Save