Repository: bitcoin/bitcoin
File: test/functional/test_runner.py (Python)

Code before:

For a description of arguments recognized by test scripts, see
`test/functional/test_framework/test_framework.py:BitcoinTestFramework.main`.

"""

import argparse
from collections import deque
import configparser
import datetime
import os
import platform
import time
import shutil
import signal
import subprocess
import sys
import tempfile
import re
import logging

os.environ["REQUIRE_WALLET_TYPE_SET"] = "1"

# Formatting. Default colors to empty strings.
DEFAULT, BOLD, GREEN, RED = ("", ""), ("", ""), ("", ""), ("", "")
try:
    # Make sure python thinks it can write unicode to its stdout
    "\u2713".encode("utf_8").decode(sys.stdout.encoding)
    TICK = "✓ "
    CROSS = "✖ "
    CIRCLE = "○ "
except UnicodeDecodeError:
    TICK = "P "
    CROSS = "x "
    CIRCLE = "o "

if platform.system() != 'Windows' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore
    if platform.system() == 'Windows':
        import ctypes
        kernel32 = ctypes.windll.kernel32  # type: ignore
        ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
        STD_OUTPUT_HANDLE = -11
        STD_ERROR_HANDLE = -12
        # Enable ascii color control to stdout
        stdout = kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
        stdout_mode = ctypes.c_int32()
        kernel32.GetConsoleMode(stdout, ctypes.byref(stdout_mode))
        kernel32.SetConsoleMode(stdout, stdout_mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
        # Enable ascii color control to stderr
        stderr = kernel32.GetStdHandle(STD_ERROR_HANDLE)
        stderr_mode = ctypes.c_int32()

Review comment (performance):
![2024-02-23 14-08-26_Disk_usage](https://github.com/bitcoin/bitcoin/assets/581308/aaf81e7a-6ae5-4554-92ed-b3878a09c67b)

Thanks for the monitoring script you provided earlier @BrandonOdiwuor! Was able to get disk usage almost at 5GB using:
```
$ ./test/functional/test_runner.py --cachedir=/mnt/tmp/cache --tmpdir=/mnt/tmp --extended --jobs=16
```
So maybe some heuristic could be applied when running many jobs in parallel?
Default number of jobs is 4, so maybe something like
```python
MIN_FREE_SPACE = max(jobs, 4) * 320 * 1024 * 1024
```
That way we get `1280 * 1024 * 1024` for 4 jobs or less, and `5120 * 1024 * 1024` for 16 jobs.

Code after:

For a description of arguments recognized by test scripts, see
`test/functional/test_framework/test_framework.py:BitcoinTestFramework.main`.

"""

import argparse
from collections import deque
import configparser
import datetime
import os
import platform
import time
import shutil
import signal
import subprocess
import sys
import tempfile
import re
import logging

os.environ["REQUIRE_WALLET_TYPE_SET"] = "1"

# Minimum amount of space to run the tests.
MIN_FREE_SPACE = 1.1 * 1024 * 1024 * 1024
# Additional space to run an extra job.
ADDITIONAL_SPACE_PER_JOB = 100 * 1024 * 1024
# Minimum amount of space required for --nocleanup
MIN_NO_CLEANUP_SPACE = 12 * 1024 * 1024 * 1024

# Formatting. Default colors to empty strings.
DEFAULT, BOLD, GREEN, RED = ("", ""), ("", ""), ("", ""), ("", "")
try:
    # Make sure python thinks it can write unicode to its stdout
    "\u2713".encode("utf_8").decode(sys.stdout.encoding)
    TICK = "✓ "
    CROSS = "✖ "
    CIRCLE = "○ "
except UnicodeDecodeError:
    TICK = "P "
    CROSS = "x "
    CIRCLE = "o "

if platform.system() != 'Windows' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore
    if platform.system() == 'Windows':
        import ctypes
        kernel32 = ctypes.windll.kernel32  # type: ignore
        ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
        STD_OUTPUT_HANDLE = -11
        STD_ERROR_HANDLE = -12
        # Enable ascii color control to stdout