summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-07-03 12:08:50 -0700
committerAndy Lutomirski <luto@amacapital.net>2014-07-03 12:08:50 -0700
commitbed76edaa6919bf98dafb6f4768933004183bf99 (patch)
tree87ac5d827512c7bbbe6c0fe7837f56199020960f
parent2a3443b531b30cd4aab424d3b2002208ff957474 (diff)
downloadmisc-tests-bed76edaa6919bf98dafb6f4768933004183bf99.tar.gz
Clean up build system and fix warnings
-rw-r--r--Makefile43
-rw-r--r--dump-vdso.c1
-rw-r--r--dump-vvar.c47
-rw-r--r--evil-clock-test.cc22
4 files changed, 71 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index bfda8fb..08da53a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,38 +1,29 @@
.PHONY: all clean
-all: timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf user_visible_state
-clean:
- rm -f timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf user_visible_state
-
-user_visible_state: user_visible_state.c
- gcc -o $@ -O2 -std=gnu99 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+SIMPLE_C_TARGETS := dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf user_visible_state
-kernel_pf: kernel_pf.c
- gcc -o $@ -O2 -std=gnu99 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+SIMPLE_CC_TARGETS := evil-clock-test
-timing_test_64: timing_test.cc
- g++ -m64 -o $@ -O2 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+SPLIT_TARGETS := timing_test test_vsyscall
-timing_test_32: timing_test.cc
- g++ -m32 -o $@ -O2 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+ALL_TARGETS := $(SIMPLE_C_TARGETS) $(SIMPLE_CC_TARGETS) $(SPLIT_TARGETS:%=%_64) $(SPLIT_TARGETS:%=%_32)
-evil-clock-test: evil-clock-test.cc
- g++ -o $@ -pthread -O2 -Wall $(EXTRA_CFLAGS) -g $^ -lrt
+CFLAGS := -O2 -g -std=gnu99 -pthread -Wall
+CCFLAGS := -O2 -g -std=gnu++11 -pthread -Wall
-test_vsyscall_64: test_vsyscall.cc
- g++ -m64 -o $@ -std=gnu++0x -O2 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+all: $(ALL_TARGETS)
-test_vsyscall_32: test_vsyscall.cc
- g++ -m32 -o $@ -std=gnu++0x -O2 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
+clean:
+ rm -f $(ALL_TARGETS)
-dump-vdso: dump-vdso.c
- gcc -o $@ -O2 $(EXTRA_CFLAGS) $^ -ldl
+$(SIMPLE_C_TARGETS): %: %.c
+ gcc -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
-dump-vvar: dump-vvar.c
- gcc -o $@ -O2 $(EXTRA_CFLAGS) $^
+$(SIMPLE_CC_TARGETS): %: %.cc
+ g++ -o $@ $(CCFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
-dump-vsyscall: dump-vsyscall.c
- gcc -o $@ -O2 $(EXTRA_CFLAGS) $^ -ldl
+$(SPLIT_TARGETS:%=%_32): %_32: %.cc
+ g++ -m32 -o $@ $(CCFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
-context_switch_latency: context_switch_latency.c
- g++ -o $@ -pthread -O2 -Wall -g $(EXTRA_CFLAGS) $^ -lrt
+$(SPLIT_TARGETS:%=%_64): %_64: %.cc
+ g++ -m64 -o $@ $(CCFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
diff --git a/dump-vdso.c b/dump-vdso.c
index dbd6439..a4b6f63 100644
--- a/dump-vdso.c
+++ b/dump-vdso.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
int main()
{
diff --git a/dump-vvar.c b/dump-vvar.c
index 14f0d39..dce7b66 100644
--- a/dump-vvar.c
+++ b/dump-vvar.c
@@ -1,13 +1,50 @@
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
+#include <sys/mman.h>
+#include <unistd.h>
int main()
{
- char page[4096];
- fprintf(stderr, "Do not rely on this program to work across "
- "kernel versions\n");
- memcpy(page, (const void *)(0xffffffffff5ff000), 4096);
- write(1, page, 4096);
+ FILE *maps;
+ void *vvar_begin, *vvar_end;
+ int found_vvar = 0;
+
+ maps = fopen("/proc/self/maps", "r");
+ char buf[1024];
+ while (fgets(buf, 1024, maps)) {
+ if (strstr(buf, "[vvar]")) {
+ found_vvar = 1;
+ break;
+ }
+ }
+ fclose(maps);
+
+ if (!found_vvar) {
+ fprintf(stderr, "Could not find vvar mapping\n");
+ return 1;
+ }
+
+ sscanf(buf, "%p-%p", &vvar_begin, &vvar_end);
+
+ fprintf(stderr, "vvar mapping is at 0x%lx to 0x%lx\n",
+ (unsigned long)vvar_begin, (unsigned long)vvar_end);
+
+ maps = fopen("/proc/self/maps", "r");
+ mremap(vvar_begin, vvar_end-vvar_begin, vvar_end-vvar_begin, MREMAP_FIXED | MREMAP_MAYMOVE, 0x0badc0de0000);
+
+ mremap(vvar_begin - 4096, 4096, 4096, MREMAP_FIXED | MREMAP_MAYMOVE, 0x0badc0de0000 - 4096);
+
+ while (fgets(buf, 1024, maps)) {
+ fprintf(stderr, "%s", buf);
+ }
+
+ vvar_end = (void*)0x0badc0de0000 + (vvar_end - vvar_begin);
+ vvar_begin = (void*)0x0badc0de0000;
+
+ write(1, vvar_begin, vvar_end - vvar_begin);
+
+ mprotect(vvar_begin, vvar_end - vvar_begin, PROT_READ | PROT_WRITE);
return 0;
}
diff --git a/evil-clock-test.cc b/evil-clock-test.cc
index 164a0b1..153cd28 100644
--- a/evil-clock-test.cc
+++ b/evil-clock-test.cc
@@ -279,7 +279,7 @@ public:
// Consume one entry from times2
if (times2[i]) {
if (times2[i] < t2max) {
- printf(" ERROR! Time2 went back by %"PRIu64"\n",
+ printf(" ERROR! Time2 went back by %" PRIu64 "\n",
t2max - times2[i]);
worst_error = INT64_MAX;
} else {
@@ -297,7 +297,7 @@ public:
// Consume one entry from times1
if (times1[i]) {
if (times1[i] < t1max) {
- printf(" ERROR! Time1 went back by %"PRIu64"\n",
+ printf(" ERROR! Time1 went back by %" PRIu64 "\n",
t1max - times1[i]);
worst_error = INT64_MAX;
} else {
@@ -313,7 +313,7 @@ public:
if (nsamples == 0)
printf(" No data!\n");
else if (worst_error <= 0)
- printf(" Passed with margin %" PRIi64 " (%"PRIu64" samples)\n",
+ printf(" Passed with margin %" PRIi64 " (%" PRIu64 " samples)\n",
-worst_error, nsamples);
else
printf(" Failed %" PRIu64 "/%" PRIu64 " times with worst error %" PRIi64 "\n",
@@ -705,10 +705,10 @@ static void run()
if (t->nsamples == 0)
printf("Now test got no data\n");
else if (t->worst_error > 0)
- printf("Now test failed : worst error %"PRIi64" with %"PRIu64" samples\n",
+ printf("Now test failed : worst error %" PRIi64 " with %" PRIu64 " samples\n",
t->worst_error, t->nsamples);
else
- printf("Now test passed : margin %"PRIi64" with %"PRIu64" samples\n",
+ printf("Now test passed : margin %" PRIi64 " with %" PRIu64 " samples\n",
-t->worst_error, t->nsamples);
delete t;
@@ -726,10 +726,10 @@ static void run()
if (t->nsamples == 0)
printf("Load3 test got no data\n");
else if (t->worst_error > 0)
- printf("Load3 test failed: worst error %"PRIi64" with %"PRIu64" samples\n",
+ printf("Load3 test failed: worst error %" PRIi64 " with %" PRIu64 " samples\n",
t->worst_error, t->nsamples);
else
- printf("Load3 test passed: margin %"PRIi64" with %"PRIu64" samples\n",
+ printf("Load3 test passed: margin %" PRIi64 " with %" PRIu64 " samples\n",
-t->worst_error, t->nsamples);
delete t;
@@ -747,10 +747,10 @@ static void run()
if (t->nsamples == 0) {
printf("Load test got no data\n");
} else if (t->worst_error > 0) {
- printf("Load test failed : worst error %"PRIi64" with %"PRIu64" samples\n",
+ printf("Load test failed : worst error %" PRIi64 " with %" PRIu64 " samples\n",
t->worst_error, t->nsamples);
} else {
- printf("Load test passed : margin %"PRIi64" with %"PRIu64" samples\n",
+ printf("Load test passed : margin %" PRIi64 " with %" PRIu64 " samples\n",
-t->worst_error, t->nsamples);
}
@@ -769,11 +769,11 @@ static void run()
if (t->nsamples == 0) {
printf("Store test got no data\n");
} else if (t->worst_error > 0) {
- printf("Store test failed%s: worst error %"PRIi64" with %"PRIu64" samples\n",
+ printf("Store test failed%s: worst error %" PRIi64 " with %" PRIu64 " samples\n",
ClockType::is_strict ? "" : " as expected",
t->worst_error, t->nsamples);
} else {
- printf("Store test passed: margin %"PRIi64" with %"PRIu64" samples\n",
+ printf("Store test passed: margin %" PRIi64 " with %" PRIu64 " samples\n",
-t->worst_error, t->nsamples);
}