Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Xcode Server: Enabling Code Diagnostic Tools

DZone's Guide to

Xcode Server: Enabling Code Diagnostic Tools

Learn how Xcode Server enables various diagnostic tools to clean up your code and boost your mobile app's performance in ways automated testing sometimes can't.

· Mobile Zone
Free Resource

Xcode comes up with some cool tools that can be used to detect some crazy bugs that are hard to catch with manual or functional automated testing. The memory and threading related issues are hard to find unless they made the impact on the application. In my previous post on activating code diagnostic tools on iOS CI, we have seen that how to enable Apple's code diagnostic tools on CI Server like TravisCI or any other third party CI server which uses command line tool. In this short post, how we can enable those tools using Apple's own Continuous Integration server a.k.a Xcode Server.

Just to recap of code diagnostic tools, Xcode has four different types of runtime tools also known as code diagnostic tools to find the issues. These tools are

Address Sanitizer a.k.a ASan reports the memory related issues like memory corruption and other memory-related security vulnerability issues. You can read more about the Address Sanitizer here.

Thread Sanitizer a.k.a TSan detects data races problems. It also detects other thread related issues like thread leaks. There is detailed documentation about Thread Sanitizer on Apple's official documentation here.

The Main Thread Checker is new tool launched with Xcode 9 which detects the invalid use of Apple's frameworks like UIKit, AppKit etc that supposed to be used from main thread but accidentally used in the background thread.

Undefines Behaviour Sanitizer a.k.a UBSan detects undefined behaviors in the code at runtime. The behaviors like dividing by zero, loading memory from a misaligned pointer, or dereferencing a null pointer. You can read more about UBSan here.

Apple has brief documentation of all these tools on the official documentation page of code diagnostic.

We can enable all those tools from Xcode Scheme setting by Edit Scheme-> Run/Test-> Diagnostics.

You can see that all those tools can be activated by using the checkboxes. One thing to note that, you cannot enable the thread sanitizer and address sanitizer at the same time.

Since Xcode 9, Xcode Server is inbuilt with Xcode application and there isn't any need to get macOS server to start the Xcode Server. We can start the server right from the Xcode and start creating the Bots.

In Xcode 9, while creating the Bot, we have a tab called and within arguments, we can find the section to add additional arguments

We can use that section to enable the code diagnostics tools.

We can pass different arguments to enable address sanitizer, thread sanitizer or undefined behavior sanitizer. In the image above we have enabled the thread sanitizer and undefined behavior sanitizer. Now that, our run and test phase with TSan and UBSan enabled.

Xcode Server has given us cool option to pass additional arguments to which can be used to enable Xcode code diagnostics tools. We can explicitly pass arguments even if we are not passed in the scheme. It would be the great idea to enable those tools on Continuous Integration environments on Xcode Server to catch memory and threading issues. So don't wait, if you are using Xcode Server enable ASan, TSan, UBSan and Main Thread Checker right now!

Topics:
mobile ,xcode ,xcode server ,mobile app development ,ios

Published at DZone with permission of Shashikant Jagtap, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}