Debian Codegraph @

tests/scripts/options/shuffle

raw
1 # -*-perl-*-
2
3 $description = "Test the --shuffle option.";
4
5 $details = "Verify that --shuffle has expected effect on target order and argument order.";
6
7 #
8 # Test --shuffle=random
9 #
10
11 # TEST 1: Fixed seed should yield the same order from run to run.
12
13 $makefile = &get_tmpfile;
14
15 open(MAKEFILE, "> $makefile");
16 print MAKEFILE <<'EOF';
17 # More target prerequisites lower collision chance in TEST 2
18 all: a_ b_ c_ d_ e_ f_ g_ i_ j_ k_ l_
19 %: ; echo $@
20 EOF
21 close(MAKEFILE);
22
23 $log1 = &get_logfile;
24 $log2 = &get_logfile;
25 &run_make_with_options($makefile, "--shuffle=12345", $log1);
26 &run_make_with_options($makefile, "--shuffle=12345", $log2);
27
28 &compare_output(&read_file_into_string($log1), $log2);
29
30 # TEST 2: Sequential runs should produce different orders.
31
32 $log3 = &get_logfile;
33 $log4 = &get_logfile;
34 &run_make_with_options($makefile, "--shuffle", $log3);
35 &run_make_with_options($makefile, "--shuffle", $log4);
36
37 ++$tests_run;
38 if (&read_file_into_string($log3) ne &read_file_into_string($log4)) {
39 print "ok\n" if $debug;
40 ++$tests_passed;
41 }
42
43 #
44 # Test --shuffle=reverse
45 #
46
47 run_make_test('
48 %: ; @echo $@
49 all: a b c
50 ',
51 '--shuffle=reverse', "c\nb\na\nall");
52
53 run_make_test('
54 %: ; @echo $@
55 all: a b c
56 ',
57 '--shuffle=none', "a\nb\nc\nall");
58
59 run_make_test('
60 %: ; @echo $@
61 all: a b c
62 ',
63 '--shuffle=identity', "a\nb\nc\nall");
64
65 # Make sure prerequisites get reverse order and commands don't get affected.
66 run_make_test('
67 all: foo.o ; @echo $@
68 %.o : %.c ; @echo cc -c -o $@ $<
69 foo.o : foo.c foo.h bar.h baz.h
70 %.h: ; @echo $@
71 %.c: ; @echo $@
72 ',
73 '--shuffle=reverse',
74 "baz.h\nbar.h\nfoo.h\nfoo.c\ncc -c -o foo.o foo.c\nall");
75
76 # Make sure pattern prerequisites get reverse order and commands don't get
77 # affected.
78 run_make_test('
79 all: foo_ ; @echo $@
80 foo%: arg%1 arg%2 arg%3 arg%4 ; @echo bld $@ $< $(word 3,$^) $(word 2,$^) $(word 4,$^)
81
82 arg%: ; @echo $@
83 ',
84 '--shuffle=reverse',
85 "arg_4\narg_3\narg_2\narg_1\nbld foo_ arg_1 arg_3 arg_2 arg_4\nall");
86
87 # Check if make can survive circular dependency.
88 run_make_test('
89 all: a_ b_ ; @echo $@
90 %_: ; @echo $@
91
92 a_: b_
93 b_: a_
94 ',
95 '--shuffle=reverse', "#MAKE#: Circular a_ <- b_ dependency dropped.\na_\nb_\nall");
96
97 # Check if order-only dependencies get reordered.
98 run_make_test('
99 all: a_ ; @echo $@
100 %_: ; @echo $@
101 a_: b_ c_ | d_ e_
102 ',
103 '--shuffle=reverse', "e_\nd_\nc_\nb_\na_\nall");
104
105 # Check if goals are reordered.
106 run_make_test('
107 %_: ; @echo $@
108 ',
109 '--shuffle=reverse a_ b_ c_', "c_\nb_\na_");
110
111 # .NOTPARALLEL should prevent reordering from happening.
112 run_make_test('
113 %_: ; @echo $@
114 # disable shuffling
115 .NOTPARALLEL:
116 ',
117 '--shuffle=reverse a_ b_ c_', "a_\nb_\nc_");
118
119 # Check if SECONDEXPANSION targets also get reshuffled.
120 run_make_test('
121 .SECONDEXPANSION:
122 all: $$(var)
123 %_: ; @echo $@
124 var = a_ b_ c_
125 ',
126 '--shuffle=reverse', "c_\nb_\na_");
127
128 1;