'Emrun and headless chrome - how to make those two work together?
I would like to use headless chrome in docker environment to run my c++ tests compiled to web assembly.
I've made sure that my test executable was linked with --emrun flag to ensure that all output gets posted to the emrun server and printed to the console (which is then captured by the CTest framework).
However, when running the headless chrome with
emrun --browser=chrome --browser_args="--no-sandbox --disable-gpu --use-gl=swiftshader --headless" ./MyTestExecutable.html --gtest_filter=MyTestFixture.myTest
nothing gets printed to the output. However, if I change the command to
emrun --browser=chrome --browser_args="--no-sandbox --disable-gpu --use-gl=swiftshader --headless --remote-debugging-port=9222" ./MyTestExecutable.html --gtest_filter=MyTestFixture.myTest
the test output is happily printed to the command line but truncated if there is more than cca 9kB of output, which is a problem of its own - see below. However, the chrome debugging session keeps hanging and using the port 9222. My current workaround is to make sure that each unit test in the CTest framework gets its own unique debugging port and let chrome sessions remain spawned until the container is stopped - docker cleans them up then. This solution is quite dirty and I don't like it.
I wonder if anyone knows why nothing gets printed from the emrun server if --remote-debugging-port is not given to Chrome?
My hunch is that chrome stops sending data to the emrun server after it finishes execution and enabling the debugging somehow slows chrome down thus making time for at least some output to be sent to the emrun server (this would also explain truncation for large output sizes).
I also went to check out how do the Emscripten guys run their CI tests and saw that they use full chrome under Xvfb instead of headless chrome. I've tried that as well, however, that caused some other problems, like chrome crashing with SIGTRAP if run inside the container but not as the root user and Jenkins' docker plugin runs all containers in user mode (i.e. you are not the root within the container - theoretically I could make Jenkins run containers as root, but that would cause other issues which I would prefer not to have).
Besides that, the log truncation was still present in case of chrome under Xvfb, so this is still problematic for me.
Finally, I tried using firefox for my tests and it kinda works but behaves weirdly:
emrun --browser=firefox --browser_args="--headless" ./MyTestExecutable.html --gtest_filter=MyTestFixture.myTest
works OK and output is not truncated. However, running the same command again fails with the startup of the emrun server as the port it listens on by default (6931) is being in use. That is weird because the emrun server is not listed in the ps output, however several firefox-bin are, which indicate that firefox kept hanging after emrun process finished and, even weirder, killing those processes makes port 6931 free again. So it appears that firefox somehow "captured" the ownership of the port on which the emrun server was listening on. I really don't have a clue how is this even possible.
So, my questions are how to make emrun play nicely with headless chrome and why the application output gets truncated when using chrome? My test framework requires the entire output of the application to determine whether the test has passed or failed and this is currently not possible with chrome for tests that have lots of output.
What are your experiences? If you have ever worked on porting your c++ application to the web using Emscripten, how did you set up your CI environment?
Solution 1:[1]
The best solution I could come up with so far is this:
emrun --browser=chrome --hostname=localhost --kill_exit --browser_args="--headless --remote-debugging-port=0 --disable-gpu --disable-software-rasterizer" web/index.html
Specifying a port of 0 seems to fix the console output and at the same time assign a random port number, so you don't have to bother with this in the test framework.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
