File: test_OTF2_IdMap.py

package info (click to toggle)
otf2 3.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,000 kB
  • sloc: ansic: 92,997; python: 16,977; cpp: 9,057; sh: 6,299; makefile: 238; awk: 54
file content (95 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python

import unittest

import _otf2


def traverse(local_id, global_id, user_data):
    user_data[global_id] = local_id


class TestOTF2AnchorFile(unittest.TestCase):
    def test_1(self):
        id_map = _otf2.IdMap_Create(_otf2.ID_MAP_SPARSE, 10)
        self.assertIsNotNone(id_map)
        _otf2.IdMap_Free(id_map)

    def test_2(self):
        id_map = _otf2.IdMap_Create(_otf2.ID_MAP_SPARSE, 100)
        self.assertIsNotNone(id_map)
        _otf2.IdMap_Free(id_map)

    def test_3(self):
        id_map = _otf2.IdMap_Create(_otf2.ID_MAP_SPARSE, 6)
        self.assertIsNotNone(id_map)

        _otf2.IdMap_AddIdPair(id_map, 42, 0)
        _otf2.IdMap_AddIdPair(id_map, 13, 1)
        _otf2.IdMap_AddIdPair(id_map, 0, 2)

        array = [0, 0, 0]
        _otf2.IdMap_Traverse(id_map, traverse, array)

        self.assertEqual(42, array[0])
        self.assertEqual(13, array[1])
        self.assertEqual(0, array[2])

        _otf2.IdMap_Free(id_map)

    def test_4(self):
        mappings = [0, 5, 2, 1, 4]

        id_map = _otf2.IdMap_CreateFromUint64Array(mappings, True)
        self.assertIsNotNone(id_map)

        mode = _otf2.IdMap_GetMode(id_map)
        self.assertEqual(mode, _otf2.ID_MAP_SPARSE)

        for i in range(5):
            global_id = _otf2.IdMap_GetGlobalId(id_map, i)
            self.assertEqual(mappings[i], global_id)
        _otf2.IdMap_Free(id_map)

    def test_5(self):
        mappings = [0, 5, 2, 1, 3]

        id_map = _otf2.IdMap_CreateFromUint64Array(mappings, True)
        self.assertIsNotNone(id_map)

        mode = _otf2.IdMap_GetMode(id_map)
        self.assertEqual(mode, _otf2.ID_MAP_DENSE)

        for i in range(5):
            global_id = _otf2.IdMap_GetGlobalId(id_map, i)
            self.assertEqual(mappings[i], global_id)

        _otf2.IdMap_Free(id_map)

    def test_6(self):
        mappings = [0, 1, 2, 3, 4]

        id_map = _otf2.IdMap_CreateFromUint64Array(mappings, True)
        self.assertEqual(id_map, None)

        id_map = _otf2.IdMap_CreateFromUint64Array([], True)
        self.assertEqual(id_map, None)

    def test_7(self):
        ids = [4, 0, 2, 1, 3]

        id_map = _otf2.IdMap_Create(_otf2.ID_MAP_SPARSE, 5)
        self.assertIsNotNone(id_map)

        for i in range(5):
            _otf2.IdMap_AddIdPair(id_map, ids[i], ids[i])

        for i in range(5):
            global_id = _otf2.IdMap_GetGlobalId(id_map, i)
            self.assertEqual(i, global_id)

        _otf2.IdMap_Free(id_map)


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