Пример #1
0
    def test_open_multi_object(self):
        """
        Test opening an multiple objects from a blank slate
        """
        sim = get_mock_simulation()

        sim.replicas = [
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE)
        ]

        work = MobileWorkload(sim, objects=["A", "B", "C", "D", "E"])
        self.assertEqual(len(work.objects), 5)
        self.assertEqual(work.objects, ["A", "B", "C", "D", "E"])

        self.assertIsNotNone(work.location)
        self.assertIsNotNone(work.device)
        self.assertIsNotNone(work.current)

        for idx in xrange(500):
            work.update()
            self.assertIsNotNone(work.current)
            self.assertEqual(len(work.objects), 5)
            self.assertLessEqual(len(filter(None, work.objects)), 5)
Пример #2
0
    def test_workload(self):
        """
        Test the workload generating work in simulation
        """

        sim = get_mock_simulation()
        sim.env = simpy.Environment()

        sim.replicas = [
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE)
        ]

        work = MobileWorkloadTests(
            sim, move_prob=1.0, switch_prob=1.0, read_prob=0.5,
            access_mean=20, access_stddev=4, objects=["A", "B", "C", "D", "E"]
        )

        env.run(until=1000)

        calls = sum(replica.write.call_count for replica in sim.replicas)
        calls += sum(replica.read.call_count for replica in sim.replicas)
        self.assertGreater(calls, 25)
Пример #3
0
    def test_name(self):
        """
        Test the workload name (as a user)
        """
        sim  = get_mock_simulation()
        work = MobileWorkload(sim, objects=['A', 'B', 'C'])

        self.assertEqual(work.name, "user 1")
Пример #4
0
    def setUp(self):
        """
        Sets up the environment and the workload class.
        """
        sim = get_mock_simulation()
        sim.env = simpy.Environment()
        device  = random.choice(sim.replicas)

        self.klass.counter.reset()
        self.work = self.klass(sim, device=device, objects=self.objects)
Пример #5
0
    def setUp(self):
        """
        Sets up the environment and the workload class.
        """
        sim = get_mock_simulation()
        sim.env = simpy.Environment()
        device = random.choice(sim.replicas)

        self.klass.counter.reset()
        self.work = self.klass(sim, device=device, objects=self.objects)
Пример #6
0
    def test_objects_int(self):
        """
        Ensure multi-object workload can be initialized with int
        """
        sim  = get_mock_simulation()
        work = MobileWorkload(sim, objects=20)

        self.assertEqual(len(work.objects), 20)
        self.assertEqual(work.objects, tuple([
            char for char in CharacterSequence(limit="U", upper=True)
        ]))
Пример #7
0
    def test_objects_list(self):
        """
        Ensure multi-objects workload can be initialized with a list
        """
        sim  = get_mock_simulation()
        work = MobileWorkload(sim, objects=[
            "foo", "bar", "baz", "qux", "zoo",
        ])

        self.assertEqual(len(work.objects), 5)
        self.assertEqual(work.objects, [
            "foo", "bar", "baz", "qux", "zoo",
        ])
Пример #8
0
    def test_locations(self):
        """
        Test the workload extracting locations from simulation
        """
        sim = get_mock_simulation()

        sim.replicas = [
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.HOME),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.WORK),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE),
            get_mock_replica(sim, location=Location.MOBILE)
        ]

        work = MobileWorkload(sim, objects=['A', 'B', 'C'])
        self.assertEqual(len(work.locations), 3)

        for loc, num in ((Location.HOME, 2), (Location.WORK, 2), (Location.MOBILE, 3)):
            self.assertEqual(len(work.locations[loc]), num)
Пример #9
0
    def test_workload(self):
        """
        Test the workload generating work in simulation
        """

        sim = get_mock_simulation()
        sim.env = simpy.Environment()

        sim.replicas = [
            get_mock_replica(sim, id="r0", location=Location.HOME),
            get_mock_replica(sim, id="r1", location=Location.MOBILE),
        ]

        # set up the access tracking
        for replica in sim.replicas:
            replica.read = AccessTracking(sim.env)
            replica.write = AccessTracking(sim.env)

        work = TracesWorkload(TRACES, sim)
        sim.env.run(until=2000)

        writes = sum(replica.write.call_count for replica in sim.replicas)
        reads = sum(replica.read.call_count for replica in sim.replicas)
        self.assertEqual(reads, 6)
        self.assertEqual(writes, 12)

        devices = {device.id: device for device in sim.replicas}

        for access in work.reader:
            device = devices[access.replica]
            method = None

            if access.method == READ:
                method = device.read

            if access.method == WRITE:
                method = device.write

            self.assertIn(access.timestep, method.history)
            method.mock.assert_any_call(access.object)
Пример #10
0
    def test_workload(self):
        """
        Test the workload generating work in simulation
        """

        sim = get_mock_simulation()
        sim.env = simpy.Environment()

        sim.replicas = [
            get_mock_replica(sim, id="r0", location=Location.HOME),
            get_mock_replica(sim, id="r1", location=Location.MOBILE),
        ]

        # set up the access tracking
        for replica in sim.replicas:
            replica.read = AccessTracking(sim.env)
            replica.write = AccessTracking(sim.env)

        work = TracesWorkload(TRACES, sim)
        sim.env.run(until=2000)

        writes = sum(replica.write.call_count for replica in sim.replicas)
        reads = sum(replica.read.call_count for replica in sim.replicas)
        self.assertEqual(reads, 6)
        self.assertEqual(writes, 12)

        devices = {device.id: device for device in sim.replicas}

        for access in work.reader:
            device = devices[access.replica]
            method = None

            if access.method == READ:
                method = device.read

            if access.method == WRITE:
                method = device.write

            self.assertIn(access.timestep, method.history)
            method.mock.assert_any_call(access.object)
Пример #11
0
 def setUp(self):
     self.File = get_object()
     self.name = self.File.__name__
     self.sim  = get_mock_simulation()
     self.replica = random.choice(self.sim.replicas)
Пример #12
0
 def setUp(self):
     self.File = get_object()
     self.name = self.File.__name__
     self.sim = get_mock_simulation()
     self.replica = random.choice(self.sim.replicas)