Skip to content

Commit

Permalink
Skip tests using objc_msgSend if not available (#263)
Browse files Browse the repository at this point in the history
* Add __GNUSTEP_MSGSEND__ definition

* Mark test as skipped if return code is 77

* Skip tests using objc_msgSend if not available

* ManyManySelectors: Skip objc_msgSend if not available

* Skip UnexpectedException test on ARM and AArch64

* Add UnexpectedException.m to list of unit tests

* Call manyArgs with objc_msgSend directly
  • Loading branch information
hmelder committed Jan 4, 2024
1 parent 5cf2b73 commit 3c42c64
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
7 changes: 2 additions & 5 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(TESTS
hash_table_delete.c
hash_test.c
setSuperclass.m
UnexpectedException.m
)

set(ENABLE_ALL_OBJC_ARC_TESTS On)
Expand Down Expand Up @@ -79,11 +80,6 @@ if (ENABLE_ALL_OBJC_ARC_TESTS)
)
endif()

# UnexpectedException test currently fails on ARM and needs to be fixed
if(NOT ARCHITECTURE MATCHES "^(arm|aarch64)")
list(APPEND TESTS UnexpectedException.m)
endif()

# List of single-file tests that won't work with the legacy ABI and so
# shouldn't be run in legacy mode.
set(NEW_TESTS
Expand Down Expand Up @@ -124,6 +120,7 @@ function(addtest_flags TEST_NAME FLAGS TEST_SOURCE)
LINK_FLAGS ${INCREMENTAL}
LINKER_LANGUAGE C
)
set_property(TEST ${TEST_NAME} PROPERTY SKIP_RETURN_CODE 77)
set_property(TEST ${TEST_NAME} PROPERTY
ENVIRONMENT "LD_LIBRARY_PATH=" "LLVM_PROFILE_FILE=${TEST_NAME}.profraw"
)
Expand Down
4 changes: 3 additions & 1 deletion Test/ManyManySelectors.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static id x(id self, SEL _cmd)

int main(void)
{

SEL nextSel;
Class cls = [Test class];
assert(cls != Nil);
Expand All @@ -46,8 +47,9 @@ int main(void)
objc_msg_lookup(cls, nextSel)(cls, nextSel);
assert(methodCalled == YES);
methodCalled = NO;
#ifdef __GNUSTEP_MSGSEND__
objc_msgSend([Test class], nextSel);
assert(methodCalled == YES);
#endif
return 0;
}

4 changes: 4 additions & 0 deletions Test/UnexpectedException.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ LONG WINAPI _UnhandledExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo)

int main(void)
{
#if !(defined(__arm__) || defined(__ARM_ARCH_ISA_A64))
#ifdef _WIN32
// also verify that an existing handler still gets called after we set ours
SetUnhandledExceptionFilter(&_UnhandledExceptionFilter);
Expand All @@ -40,4 +41,7 @@ int main(void)
assert(0 && "should not be reached!");

return -1;
#endif
// FIXME: Test currently fails on ARM and AArch64
return 77; // Skip test
}
12 changes: 10 additions & 2 deletions Test/objc_msgSend.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

//#define assert(x) if (!(x)) { printf("Failed %d\n", __LINE__); }

typedef void (*fwdManyFunc)(id, SEL, int, int, int, int, int, int, int, int, int, int, int, float, float, float, float, float, float, float, float, float, float, float);

typedef struct { int a,b,c,d,e; } s;
@interface Fake
Expand Down Expand Up @@ -175,6 +176,7 @@ IMP forward(id o, SEL s)

int main(void)
{
#ifdef __GNUSTEP_MSGSEND__
__objc_msg_forward2 = forward;
__objc_msg_forward3 = forward_slot;
TestCls = objc_getClass("MsgTest");
Expand Down Expand Up @@ -220,8 +222,12 @@ int main(void)
assert(0 == [f dzero]);
assert(0 == [f ldzero]);
assert(0 == [f fzero]);
[TestCls manyArgs: 0 : 1 : 2 : 3: 4: 5: 6: 7: 8: 9: 10 : 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10];
// Call manyArgs with objc_msgSend explicitly to test the slow lookup path
SEL manyArgsSel = sel_registerName("manyArgs::::::::::::::::::::::");
((fwdManyFunc)objc_msgSend)(TestCls, manyArgsSel, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assert(forwardcalls == 2);
[TestCls manyArgs: 0 : 1 : 2 : 3: 4: 5: 6: 7: 8: 9: 10 : 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10];
assert(forwardcalls == 3);
#ifdef BENCHMARK
const int iterations = 1000000000;
double times[3];
Expand Down Expand Up @@ -252,6 +258,8 @@ int main(void)
times[2] = ((double)c2 - (double)c1) / (double)CLOCKS_PER_SEC;
fprintf(stderr, "Direct IMP call took %f seconds. \n", times[2]);
printf("%f\t%f\t%f\n", times[0], times[1], times[2]);
#endif
#endif // BENCHMARK
return 0;
#endif // __GNUSTEP_MSGSEND__
return 77; // Skip test
}
6 changes: 6 additions & 0 deletions objc/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
defined(__ARM_ARCH_ISA_A64) || \
(defined(__riscv) && __riscv_xlen == 64 && \
defined(__riscv_float_abi_double))

// Define __GNUSTEP_MSGSEND__ if available
#ifndef __GNUSTEP_MSGSEND__
#define __GNUSTEP_MSGSEND__
#endif

/**
* Standard message sending function. This function must be cast to the
* correct types for the function before use. The first argument is the
Expand Down

0 comments on commit 3c42c64

Please sign in to comment.