Skip to content

Commit 4856ef7

Browse files
authored
Merge pull request #130 from madsmtm/assembly-tests
Assembly tests
2 parents 63badcc + a644265 commit 4856ef7

16 files changed

Lines changed: 302 additions & 26 deletions

.github/workflows/ci.yml

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
rust:
6161
toolchain: nightly
6262
# Run on nightly to help find regressions
63-
args: --features tests/ui
63+
test-args: --features tests/ui
6464
- name: Build macOS 32bit
6565
os: macos-10.15
6666
target: i686-apple-darwin
@@ -77,14 +77,15 @@ jobs:
7777
- name: Test GNUStep
7878
os: ubuntu-latest
7979
target: x86_64-unknown-linux-gnu
80-
features: gnustep-1-9
81-
args: --features gnustep-1-9
80+
host-args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9
81+
args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9
8282
- name: Test GNUStep 32bit
8383
os: ubuntu-latest
8484
target: i686-unknown-linux-gnu
8585
cflags: -m32
8686
configureflags: --target=x86-pc-linux-gnu
87-
args: --features gnustep-1-9
87+
host-args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9
88+
args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9
8889
- name: Test iOS simulator x86 64bit
8990
os: macos-11
9091
target: x86_64-apple-ios
@@ -270,28 +271,6 @@ jobs:
270271
if: matrix.dinghy && steps.extern-cache.outputs.cache-hit != 'true'
271272
run: cargo install cargo-dinghy --version=^0.4 --root=$HOME/extern --target=x86_64-apple-darwin
272273

273-
- name: Run Cargo Dinghy
274-
if: matrix.dinghy
275-
run: |
276-
# Launch the simulator
277-
xcrun simctl list runtimes
278-
RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1)
279-
export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 $RUNTIME_ID)
280-
xcrun simctl boot $SIM_ID
281-
282-
# Build
283-
cargo dinghy build
284-
285-
# Run tests
286-
cargo dinghy --device=$SIM_ID test --no-default-features
287-
# Enable a few features. We're doing it this way because cargo dingy
288-
# doesn't support specifying features from a workspace.
289-
sed -i -e '/\[features\]/a\
290-
default = ["exception", "verify_message", "catch_all"]
291-
' objc2/Cargo.toml
292-
cargo dinghy --device=$SIM_ID test
293-
cargo dinghy --device=$SIM_ID test --release
294-
295274
- name: Build
296275
if: ${{ !matrix.dinghy }}
297276
uses: actions-rs/cargo@v1
@@ -343,3 +322,36 @@ jobs:
343322
command: test
344323
# Not using --all-features because that would enable e.g. gnustep
345324
args: --features ${{ env.FEATURES }},${{ env.UNSTABLE_FEATURES }} ${{ env.TESTARGS }}
325+
326+
- name: Run assembly tests
327+
# Not run on GNUStep yet since a lot of function labels are mangled and
328+
# not inlined (and hence quite hard to match on, at some point we'll
329+
# need to find a solution to that).
330+
if: ${{ !contains(matrix.os, 'ubuntu') }}
331+
shell: bash
332+
run:
333+
export HOST_TARGET=$(rustc -vV | grep host | cut -f2 -d' ')
334+
335+
cargo run ${{ matrix.host-args }} --features assembly --target=$HOST_TARGET test_assembly ${{ matrix.args }}
336+
337+
- name: Run Cargo Dinghy
338+
if: matrix.dinghy
339+
run: |
340+
# Launch the simulator
341+
xcrun simctl list runtimes
342+
RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1)
343+
export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 $RUNTIME_ID)
344+
xcrun simctl boot $SIM_ID
345+
346+
# Build
347+
cargo dinghy build
348+
349+
# Run tests
350+
cargo dinghy --device=$SIM_ID test --no-default-features
351+
# Enable a few features. We're doing it this way because cargo dingy
352+
# doesn't support specifying features from a workspace.
353+
sed -i -e '/\[features\]/a\
354+
default = ["exception", "verify_message", "catch_all"]
355+
' objc2/Cargo.toml
356+
cargo dinghy --device=$SIM_ID test
357+
cargo dinghy --device=$SIM_ID test --release

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ members = [
77
"block2",
88
"block-sys",
99
"tests",
10+
"tests/assembly/*",
1011
]

tests/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ build = "build.rs"
1818
#
1919
# Also, they're slower than most tests.
2020
ui = ["trybuild"]
21+
assembly = ["cargo_metadata"]
2122

2223
[dependencies]
2324
block2 = { path = "../block2" }
@@ -29,9 +30,14 @@ objc2-foundation = { path = "../objc2-foundation" }
2930

3031
# Put here instead of dev-dependencies because we want to make it optional
3132
trybuild = { version = "1.0", optional = true }
33+
cargo_metadata = { version = "0.14", optional = true }
3234

3335
[build-dependencies]
3436
cc = "1.0"
3537

3638
[dev-dependencies]
3739
paste = "1.0"
40+
41+
[[bin]]
42+
name = "test_assembly"
43+
required-features = ["assembly"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "test_msg_send_zero_cost"
3+
version = "0.1.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[lib]
8+
path = "lib.rs"
9+
10+
[dependencies]
11+
objc2 = { path = "../../../objc2" }
12+
objc-sys = { path = "../../../objc-sys" }
13+
block-sys = { path = "../../../block-sys" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.globl _handle
3+
.p2align 2
4+
_handle:
5+
b _objc_msgSend
6+
7+
.subsections_via_symbols
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.globl _handle
3+
.p2align 2
4+
_handle:
5+
b _objc_msgSend
6+
7+
; Stripped __LLVM section
8+
9+
; Stripped __LLVM section
10+
11+
.subsections_via_symbols
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.globl _handle
3+
.p2align 2
4+
_handle:
5+
b _objc_msgSend
6+
7+
; Stripped __LLVM section
8+
9+
; Stripped __LLVM section
10+
11+
.subsections_via_symbols
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.ios_version_min 7, 0
3+
.syntax unified
4+
.globl _handle
5+
.p2align 2
6+
.code 32
7+
_handle:
8+
b _objc_msgSend
9+
10+
.subsections_via_symbols
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.syntax unified
3+
.globl _handle
4+
.p2align 2
5+
.code 32
6+
_handle:
7+
push {r7, lr}
8+
mov r7, sp
9+
bl _objc_msgSend
10+
pop {r7, pc}
11+
12+
.subsections_via_symbols
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.intel_syntax noprefix
3+
.globl _handle
4+
.p2align 4, 0x90
5+
_handle:
6+
push ebp
7+
mov ebp, esp
8+
pop ebp
9+
jmp _objc_msgSend
10+
11+
.subsections_via_symbols

0 commit comments

Comments
 (0)