Skip to content

Commit

Permalink
Synchronize tests execution with fifo pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
mkozlowski committed Sep 29, 2024
1 parent bdbdcf2 commit 27c3fd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test-malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);

Expand Down

0 comments on commit 27c3fd8

Please sign in to comment.