diff --git a/tests/run.sh b/tests/run.sh index c41387f..cb62a90 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -23,6 +23,10 @@ BOLD='\033[1m' NOFMT='\033[0m' TEST_CNT=0 +TEST_PIPE=./test-pipe + +# remove stale test pipe (if any) +rm $TEST_PIPE do_memcr_test() { @@ -32,12 +36,15 @@ do_memcr_test() TEST_CNT=$((TEST_CNT + 1)) echo "${WHITE}[test $TEST_CNT] $MEMCR_CMD for $TEST${NOFMT}" + mkfifo $TEST_PIPE + # start the test - ./$TEST & + ./$TEST $TEST_PIPE & TPID=$! - # wait - sleep 0.05 + # wait for test to be ready + cat $TEST_PIPE + rm $TEST_PIPE # memcr $MEMCR_CMD -p $TPID diff --git a/tests/test-malloc.c b/tests/test-malloc.c index a3773d3..a1fe55e 100644 --- a/tests/test-malloc.c +++ b/tests/test-malloc.c @@ -21,11 +21,30 @@ static void sighandler(int num) signalled = num; } +static void notify_ready(const char *pipe) +{ + int ret; + int fd; + char msg[64]; + + fd = open(pipe, O_WRONLY); + assert(fd >= 0); + + snprintf(msg, sizeof(msg), PFX "pid %d ready\n", getpid()); + ret = write(fd, msg, strlen(msg)); + assert(ret == strlen(msg)); + + close(fd); +} + int main(int argc, char *argv[]) { int ret; void *memb; + if (argc < 2) + return 1; + signal(SIGUSR1, sighandler); printf(PFX "pid %d\n", getpid()); @@ -46,6 +65,8 @@ int main(int argc, char *argv[]) printf(PFX "waiting for SIGUSR1\n"); + notify_ready(argv[1]); + while (!signalled) usleep(10 * 1000);