Skip to content

Commit

Permalink
Split tests out from 'common' which require a native compiler
Browse files Browse the repository at this point in the history
Split out tests (and parts of tests) which require a native compiler
from the 'common' suite to a new suite called 'native', so we can
selectively avoid running those tests when only a cross-compiler is
available.

Also move test '211 cmake module' to 'cmake' suite, since it appears
that the way we use cmake requires a native compiler.
  • Loading branch information
jon-turney authored and nirbheek committed Sep 10, 2020
1 parent 79b2eeb commit 88e13c5
Show file tree
Hide file tree
Showing 56 changed files with 131 additions and 34 deletions.
2 changes: 1 addition & 1 deletion run_cross_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def runtests(cross_file, failfast):
tests = ['--only', 'common']
tests = ['--only', 'common', 'native']
cmd = mesonlib.python_command + ['run_project_tests.py', '--backend', 'ninja'] + (['--failfast'] if failfast else []) + tests + ['--cross-file', cross_file]
return subprocess.call(cmd)

Expand Down
3 changes: 2 additions & 1 deletion run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from run_tests import ensure_backend_detects_changes
from run_tests import guess_backend

ALL_TESTS = ['cmake', 'common', 'warning-meson', 'failing-meson', 'failing-build', 'failing-test',
ALL_TESTS = ['cmake', 'common', 'native', 'warning-meson', 'failing-meson', 'failing-build', 'failing-test',
'keyval', 'platform-osx', 'platform-windows', 'platform-linux',
'java', 'C#', 'vala', 'rust', 'd', 'objective c', 'objective c++',
'fortran', 'swift', 'cuda', 'python3', 'python', 'fpga', 'frameworks', 'nasm', 'wasm'
Expand Down Expand Up @@ -961,6 +961,7 @@ def __init__(self, category: str, subdir: str, skip: bool = False, stdout_mandat
all_tests = [
TestCategory('cmake', 'cmake', not shutil.which('cmake') or (os.environ.get('compiler') == 'msvc2015' and under_ci)),
TestCategory('common', 'common'),
TestCategory('native', 'native'),
TestCategory('warning-meson', 'warning', stdout_mandatory=True),
TestCategory('failing-meson', 'failing', stdout_mandatory=True),
TestCategory('failing-build', 'failing build'),
Expand Down
2 changes: 1 addition & 1 deletion run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6928,7 +6928,7 @@ def test_override_with_exe_dep(self):
'''
Test that we produce the correct dependencies when a program is overridden with an executable.
'''
testdir = os.path.join(self.common_test_dir, '201 override with exe')
testdir = os.path.join(self.src_root, 'test cases', 'native', '201 override with exe')
self.init(testdir)
with open(os.path.join(self.builddir, 'build.ninja')) as bfile:
for line in bfile:
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions test cases/common/1 trivial/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ elif cc.get_id() == 'intel-cl'
add_project_arguments('/Qdiag-error:10159', language : 'c')
endif

if meson.is_cross_build()
native_exe = executable('native-trivialprog', sources : sources, native : true)
test('native exe in cross build', native_exe)
endif

exe = executable('trivialprog', sources : sources)
assert(exe.name() == 'trivialprog')
test('runtest', exe) # This is a comment
Expand Down
17 changes: 5 additions & 12 deletions test cases/common/21 global arg/meson.build
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
project('global arg test', 'cpp', 'c')

add_global_arguments('-DMYTHING', language : 'c', native : true)
add_global_arguments('-DMYTHING', language : 'c', native : false)
add_global_arguments('-DMYCPPTHING', language : 'cpp', native : true)
add_global_arguments('-DMYCPPTHING', language : 'cpp', native : false)

add_global_arguments('-DGLOBAL_BUILD', language : 'c', native : true)
add_global_arguments('-DGLOBAL_HOST', language : 'c', native : false)
add_global_arguments('-DMYTHING', language : 'c')
add_global_arguments('-DMYCPPTHING', language : 'cpp')
add_global_arguments('-DGLOBAL_HOST', language : 'c')

build_c_args = ['-DARG_BUILD']
c_args = ['-DARG_HOST']

add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'], native: true)
add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'], native: false)
add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'])

exe1 = executable('prog1', 'prog.c', c_args : build_c_args, native : true)
exe2 = executable('prog2', 'prog.c', c_args : c_args, native : false)
exe2 = executable('prog2', 'prog.c', c_args : c_args)
exe3 = executable('prog3', 'prog.cc')

test('prog1', exe1)
test('prog2', exe2)
test('prog3', exe3)
6 changes: 0 additions & 6 deletions test cases/common/56 install script/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@ t = custom_target(

meson.add_install_script('myinstall.py', 'customtarget', t, '--mode=copy')
meson.add_install_script('myinstall.py', 'customtargetindex', t[0], '--mode=copy')

meson.add_install_script(exe, 'generated.txt')
wrap = find_program('wrap.py')
# Yes, these are getting silly
meson.add_install_script(wrap, exe, 'wrapped.txt')
meson.add_install_script(wrap, wrap, exe, 'wrapped2.txt')
2 changes: 0 additions & 2 deletions test cases/common/56 install script/src/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
meson.add_install_script('myinstall.py', 'this/does', 'something-different.dat')

afile = files('a file.txt')

exe = executable('exe', 'exe.c', install : false, native : true)
5 changes: 1 addition & 4 deletions test cases/common/56 install script/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
{"type": "file", "file": "usr/dir/conf.txt"},
{"type": "file", "file": "usr/customtarget/1.txt"},
{"type": "file", "file": "usr/customtarget/2.txt"},
{"type": "file", "file": "usr/customtargetindex/1.txt"},
{"type": "file", "file": "usr/generated.txt"},
{"type": "file", "file": "usr/wrapped.txt"},
{"type": "file", "file": "usr/wrapped2.txt"}
{"type": "file", "file": "usr/customtargetindex/1.txt"}
]
}
3 changes: 1 addition & 2 deletions test cases/common/85 add language/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ project('add language', 'c')

test('C', executable('cprog', 'prog.c'))

assert(add_languages('cpp'), 'Add_languages returned false on success')
assert(add_languages('cpp', native: false), 'Add_languages returned false on success')
assert(not add_languages('klingon', required : false), 'Add_languages returned true on failure.')

test('C++', executable('cppprog', 'prog.cc'))

add_languages('c', native: true)
add_languages('c', native: false)
9 changes: 9 additions & 0 deletions test cases/native/1 trivial/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project('trivial native test', 'c')

sources = 'trivial.c'
cc = meson.get_compiler('c', native: true)

if meson.is_cross_build()
native_exe = executable('native-trivialprog', sources : sources, native : true)
test('native exe in cross build', native_exe)
endif
6 changes: 6 additions & 0 deletions test cases/native/1 trivial/trivial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<stdio.h>

int main(void) {
printf("Trivial test is working.\n");
return 0;
}
14 changes: 14 additions & 0 deletions test cases/native/21 global arg/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project('global arg test', 'cpp', 'c')

add_global_arguments('-DMYTHING', language : 'c', native : true)
add_global_arguments('-DMYCPPTHING', language : 'cpp', native : true)
add_global_arguments('-DGLOBAL_BUILD', language : 'c', native : true)

build_c_args = ['-DARG_BUILD']
c_args = ['-DARG_HOST']

add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'], native: true)

exe1 = executable('prog1', 'prog.c', c_args : build_c_args, native : true)

test('prog1', exe1)
43 changes: 43 additions & 0 deletions test cases/native/21 global arg/prog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef MYTHING
#error "Global argument not set"
#endif

#ifdef MYCPPTHING
#error "Wrong global argument set"
#endif

#ifndef MYCANDCPPTHING
#error "Global argument not set"
#endif

#if !defined(GLOBAL_HOST) && !defined(GLOBAL_BUILD)
#error "Neither global_host nor glogal_build is set."
#endif

#if defined(GLOBAL_HOST) && defined(GLOBAL_BUILD)
#error "Both global build and global host set."
#endif

#ifdef GLOBAL_BUILD
#ifndef ARG_BUILD
#error "Global is build but arg_build is not set."
#endif

#ifdef ARG_HOST
#error "Global is build but arg host is set."
#endif
#endif

#ifdef GLOBAL_HOST
#ifndef ARG_HOST
#error "Global is host but arg_host is not set."
#endif

#ifdef ARG_BUILD
#error "Global is host but arg_build is set."
#endif
#endif

int main(void) {
return 0;
}
15 changes: 15 additions & 0 deletions test cases/native/21 global arg/prog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifdef MYTHING
#error "Wrong global argument set"
#endif

#ifndef MYCPPTHING
#error "Global argument not set"
#endif

#ifndef MYCANDCPPTHING
#error "Global argument not set"
#endif

int main(void) {
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
12 changes: 12 additions & 0 deletions test cases/native/56 install script/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project('custom install script', 'c')

# this is just to ensure that the install directory exists before exe is run
install_data('file.txt', install_dir: '.')

subdir('src')

meson.add_install_script(exe, 'generated.txt')
wrap = find_program('wrap.py')
# Yes, these are getting silly
meson.add_install_script(wrap, exe, 'wrapped.txt')
meson.add_install_script(wrap, wrap, exe, 'wrapped2.txt')
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ int main(int argc, char * argv[]) {
strcat(fullname, argv[1]);

FILE * fp = fopen(fullname, "w");
if (!fp)
return 1;

fputs("Some text\n", fp);
fclose(fp);

Expand Down
1 change: 1 addition & 0 deletions test cases/native/56 install script/src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exe = executable('exe', 'exe.c', install : false, native : true)
8 changes: 8 additions & 0 deletions test cases/native/56 install script/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"installed": [
{"type": "file", "file": "usr/file.txt"},
{"type": "file", "file": "usr/generated.txt"},
{"type": "file", "file": "usr/wrapped.txt"},
{"type": "file", "file": "usr/wrapped2.txt"}
]
}
File renamed without changes.
3 changes: 3 additions & 0 deletions test cases/native/85 add language/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project('add language', 'c')
assert(add_languages('cpp', native: true), 'Add_languages returned false on success')
test('C++', executable('cppprog', 'prog.cc', native: true))
6 changes: 6 additions & 0 deletions test cases/native/85 add language/prog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<iostream>

int main(int, char**) {
std::cout << "I am C++.\n";
return 0;
}

0 comments on commit 88e13c5

Please sign in to comment.