Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Jul 16, 2024

This PR includes changes split from #30454. They improve the functional test framework, allowing users to run individual functional tests from the build directory in the new CMake-based build system.

This functionality is not available for out-of-source builds using the current Autotools-based build system, which always requires write permissions for the source directory. Nevertheless, this PR can be tested as suggested in #30463 (comment):

  1. Make an out-of-source build:
$ ./autogen.sh
$ mkdir ../build && cd ../build
$ ../bitcoin/configure
$ make
  1. Create a symlink in the build directory to a functional test:
$ ln --symbolic ../../../bitcoin/test/functional/wallet_disable.py ./test/functional/
  1. Run this symlink:
$ ./test/functional/wallet_disable.py

The last command fails on the master branch:

Traceback (most recent call last):
  File "/home/hebasto/git/build/./test/functional/wallet_disable.py", line 31, in <module>
    DisableWalletTest().main()
    ^^^^^^^^^^^^^^^^^^^
  File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 106, in __init__
    self.parse_args()
  File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 210, in parse_args
    config.read_file(open(self.options.configfile))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/hebasto/git/bitcoin/test/config.ini'

and succeeds with this PR.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 16, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, stickies-v, glozow

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30207 (validation: Improve, document and test logic for chains building on invalid blocks by mzumsande)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko
Copy link
Member

maflcko commented Jul 16, 2024

The first commit could be split up as a scripted-diff? Also, formatting:

diff --git a/test/functional/interface_http.py b/test/functional/interface_http.py
index 567aa33cbe..dbdceb52d1 100755
--- a/test/functional/interface_http.py
+++ b/test/functional/interface_http.py
@@ -109 +109 @@ if __name__ == '__main__':
-    HTTPBasicsTest(__file__).main ()
+    HTTPBasicsTest(__file__).main()
--
diff --git a/test/functional/rpc_getchaintips.py b/test/functional/rpc_getchaintips.py
index 65a9583c22..1bd4413ce1 100755
--- a/test/functional/rpc_getchaintips.py
+++ b/test/functional/rpc_getchaintips.py
@@ -61 +61 @@ if __name__ == '__main__':
-    GetChainTipsTest(__file__).main ()
+    GetChainTipsTest(__file__).main()

hebasto added 3 commits July 16, 2024 22:06
-BEGIN VERIFY SCRIPT-
sed -i -e 's/\s*().main\s*()/(__file__).main()/' $(git ls-files test/functional/*.py)
sed -i -e 's/def __init__(self)/def __init__(self, test_file)/' test/functional/test_framework/test_framework.py
-END VERIFY SCRIPT-
In CMake-based build system (1) `config.ini` is created in the build
directory, and (2) `cache` must also be created in the same directory.

This change enables running individual functional tests from the build
directory.
@hebasto
Copy link
Member Author

hebasto commented Jul 16, 2024

The first commit could be split up as a scripted-diff? Also, formatting:

diff --git a/test/functional/interface_http.py b/test/functional/interface_http.py
index 567aa33cbe..dbdceb52d1 100755
--- a/test/functional/interface_http.py
+++ b/test/functional/interface_http.py
@@ -109 +109 @@ if __name__ == '__main__':
-    HTTPBasicsTest(__file__).main ()
+    HTTPBasicsTest(__file__).main()
--
diff --git a/test/functional/rpc_getchaintips.py b/test/functional/rpc_getchaintips.py
index 65a9583c22..1bd4413ce1 100755
--- a/test/functional/rpc_getchaintips.py
+++ b/test/functional/rpc_getchaintips.py
@@ -61 +61 @@ if __name__ == '__main__':
-    GetChainTipsTest(__file__).main ()
+    GetChainTipsTest(__file__).main()

Thanks! Implemented.

@maflcko
Copy link
Member

maflcko commented Jul 17, 2024

No behaviour changes for Autotools builds.

I don't think this is true. This is a bugfix.

Previously one could not run the tests in the autotools out-of-source build dir:

$ ./test/functional/wallet_disable.py 
bash: ./test/functional/wallet_disable.py: No such file or directory
$ ln --symbolic ../../../test/functional/wallet_disable.py ./test/functional/
$ ./test/functional/wallet_disable.py 
Traceback (most recent call last):
  File "./test/functional/wallet_disable.py", line 31, in <module>
    DisableWalletTest().main()
    ^^^^^^^^^^^^^^^^^^^
  File "$srcdir/test/functional/test_framework/test_framework.py", line 106, in __init__
    self.parse_args()
  File "$srcdir/test/functional/test_framework/test_framework.py", line 210, in parse_args
    config.read_file(open(self.options.configfile))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '$srcdir/test/config.ini'

After this fix, it is possible.

Wrong: Also, the output of ./test/functional/test_runner.py --help changes, so this very much is a behavior change.

@maflcko
Copy link
Member

maflcko commented Jul 17, 2024

Concept ACK on the behavior changes and the bugfix, but please properly describe the changes.

@maflcko maflcko added this to the 28.0 milestone Jul 17, 2024
@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

@maflcko

Previously one could not run the tests in the autotools out-of-source build dir:

After this fix, it is possible.

That's true. But I did not consider this case as it requires a manual creation of a symlink to a test, which Autottols do not do, but CMake does.

@maflcko
Copy link
Member

maflcko commented Jul 17, 2024

In any case, creating the symlinks seems like a good way to test this, no?

@maflcko
Copy link
Member

maflcko commented Jul 17, 2024

Tested with the steps I provided.

tested ACK a8e3af1 🎨

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: tested ACK a8e3af1a82dd584a1cc3ffbe587e66889f72e3c 🎨
0l6ISxyQX7ey5ttupZ8f66fkchEymRF7a/bxNMR0+JttWLFMFvFkaYsxPISzikFFEUg17o1uHFGeuqHoN7xpBg==

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

In any case, creating the symlinks seems like a good way to test this, no?

Sure thing. The PR description has been updated.

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

Friendly ping @stickies-v :)

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a8e3af1

I'm able to run individual tests from an out-of-source build with the instructions provided. I tried running a bunch of other tests than wallet_disable too, including all the ones that reference __file__ and those seem to work fine too.

@maflcko
Copy link
Member

maflcko commented Jul 22, 2024

Discussions are resolved and this seems rfm with two reviews?

@glozow
Copy link
Member

glozow commented Jul 22, 2024

ACK a8e3af1, tested with the steps in op

glozow added a commit that referenced this pull request Aug 29, 2024
…#30463)

bd7ce05 test: fix `TestShell` initialization (late follow-up for #30463) (Sebastian Falbesoner)

Pull request description:

  Creating a `TestShell` instance as stated in the [docs](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test-shell.md) currently fails on master:
  ```
  $ python3
  Python 3.10.13 (main, Mar 15 2024, 07:36:23) [Clang 16.0.6 ] on openbsd7
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.path.insert(0, "/home/thestack/bitcoin/test/functional")
  >>> from test_framework.test_shell import TestShell
  >>> test = TestShell().setup(num_nodes=2, setup_clean_chain=True)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/thestack/bitcoin/test/functional/test_framework/test_shell.py", line 70, in __new__
      TestShell.instance = TestShell.__TestShell()
  TypeError: BitcoinTestFramework.__init__() missing 1 required positional argument: 'test_file'
  ```
  Since #30463, BitcoinTestFramework instances expect the path of the calling test at construction, in order to find shared data like the configuration (config.ini) and the cache. Note that in contrast to actual functional tests, we can't simply pass `__file__` here, as the test shell module sits within the `test_framework` subfolder, so we have to navigate up to the parent directory and append some dummy test file name.

  On the long-term we should probably add some TestShell instantation smoke-test to detect issues like this early. As I'm not too familiar with the CI I'm not sure what is a good way to achieve this (a functional test obviously can't be used, as that's already a BitcoinTestFramework test in itself), but happy to take suggestions.

ACKs for top commit:
  ismaelsadeeq:
    Tested ACK bd7ce05
  danielabrozzoni:
    tACK bd7ce05
  brunoerg:
    ACK bd7ce05

Tree-SHA512: c3a2365e2cda48a233ee724673c490787981354914f33e10eadbbad9c68e8403d84c5551229a611401e743886539de380ba4bfcb77032b6c85731e3bbe962dc1
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Aug 30, 2024
achow101 added a commit that referenced this pull request Sep 5, 2024
b2a1379 depends: build libevent with -D_GNU_SOURCE (fanquake)
199bb09 test: fixing failing system_tests/run_command under some Locales (Jadi)
342baab test: Avoid intermittent timeout in p2p_headers_sync_with_minchainwork.py (MarcoFalke)
5577d5a test: fix `TestShell` initialization (late follow-up for #30463) (Sebastian Falbesoner)

Pull request description:

  Backports:
  * #30714
  * #30743
  * #30761
  * #30788

ACKs for top commit:
  willcl-ark:
    ACK b2a1379
  achow101:
    ACK b2a1379
  stickies-v:
    ACK b2a1379

Tree-SHA512: bf08ac0c613395def974a1b287345d4a64edc066c14f8c9f0184478b0e33e48333760eeb6e96b6b5fbafbb21b40d01875e3f526213a2734e226b2e111d71f3a3
@bitcoin bitcoin locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

No open projects
Status: ⭐ Prerequisites

Development

Successfully merging this pull request may close these issues.

5 participants