-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should make testing across multiple platforms easier.
- Loading branch information
1 parent
d671568
commit 11a0064
Showing
4 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
MAKEFLAGS += -rR | ||
|
||
ifeq ("$(origin CC)", "default") | ||
undefine CC | ||
endif | ||
|
||
CC ?= $(CROSS_COMPILE)gcc | ||
|
||
CFLAGS = -Wall -Werror -g -O2 | ||
|
||
SRC = $(wildcard *.c) | ||
BIN = $(SRC:%.c=%) | ||
|
||
MEMCR ?= ../memcr | ||
|
||
all: $(BIN) | ||
@./run.sh $(MEMCR) | ||
|
||
$(BIN): %: %.c Makefile | ||
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) | ||
|
||
clean: | ||
rm -f $(BIN) | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/sh | ||
|
||
#set -x | ||
|
||
# $1 should point to memcr executable | ||
[ -n "$1" ] || exit 1 | ||
[ -x "$1" ] || exit 2 | ||
|
||
MEMCR=$1 | ||
|
||
CUID=$(id -u) | ||
if [ "$CUID" != "0" ]; then | ||
DO="sudo" | ||
else | ||
DO="" | ||
fi | ||
|
||
TESTS="test-malloc" | ||
|
||
for TEST in $TESTS; do | ||
echo "######## running $TEST ########" | ||
|
||
# start the test | ||
./$TEST & | ||
|
||
# wait | ||
sleep 0.2 | ||
|
||
# memcr | ||
$DO $MEMCR -p $! -n -f | ||
if [ $? -ne 0 ]; then | ||
kill $! | ||
echo "[-] $TEST failed" | ||
break | ||
fi | ||
|
||
# stop the test | ||
kill -USR1 $! | ||
wait $! | ||
if [ $? -eq 0 ]; then | ||
echo "[+] $TEST passed" | ||
else | ||
echo "[-] $TEST failed" | ||
break | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <signal.h> | ||
#include <assert.h> | ||
|
||
#define PFX "[test-malloc] " | ||
|
||
#define TEST_SIZE (16 * 1024 * 1024) /* 16 MB */ | ||
|
||
static volatile sig_atomic_t signalled; | ||
|
||
static char mema[TEST_SIZE]; | ||
|
||
static void sighandler(int num) | ||
{ | ||
signalled = num; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int ret; | ||
void *memb; | ||
|
||
signal(SIGUSR1, sighandler); | ||
|
||
printf(PFX "pid %d\n", getpid()); | ||
|
||
memset(mema, 0x5b, sizeof(mema)); | ||
|
||
memb = malloc(TEST_SIZE); | ||
assert(memb); | ||
|
||
memset(mema, 0x5b, sizeof(mema)); | ||
memcpy(memb, mema, sizeof(mema)); | ||
|
||
ret = memcmp(mema, memb, sizeof(mema)); | ||
assert(ret == 0); | ||
|
||
printf(PFX "mema %d kB @ %p\n", TEST_SIZE / 1024, mema); | ||
printf(PFX "memb %d kB @ %p\n", TEST_SIZE / 1024, memb); | ||
|
||
printf(PFX "waiting for SIGUSR1\n"); | ||
|
||
while (!signalled) | ||
usleep(10 * 1000); | ||
|
||
printf(PFX "signalled (%s)\n", strsignal(signalled)); | ||
|
||
ret = memcmp(mema, memb, sizeof(mema)); | ||
assert(ret == 0); | ||
|
||
printf(PFX "ok\n"); | ||
|
||
free(memb); | ||
return 0; | ||
} |