meson test / qemu-system-arm and the -kernel parameter

288 views
Skip to first unread message

alexander....@gmail.com

unread,
Jan 2, 2018, 6:21:17 PM1/2/18
to The Meson Build System
Hi

I'm working with microcontrollers and configured a meson project with llvm and qemu.
And now I got a problem: I want to use the test feature from meson together with qemu.

So I defined the <exe_wrapper = 'qemu-system-arm'> in my cross-file.

And defined my test executable. This works fine.
But when meson calls my test it invokes the following:

qemu-system-arm <binary> -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic -kernel

And it should look like this to work :

qemu-system-arm -kernel <binary> -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic 

In short : I need to have the "-kernel" flag before the binary path.

Does someone knows how to do this?
Or is this not possible at the moment?

Sincerely Alex

PS: I know the args and env options. with the args option, all option are after the binary path and with the env option all options are before the exe_wrapper binary.
So these are not suitable for my problem.

Philipp Ittershagen

unread,
Jan 3, 2018, 4:24:04 AM1/3/18
to alexander....@gmail.com, The Meson Build System

Hi Alex,

On Tue, Jan 02 2018, alexander....@gmail.com wrote:
> So I defined the <exe_wrapper = 'qemu-system-arm'> in my
> cross-file.
>
> [...]
>
> In short : I need to have the "-kernel" flag before the binary
> path.
>
> Does someone knows how to do this?

One possible solution is to write your own shell script and
provide it as the exe_wrapper.


Philipp

Jussi Pakkanen

unread,
Jan 3, 2018, 5:52:03 AM1/3/18
to alexander....@gmail.com, The Meson Build System
On Wed, Jan 3, 2018 at 1:21 AM, <alexander....@gmail.com> wrote:

> And defined my test executable. This works fine.
> But when meson calls my test it invokes the following:
>
> qemu-system-arm <binary> -machine lm3s811evb -cpu cortex-m3 -semihosting
> -nographic -kernel
>
> And it should look like this to work :
>
> qemu-system-arm -kernel <binary> -machine lm3s811evb -cpu cortex-m3
> -semihosting -nographic

What is the specific value of your exe wrapper and what happens if you
set it to this:

exe_wrapper = ['qemu-system-arm', '-machine', 'lm3s811evb', '-cpu',
'cortex-m3', '-semihosting', '-nographic', '-kernel']

alexander....@gmail.com

unread,
Jan 3, 2018, 7:24:34 AM1/3/18
to The Meson Build System
Hi

Thank you both for your fast answer.
first : I updated to version 0.44.0

I would prefer the solution from Jussi Pakkanen but as you will see further in this email it doesn't work.
For your question : I want include the TDD (Test-Driven-Development) workflow into my designs.
For this I want to compile the testcode to my target and run it in qemu.

When I look back how much time I already burned it might not was the best idea... :/
Maybe I should just use a native compiler and run the test code on the host machine.


@ Phillip : I'm trying to get it working with the script. At the moment I struggle with an OSError
Traceback (most recent call last):
  File "/home/ottale/.local/bin/meson", line 37, in <module>
    sys.exit(main())
  File "/home/ottale/.local/bin/meson", line 34, in main
    return mesonmain.run(sys.argv[1:], launcher)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mesonmain.py", line 292, in run
    return mtest.run(remaining_args)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 631, in run
    return th.doit()
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 365, in doit
    self.run_tests(tests)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 512, in run_tests
    self.drain_futures(futures)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 528, in drain_futures
    self.print_stats(numlen, tests, name, result.result(), i)
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 405, in result
    return self.__get_result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 252, in run_single_test
    preexec_fn=setsid)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
FAILED: meson-test 
/usr/bin/python3 -u /home/ottale/.local/bin/meson test --no-rebuild --print-errorlogs
ninja: build stopped: subcommand failed.



@ Jussi Pakkanen : I got this error:
Traceback (most recent call last):
  File "/home/ottale/.local/bin/meson", line 37, in <module>
    sys.exit(main())
  File "/home/ottale/.local/bin/meson", line 34, in main
    return mesonmain.run(sys.argv[1:], launcher)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mesonmain.py", line 292, in run
    return mtest.run(remaining_args)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 631, in run
    return th.doit()
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 365, in doit
    self.run_tests(tests)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 512, in run_tests
    self.drain_futures(futures)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 528, in drain_futures
    self.print_stats(numlen, tests, name, result.result(), i)
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 398, in result
    return self.__get_result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/ottale/.local/lib/python3.5/site-packages/mesonbuild/mtest.py", line 252, in run_single_test
    preexec_fn=setsid)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1474, in _execute_child
    executable = os.fsencode(executable)
  File "/usr/lib/python3.5/os.py", line 862, in fsencode
    raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
TypeError: expect bytes or str, not list
FAILED: meson-test 
/usr/bin/python3 -u /home/ottale/.local/bin/meson test --no-rebuild --print-errorlogs
ninja: build stopped: subcommand failed.


But (sadly as aspected) this also does not work : 
'qemu-system-arm -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic -kernel'

this ends up in an 
FileNotFoundError: [Errno 2] No such file or directory: 'qemu-system-arm -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic -kernel'

Regards Alex


Philipp Ittershagen

unread,
Jan 3, 2018, 7:45:52 AM1/3/18
to alexander....@gmail.com, The Meson Build System

On Wed, Jan 03 2018, alexander....@gmail.com wrote:
> I would prefer the solution from Jussi Pakkanen but as you will
> see further in this email it doesn't work. For your question :
> I want include the TDD (Test-Driven-Development) workflow into
> my designs. For this I want to compile the testcode to my
> target and run it in qemu.
>
> When I look back how much time I already burned it might not was
> the best idea... :/ Maybe I should just use a native compiler
> and run the test code on the host machine.

I'm not sure I understand but judging by your qemu parameters,
running the code on your native build machine does not make sense:
how do you want to test the bare metal binary for the foreign
platform on your build machine? IMHO TDD with QEMU here is your
only way of getting this to work.

If you are just trying to test a binary cross compiled for a linux
running on another platform (e.g. Raspberry Pi), then you might
want to use the user-space emulator qemu-arm.

> OSError: [Errno 8] Exec format error

There's probably an issue with your script:

- Do you miss the shebang line ('#!/bin/sh') in your script?
- Are you sure there is no typo/space in the first line?
- Is the file marked executable?


Philipp

Jussi Pakkanen

unread,
Jan 3, 2018, 7:47:17 AM1/3/18
to alexander....@gmail.com, The Meson Build System
On Wed, Jan 3, 2018 at 2:24 PM, <alexander....@gmail.com> wrote:

> But (sadly as aspected) this also does not work :
> 'qemu-system-arm -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic
> -kernel'
>
> this ends up in an
> FileNotFoundError: [Errno 2] No such file or directory: 'qemu-system-arm
> -machine lm3s811evb -cpu cortex-m3 -semihosting -nographic -kernel'

In Meson, everything dealing with command lines, arguments and the
like is treated as an array. We take care of quoting all special
characters, especially spaces, so that they work on all backends.
Meson considers that a single command name (which happens to have
spaces). You need to specify it as an array instead.

mikkelfj

unread,
Jan 3, 2018, 2:42:46 PM1/3/18
to The Meson Build System
If you get it to work, could you write a blog about it, or make a github demo project?

I think it could be useful for others to learn from.

alexander....@gmail.com

unread,
Jan 3, 2018, 6:15:45 PM1/3/18
to The Meson Build System
Hi

Thanks for your answers.

Phillip got it right. I forgot the shebang.
After that I had an annoying bug with qemu and was not shure where the problem was.

But now It works!

I will post here the link to my github repo as soon as I cleaned up my mess :-P
I have several (working) examples with different STM32 Controllers and LLVM / Meson build

Regards Alex
Reply all
Reply to author
Forward
0 new messages