summaryrefslogtreecommitdiff
path: root/tests/thread_pool_test.py
blob: 58a00fe39ce4764c981b3665b58c4589e5041ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.

import unittest
import gras
from gras import TestUtils
import numpy

class ThreadPoolTest(unittest.TestCase):

    def test_make_config(self):
        c = gras.ThreadPoolConfig()
        print c.thread_count
        print c.yield_strategy

    def test_make_tp(self):
        c = gras.ThreadPoolConfig()
        tp = gras.ThreadPool(c)

    def test_make_tp_set_active(self):
        c = gras.ThreadPoolConfig()
        tp = gras.ThreadPool(c)
        tp.set_active()

    def test_thread_priority(self):
        #here we assume prio 0.0 (default) can always be set
        self.assertTrue(gras.ThreadPool.test_thread_priority(0.0))

    def test_migrate_to_thread_pool(self):
        tb = gras.TopBlock()
        vec_source = TestUtils.VectorSource(numpy.uint32, [0, 9, 8, 7, 6])
        vec_sink = TestUtils.VectorSink(numpy.uint32)

        c = gras.ThreadPoolConfig()
        tp = gras.ThreadPool(c)

        vec_source.set_thread_pool(tp)
        tb.connect(vec_source, vec_sink)
        tb.run()

        self.assertEqual(vec_sink.data(), (0, 9, 8, 7, 6))

if __name__ == '__main__':
    unittest.main()