1# Copyright 2022 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the 'License');
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an 'AS IS' BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import logging
16import os
17import platform
18import signal
19
20from mobly import base_test
21from mobly import signals
22from mobly import test_runner
23
24
25class TerminatedTest(base_test.BaseTestClass):
26
27  def test_terminated(self):
28    # SIGTERM handler does not work on Windows. So just simulate the behaviour
29    # for the purpose of this test.
30    if platform.system() == 'Windows':
31      logging.warning('Test received a SIGTERM. Aborting all tests.')
32      raise signals.TestAbortAll('Test received a SIGTERM.')
33    else:
34      os.kill(os.getpid(), signal.SIGTERM)
35
36
37if __name__ == '__main__':
38  test_runner.main()
39