Skip to content

Commit

Permalink
Run tests on different OS versions (#475)
Browse files Browse the repository at this point in the history
* Run tests on different OS versions

* Fix compilation for older macOS/Xcode

* Use macOS 11 for old builds

* Fix lint for visionOS

* Fix Xcode and macOS versions in unit-tests

* Use Xcode 11 and macOS 11 for watchOS tests

* Use watchOS 7.4.0

* Add retries to simulator install
  • Loading branch information
bamx23 committed May 18, 2024
1 parent f41b596 commit a2828d8
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 33 deletions.
63 changes: 52 additions & 11 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,71 @@ concurrency:

jobs:
unit-tests:
runs-on: macos-latest
timeout-minutes: 10
runs-on: "macos-${{ matrix.macos-version || 'latest' }}"
strategy:
fail-fast: false
matrix:
platform:
- iOS
- macOS
- watchOS
- tvOS
- mac-catalyst
- visionOS
include:
- platform: iOS
- platform: iOS
os-version: ~12.4.0
runtime: "12.4"
macos-version: "12"
xcode-version: "13.4.1"

- platform: watchOS
- platform: watchOS
os-version: ~7.4.0
runtime: "7.4"
macos-version: "12"
xcode-version: "13.4.1"
# TODO: Test with an older watchOS version if possible

- platform: tvOS
- platform: tvOS
os-version: ~12.4.0
runtime: "12.4"
macos-version: "12"
xcode-version: "13.4.1"

- platform: visionOS

- platform: macOS
- platform: macOS
macos-version: "11"

- platform: mac-catalyst
- platform: mac-catalyst
macos-version: "11"
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Use Latest Stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
xcode-version: ${{ matrix.xcode-version || 'latest-stable' }}

- name: Cache
if: ${{ matrix.runtime }}
uses: actions/cache@v3
with:
path: "~/Downloads"
key: ${{ runner.os }}-runtimes-downloads-${{ matrix.platform }}-${{ matrix.runtime }}

- name: Install Simulator
if: ${{ matrix.runtime }}
uses: nick-fields/retry@v2
with:
timeout_minutes: 20
max_attempts: 3
command: sudo xcodes runtimes install --keep-archive '${{ matrix.platform }} ${{ matrix.runtime }}'

- name: Run Unit Tests
uses: bamx23/xcodebuild@vision-os
uses: bamx23/xcodebuild@os-version
timeout-minutes: 10
with:
workspace: ".swiftpm/xcode/package.xcworkspace"
scheme: "KSCrash-Package"
platform: ${{ matrix.platform }}
os-version: ${{ matrix.os-version }}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@
<Test
Identifier = "KSObjC_Tests/testCopyArrayContentsMutable">
</Test>
<Test
Identifier = "KSObjC_Tests/testDateDescription">
</Test>
<Test
Identifier = "KSObjC_Tests/testDateIsValid">
</Test>
<Test
Identifier = "KSObjC_Tests/testGetDateContents">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
Expand Down
2 changes: 1 addition & 1 deletion Sources/KSCrashCore/include/KSSystemCapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define KSCRASH_HOST_IOS (KSCRASH_HOST_APPLE && TARGET_OS_IOS)
#define KSCRASH_HOST_TV (KSCRASH_HOST_APPLE && TARGET_OS_TV)
#define KSCRASH_HOST_WATCH (KSCRASH_HOST_APPLE && TARGET_OS_WATCH)
#define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION))
#define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || KSCRASH_HOST_VISION))

#if KSCRASH_HOST_APPLE
#define KSCRASH_CAN_GET_MAC_ADDRESS 1
Expand Down
23 changes: 4 additions & 19 deletions Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#import <inttypes.h>
#import <mach/machine.h>
#include <mach-o/arch.h>
#include <mach-o/utils.h>

#import "KSCrashReportFields.h"
#import "KSJSONCodecObjC.h"
#import "KSCPU.h"

#if defined(__LP64__)
#define FMT_LONG_DIGITS "16"
Expand Down Expand Up @@ -267,26 +267,11 @@ - (NSString*) CPUArchForMajor:(cpu_type_t) majorCode minor:(cpu_subtype_t) minor
{
#if KSCRASH_HOST_APPLE
// In Apple platforms we can use this function to get the name of a particular architecture
#if !KSCRASH_HOST_VISION
if(@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
{
const char *archName = macho_arch_name_for_cpu_type(majorCode, minorCode);
if(archName)
{
return [[NSString alloc] initWithUTF8String:archName];
}
}
#if !KSCRASH_HOST_VISION
else
const char *archName = kscpu_archForCPU(majorCode, minorCode);
if(archName)
{
const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
if (info && info->name)
{
return [[NSString alloc] initWithUTF8String:info->name];
}
return [[NSString alloc] initWithUTF8String:archName];
}
#endif
#endif

switch(majorCode)
Expand Down
46 changes: 44 additions & 2 deletions Sources/KSCrashRecordingCore/KSCPU.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,34 @@

#include <mach/mach.h>
#include <mach-o/arch.h>

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000 // Xcode 14
#include <mach-o/utils.h>
#define _HAS_MACH_O_UTILS 1
#else
#define _HAS_MACH_O_UTILS 0
#endif

//#define KSLogger_LocalLevel TRACE
#include "KSLogger.h"

#if !_HAS_MACH_O_UTILS || !KSCRASH_HOST_VISION
static inline const char* currentArch_nx(void)
{
const NXArchInfo* archInfo = NXGetLocalArchInfo();
return archInfo == NULL ? NULL : archInfo->name;
}

static inline const char* archForCPU_nx(cpu_type_t majorCode, cpu_subtype_t minorCode)
{
const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
return info == NULL ? NULL : info->name;
}
#endif

const char* kscpu_currentArch(void)
{
#if _HAS_MACH_O_UTILS
#if !KSCRASH_HOST_VISION
if(__builtin_available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
Expand All @@ -48,10 +68,32 @@ const char* kscpu_currentArch(void)
#if !KSCRASH_HOST_VISION
else
{
const NXArchInfo* archInfo = NXGetLocalArchInfo();
return archInfo == NULL ? NULL : archInfo->name;
return currentArch_nx();
}
#endif
#else // _HAS_MACH_O_UTILS
return currentArch_nx();
#endif // _HAS_MACH_O_UTILS
}

const char* kscpu_archForCPU(cpu_type_t majorCode, cpu_subtype_t minorCode)
{
#if _HAS_MACH_O_UTILS
#if !KSCRASH_HOST_VISION
if(__builtin_available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
{
return macho_arch_name_for_cpu_type(majorCode, minorCode);
}
#if !KSCRASH_HOST_VISION
else
{
return archForCPU_nx(majorCode, minorCode);
}
#endif
#else // _HAS_MACH_O_UTILS
return archForCPU_nx(majorCode, minorCode);
#endif // _HAS_MACH_O_UTILS
}

#if KSCRASH_HAS_THREADS_API
Expand Down
9 changes: 9 additions & 0 deletions Sources/KSCrashRecordingCore/include/KSCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ extern "C" {
*/
const char* kscpu_currentArch(void);

/** Get the CPU architecture for given major and minor codes.
*
* @param majorCode The major code as defined in kernel.
* @param minorCode The minor code as defined in kernel.
*
* @return The architecture name.
*/
const char* kscpu_archForCPU(cpu_type_t majorCode, cpu_subtype_t minorCode);

/** Get the frame pointer for a machine context.
* The frame pointer marks the top of the call stack.
*
Expand Down

0 comments on commit a2828d8

Please sign in to comment.