| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os |
| 6 |
import signal |
| 7 |
import sys |
| 8 |
import pytest |
| 9 |
from scalene.scalene_profiler import Scalene |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
@pytest.fixture |
| 16 |
def scalene_cleanup(): |
| 17 |
|
| 18 |
yield |
| 19 |
|
| 20 |
for sig in Scalene.__signals.get_all_signals(): |
| 21 |
signal.signal(sig, signal.SIG_DFL) |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.skipif( |
| 25 |
sys.platform != "win32", reason="Test only applicable to win32 platform" |
| 26 |
) |
| 27 |
def test_enable_signals_win32(scalene_cleanup): |
| 28 |
|
| 29 |
Scalene.__signals = type( |
| 30 |
"Signals", |
| 31 |
(), |
| 32 |
{ |
| 33 |
"malloc_signal": signal.SIGINT, |
| 34 |
"free_signal": signal.SIGINT, |
| 35 |
"memcpy_signal": signal.SIGINT, |
| 36 |
"cpu_signal": signal.SIGINT, |
| 37 |
"cpu_timer_signal": signal.ITIMER_REAL, |
| 38 |
"get_all_signals": staticmethod(lambda: [signal.SIGINT]), |
| 39 |
}, |
| 40 |
) |
| 41 |
Scalene.__args = type("Args", (), {"cpu_sampling_rate": 0.01}) |
| 42 |
Scalene.__orig_signal = staticmethod(signal.signal) |
| 43 |
Scalene.__orig_siginterrupt = staticmethod(signal.siginterrupt) |
| 44 |
Scalene.__orig_setitimer = staticmethod(signal.setitimer) |
| 45 |
|
| 46 |
|
| 47 |
Scalene.enable_signals_win32 = staticmethod(lambda: None) |
| 48 |
|
| 49 |
|
| 50 |
Scalene.enable_signals() |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
assert Scalene.enable_signals_win32.called |