|
| 1 | +# REQUIRES: python, system-windows |
| 2 | +# RUN: %python %s %lldb-dap > %t.out 2>&1 |
| 3 | +# RUN: FileCheck %s --check-prefix=ERROR --allow-empty < %t.out |
| 4 | + |
| 5 | +# ERROR-NOT: DAP session error: |
| 6 | + |
| 7 | +# Test that we can successfully start the dap server from the console on Windows. |
| 8 | + |
| 9 | +import sys |
| 10 | +import subprocess |
| 11 | +import os |
| 12 | + |
| 13 | +lldb_dap_path = sys.argv[1] |
| 14 | +if lldb_dap_path.startswith('%'): |
| 15 | + lldb_dap_path = lldb_dap_path[1:] |
| 16 | +lldb_dap_path = os.path.normpath(lldb_dap_path) |
| 17 | + |
| 18 | +import ctypes |
| 19 | +from ctypes import wintypes |
| 20 | +import msvcrt |
| 21 | + |
| 22 | +GENERIC_READ = 0x80000000 |
| 23 | +GENERIC_WRITE = 0x40000000 |
| 24 | +OPEN_EXISTING = 3 |
| 25 | +FILE_SHARE_READ = 0x00000001 |
| 26 | +FILE_SHARE_WRITE = 0x00000002 |
| 27 | + |
| 28 | +kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) |
| 29 | + |
| 30 | +conin_handle = kernel32.CreateFileW( |
| 31 | + "CONIN$", |
| 32 | + GENERIC_READ | GENERIC_WRITE, |
| 33 | + FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 34 | + None, |
| 35 | + OPEN_EXISTING, |
| 36 | + 0, |
| 37 | + None |
| 38 | +) |
| 39 | + |
| 40 | +if conin_handle == -1: |
| 41 | + print("Failed to open CONIN$", file=sys.stderr) |
| 42 | + sys.exit(1) |
| 43 | + |
| 44 | +conin_fd = msvcrt.open_osfhandle(conin_handle, os.O_RDONLY) |
| 45 | + |
| 46 | +proc = subprocess.Popen( |
| 47 | + [lldb_dap_path], |
| 48 | + stdin=conin_fd, |
| 49 | + stdout=subprocess.PIPE, |
| 50 | + stderr=subprocess.STDOUT |
| 51 | +) |
| 52 | + |
| 53 | +os.close(conin_fd) |
| 54 | + |
| 55 | +try: |
| 56 | + output, _ = proc.communicate(timeout=2) |
| 57 | +except subprocess.TimeoutExpired: |
| 58 | + proc.kill() |
| 59 | + output, _ = proc.communicate() |
| 60 | + |
| 61 | +sys.stdout.buffer.write(output) |
| 62 | +sys.stdout.flush() |
0 commit comments