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>
1 file changed
tree: 4289267f81cd7c95a1ce482b9b8c95410c431d3a
  1. .allstar/
  2. .vscode/
  3. build_overrides/
  4. docker/
  5. docs/
  6. kudzu/
  7. pw_alignment/
  8. pw_allocator/
  9. pw_analog/
  10. pw_android_toolchain/
  11. pw_arduino_build/
  12. pw_assert/
  13. pw_assert_basic/
  14. pw_assert_log/
  15. pw_assert_tokenized/
  16. pw_assert_zephyr/
  17. pw_async/
  18. pw_async_basic/
  19. pw_base64/
  20. pw_bloat/
  21. pw_blob_store/
  22. pw_bluetooth/
  23. pw_bluetooth_hci/
  24. pw_bluetooth_profiles/
  25. pw_boot/
  26. pw_boot_cortex_m/
  27. pw_build/
  28. pw_build_info/
  29. pw_build_mcuxpresso/
  30. pw_bytes/
  31. pw_checksum/
  32. pw_chre/
  33. pw_chrono/
  34. pw_chrono_embos/
  35. pw_chrono_freertos/
  36. pw_chrono_rp2040/
  37. pw_chrono_stl/
  38. pw_chrono_threadx/
  39. pw_chrono_zephyr/
  40. pw_cli/
  41. pw_compilation_testing/
  42. pw_console/
  43. pw_containers/
  44. pw_cpu_exception/
  45. pw_cpu_exception_cortex_m/
  46. pw_crypto/
  47. pw_digital_io/
  48. pw_digital_io_mcuxpresso/
  49. pw_digital_io_rp2040/
  50. pw_docgen/
  51. pw_doctor/
  52. pw_emu/
  53. pw_env_setup/
  54. pw_file/
  55. pw_function/
  56. pw_fuzzer/
  57. pw_hdlc/
  58. pw_hex_dump/
  59. pw_i2c/
  60. pw_i2c_linux/
  61. pw_i2c_mcuxpresso/
  62. pw_ide/
  63. pw_interrupt/
  64. pw_interrupt_cortex_m/
  65. pw_interrupt_xtensa/
  66. pw_interrupt_zephyr/
  67. pw_intrusive_ptr/
  68. pw_kvs/
  69. pw_libc/
  70. pw_log/
  71. pw_log_android/
  72. pw_log_basic/
  73. pw_log_null/
  74. pw_log_rpc/
  75. pw_log_string/
  76. pw_log_tokenized/
  77. pw_log_zephyr/
  78. pw_malloc/
  79. pw_malloc_freelist/
  80. pw_metric/
  81. pw_minimal_cpp_stdlib/
  82. pw_module/
  83. pw_multisink/
  84. pw_package/
  85. pw_perf_test/
  86. pw_persistent_ram/
  87. pw_polyfill/
  88. pw_preprocessor/
  89. pw_presubmit/
  90. pw_protobuf/
  91. pw_protobuf_compiler/
  92. pw_random/
  93. pw_result/
  94. pw_ring_buffer/
  95. pw_router/
  96. pw_rpc/
  97. pw_rpc_transport/
  98. pw_rust/
  99. pw_snapshot/
  100. pw_software_update/
  101. pw_span/
  102. pw_spi/
  103. pw_spi_mcuxpresso/
  104. pw_status/
  105. pw_stm32cube_build/
  106. pw_stream/
  107. pw_stream_shmem_mcuxpresso/
  108. pw_stream_uart_linux/
  109. pw_stream_uart_mcuxpresso/
  110. pw_string/
  111. pw_symbolizer/
  112. pw_sync/
  113. pw_sync_baremetal/
  114. pw_sync_embos/
  115. pw_sync_freertos/
  116. pw_sync_stl/
  117. pw_sync_threadx/
  118. pw_sync_zephyr/
  119. pw_sys_io/
  120. pw_sys_io_ambiq_sdk/
  121. pw_sys_io_arduino/
  122. pw_sys_io_baremetal_lm3s6965evb/
  123. pw_sys_io_baremetal_stm32f429/
  124. pw_sys_io_emcraft_sf2/
  125. pw_sys_io_mcuxpresso/
  126. pw_sys_io_rp2040/
  127. pw_sys_io_stdio/
  128. pw_sys_io_stm32cube/
  129. pw_sys_io_zephyr/
  130. pw_system/
  131. pw_target_runner/
  132. pw_thread/
  133. pw_thread_embos/
  134. pw_thread_freertos/
  135. pw_thread_stl/
  136. pw_thread_threadx/
  137. pw_thread_zephyr/
  138. pw_tls_client/
  139. pw_tls_client_boringssl/
  140. pw_tls_client_mbedtls/
  141. pw_tokenizer/
  142. pw_tool/
  143. pw_toolchain/
  144. pw_toolchain_bazel/
  145. pw_trace/
  146. pw_trace_tokenized/
  147. pw_transfer/
  148. pw_unit_test/
  149. pw_unit_test_zephyr/
  150. pw_varint/
  151. pw_watch/
  152. pw_web/
  153. pw_work_queue/
  154. seed/
  155. targets/
  156. third_party/
  157. ts/
  158. zephyr/
  159. .bazelignore
  160. .bazelrc
  161. .black.toml
  162. .clang-format
  163. .clang-tidy
  164. .eslintrc.cjs
  165. .git-blame-ignore-revs
  166. .gitattributes
  167. .gitignore
  168. .gn
  169. .mypy.ini
  170. .prettierignore
  171. .prettierrc.cjs
  172. .pw_ide.yaml
  173. .pylintrc
  174. activate.bat
  175. Android.bp
  176. AUTHORS
  177. bootstrap.bat
  178. bootstrap.sh
  179. BUILD.bazel
  180. BUILD.gn
  181. BUILDCONFIG.gn
  182. CMakeLists.txt
  183. jest.config.ts
  184. Kconfig.zephyr
  185. LICENSE
  186. modules.gni
  187. OWNERS
  188. package-lock.json
  189. package.json
  190. pigweed.json
  191. PIGWEED_MODULES
  192. README.md
  193. rollup.config.js
  194. tsconfig.json
  195. WORKSPACE
README.md

Pigweed

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/.

Links