aboutsummaryrefslogtreecommitdiffstats
path: root/net/lapb/lapb_in.c
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2009-02-16 03:00:50 -0500
committerIngo Molnar <mingo@elte.hu>2009-02-16 03:37:04 -0500
commit98c061b6cf2e7a1010286a7a4f672c4623e1b3e0 (patch)
tree6ae67c63f86e7b3e46e5bcd516a93c7b9b38762a /net/lapb/lapb_in.c
parent3bd25d0fa3ed588a6735b815cb0c146c23888ace (diff)
x86: make APIC_init_uniprocessor() more like smp_prepare_cpus()
Impact: cleanup 1. move localise_nmi_watchdog() later 2. change setup_boot_APIC_clock() to setup_boot_clock() for 64-bit Signed-off-by: Yinghai Lu <yinghai@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'net/lapb/lapb_in.c')
0 files changed, 0 insertions, 0 deletions
283'>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)