summaryrefslogtreecommitdiff
path: root/tests/scripts/options/shuffle
blob: 5661683c0ab1088fb94685e914bfff16c1bfed61 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#                                                                    -*-perl-*-

$description = "Test the --shuffle option.";

$details = "Verify that --shuffle has expected effect on target order and argument order.";

#
# Test --shuffle=random
#

# TEST 1: Fixed seed should yield the same order from run to run.

$makefile = &get_tmpfile;

open(MAKEFILE, "> $makefile");
print MAKEFILE <<'EOF';
# More target prerequisites lower collision chance in TEST 2
all: a_ b_ c_ d_ e_ f_ g_ i_ j_ k_ l_
%: ; echo $@
EOF
close(MAKEFILE);

$log1 = &get_logfile;
$log2 = &get_logfile;
&run_make_with_options($makefile, "--shuffle=12345", $log1);
&run_make_with_options($makefile, "--shuffle=12345", $log2);

&compare_output(&read_file_into_string($log1), $log2);

# TEST 2: Sequential runs should produce different orders.

$log3 = &get_logfile;
$log4 = &get_logfile;
&run_make_with_options($makefile, "--shuffle", $log3);
&run_make_with_options($makefile, "--shuffle", $log4);

++$tests_run;
if (&read_file_into_string($log3) ne &read_file_into_string($log4)) {
  print "ok\n" if $debug;
  ++$tests_passed;
}

#
# Test --shuffle=reverse
#

run_make_test('
%: ; @echo $@
all: a b c
',
              '--shuffle=reverse', "c\nb\na\nall");

run_make_test('
%: ; @echo $@
all: a b c
',
              '--shuffle=none', "a\nb\nc\nall");

run_make_test('
%: ; @echo $@
all: a b c
',
              '--shuffle=identity', "a\nb\nc\nall");

# Make sure prerequisites get reverse order and commands don't get affected.
run_make_test('
all: foo.o ; @echo $@
%.o : %.c ; @echo cc -c -o $@ $<
foo.o : foo.c foo.h bar.h baz.h
%.h: ; @echo $@
%.c: ; @echo $@
',
              '--shuffle=reverse',
              "baz.h\nbar.h\nfoo.h\nfoo.c\ncc -c -o foo.o foo.c\nall");

# Make sure pattern prerequisites get reverse order and commands don't get
# affected.
run_make_test('
all: foo_ ; @echo $@
foo%: arg%1 arg%2 arg%3 arg%4 ; @echo bld $@ $< $(word 3,$^) $(word 2,$^) $(word 4,$^)

arg%: ; @echo $@
',
              '--shuffle=reverse',
              "arg_4\narg_3\narg_2\narg_1\nbld foo_ arg_1 arg_3 arg_2 arg_4\nall");

# Check if make can survive circular dependency.
run_make_test('
all: a_ b_ ; @echo $@
%_: ; @echo $@

a_: b_
b_: a_
',
              '--shuffle=reverse', "#MAKE#: Circular a_ <- b_ dependency dropped.\na_\nb_\nall");

# Check if order-only dependencies get reordered.
run_make_test('
all: a_ ; @echo $@
%_: ; @echo $@
a_: b_ c_ | d_ e_
',
              '--shuffle=reverse', "e_\nd_\nc_\nb_\na_\nall");

# Check if goals are reordered.
run_make_test('
%_: ; @echo $@
',
              '--shuffle=reverse a_ b_ c_', "c_\nb_\na_");

# .NOTPARALLEL should prevent reordering from happening.
run_make_test('
%_: ; @echo $@
# disable shuffling
.NOTPARALLEL:
',
              '--shuffle=reverse a_ b_ c_', "a_\nb_\nc_");

# Check if SECONDEXPANSION targets also get reshuffled.
run_make_test('
.SECONDEXPANSION:
all: $$(var)
%_: ; @echo $@
var = a_ b_ c_
',
              '--shuffle=reverse', "c_\nb_\na_");

1;