简体   繁体   English

"Emrun 和 headless chrome - 如何让这两者协同工作?"

[英]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.我想在 docker 环境中使用 headless chrome 来运行编译为 web 程序集的 c++ 测试。

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).我确保我的测试可执行文件与--emrun标志链接,以确保所有输出都发布到 emrun 服务器并打印到控制台(然后由 CTest 框架捕获)。

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.测试输出很高兴地打印到命令行,但如果输出超过 cca 9kB,则会被截断,这本身就是一个问题 - 见下文。 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.但是,chrome 调试会话一直挂起并使用端口 9222。我当前的解决方法是确保 CTest 框架中的每个单元测试都有自己独特的调试端口,并让 chrome 会话保持生成直到容器停止 - docker 清理它们那就起来吧。 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?我想知道是否有人知道如果没有将--remote-debugging-port提供给 Chrome,为什么 emrun 服务器不会打印任何内容?

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).我的预感是 chrome 在完成执行后停止向 emrun 服务器发送数据,并且启用调试会以某种方式减慢 chrome 的速度,从而为至少一些输出发送到 emrun 服务器腾出时间(这也可以解释大输出大小的截断) .

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.我还去看看 Emscripten 的人是如何运行他们的 CI 测试的,并看到他们在 Xvfb 下使用全铬而不是无头铬。 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 (ie 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).但是,我也尝试过,这会导致其他一些问题,例如如果在容器内运行但不是以 root 用户身份运行,则 chrome 会因 SIGTRAP 崩溃,并且 Jenkins 的 docker 插件在用户模式下运行所有​​容器(即您不是 root在容器内——理论上我可以让 Jenkins 以 root 身份运行容器,但这会导致其他我不希望出现的问题)。

Besides that, the log truncation was still present in case of chrome under Xvfb, so this is still problematic for me.除此之外,在 Xvfb 下的 chrome 情况下,日志截断仍然存在,所以这对我来说仍然是个问题。

Finally, I tried using firefox for my tests and it kinda works but behaves weirdly:最后,我尝试使用 firefox 进行测试,它有点工作,但表现得很奇怪:

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.但是,在启动 emrun 服务器时再次运行相同的命令会失败,因为它默认侦听的端口 (6931) 正在使用中。 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.这很奇怪,因为ps输出中没有列出 emrun 服务器,但是有几个firefox-bin ,这表明 emrun 进程完成后 firefox 一直挂起,更奇怪的是,杀死这些进程会使端口 6931 再次空闲。 So it appears that firefox somehow "captured" the ownership of the port on which the emrun server was listening on.因此,Firefox 似乎以某种方式“捕获”了 emrun 服务器正在侦听的端口的所有权。 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?所以,我的问题是如何使 emrun 与 headless chrome 很好地配合,以及为什么在使用 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.我的测试框架需要应用程序的整个输出来确定测试是通过还是失败,而对于具有大量输出的测试,chrome 目前无法做到这一点。

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?如果您曾经使用 Emscripten 将您的 c++ 应用程序移植到 Web,那么您是如何设置 CI 环境的?

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.指定端口 0 似乎可以修复控制台输出,同时分配一个随机端口号,因此您不必在测试框架中为此烦恼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何编译Freetype(2)和Harfbuzz(使用Visual Studio)以使其协同工作? - How to compile Freetype (2) and Harfbuzz (with visual studio) to make them work together? 如何使大括号初始化和默认值一起工作? - How to make brace initialization and default values work together? 如何使初始化列表和类成员初始化程序一起工作? - How to make initializer list and class member initializer work together? 如何使编码器与两个库一起工作? - How to make encoder work with two libraries? 无法使QTcpSocket / QTcpServer一起工作 - Can't make QTcpSocket/QTcpServer work together 如何重载和覆盖一起工作? - How Overloading and Overriding work together? 继承和memcpy - 它如何一起工作? - inheritance and memcpy - How is it work together? 你可以静态地将相同的protobuf消息链接到多个DLL - 然后让这些DLL一起工作吗? - Can you statically link the same protobuf message into multiple DLLs - and then have those DLLs work together? 如何使用一些boost库使std :: find_if和std :: map一起工作? - How can I make std::find_if and std::map work together using some boost library? 如何使boost_to_unique_lock + condition_variable协同工作? - how to make boost upgrade_to_unique_lock + condition_variable work together?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM