10 TEST1(beta_sanity_check
, char *filename
) {
11 FILE *f
= fopen(filename
, "r");
12 osl_scop_p scop
= osl_scop_read(f
);
15 EXPECT_TRUE(clay_beta_sanity_check(scop
), "");
19 TEST(beta_sanity_check_fail
) {
20 FILE *f
= fopen("malformed.scop", "r");
21 osl_scop_p scop
= osl_scop_read(f
);
24 EXPECT_TRUE(!clay_beta_sanity_check(scop
),
25 "Malformed scop passed the sanity check");
29 TEST(beta_next_interleave
) {
30 FILE *f
= fopen("trickypeel.after.scop", "r");
31 ASSERT_TRUE(f
!= NULL
, "Failed to open file trickypeel.after.scop");
32 osl_scop_p scop
= osl_scop_read(f
);
35 clay_array_p
*betas
= (clay_array_p
*) malloc(sizeof(clay_array_p
*) * 4);
36 betas
[0] = clay_array_malloc();
37 betas
[1] = clay_array_malloc();
38 betas
[2] = clay_array_malloc();
39 betas
[3] = clay_array_malloc();
41 clay_array_add(betas
[0], 0);
42 clay_array_add(betas
[0], 0);
44 clay_array_add(betas
[1], 1);
45 clay_array_add(betas
[1], 0);
47 clay_array_add(betas
[2], 2);
48 clay_array_add(betas
[2], 0);
50 clay_array_add(betas
[3], 3);
51 clay_array_add(betas
[3], 0);
53 clay_array_p beta
= clay_array_malloc(), b1
;
55 for (i
= 0; i
< 4; i
++) {
56 b1
= clay_beta_next(scop
->statement
, beta
, &stmt
);
57 clay_array_free(beta
);
59 EXPECT_TRUE(clay_beta_equals(betas
[i
], beta
), "Unexpected next beta");
61 EXPECT_TRUE(stmt
== scop
->statement
, "Wrong statement found");
63 EXPECT_TRUE(stmt
== scop
->statement
->next
, "Wrong statement found");
66 b1
= clay_beta_next(scop
->statement
, beta
, &stmt
);
67 clay_array_free(beta
);
68 EXPECT_TRUE(b1
== NULL
, "Next-beta cycle did not end with NULL");
69 EXPECT_TRUE(stmt
== NULL
,
70 "Next-beta cycle did not reutrn pointer to NULL statement at the end");
76 TEST(beta_next_empty
) {
77 osl_scop_p scop
= osl_scop_malloc();
78 scop
->statement
= osl_statement_malloc();
80 scop
->statement
->scattering
= osl_relation_malloc(0, 4);
82 clay_array_p beta
= clay_array_malloc();
83 clay_array_p next
= clay_beta_next(scop
->statement
, beta
, &stmt
);
84 EXPECT_TRUE(next
== NULL
, "Found a beta for an empty statement");
85 EXPECT_TRUE(stmt
== NULL
, "Found a next statement for an empty one");
87 clay_array_free(beta
);
91 TEST(beta_next_null
) {
92 osl_statement_p statement
= osl_statement_malloc(), stmt
;
93 statement
->scattering
= osl_relation_malloc(0, 2);
94 clay_array_p beta
= clay_array_malloc(), next
;
96 next
= clay_beta_next(NULL
, beta
, &stmt
);
97 EXPECT_TRUE(next
== NULL
, "Found a beta for a NULL statement");
98 EXPECT_TRUE(stmt
== NULL
, "Found a next statement for a NULL one");
100 next
= clay_beta_next(statement
, NULL
, &stmt
);
101 EXPECT_TRUE(next
== NULL
, "Found next beta for a NULL beta");
102 EXPECT_TRUE(stmt
== NULL
, "Found a next statement for a NULL beta");
104 next
= clay_beta_next(NULL
, NULL
, &stmt
);
105 EXPECT_TRUE(next
== NULL
, "Found a beta for a NULL statement");
106 EXPECT_TRUE(stmt
== NULL
, "Found a next statement for a NULL one");
108 clay_array_free(beta
);
109 osl_statement_free(statement
);
112 TEST(statement_relations_interleave
) {
113 FILE *f
= fopen("trickypeel.after.scop", "r");
114 ASSERT_TRUE(f
!= NULL
, "Failed to open file trickypeel.after.scop");
115 osl_scop_p scop
= osl_scop_read(f
);
118 // stmt1 = beta1, beta3; stmt2 = beta2, beta4; betas are ordered
119 clay_array_p beta3
= clay_beta_extract(scop
->statement
->scattering
);
120 clay_array_p beta4
= clay_beta_extract(scop
->statement
->next
->scattering
);
121 clay_array_p beta1
= clay_beta_extract(scop
->statement
->scattering
->next
);
122 clay_array_p beta2
= clay_beta_extract(scop
->statement
->next
->scattering
->next
);
125 for (i
= 0; i
< 2; i
++) {
126 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
, beta1
),
127 "Statement is after itself");
128 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
, beta2
),
129 "Statement is after another, which interleaves it");
130 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
, beta3
),
131 "Statement is after itself");
132 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
, beta4
),
133 "Statement is after another, but should be before");
135 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
, beta1
),
136 "Statement is before itself");
137 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
, beta2
),
138 "Statement is before another, which interleaves it");
139 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
, beta3
),
140 "Statement is before itself");
141 EXPECT_TRUE(clay_statement_is_before(scop
->statement
, beta4
),
142 "Statement is not before the following beta");
144 EXPECT_TRUE(clay_statement_is_after(scop
->statement
->next
, beta1
),
145 "Statement is not after the previous beta");
146 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
->next
, beta2
),
147 "Statement is after itself");
148 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
->next
, beta3
),
149 "Statement is after another, which interleaves it");
150 EXPECT_TRUE(!clay_statement_is_after(scop
->statement
->next
, beta4
),
151 "Statement is after itself");
153 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
->next
, beta1
),
154 "Statement is before another, but should be after");
155 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
->next
, beta2
),
156 "Statement is before itself");
157 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
->next
, beta3
),
158 "Statement is before another, which interleaves it");
159 EXPECT_TRUE(!clay_statement_is_before(scop
->statement
->next
, beta4
),
160 "Statement is before itself");
162 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
, beta1
),
163 "Statement interleaves itself");
164 EXPECT_TRUE(clay_statement_interleaves(scop
->statement
, beta2
),
165 "Statement doesn't interleave the beta it should");
166 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
, beta3
),
167 "Statement interleaves itself");
168 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
, beta4
),
169 "Statement interleaves the following beta");
171 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
->next
, beta1
),
172 "Statement interleaves the previous beta");
173 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
->next
, beta2
),
174 "Statement interleaves itself");
175 EXPECT_TRUE(clay_statement_interleaves(scop
->statement
->next
, beta3
),
176 "Statement doesn't interleave the beta it should");
177 EXPECT_TRUE(!clay_statement_interleaves(scop
->statement
->next
, beta4
),
178 "Statement interleaves itself");
186 clay_array_free(beta1
);
187 clay_array_free(beta2
);
188 clay_array_free(beta3
);
189 clay_array_free(beta4
);
194 RUN_TEST(beta_next_interleave
);
195 RUN_TEST(beta_next_null
);
196 RUN_TEST(beta_next_empty
);
197 RUN_TEST(statement_relations_interleave
);
198 RUN_TEST1(beta_sanity_check
, "trickypeel.before.scop");
199 RUN_TEST1(beta_sanity_check
, "trickypeel.after.scop");
200 RUN_TEST1(beta_sanity_check
, "peel.before.scop");
201 RUN_TEST1(beta_sanity_check
, "peel.after.scop");
202 RUN_TEST(beta_sanity_check_fail
);