Skip to content

Commit 6c75933

Browse files
committed
fix: address PR review comments
- Replace volatile with pthread_mutex/cond for inter-thread synchronization in proc_task_comm.c test (volatile does not provide atomicity or memory ordering guarantees) - Remove redundant 'make -C test/zdtm' from test/Dockerfile since zdtm.py compiles tests on the fly - Split castai-test Makefile target into castai-test-build (image) and castai-test (run), volume-mounting test/ so test code changes take effect without rebuilding the Docker image
1 parent 11f30a1 commit 6c75933

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,19 @@ docker-test:
423423

424424
#
425425
# CastAI custom targets
426-
castai-test:
426+
#
427+
# castai-test-build: build the Docker image with CRIU compiled.
428+
# Only needed when CRIU source (not test) code changes.
429+
# castai-test: run the full ZDTM test suite inside Docker.
430+
# Volume-mounts test/ so test code changes take effect immediately
431+
# without rebuilding the image (zdtm.py compiles tests on the fly).
432+
castai-test-build:
427433
docker build -t criu-test -f test/Dockerfile .
434+
.PHONY: castai-test-build
435+
436+
castai-test: castai-test-build
428437
docker run --rm --privileged --cgroupns=host -v /lib/modules:/lib/modules \
438+
-v $(CURDIR)/test:/criu/test \
429439
criu-test run -a -p 4 --keep-going --ignore-taint
430440
.PHONY: castai-test
431441

test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
2828

2929
COPY . /criu
3030
WORKDIR /criu
31-
RUN make mrproper && make -j $(nproc) && make -C test/zdtm -j $(nproc)
31+
RUN make mrproper && make -j $(nproc)
3232

3333
ENTRYPOINT ["./test/zdtm.py"]

test/zdtm/static/proc_task_comm.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ static pid_t dead_thread_tid;
3535
/* Live thread state */
3636
static int live_thread_fd = -1;
3737
static pid_t live_thread_tid;
38-
static volatile int live_thread_ready;
38+
39+
/* Synchronization for live thread */
40+
static pthread_mutex_t live_mutex = PTHREAD_MUTEX_INITIALIZER;
41+
static pthread_cond_t live_cond = PTHREAD_COND_INITIALIZER;
42+
static int live_thread_state; /* 0=init, 1=ready, 2=exit */
3943

4044
/*
4145
* Dead thread: opens /proc/self/task/<tid>/comm, then exits.
@@ -80,11 +84,14 @@ static void *live_thread_fn(void *arg)
8084
live_thread_tid, path, live_thread_fd);
8185

8286
/* Signal main thread that we're ready */
83-
live_thread_ready = 1;
87+
pthread_mutex_lock(&live_mutex);
88+
live_thread_state = 1;
89+
pthread_cond_signal(&live_cond);
8490

85-
/* Stay alive through C/R */
86-
while (live_thread_ready != 2)
87-
usleep(10000);
91+
/* Wait for main thread to tell us to exit */
92+
while (live_thread_state != 2)
93+
pthread_cond_wait(&live_cond, &live_mutex);
94+
pthread_mutex_unlock(&live_mutex);
8895

8996
return NULL;
9097
}
@@ -130,8 +137,10 @@ int main(int argc, char **argv)
130137
}
131138

132139
/* Wait for live thread to be ready */
133-
while (!live_thread_ready)
134-
usleep(1000);
140+
pthread_mutex_lock(&live_mutex);
141+
while (live_thread_state != 1)
142+
pthread_cond_wait(&live_cond, &live_mutex);
143+
pthread_mutex_unlock(&live_mutex);
135144

136145
if (live_thread_fd < 0) {
137146
fail("Live thread did not produce a valid fd");
@@ -193,14 +202,20 @@ int main(int argc, char **argv)
193202
close(live_thread_fd);
194203
pass();
195204

196-
live_thread_ready = 2;
205+
pthread_mutex_lock(&live_mutex);
206+
live_thread_state = 2;
207+
pthread_cond_signal(&live_cond);
208+
pthread_mutex_unlock(&live_mutex);
197209
pthread_join(live_th, NULL);
198210
return 0;
199211

200212
out:
201213
close(dead_thread_fd);
202214
close(live_thread_fd);
203-
live_thread_ready = 2;
215+
pthread_mutex_lock(&live_mutex);
216+
live_thread_state = 2;
217+
pthread_cond_signal(&live_cond);
218+
pthread_mutex_unlock(&live_mutex);
204219
pthread_join(live_th, NULL);
205220
return 1;
206221
}

0 commit comments

Comments
 (0)