aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-07-09 19:33:00 -0400
committerDave Airlie <airlied@redhat.com>2009-07-15 03:13:16 -0400
commit77bd36f014bc5a3f28507a4e86a81b2b3d2439c3 (patch)
tree06431066e98704851383839e4f6d857b3c488d96 /net/unix/af_unix.c
parent5176fdc4c5873e52f9cb6e166d80e843847e7eb4 (diff)
drm/radeon/kms: don't swap PCIEGART PTEs in VRAM.
On powerpc, since we aren't using any hw swappers, this will get flipped around by default in hw. tested on a G5 + rv515. Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'net/unix/af_unix.c')
0 files changed, 0 insertions, 0 deletions
65' href='#n265'>265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
#!/usr/bin/env python

from __future__ import division

import unittest

import schedcat.mapping.binpack as bp
import schedcat.mapping.rollback as rb

class TooLarge(unittest.TestCase):
    def setUp(self):
        self.cap   = 10
        self.items = range(100, 1000)
        self.bins  = 9
        self.empty = [[]] * self.bins

    def test_next_fit(self):
        sets = bp.next_fit(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_first_fit(self):
        sets = bp.first_fit(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_worst_fit(self):
        sets = bp.worst_fit(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_best_fit(self):
        sets = bp.best_fit(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_next_fit_decreasing(self):
        sets = bp.next_fit_decreasing(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_first_fit_decreasing(self):
        sets = bp.first_fit_decreasing(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_worst_fit_decreasing(self):
        sets = bp.worst_fit_decreasing(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

    def test_best_fit_decreasing(self):
        sets = bp.best_fit_decreasing(self.items, self.bins, self.cap)
        self.assertEqual(sets, self.empty)

class NotLossy(unittest.TestCase):
    def setUp(self):
        self.items = range(100, 1000)
        self.bins  = 1
        self.cap   = sum(self.items)
        self.expected = [self.items]

    def test_next_fit(self):
        sets = bp.next_fit(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_first_fit(self):
        sets = bp.first_fit(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_worst_fit(self):
        sets = bp.worst_fit(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_best_fit(self):
        sets = bp.best_fit(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_next_fit_decreasing(self):
        sets = bp.next_fit_decreasing(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_first_fit_decreasing(self):
        sets = bp.first_fit_decreasing(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_worst_fit_decreasing(self):
        sets = bp.worst_fit_decreasing(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)

    def test_best_fit_decreasing(self):
        sets = bp.best_fit_decreasing(self.items, self.bins, self.cap)
        sets[0].sort()
        self.assertEqual(sets, self.expected)


class KnownExample(unittest.TestCase):
    def setUp(self):
        self.items = [8, 5, 7, 6, 2, 4, 1]
        self.bins  = 5
        self.cap   = 10

    def test_next_fit(self):
        sets = bp.next_fit(self.items, self.bins, self.cap)
        self.expected = [[8], [5], [7], [6, 2], [4, 1]]
        self.assertEqual(sets, self.expected)

    def test_first_fit(self):
        sets = bp.first_fit(self.items, self.bins, self.cap)
        self.expected = [[8, 2], [5, 4, 1], [7], [6], []]
        self.assertEqual(sets, self.expected)

    def test_worst_fit(self):
        self.bins = 4
        sets = bp.worst_fit(self.items, self.bins, self.cap)
        self.expected = [[8], [5, 2, 1], [7], [6, 4]]
        self.assertEqual(sets, self.expected)

    def test_best_fit(self):
        sets = bp.best_fit(self.items, self.bins, self.cap)
        self.expected = [[8, 2], [5], [7, 1], [6, 4], []]
        self.assertEqual(sets, self.expected)


class RollbackBins(unittest.TestCase):
    def setUp(self):
        self.bin = rb.Bin([0.2])
        self.bin2 = rb.Bin([2], size=lambda x: x + 0.1, capacity=10)

    def test_try_to_add_float(self):
        self.assertTrue(self.bin.try_to_add(0.3))
        self.assertFalse(self.bin.try_to_add(0.6))
        self.assertTrue(self.bin.try_to_add(0.5))
        self.assertFalse(self.bin.try_to_add(0.0000001))
        self.assertEqual([0.2,0.3,0.5], self.bin.items)

    def test_try_to_add_int(self):
        self.assertTrue(self.bin2.try_to_add(3))
        self.assertFalse(self.bin2.try_to_add(6))
        self.assertFalse(self.bin2.try_to_add(5))
        self.assertTrue(self.bin2.try_to_add(1))
        self.assertEqual([2,3,1], self.bin2.items)


class Heuristics(unittest.TestCase):
    def setUp(self):
        self.items = [8, 5, 7, 6, 2, 4, 1]
        self.bins  = [rb.Bin(capacity = 10) for _ in range(5)]
        self.bins  = [rb.CheckedBin(b) for b in self.bins]
        self.make_bin = lambda x: rb.CheckedBin(rb.Bin(capacity = x))

    def test_base(self):
        h = rb.Heuristic(self.bins)
        self.assertEqual(0, h.binpack(self.items))
        self.assertEqual(h.misfits, self.items)
        h.misfits = []
        self.assertRaises(bp.DidNotFit, h.binpack, self.items,
                          report_misfit=bp.report_failure)
        self.assertEqual([8], h.misfits)

    def test_next_fit_fixed(self):
        h = rb.NextFit(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5], [7], [6, 2], [4, 1]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_next_fit_make(self):
        h = rb.NextFit(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5], [7], [6, 2], [4, 1]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_next_fit_small(self):
        h = rb.NextFit(make_bin=lambda: self.make_bin(7))
        expected = [[5], [7], [6], [2, 4, 1]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_next_fit_few(self):
        h = rb.NextFit(self.bins[:4])
        expected = [[8], [5], [7], [6, 2]]
        misfits  = [4, 1]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)


    def test_first_fit_fixed(self):
        h = rb.FirstFit(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5, 4, 1], [7], [6], []]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_first_fit_make(self):
        h = rb.FirstFit(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5, 4, 1], [7], [6]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_first_fit_small(self):
        h = rb.FirstFit(make_bin=lambda: self.make_bin(7))
        expected = [[5,2], [7], [6, 1], [4]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_first_fit_few(self):
        h = rb.FirstFit(self.bins[:3])
        expected = [[8, 2], [5, 4, 1], [7]]
        misfits  = [6]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)


    def test_worst_fit_fixed(self):
        h = rb.WorstFit(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5, 1], [7], [6], [2, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_worst_fit_make(self):
        h = rb.WorstFit(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5, 2, 1], [7], [6, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_worst_fit_small(self):
        h = rb.WorstFit(make_bin=lambda: self.make_bin(7))
        expected = [[5, 2], [7], [6], [4, 1]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_worst_fit_few(self):
        h = rb.WorstFit(self.bins[:4])
        expected = [[8], [5, 2, 1], [7], [6, 4]]
        misfits  = []
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)


    def test_best_fit_fixed(self):
        h = rb.BestFit(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5], [7, 1], [6, 4], []]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_best_fit_make(self):
        h = rb.BestFit(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5], [7, 1], [6, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_best_fit_small(self):
        h = rb.BestFit(make_bin=lambda: self.make_bin(7))
        expected = [[5, 2], [7], [6, 1], [4]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_best_fit_few(self):
        h = rb.BestFit(self.bins[:3])
        expected = [[8, 2], [5, 4, 1], [7]]
        misfits  = [6]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)


    def test_max_spare_cap_fixed(self):
        h = rb.MaxSpareCapacity(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5, 1], [7], [6], [2, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_max_spare_cap_make(self):
        h = rb.MaxSpareCapacity(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8], [5, 2, 1], [7], [6, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_max_spare_cap_small(self):
        h = rb.MaxSpareCapacity(make_bin=lambda: self.make_bin(7))
        expected = [[5, 2], [7], [6], [4, 1]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_max_spare_cap_few(self):
        h = rb.MaxSpareCapacity(self.bins[:4])
        expected = [[8], [5, 2, 1], [7], [6, 4]]
        misfits  = []
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)


    def test_min_spare_cap_fixed(self):
        h = rb.MinSpareCapacity(self.bins)
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5], [7, 1], [6, 4], []]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_min_spare_cap_make(self):
        h = rb.MinSpareCapacity(make_bin=lambda: self.make_bin(10))
        self.assertEqual(len(self.items), h.binpack(self.items))
        expected = [[8, 2], [5], [7, 1], [6, 4]]
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)

    def test_min_spare_cap_small(self):
        h = rb.MinSpareCapacity(make_bin=lambda: self.make_bin(7))
        expected = [[5, 2], [7], [6, 1], [4]]
        misfits  = [8]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)

    def test_min_spare_cap_few(self):
        h = rb.MinSpareCapacity(self.bins[:3])
        expected = [[8, 2], [5, 4, 1], [7]]
        misfits  = [6]
        self.assertEqual(len(self.items) - len(misfits),
                         h.binpack(self.items))
        did_part = [bin.items for bin in h.bins]
        self.assertEqual(expected, did_part)
        self.assertEqual(misfits, h.misfits)