+/* Tests all possible full allocations in all possible range sets
+ (up to a small maximum number of bits). */
+static void
+test_allocate_fully (void)
+{
+ const int positions = 9;
+ unsigned int init_pat;
+ int request;
+
+#if __GNUC__ == 4 && __GNUC_MINOR__ == 2 && __llvm__
+ /* This test seems to trigger a bug in llvm-gcc 4.2 on Mac OS X 10.8.0.
+ Exit code 77 tells the Autotest framework that the test was skipped. */
+ exit (77);
+#endif
+
+ for (init_pat = 0; init_pat < (1u << positions); init_pat++)
+ for (request = 1; request <= positions + 1; request++)
+ {
+ struct range_set *rs;
+ unsigned long int start, expect_start;
+ bool success, expect_success;
+ unsigned int final_pat;
+ int i;
+
+ /* Figure out expected results. */
+ expect_success = false;
+ expect_start = 0;
+ final_pat = init_pat;
+ for (i = 0; i < positions - request + 1; i++)
+ {
+ int j;
+
+ final_pat = init_pat;
+ for (j = i; j < i + request; j++)
+ {
+ if (!(init_pat & (1u << j)))
+ goto next;
+ final_pat &= ~(1u << j);
+ }
+
+ expect_success = true;
+ expect_start = i;
+ break;
+ next:
+ final_pat = init_pat;
+ }
+
+ /* Test. */
+ rs = make_pattern (init_pat);
+ success = range_set_allocate_fully (rs, request, &start);
+ check_pattern (rs, final_pat);
+ range_set_destroy (rs);
+
+ /* Check results. */
+ check (success == expect_success);
+ if (expect_success)
+ check (start == expect_start);
+ }
+}
+