commit | a10b00e890dccb6d4630be6461834360bce3cf81 | [log] [tgz] |
---|---|---|
author | Octavian Purdila <tavip@google.com> | Thu Oct 19 00:29:47 2023 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Thu Oct 19 00:29:47 2023 +0000 |
tree | 4289267f81cd7c95a1ce482b9b8c95410c431d3a | |
parent | 2eb3273c02f1ab80d2d13017eda4549bd6394ccf [diff] |
pw_emu: Fix pid file race condition There is a race condition between writing and reading the pid file where the reader can get an empty line: ====================================================================== ERROR: test_get_channel_addr (__main__.TestQemuChannelsTcp) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/google/home/tavip/src/pigweed/pw_emu/py/pw_emu/core.py", line 828, in _start_proc pid = int(file.readline()) ValueError: invalid literal for int() with base 10: '' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "pw_emu/py/tests/qemu_test.py", line 79, in setUp self._emu.start(target='test-target', pause=True) File "/usr/local/google/home/tavip/src/pigweed/pw_emu/py/pw_emu/frontend.py", line 100, in start self._connector = self._launcher.start( File "/usr/local/google/home/tavip/src/pigweed/pw_emu/py/pw_emu/core.py", line 909, in start raise err File "/usr/local/google/home/tavip/src/pigweed/pw_emu/py/pw_emu/core.py", line 905, in start proc = self._start_proc(self._emu, cmd, foreground) File "/usr/local/google/home/tavip/src/pigweed/pw_emu/py/pw_emu/core.py", line 831, in _start_proc raise RunError(name, str(err)) pw_emu.core.RunError: error running `qemu`: invalid literal for int() with base 10: To fix this race condition use a temporary file to write the pid than rename that temporary file to the pid file. Test: stress --cpu 512 --io 20 and run 1000 iterations of TestQemuChannelsTcp.test_get_channel_addr Change-Id: I644027246a039b105de7da503af70f9e8d9e6980 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/176782 Commit-Queue: Octavian Purdila <tavip@google.com> Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.
For more information please see our website: https://pigweed.dev/.