Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize tests execution with fifo pipe #98

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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