Page MenuHomePhabricator

test: fix creation of std::string objects with \0s
ClosedPublic

Authored by PiRK on Jan 10 2022, 16:48.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC952efc13f0d1: test: fix creation of std::string objects with \0s
Summary

A string literal "abc" contains a terminating \0, so that is 4
bytes. There is no need to write "abc\0" unless two terminating
\0s are necessary.

std::string objects do not internally contain a terminating \0, so
std::string("abc") creates a string with size 3 and is the same as
std::string("abc", 3).

In "\01" the 01 part is interpreted as one number (1) and that is
the same as "\1" which is a string like {1, 0} whereas "\0z" is a
string like {0, 'z', 0}. To create a string like {0, '1', 0} one
must use "\0" "1".

Adjust the tests accordingly.

This is a backport of core#20000

Test Plan

ninja check

Event Timeline

PiRK requested review of this revision.Jan 10 2022, 16:48

Tail of the build log:

wallet_reorgsrestore.py                   | ○ Skipped | 0 s
wallet_resendwallettransactions.py        | ○ Skipped | 0 s
wallet_send.py                            | ○ Skipped | 0 s
wallet_startup.py                         | ○ Skipped | 0 s
wallet_txn_clone.py                       | ○ Skipped | 0 s
wallet_txn_clone.py --mineblock           | ○ Skipped | 0 s
wallet_txn_doublespend.py                 | ○ Skipped | 0 s
wallet_txn_doublespend.py --mineblock     | ○ Skipped | 0 s
wallet_watchonly.py                       | ○ Skipped | 0 s
wallet_watchonly.py --usecli              | ○ Skipped | 0 s

ALL                                       | ✓ Passed  | 546 s (accumulated) 
Runtime: 110 s

----------------------------------------------------------------------
Ran 10 tests in 0.132s

OK

[27/416] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
[28/416] cd /work/contrib/devtools/chainparams && /usr/bin/python3.7 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[118/416] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/script_tests.cpp.o
In file included from /usr/include/boost/test/unit_test.hpp:19,
                 from ../../src/test/script_tests.cpp:30:
../../src/test/script_tests.cpp: In member function ‘void script_tests::script_build::test_method()’:
../../src/test/script_tests.cpp:540:22: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without
 BOOST_AUTO_TEST_CASE(script_build) {
                      ^~~~~~~~~~~~
[163/416] Running seeder test suite
PASSED: seeder test suite
[166/416] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o
FAILED: src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DBOOST_AC_USE_STD_ATOMIC -DBOOST_SP_USE_STD_ATOMIC -DBOOST_TEST_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/univalue/include -I../../src/. -Isrc -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIE -fvisibility=hidden -fstack-reuse=none -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o -MF src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o.d -o src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o -c ../../src/test/base58_tests.cpp
../../src/test/base58_tests.cpp:20:17: error: redundant redeclaration of ‘UniValue read_json(const string&)’ in same scope [-Werror=redundant-decls]
 extern UniValue read_json(const std::string &jsondata);
                 ^~~~~~~~~
In file included from ../../src/test/base58_tests.cpp:8:
../../src/./test/jsonutil.h:11:10: note: previous declaration of ‘UniValue read_json(const string&)’
 UniValue read_json(const std::string &jsondata);
          ^~~~~~~~~
cc1plus: all warnings being treated as errors
[172/416] Running pow test suite
PASSED: pow test suite
[175/416] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[192/416] Running avalanche test suite
PASSED: avalanche test suite
[193/416] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/util_tests.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-without-wallet failed with exit code 1

Tail of the build log:

wallet_listreceivedby.py                  | ✓ Passed  | 19 s
wallet_listsinceblock.py                  | ✓ Passed  | 6 s
wallet_listsinceblock.py --descriptors    | ✓ Passed  | 9 s
wallet_listtransactions.py                | ✓ Passed  | 10 s
wallet_listtransactions.py --descriptors  | ✓ Passed  | 14 s
wallet_multiwallet.py --usecli            | ✓ Passed  | 17 s
wallet_reorgsrestore.py                   | ✓ Passed  | 4 s
wallet_resendwallettransactions.py        | ✓ Passed  | 4 s
wallet_send.py                            | ✓ Passed  | 8 s
wallet_startup.py                         | ✓ Passed  | 3 s
wallet_txn_clone.py                       | ✓ Passed  | 3 s
wallet_txn_clone.py --mineblock           | ✓ Passed  | 4 s
wallet_txn_doublespend.py                 | ✓ Passed  | 3 s
wallet_txn_doublespend.py --mineblock     | ✓ Passed  | 4 s
wallet_watchonly.py                       | ✓ Passed  | 1 s
wallet_watchonly.py --usecli              | ✓ Passed  | 2 s

ALL                                       | ✓ Passed  | 1503 s (accumulated) 
Runtime: 301 s

----------------------------------------------------------------------
Ran 10 tests in 0.160s

OK

[27/456] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
[29/456] cd /work/contrib/devtools/chainparams && /usr/bin/python3.7 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[68/456] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o
FAILED: src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DABORT_ON_FAILED_ASSUME -DBOOST_AC_USE_STD_ATOMIC -DBOOST_SP_USE_STD_ATOMIC -DBOOST_TEST_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DDEBUG -DDEBUG_LOCKORDER -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/univalue/include -I../../src/. -Isrc -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -O0 -fPIE -fvisibility=hidden -g3 -ftrapv -fstack-reuse=none -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o -MF src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o.d -o src/test/CMakeFiles/test_bitcoin.dir/base58_tests.cpp.o -c ../../src/test/base58_tests.cpp
../../src/test/base58_tests.cpp:20:17: error: redundant redeclaration of ‘UniValue read_json(const string&)’ in same scope [-Werror=redundant-decls]
 extern UniValue read_json(const std::string &jsondata);
                 ^~~~~~~~~
In file included from ../../src/test/base58_tests.cpp:8:
../../src/./test/jsonutil.h:11:10: note: previous declaration of ‘UniValue read_json(const string&)’
 UniValue read_json(const std::string &jsondata);
          ^~~~~~~~~
cc1plus: all warnings being treated as errors
[196/456] Running seeder test suite
PASSED: seeder test suite
[207/456] Running avalanche test suite
PASSED: avalanche test suite
[210/456] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[213/456] Running pow test suite
PASSED: pow test suite
[215/456] Running secp256k1 test suite
PASSED: secp256k1 test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

Tail of the build log:

tool_wallet.py --descriptors              | ✓ Passed  | 2 s
wallet_abandonconflict.py                 | ✓ Passed  | 6 s
wallet_address_types.py                   | ✓ Passed  | 12 s
wallet_address_types.py --descriptors     | ✓ Passed  | 8 s
wallet_avoidreuse.py                      | ✓ Passed  | 5 s
wallet_avoidreuse.py --descriptors        | ✓ Passed  | 6 s
wallet_backup.py                          | ✓ Passed  | 30 s
wallet_balance.py                         | ✓ Passed  | 20 s
wallet_balance.py --descriptors           | ✓ Passed  | 20 s
wallet_basic.py                           | ✓ Passed  | 26 s
wallet_coinbase_category.py               | ✓ Passed  | 1 s
wallet_create_tx.py                       | ✓ Passed  | 5 s
wallet_createwallet.py                    | ✓ Passed  | 2 s
wallet_createwallet.py --descriptors      | ✓ Passed  | 2 s
wallet_createwallet.py --usecli           | ✓ Passed  | 2 s
wallet_descriptor.py                      | ✓ Passed  | 7 s
wallet_disable.py                         | ✓ Passed  | 1 s
wallet_dump.py                            | ✓ Passed  | 5 s
wallet_encryption.py                      | ✓ Passed  | 5 s
wallet_encryption.py --descriptors        | ✓ Passed  | 5 s
wallet_hd.py                              | ✓ Passed  | 6 s
wallet_hd.py --descriptors                | ✓ Passed  | 5 s
wallet_import_rescan.py                   | ✓ Passed  | 5 s
wallet_import_with_label.py               | ✓ Passed  | 1 s
wallet_importdescriptors.py               | ✓ Passed  | 5 s
wallet_importmulti.py                     | ✓ Passed  | 3 s
wallet_importprunedfunds.py               | ✓ Passed  | 2 s
wallet_importprunedfunds.py --descriptors | ✓ Passed  | 2 s
wallet_keypool.py                         | ✓ Passed  | 3 s
wallet_keypool_topup.py                   | ✓ Passed  | 2 s
wallet_keypool_topup.py --descriptors     | ✓ Passed  | 3 s
wallet_labels.py                          | ✓ Passed  | 2 s
wallet_labels.py --descriptors            | ✓ Passed  | 1 s
wallet_listreceivedby.py                  | ✓ Passed  | 19 s
wallet_listsinceblock.py                  | ✓ Passed  | 4 s
wallet_listsinceblock.py --descriptors    | ✓ Passed  | 8 s
wallet_listtransactions.py                | ✓ Passed  | 25 s
wallet_listtransactions.py --descriptors  | ✓ Passed  | 5 s
wallet_multiwallet.py --usecli            | ✓ Passed  | 11 s
wallet_reorgsrestore.py                   | ✓ Passed  | 3 s
wallet_resendwallettransactions.py        | ✓ Passed  | 13 s
wallet_send.py                            | ✓ Passed  | 7 s
wallet_startup.py                         | ✓ Passed  | 2 s
wallet_txn_clone.py                       | ✓ Passed  | 2 s
wallet_txn_clone.py --mineblock           | ✓ Passed  | 3 s
wallet_txn_doublespend.py                 | ✓ Passed  | 1 s
wallet_txn_doublespend.py --mineblock     | ✓ Passed  | 3 s
wallet_watchonly.py                       | ✓ Passed  | 1 s
wallet_watchonly.py --usecli              | ✓ Passed  | 1 s

ALL                                       | ✓ Passed  | 1105 s (accumulated) 
Runtime: 221 s

----------------------------------------------------------------------
Ran 10 tests in 0.094s

OK

ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1
PiRK planned changes to this revision.Jan 11 2022, 07:28
PiRK edited the test plan for this revision. (Show Details)

Fix a rebase accident causing a compiler warning (redundant redeclaration of ‘UniValue read_json(const string&)’ in same scope).
Add missing changes in netbase_tests.cpp
Simpler test plan (only unit tests)

This revision is now accepted and ready to land.Jan 11 2022, 10:25