Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmocka: support for xtensa-gcc #736

Open
lgirdwood opened this issue Dec 17, 2018 · 17 comments
Open

cmocka: support for xtensa-gcc #736

lgirdwood opened this issue Dec 17, 2018 · 17 comments
Assignees
Labels
enhancement New feature or request P3 Low-impact bugs or features

Comments

@lgirdwood
Copy link
Member

cmocka must also be able to use xtensa GCC as compiler.

@jajanusz
Copy link
Contributor

@lgirdwood
These unit tests has to be run somewhere.
Is qemu usable? If so, then I'll need some info how to run it.
In xtensa simulator I can run simple program like main() { printf("Hello"); } and it will print to stdout. I should be able to do it somehow in qemu.
AFAIK we use qemu in our ROM boot tests. If you could point me to some info how to setup it locally, it'd be helpful.

@michalgrodzicki
Copy link

@lgirdwood any comment?

@lgirdwood
Copy link
Member Author

@jajanusz qemu simulates bare metal DSP from BYT -> ICL so it's missing C library support. In order to run the UTs on qemu (including CI) we would have to follow ROM test approach. i.e.

  1. UT includes xtensa-crt.S that creates C runtime environment and jumps to main()
  2. printf() would call trace() infrastructure which would write to special memory device (which qemu printf()).

It seems we are missing qemu build instructions on sof-docs atm so (in qemu directory)

'./configure' '--prefix=.' '--target-list=xtensa-softmmu,x86_64-softmmu' '--enable-gtk' '--enable-sdl' '--enable-spice' '--audio-drv-list=alsa' '--enable-libusb' '--enable-usb-redir' '--enable-coroutine-pool' '--disable-opengl' '--enable-fdt'
make

Then you can run it by

xtensa-host.sh
usage: ./xtensa-host.sh device [-k kernel] [-t] [-d] [-i] [-r rom] [-c] [-g] [-o time log]
supported devices: byt, cht, hsw, bdw, bxt, sue, cnl, icl, skl, kbl, hky
[-k] | [--kernel]: load firmware kernel image
[-r] | [--rom]: load firmware ROM image
[-t] | [--trace]: trace DSP instructions
[-i] | [--irqs]: trace DSP IRQs
[-d] | [--debug]: enable GDB debugging - uses tcp::1234
[-c] | [--console]: Stall DSP and enter console before executing
[-g] | [--guest]: Display guest errors
[-o] | [--timeout]: Kill after timeout seconds

@xiulipan
Copy link
Contributor

@jajanusz
you can check the
https://github.com/thesofproject/sof/blob/master/scripts/qemu-check.sh

In this script, there are some example about how to read DSP => HOST IPC payload(IPC ready message)

@lgirdwood
Copy link
Member Author

@xiulipan would you be able to add some instructions on sof-decs for building and using qemu. You can aslo copy and pase the docs from the SOF wiki on alsa-project.org

@xiulipan
Copy link
Contributor

@lgirdwood good idea.
I create a issue in sof-docs to track this thesofproject/sof-docs#102

@jajanusz
Copy link
Contributor

jajanusz commented Apr 30, 2019

It seems we are missing qemu build instructions on sof-docs atm so (in qemu directory)

'./configure' '--prefix=.' '--target-list=xtensa-softmmu,x86_64-softmmu' '--enable-gtk' '--enable-sdl' '--enable-spice' '--audio-drv-list=alsa' '--enable-libusb' '--enable-usb-redir' '--enable-coroutine-pool' '--disable-opengl' '--enable-fdt'
make

Then you can run it by

xtensa-host.sh
usage: ./xtensa-host.sh device [-k kernel] [-t] [-d] [-i] [-r rom] [-c] [-g] [-o time log]
supported devices: byt, cht, hsw, bdw, bxt, sue, cnl, icl, skl, kbl, hky
[-k] | [--kernel]: load firmware kernel image
[-r] | [--rom]: load firmware ROM image
[-t] | [--trace]: trace DSP instructions
[-i] | [--irqs]: trace DSP IRQs
[-d] | [--debug]: enable GDB debugging - uses tcp::1234
[-c] | [--console]: Stall DSP and enter console before executing
[-g] | [--guest]: Display guest errors
[-o] | [--timeout]: Kill after timeout seconds

With these instructions I get:

  CC      util/memfd.o
util/memfd.c: In function ‘qemu_memfd_alloc’:
util/memfd.c:77:15: error: implicit declaration of function ‘memfd_create’; did you mean ‘timer_create’? [-Werror=implicit-function-declaration]
         mfd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
               ^~~~~~~~~~~~
               timer_create
util/memfd.c:77:15: error: nested extern declaration of ‘memfd_create’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
/home/admin/sof/repo/qwd/qemu/rules.mak:66: recipe for target 'util/memfd.o' failed
make: *** [util/memfd.o] Error 1

I used git clone https://github.com/thesofproject/qemu and then your instructions. Maybe some submodules use top commits instead of specific commits and it broke in meantime.

@lgirdwood
Copy link
Member Author

@jajanusz what distro and version are you using, it could be an older version of a dependency library....

@lgirdwood
Copy link
Member Author

@jajanusz see here too, could be old dependency systemd/systemd#8099

@jajanusz
Copy link
Contributor

@lgirdwood

admin@Linux-Ubuntu-Dev:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:        16.04
Codename:       xenial

@lgirdwood
Copy link
Member Author

lgirdwood commented Apr 30, 2019

@jajanusz 16.4 is ancient, 3 years old. Please update. In general using LTS versions > 1 year old is not good for development. Fwiw I'm on 18.10, will be moving to 19.04 soon.

@jajanusz
Copy link
Contributor

jajanusz commented Apr 30, 2019

@lgirdwood I thought we support Ubuntu 16 & 18 (because docs refer to them), that's why I assumend qemu will also work on 16.04.
Thanks for help, I'll get newer distro and see if that helps.

@plbossart
Copy link
Member

out of curiosity has anyone used 19.04 for SOF work since it was released on April 19?

@xiulipan
Copy link
Contributor

@lgirdwood @plbossart
It seems there are some update in QEMU repo?
I am now testing use Dockerhub to auto build the image used for CI test.

@lgirdwood
Copy link
Member Author

@xiulipan don't autobuild qemu for each SOF PR (too long, travis will timeout), just use the latest prebuilt binary in container. I will tag it in future so you can keep uptodate.

@xiulipan
Copy link
Contributor

@lgirdwood
I am trying to track the https://github.com/thesofproject/qemu on DockerHub only to auto update the image used for CI.
It will make the binary used for CI always auto update after we have change in QEMU. I think we will have more patches in QEMU.

Related PR here: thesofproject/qemu#4

@jajanusz
Copy link
Contributor

jajanusz commented May 2, 2019

@lgirdwood I checked with ubuntu 19.04 and QEMU built successfully.
@plbossart I built SOF (FW) today on 19.04 with instructions for 18.10 from https://thesofproject.github.io/latest/getting_started/build-guide/build-from-scratch.html
Need just minor fix for crosstool-ng -> thesofproject/crosstool-ng#3

@jajanusz jajanusz added the P3 Low-impact bugs or features label Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P3 Low-impact bugs or features
Projects
None yet
Development

No branches or pull requests

5 participants