xref: /llvm-project/llvm/utils/lit/tests/shtest-external-shell-kill.py (revision 30d77fb80857e645b300c8f59cad9414d090e083)
1fba457d7SJoel E. Denny# This test exercises an external shell use case that, at least at one time,
2fba457d7SJoel E. Denny# appeared in the following tests:
3fba457d7SJoel E. Denny#
4fba457d7SJoel E. Denny#   compiler-rt/test/fuzzer/fork-sigusr.test
5fba457d7SJoel E. Denny#   compiler-rt/test/fuzzer/merge-sigusr.test
6fba457d7SJoel E. Denny#   compiler-rt/test/fuzzer/sigint.test
7fba457d7SJoel E. Denny#   compiler-rt/test/fuzzer/sigusr.test
8fba457d7SJoel E. Denny#
9fba457d7SJoel E. Denny# That is, a RUN line can be:
10fba457d7SJoel E. Denny#
11fba457d7SJoel E. Denny#   cmd & PID=$!
12fba457d7SJoel E. Denny#
13fba457d7SJoel E. Denny# It is important that '&' only puts 'cmd' in the background and not the
14fba457d7SJoel E. Denny# debugging commands that lit inserts before 'cmd'.  Otherwise:
15fba457d7SJoel E. Denny#
16fba457d7SJoel E. Denny# - The debugging commands might execute later than they are supposed to.
17fba457d7SJoel E. Denny# - A later 'kill $PID' can kill more than just 'cmd'.  We've seen it even
18fba457d7SJoel E. Denny#   manage to terminate the shell running lit.
19fba457d7SJoel E. Denny#
20fba457d7SJoel E. Denny# The last FileCheck directive below checks that the debugging commands for the
21fba457d7SJoel E. Denny# above RUN line are not killed and do execute at the right time.
22fba457d7SJoel E. Denny
23*30d77fb8SJoel E. Denny# RUN: %{lit} -a %{inputs}/shtest-external-shell-kill | %{filter-lit} | FileCheck %s
24fba457d7SJoel E. Denny# END.
25fba457d7SJoel E. Denny
26fba457d7SJoel E. Denny#       CHECK: Command Output (stdout):
27fba457d7SJoel E. Denny#  CHECK-NEXT: --
28fba457d7SJoel E. Denny#  CHECK-NEXT: start
29fba457d7SJoel E. Denny#  CHECK-NEXT: end
30fba457d7SJoel E. Denny# CHECK-EMPTY:
31fba457d7SJoel E. Denny#  CHECK-NEXT: --
32fba457d7SJoel E. Denny#  CHECK-NEXT: Command Output (stderr):
33fba457d7SJoel E. Denny#  CHECK-NEXT: --
34fba457d7SJoel E. Denny#  CHECK-NEXT: RUN: at line 1: echo start
35fba457d7SJoel E. Denny#  CHECK-NEXT: echo start
36fba457d7SJoel E. Denny#  CHECK-NEXT: RUN: at line 2: sleep [[#]] & PID=$!
37