mobly icon indicating copy to clipboard operation
mobly copied to clipboard

Fix ps check of child pids on BSD-based MacOS. Use pgrep instead.

Open stuartmls opened this issue 1 year ago • 2 comments

Issue:

Unregistering a service results in the following error:

ps: illegal option -- -
usage: ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]]
          [-g grp[,grp...]] [-u [uid,uid...]]
          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
       ps [-L]

Call-stack:

_collect_process_tree (lib/python3.12/site-packages/mobly/utils.py:271) _kill_process_tree (lib/python3.12/site-packages/mobly/utils.py:316) stop_standing_subprocess (lib/python3.12/site-packages/mobly/utils.py:555) _stop_server (lib/python3.12/site-packages/mobly/controllers/android_device_lib/snippet_client_v2.py:699) stop (python3.12/site-packages/mobly/controllers/android_device_lib/snippet_client_v2.py:660) remove_snippet_client (lib/python3.12/site-packages/mobly/controllers/android_device_lib/services/snippet_management_service.py:110) unload_snippet (lib/python3.12/site-packages/mobly/controllers/android_device.py:963) stop (lib/python3.12/site-packages/snippet_uiautomator/uiautomator.py:227) unregister (lib/python3.12/site-packages/mobly/controllers/android_device_lib/service_manager.py:109)

Sample code:

from mobly.controllers import android_device
from snippet_uiautomator import uiautomator

ad = android_device.AndroidDevice(sn)
ui = uiautomator.UiAutomatorService
ad.services.register(uiautomator.ANDROID_SERVICE_NAME, ui)
...    
ad.services.unregister(uiautomator.ANDROID_SERVICE_NAME)

This change is Reviewable

Co-authored-by: [email protected]

stuartmls avatar Apr 09 '24 13:04 stuartmls

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Apr 09 '24 13:04 google-cla[bot]

Thanks for noticing this bug and creating the fix. Could you help add unit tests for it?

mhaoli avatar Apr 12 '24 11:04 mhaoli

Closing this as I already fixed this error in #920

mhaoli avatar May 14 '24 04:05 mhaoli