[lldb] Skip TestAppleSimulatorOSType if json parsing fails
authorAugusto Noronha <augusto2112@me.com>
Mon, 6 Sep 2021 20:03:47 +0000 (17:03 -0300)
committerAugusto Noronha <augusto2112@me.com>
Thu, 16 Sep 2021 19:38:20 +0000 (16:38 -0300)
xcodebuild, which is invoked by the apple_simulator_test decorator, may
may return a successful status even if it was unable to run due to the
authorization agent denying it. This causes the TestAppleSimulatorOSType
to run when it shouldn't, and throw an excpection when parsing the JSON
that lists the simulators available. Wrap the json parsing in a
try/except block and if it fails, skip the ttest.

Differential Revision: https://reviews.llvm.org/D109336

lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py

index 0194234..1230af9 100644 (file)
@@ -20,7 +20,16 @@ class TestAppleSimulatorOSType(gdbremote_testcase.GdbRemoteTestCaseBase):
         cmd = ['xcrun', 'simctl', 'list', '-j', 'devices']
         self.trace(' '.join(cmd))
         sim_devices_str = subprocess.check_output(cmd).decode("utf-8")
-        sim_devices = json.loads(sim_devices_str)['devices']
+
+        # xcodebuild, which is invoked by the apple_simulator_test decorator,
+        # may return a successful status even if it was unable to run due to 
+        # the authorization agent denying it. Try to parse the json that lists 
+        # the simulators but if that fails skip the test.
+        try:
+            sim_devices = json.loads(sim_devices_str)['devices']
+        except json.decoder.JSONDecodeError:
+            self.skipTest("Could not parse JSON of simulators available")
+
         # Find an available simulator for the requested platform
         deviceUDID = None
         deviceRuntime = None