aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcomex2015-01-25 21:56:22 -0500
committercomex2015-01-25 22:01:25 -0500
commit1b5ec6c220f3ea457077a17f4cf6003502a06bb0 (patch)
tree19f8594402414d15b94c237d0f99e6efb6ac415e /test
parentthis is dumb (diff)
downloadsubstitute-1b5ec6c220f3ea457077a17f4cf6003502a06bb0.tar.gz
right, fix cleanup. (compared to the old system, this avoids busywaiting, and properly frees the thread resources)
Diffstat (limited to '')
-rw-r--r--test/injected-test-dylib.c26
-rw-r--r--test/test-inject.c13
2 files changed, 36 insertions, 3 deletions
diff --git a/test/injected-test-dylib.c b/test/injected-test-dylib.c
new file mode 100644
index 0000000..9a92ff2
--- /dev/null
+++ b/test/injected-test-dylib.c
@@ -0,0 +1,26 @@
+#include "substitute-internal.h"
+#include <stdio.h>
+#include <mach/mach.h>
+#include <assert.h>
+__attribute__((constructor))
+static void hi() {
+ printf("constructor\n");
+}
+
+void substitute_init(struct shuttle *shuttle, size_t nshuttle) {
+ printf("substitute_init nshuttle=%zd\n", nshuttle);
+ assert(nshuttle == 1);
+ assert(shuttle[0].type == SUBSTITUTE_SHUTTLE_MACH_PORT);
+ struct {
+ mach_msg_header_t hdr;
+ char body[5];
+ } msg;
+ msg.hdr.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
+ msg.hdr.msgh_size = sizeof(msg);
+ msg.hdr.msgh_remote_port = shuttle[0].u.mach.port;
+ msg.hdr.msgh_local_port = 0;
+ msg.hdr.msgh_voucher_port = 0;
+ msg.hdr.msgh_id = 42;
+ strncpy(msg.body, "hello", 5);
+ assert(!mach_msg_send(&msg.hdr));
+}
diff --git a/test/test-inject.c b/test/test-inject.c
index 5d7bcff..fa5d029 100644
--- a/test/test-inject.c
+++ b/test/test-inject.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
+#include <time.h>
int main(int argc, char **argv) {
if (argc <= 2) {
@@ -20,16 +21,22 @@ int main(int argc, char **argv) {
.u.mach.port = port,
.u.mach.right_type = MACH_MSG_TYPE_MAKE_SEND}
};
+ clock_t a = clock();
int ret = substitute_dlopen_in_pid(pid, argv[2], 0, shuttles, 1, &error);
- printf("ret=%d err=%s\n", ret, error);
+ clock_t b = clock();
+ printf("ret=%d err=%s time=%ld\n", ret, error, (long) (b - a));
assert(!ret);
free(error);
static struct {
mach_msg_header_t hdr;
char body[5];
+ mach_msg_trailer_t huh;
} msg;
- assert(!mach_msg_overwrite(NULL, MACH_RCV_MSG, 0, sizeof(msg), port,
- MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL, &msg.hdr, 0));
+ kern_return_t kr = mach_msg_overwrite(NULL, MACH_RCV_MSG, 0, sizeof(msg), port,
+ MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL,
+ &msg.hdr, 0);
+ printf("kr=%x\n", kr);
+ assert(!kr);
printf("received '%.5s'\n", msg.body);
}