-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (80 loc) · 2.82 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
CFLAGS = -Wall -Werror
LIBS = -lpthread
PROGRAMS = jobclient jobforce jobcount jobserver
all: $(PROGRAMS)
clean::
rm -f $(PROGRAMS)
$(PROGRAMS): jobclient.h
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
TESTS = 11
test: test-jobclient test-jobserver
test-jobclient: $(PROGRAMS)
@for t in `seq $(TESTS)`; do echo Running test$$t...; env -i "PATH=$$PATH" make -j3 test$$t || break; echo; done
test-jobserver: $(PROGRAMS)
@for t in `seq $(TESTS)`; do echo Running test$$t...; env -i "PATH=$$PATH" ./jobserver -j3 make test$$t || break; echo; done
# Tests assume running with -j3 (and no concurrent activity), which means that
# each command actually runs with 2 job tokens available. One job is given
# implicitly (which then requires jobforce to get the "correct" number).
test1:
+./jobclient echo hello
test2:
@echo The 3 second sleep should not be able to start until hello 1 second is finished.
+( \
./jobclient ./slowecho 1 hello 1 second & \
./jobclient ./slowecho 2 hello 2 second & \
./jobclient ./slowecho 3 hello 3 second & \
wait; \
) | ts
test3:
@echo With jobforce, all three jobs should start simultaneously
+( \
./jobforce -1; \
./jobclient ./slowecho 1 hello 1 second & \
./jobclient ./slowecho 2 hello 2 second & \
./jobclient ./slowecho 3 hello 3 second & \
wait; \
./jobforce 1; \
) | ts
test4:
@echo "This should produce a warning about too few job tokens being available, since we've used 2 and released no jobs."
+./jobforce 2
test5:
@echo "This should produce no warning since the calls are balanced"
+./jobforce 2
+./jobforce -2
test6:
@echo "This should produce no warning since the calls are balanced (despite being inverted!)"
+./jobforce -2
+./jobforce 2
test7:
@echo This should be able to force additional jobs to be available
+./jobforce -2
+./jobforce 4
+./jobforce -2
test8:
# TODO have a test with jobforce > 2 that never finishes and check for a timeout
# It's fine to use jobforce as in test3 - releasing the implicit job for the
# duration of the process, but it's more correct to do it only while waiting.
# Some CPU will be used in the main process to set things up, so use the
# implicit job for that, then make sure we don't use up a job while we're
# blocked in wait.
test9:
@echo "All three jobs should start simultaneously (more or less), with the last one starting after the jobforce call"
+(\
./jobclient ./slowecho 1 hello 1 second & \
./jobclient ./slowecho 2 hello 2 second & \
./jobclient ./slowecho 3 hello 3 second & \
echo "launched, now waiting..."; \
./jobforce -1; \
wait; \
echo "done."; \
./jobforce 1; \
) | ts
test10:
+test `./jobcount` -eq 2
@echo "PASS - job count was 2"
test11:
@echo "The inside makeflags should be empty below"
@+echo outside makeflags = $$MAKEFLAGS && \
./jobserver -d sh -c 'echo inside makeflags = $$MAKEFLAGS'