test_profile.py 979 Bytes
Newer Older
root's avatar
root committed
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
import unittest
from unittest import mock

from cupyx import profiler


class TestProfile(unittest.TestCase):

    def test_profile(self):
        start_patch = mock.patch('cupy_backends.cuda.libs.profiler.start')
        stop_patch = mock.patch('cupy_backends.cuda.libs.profiler.stop')
        with start_patch as start, stop_patch as stop:
            with profiler.profile():
                pass
            start.assert_called_once_with()
            stop.assert_called_once_with()

    def test_err_case(self):
        start_patch = mock.patch('cupy_backends.cuda.libs.profiler.start')
        stop_patch = mock.patch('cupy_backends.cuda.libs.profiler.stop')
        with start_patch as start, stop_patch as stop:
            try:
                with profiler.profile():
                    raise Exception()
            except Exception:
                # ignore
                pass
            start.assert_called_once_with()
            stop.assert_called_once_with()