From b9c4fc728c6e34cedb387d6844f21456c38ad269 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 30 Sep 2017 16:08:41 +0300 Subject: Moved prebuilt object test under unittests. --- run_project_tests.py | 8 +++--- run_unittests.py | 37 ++++++++++++++++++++++++++ test cases/prebuilt/1 object/main.c | 5 ---- test cases/prebuilt/1 object/meson.build | 25 ----------------- test cases/prebuilt/1 object/source.c | 8 ------ test cases/unit/14 prebuilt object/main.c | 5 ++++ test cases/unit/14 prebuilt object/meson.build | 25 +++++++++++++++++ test cases/unit/14 prebuilt object/source.c | 8 ++++++ 8 files changed, 78 insertions(+), 43 deletions(-) delete mode 100644 test cases/prebuilt/1 object/main.c delete mode 100644 test cases/prebuilt/1 object/meson.build delete mode 100644 test cases/prebuilt/1 object/source.c create mode 100644 test cases/unit/14 prebuilt object/main.c create mode 100644 test cases/unit/14 prebuilt object/meson.build create mode 100644 test cases/unit/14 prebuilt object/source.c diff --git a/run_project_tests.py b/run_project_tests.py index 426e2c7..03dc8be 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -642,9 +642,8 @@ def generate_prebuilt(): object_suffix = 'obj' else: object_suffix = 'o' - objectfile = generate_pb_object(compiler, object_suffix) stlibfile = generate_pb_static(compiler, object_suffix, static_suffix) - return objectfile, stlibfile + return stlibfile def check_meson_commands_work(): global backend, meson_command, compile_commands, test_commands, install_commands @@ -684,14 +683,13 @@ if __name__ == '__main__': os.chdir(script_dir) check_format() check_meson_commands_work() - pbfiles = generate_prebuilt() + pbfile = generate_prebuilt() try: all_tests = detect_tests_to_run() (passing_tests, failing_tests, skipped_tests) = run_tests(all_tests, 'meson-test-run', options.extra_args) except StopException: pass - for f in pbfiles: - os.unlink(f) + os.unlink(pbfile) print('\nTotal passed tests:', green(str(passing_tests))) print('Total failed tests:', red(str(failing_tests))) print('Total skipped tests:', yellow(str(skipped_tests))) diff --git a/run_unittests.py b/run_unittests.py index b217714..e307626 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1298,6 +1298,43 @@ int main(int argc, char **argv) { for i in targets: self.assertPathExists(os.path.join(testdir, i)) + def detect_prebuild_env(self): + if mesonbuild.mesonlib.is_windows(): + object_suffix = 'obj' + else: + object_suffix = 'o' + static_suffix = 'a' + if shutil.which('cl'): + compiler = 'cl' + static_suffix = 'lib' + elif shutil.which('cc'): + compiler = 'cc' + elif shutil.which('gcc'): + compiler = 'gcc' + else: + raise RuntimeError("Could not find C compiler.") + return (compiler, object_suffix, static_suffix) + + def pbcompile(self, compiler, source, objectfile): + if compiler == 'cl': + cmd = [compiler, '/nologo', '/Fo' + objectfile, '/c', source] + else: + cmd = [compiler, '-c', source, '-o', objectfile] + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + + def test_prebuilt_object(self): + (compiler, object_suffix, static_suffix) = self.detect_prebuild_env() + tdir = os.path.join(self.unit_test_dir, '14 prebuilt object') + source = os.path.join(tdir, 'source.c') + objectfile = os.path.join(tdir, 'prebuilt.' + object_suffix) + self.pbcompile(compiler, source, objectfile) + try: + self.init(tdir) + self.build() + self.run_tests() + finally: + os.unlink(objectfile) class FailureTests(BasePlatformTests): ''' diff --git a/test cases/prebuilt/1 object/main.c b/test cases/prebuilt/1 object/main.c deleted file mode 100644 index 480bda5..0000000 --- a/test cases/prebuilt/1 object/main.c +++ /dev/null @@ -1,5 +0,0 @@ -int func(); - -int main(int argc, char **argv) { - return func() == 42 ? 0 : 99; -} diff --git a/test cases/prebuilt/1 object/meson.build b/test cases/prebuilt/1 object/meson.build deleted file mode 100644 index 92f966b..0000000 --- a/test cases/prebuilt/1 object/meson.build +++ /dev/null @@ -1,25 +0,0 @@ -# This test is on its own because it is special. -# To run the test you need the prebuilt object -# file for the given platform. -# -# Combined with cross compilation this would make -# the state space explode so let's just keep this -# in its own subdir so it's not run during cross -# compilation tests. - -project('prebuilt object', 'c') - -if host_machine.system() == 'windows' - prebuilt = 'prebuilt.obj' -else - prebuilt = 'prebuilt.o' -endif - -# Remember: do not put source.c in this -# declaration. run_tests.py generates the -# prebuilt object before running this test. - -e = executable('prog', 'main.c', -objects : prebuilt) - -test('objtest', e) diff --git a/test cases/prebuilt/1 object/source.c b/test cases/prebuilt/1 object/source.c deleted file mode 100644 index f39b4f3..0000000 --- a/test cases/prebuilt/1 object/source.c +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Compile this manually on new platforms and add the - * object file to revision control and Meson configuration. - */ - -int func() { - return 42; -} diff --git a/test cases/unit/14 prebuilt object/main.c b/test cases/unit/14 prebuilt object/main.c new file mode 100644 index 0000000..480bda5 --- /dev/null +++ b/test cases/unit/14 prebuilt object/main.c @@ -0,0 +1,5 @@ +int func(); + +int main(int argc, char **argv) { + return func() == 42 ? 0 : 99; +} diff --git a/test cases/unit/14 prebuilt object/meson.build b/test cases/unit/14 prebuilt object/meson.build new file mode 100644 index 0000000..92f966b --- /dev/null +++ b/test cases/unit/14 prebuilt object/meson.build @@ -0,0 +1,25 @@ +# This test is on its own because it is special. +# To run the test you need the prebuilt object +# file for the given platform. +# +# Combined with cross compilation this would make +# the state space explode so let's just keep this +# in its own subdir so it's not run during cross +# compilation tests. + +project('prebuilt object', 'c') + +if host_machine.system() == 'windows' + prebuilt = 'prebuilt.obj' +else + prebuilt = 'prebuilt.o' +endif + +# Remember: do not put source.c in this +# declaration. run_tests.py generates the +# prebuilt object before running this test. + +e = executable('prog', 'main.c', +objects : prebuilt) + +test('objtest', e) diff --git a/test cases/unit/14 prebuilt object/source.c b/test cases/unit/14 prebuilt object/source.c new file mode 100644 index 0000000..f39b4f3 --- /dev/null +++ b/test cases/unit/14 prebuilt object/source.c @@ -0,0 +1,8 @@ +/* + * Compile this manually on new platforms and add the + * object file to revision control and Meson configuration. + */ + +int func() { + return 42; +} -- cgit v1.1