aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-execmem.c11
-rw-r--r--test/test-pc-patch.c (renamed from test/test-stop-threads.c)22
2 files changed, 21 insertions, 12 deletions
diff --git a/test/test-execmem.c b/test/test-execmem.c
index 5ec64e9..9125d68 100644
--- a/test/test-execmem.c
+++ b/test/test-execmem.c
@@ -25,13 +25,18 @@ int test(size_t a) {
return 1000;
}
+static int ewrite(void *dst, const void *src, size_t len) {
+ struct execmem_foreign_write w = {dst, src, len};
+ return execmem_foreign_write_with_pc_patch(&w, 1, NULL, NULL);
+}
+
int main() {
printf("this should be 5: %d\n", test(0));
- printf("=> %d\n", execmem_write(test, other, OTHER_SIZE));
+ printf("=> %d\n", ewrite(test, other, OTHER_SIZE));
printf(" %s\n", strerror(errno));
printf("this should be 6: %d\n", test(0));
- printf("=> %d\n", execmem_write(hcreate, other, OTHER_SIZE));
+ printf("=> %d\n", ewrite(hcreate, other, OTHER_SIZE));
printf(" %s\n", strerror(errno));
- printf("modified shared cache func: %d\n", hcreate(0));
+ printf("modified shared cache func should be 6: %d\n", hcreate(0));
}
diff --git a/test/test-stop-threads.c b/test/test-pc-patch.c
index d53d8cd..5ae3570 100644
--- a/test/test-stop-threads.c
+++ b/test/test-pc-patch.c
@@ -1,7 +1,8 @@
#include "substitute-internal.h"
-#include "stop-other-threads.h"
+#include "execmem.h"
#include <stdio.h>
#include <unistd.h>
+#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
/* printf without taking any locks - because they might be taken at stop time */
@@ -32,14 +33,17 @@ int main() {
for (long i = 0; i < 10; i++)
pthread_create(&pts[i], NULL, some_thread, (void *) i);
sleep(1);
- void *stop_token;
- ulprintf("stopping\n");
- assert(!stop_other_threads(&stop_token));
- ulprintf("stopped\n");
- assert(!apply_pc_patch_callback(stop_token, patch_callback, NULL));
- ulprintf("resuming\n");
- assert(!resume_other_threads(stop_token));
- ulprintf("resumed\n");
+ char *foo = malloc(0x10000);
+ static char bar[16];
+ struct execmem_foreign_write writes[] = {
+ {foo, bar, 5},
+ {foo + 7, bar + 7, 3},
+ };
+ int ret = execmem_foreign_write_with_pc_patch(writes,
+ sizeof(writes)/sizeof(*writes),
+ patch_callback,
+ NULL);
+ ulprintf("==> %d\n", ret);
void *out;
for (long i = 0; i < 10; i++)
assert(!pthread_join(pts[i], &out));