diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-24 12:41:26 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-24 19:51:34 +0000 |
commit | 5c2600d87bd000b32b2a37c5a74275912ddd5328 (patch) | |
tree | 82ddac9827ff05735bdf7b8a24531333a3c611db | |
parent | 8e00294b3cb9808ce55160240454359638178275 (diff) |
Add new Circle CI configuration.
This one has ASAN enabled, unlike Travis.
-rw-r--r-- | .circleci/config.yml | 22 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | auto_tests/TCP_test.c | 2 | ||||
-rw-r--r-- | auto_tests/messenger_test.c | 2 | ||||
-rw-r--r-- | auto_tests/network_test.c | 3 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 8 | ||||
-rw-r--r-- | circle.yml | 148 | ||||
-rw-r--r-- | testing/random_testing.cc | 255 | ||||
-rw-r--r-- | toxcore/network.c | 2 |
9 files changed, 161 insertions, 282 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..3e6f293e --- /dev/null +++ b/.circleci/config.yml | |||
@@ -0,0 +1,22 @@ | |||
1 | version: 2 | ||
2 | |||
3 | workflows: | ||
4 | version: 2 | ||
5 | build_linux: | ||
6 | jobs: | ||
7 | - x86_64 | ||
8 | |||
9 | jobs: | ||
10 | x86_64: | ||
11 | working_directory: ~/work | ||
12 | docker: | ||
13 | - image: circleci/builder-base:latest | ||
14 | |||
15 | steps: | ||
16 | - checkout | ||
17 | - run: add-apt-repository ppa:chris-lea/libsodium | ||
18 | - run: apt update | ||
19 | - run: apt install -y clang cmake libgtest-dev libopus-dev libsodium-dev libvpx-dev pkg-config | ||
20 | - run: cmake -H. -B_build -DDEBUG=ON -DTRACE=ON -DERROR_ON_WARNING=ON -DASAN=ON -DMUST_BUILD_TOXAV=ON -DSTRICT_ABI=ON -DTEST_TIMEOUT_SECONDS=90 -DUSE_IPV6=OFF | ||
21 | - run: make -C _build -j$(nproc) | ||
22 | - run: make -C _build test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make -C _build test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt index a96e311f..613297ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -176,6 +176,7 @@ if(NOT MSVC) | |||
176 | add_cxxflag("-Wno-old-style-cast") | 176 | add_cxxflag("-Wno-old-style-cast") |
177 | 177 | ||
178 | # Downgrade to warning so we still see it. | 178 | # Downgrade to warning so we still see it. |
179 | add_flag("-Wno-error=unreachable-code") | ||
179 | add_flag("-Wno-error=unused-variable") | 180 | add_flag("-Wno-error=unused-variable") |
180 | endif() | 181 | endif() |
181 | endif() | 182 | endif() |
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index f86518b1..2db46602 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -45,7 +45,7 @@ static inline IP get_loopback() | |||
45 | return ip; | 45 | return ip; |
46 | } | 46 | } |
47 | 47 | ||
48 | static uint16_t ports[NUM_PORTS] = {1234, 33445, 25643}; | 48 | static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643}; |
49 | 49 | ||
50 | START_TEST(test_basic) | 50 | START_TEST(test_basic) |
51 | { | 51 | { |
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index bf3ea179..d7344f4d 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -355,6 +355,8 @@ int main(void) | |||
355 | /* IPv6 status from global define */ | 355 | /* IPv6 status from global define */ |
356 | Messenger_Options options = {0}; | 356 | Messenger_Options options = {0}; |
357 | options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 357 | options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; |
358 | options.port_range[0] = 41234; | ||
359 | options.port_range[1] = 44234; | ||
358 | options.log_callback = (logger_cb *)print_debug_log; | 360 | options.log_callback = (logger_cb *)print_debug_log; |
359 | m = new_messenger(&options, nullptr); | 361 | m = new_messenger(&options, nullptr); |
360 | 362 | ||
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 0abd14a4..f9de94f9 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -93,7 +93,8 @@ START_TEST(test_addr_resolv_localhost) | |||
93 | extra.family.value); | 93 | extra.family.value); |
94 | ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", | 94 | ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", |
95 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 95 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
96 | #else | 96 | #elif 0 |
97 | // TODO(iphydf): Fix this to work on IPv6-supporting systems. | ||
97 | ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET (%d), got %u.", TOX_AF_INET, ip.family.value); | 98 | ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET (%d), got %u.", TOX_AF_INET, ip.family.value); |
98 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", | 99 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", |
99 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 100 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index c60d3e1a..77dc7c49 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -167,8 +167,8 @@ START_TEST(test_basic) | |||
167 | logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]); | 167 | logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]); |
168 | 168 | ||
169 | IP ip = get_loopback(); | 169 | IP ip = get_loopback(); |
170 | Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 34567), true)); | 170 | Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 36567), true)); |
171 | Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 34568), true)); | 171 | Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 36568), true)); |
172 | ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing."); | 172 | ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing."); |
173 | networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2); | 173 | networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2); |
174 | 174 | ||
@@ -256,7 +256,7 @@ START_TEST(test_basic) | |||
256 | Logger *log3 = logger_new(); | 256 | Logger *log3 = logger_new(); |
257 | logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]); | 257 | logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]); |
258 | 258 | ||
259 | Onion *onion3 = new_onion(new_DHT(log3, new_networking(log3, ip, 34569), true)); | 259 | Onion *onion3 = new_onion(new_DHT(log3, new_networking(log3, ip, 36569), true)); |
260 | ck_assert_msg((onion3 != nullptr), "Onion failed initializing."); | 260 | ck_assert_msg((onion3 != nullptr), "Onion failed initializing."); |
261 | 261 | ||
262 | random_nonce(nonce); | 262 | random_nonce(nonce); |
@@ -478,7 +478,7 @@ START_TEST(test_announce) | |||
478 | 478 | ||
479 | for (i = 0; i < NUM_ONIONS; ++i) { | 479 | for (i = 0; i < NUM_ONIONS; ++i) { |
480 | index[i] = i + 1; | 480 | index[i] = i + 1; |
481 | onions[i] = new_onions(i + 34655, &index[i]); | 481 | onions[i] = new_onions(i + 36655, &index[i]); |
482 | ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i); | 482 | ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i); |
483 | } | 483 | } |
484 | 484 | ||
diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 9e0ef321..00000000 --- a/circle.yml +++ /dev/null | |||
@@ -1,148 +0,0 @@ | |||
1 | compile: | ||
2 | override: | ||
3 | - "echo 'TODO(zoff99): fix compile'" | ||
4 | |||
5 | test: | ||
6 | override: | ||
7 | - "echo 'TODO(zoff99): fix compile'" | ||
8 | |||
9 | #machine: | ||
10 | # environment: | ||
11 | # MAKEFLAGS: "j4" | ||
12 | ## --- Android build --- | ||
13 | # _toolchain_: "/home/ubuntu/c-toxcore/toolchains/" | ||
14 | # _s_: "/home/ubuntu/c-toxcore/src/" | ||
15 | # AND_PATH: "$_toolchain_/arm-linux-androideabi/bin:$PATH" | ||
16 | # AND_PKG_CONFIG_PATH: "$_toolchain_/arm-linux-androideabi/sysroot/usr/lib/pkgconfig" | ||
17 | # AND_CC: "$_toolchain_/arm-linux-androideabi/bin/arm-linux-androideabi-clang" | ||
18 | # AND_CXX: "$_toolchain_/arm-linux-androideabi/bin/arm-linux-androideabi-clang++" | ||
19 | ## --- Android build --- | ||
20 | #dependencies: | ||
21 | # pre: | ||
22 | # - sudo apt-get update | ||
23 | # - sudo bash -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' >> /etc/apt/sources.list" # add backports repo | ||
24 | # - sudo apt-get update | ||
25 | # - sudo apt-get install astyle/trusty-backports | ||
26 | # - sudo apt-get install clang | ||
27 | # - sudo apt-get install build-essential libtool autotools-dev automake checkinstall git yasm | ||
28 | # - sudo apt-get install libopus-dev libvpx-dev pkg-config | ||
29 | # | ||
30 | ## ------------ network_test requires that "localhost" resolves to ::1 ------------ | ||
31 | # - sudo bash -c "echo '::1 localhost ipv6-localhost ipv6-loopback' >> /etc/hosts" # ipv6 localhost entry | ||
32 | ## ------------ network_test requires that "localhost" resolves to ::1 ------------ | ||
33 | # | ||
34 | # - sudo bash -c "echo /usr/local/lib/x86_64-linux-gnu > /etc/ld.so.conf.d/fix685519.conf" # fix https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685519 | ||
35 | # | ||
36 | # - java -version ; exit 0 | ||
37 | # - gcc --version ; exit 0 | ||
38 | # - clang --version ; exit 0 | ||
39 | # - astyle --version ; exit 0 | ||
40 | # | ||
41 | #compile: | ||
42 | # override: | ||
43 | # ### ----- check code style ------ | ||
44 | # - cd .. ; cp -av c-toxcore ./astyle_check/ | ||
45 | # - cd ../astyle_check/ ; ls -al other/astyle/astylerc | ||
46 | # - cd ../astyle_check/ ; | ||
47 | # SOURCES=`find . -name "*.[ch]" -and -not -name "*.api.h" -and -not -wholename "*crypto_pwhash*" -and -not -wholename "./super_donators/*"|sort`; | ||
48 | # astyle -n --options=other/astyle/astylerc $SOURCES ; exit 0 | ||
49 | # - cd ../astyle_check/ ; git --no-pager diff | ||
50 | # - cd ../astyle_check/ ; git diff | cat > $CIRCLE_ARTIFACTS/astyle_check.patch 2>&1 | ||
51 | # ### ----- check code style ------ | ||
52 | # | ||
53 | # ### ------- get libsodium ------- | ||
54 | # - mkdir ~/libsodium | ||
55 | # - cd ~/libsodium/ ; git clone https://github.com/jedisct1/libsodium.git | ||
56 | # - cd ~/libsodium/ ; cd libsodium/ ; git checkout tags/1.0.11 | ||
57 | # - cd ~/libsodium/ ; cd libsodium/ ; ./autogen.sh | ||
58 | # - cd ~/libsodium/ ; cd libsodium/ ; ./configure && make check | ||
59 | # - cd ~/libsodium/ ; cd libsodium/ ; sudo bash -c "printf 'y\naa\n\n' | checkinstall --install --pkgname libsodium --pkgversion 1.0.0 --nodoc --deldesc=no --pkglicense='GPL2'" | ||
60 | # - cd ~/libsodium/ ; cd libsodium/ ; sudo ldconfig | ||
61 | # ### ------- get libsodium ------- | ||
62 | # | ||
63 | ###### ------------ BUILD ------------ | ||
64 | # - cmake -DASAN=ON -DDEBUG=ON -DSTRICT_ABI=ON -DTRACE=ON -DWARNINGS=OFF . | ||
65 | # #- cmake . | ||
66 | # - make | ||
67 | # - sudo make install | ||
68 | # - sudo ldconfig -v 2>/dev/null | grep toxcore | ||
69 | # - sudo ldconfig -v 2>/dev/null | grep sodium | ||
70 | ###### ------------ BUILD ------------ | ||
71 | # | ||
72 | ## --- Android build --- | ||
73 | # - echo 'export PATH="$AND_PATH";export PKG_CONFIG_PATH="$AND_PKG_CONFIG_PATH";export CC="$AND_CC";export CXX="$AND_CXX";export CPPFLAGS="";export LDFLAGS=""' > ~/pp | ||
74 | # - chmod u+x ~/pp | ||
75 | # - mkdir -p "$_s_" | ||
76 | # | ||
77 | # - rm -Rf /home/ubuntu/install_dest/ ; mkdir -p /home/ubuntu/install_dest/ | ||
78 | # - mkdir -p $CIRCLE_ARTIFACTS/android/ | ||
79 | # | ||
80 | # | ||
81 | # - . ~/pp;mkdir -p "$PKG_CONFIG_PATH" | ||
82 | # - . ~/pp;curl -s http://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip -o android-ndk-r13b-linux-x86_64.zip | ||
83 | # - . ~/pp;unzip android-ndk-r13b-linux-x86_64.zip | ||
84 | # - . ~/pp;mv -v /home/ubuntu/c-toxcore/android-ndk-r13b /home/ubuntu/android-ndk | ||
85 | # - . ~/pp;/home/ubuntu/android-ndk/build/tools/make_standalone_toolchain.py --arch arm --install-dir "$_toolchain_"/arm-linux-androideabi --api 12 --force | ||
86 | # | ||
87 | # - . ~/pp;cd $_s_;git clone --depth=1 --branch=v1.3.0 https://github.com/yasm/yasm.git | ||
88 | # - . ~/pp;cd $_s_/yasm/;autoreconf -fi | ||
89 | # - . ~/pp;rm -Rf ~/build/ | ||
90 | # - . ~/pp;mkdir -p ~/build/ | ||
91 | # - . ~/pp;cd ~/build/;$_s_/yasm/configure --prefix="$_toolchain_"/arm-linux-androideabi/sysroot/usr --disable-shared --disable-soname-versions --host=arm-linux-androideabi --with-sysroot="$_toolchain_"/arm-linux-androideabi/sysroot | ||
92 | # - . ~/pp;cd ~/build/;make -j4 | ||
93 | # - . ~/pp;cd ~/build/;make install | ||
94 | # | ||
95 | # | ||
96 | # - . ~/pp;cd $_s_;git clone --depth=1 --branch=v1.6.0 https://github.com/webmproject/libvpx.git | ||
97 | # - . ~/pp;rm -Rf ~/build/ | ||
98 | # - . ~/pp;mkdir -p ~/build/ | ||
99 | # - . ~/pp;cd ~/build/;$_s_/libvpx/configure --prefix="$_toolchain_"/arm-linux-androideabi/sysroot/usr --disable-examples --disable-unit-tests --sdk-path=/home/ubuntu/android-ndk --target=armv7-android-gcc | ||
100 | # - . ~/pp;cd ~/build/;make -j4 | ||
101 | # - . ~/pp;cd ~/build/;make install | ||
102 | # - . ~/pp;cd ~/build/;make clean | ||
103 | # - rm -Rf /home/ubuntu/install_dest/ ; mkdir -p /home/ubuntu/install_dest/ | ||
104 | # - . ~/pp;cd ~/build/;make DESTDIR=/home/ubuntu/install_dest/ install | ||
105 | # - cd /home/ubuntu/install_dest/ ; cd home/ubuntu/c-toxcore/toolchains/arm-linux-androideabi/sysroot/ ; zip -r $CIRCLE_ARTIFACTS/android/libvpx.zip * | ||
106 | # | ||
107 | # | ||
108 | # - . ~/pp;cd $_s_;git clone --depth=1 --branch=v1.1.3 https://github.com/xiph/opus.git | ||
109 | # - . ~/pp;cd $_s_/opus/;autoreconf -fi | ||
110 | # - . ~/pp;rm -Rf ~/build/ | ||
111 | # - . ~/pp;mkdir -p ~/build/ | ||
112 | # - . ~/pp;cd ~/build/;$_s_/opus/configure --prefix="$_toolchain_"/arm-linux-androideabi/sysroot/usr --disable-shared --disable-soname-versions --host=arm-linux-androideabi --with-sysroot="$_toolchain_"/arm-linux-androideabi/sysroot | ||
113 | # - . ~/pp;cd ~/build/;make -j4 | ||
114 | # - . ~/pp;cd ~/build/;make install | ||
115 | # - . ~/pp;cd ~/build/;make clean | ||
116 | # - rm -Rf /home/ubuntu/install_dest/ ; mkdir -p /home/ubuntu/install_dest/ | ||
117 | # - . ~/pp;cd ~/build/;make DESTDIR=/home/ubuntu/install_dest/ install | ||
118 | # - cd /home/ubuntu/install_dest/ ; cd home/ubuntu/c-toxcore/toolchains/arm-linux-androideabi/sysroot/ ; zip -r $CIRCLE_ARTIFACTS/android/opus.zip * | ||
119 | # | ||
120 | # | ||
121 | # - . ~/pp;cd $_s_;git clone --depth=1 --branch=1.0.11 https://github.com/jedisct1/libsodium.git | ||
122 | # - . ~/pp;cd $_s_/libsodium/;autoreconf -fi | ||
123 | # - . ~/pp;rm -Rf ~/build/ | ||
124 | # - . ~/pp;mkdir -p ~/build/ | ||
125 | # - . ~/pp;cd ~/build/;$_s_/libsodium/configure --prefix="$_toolchain_"/arm-linux-androideabi/sysroot/usr --disable-shared --disable-soname-versions --host=arm-linux-androideabi --with-sysroot="$_toolchain_"/arm-linux-androideabi/sysroot --enable-minimal --disable-pie | ||
126 | # - . ~/pp;cd ~/build/;make -j4 | ||
127 | # - . ~/pp;cd ~/build/;make install | ||
128 | # - . ~/pp;cd ~/build/;make clean | ||
129 | # - rm -Rf /home/ubuntu/install_dest/ ; mkdir -p /home/ubuntu/install_dest/ | ||
130 | # - . ~/pp;cd ~/build/;make DESTDIR=/home/ubuntu/install_dest/ install | ||
131 | # - cd /home/ubuntu/install_dest/ ; cd home/ubuntu/c-toxcore/toolchains/arm-linux-androideabi/sysroot/ ; zip -r $CIRCLE_ARTIFACTS/android/libsodium.zip * | ||
132 | # | ||
133 | # | ||
134 | # - . ~/pp;cd ~/c-toxcore/;autoreconf -fi | ||
135 | # - . ~/pp;rm -Rf ~/build/ | ||
136 | # - . ~/pp;mkdir -p ~/build/ | ||
137 | # - . ~/pp;cd ~/build/;~/c-toxcore/configure --prefix="$_toolchain_"/arm-linux-androideabi/sysroot/usr --disable-soname-versions --host=arm-linux-androideabi --with-sysroot="$_toolchain_"/arm-linux-androideabi/sysroot --disable-testing --disable-rt | ||
138 | # - . ~/pp;cd ~/build/;make -j4 | ||
139 | # - . ~/pp;cd ~/build/;make install | ||
140 | # - . ~/pp;cd ~/build/;make clean | ||
141 | # - rm -Rf /home/ubuntu/install_dest/ ; mkdir -p /home/ubuntu/install_dest/ | ||
142 | # - . ~/pp;cd ~/build/;make DESTDIR=/home/ubuntu/install_dest/ install | ||
143 | # - cd /home/ubuntu/install_dest/ ; cd home/ubuntu/c-toxcore/toolchains/arm-linux-androideabi/sysroot/ ; zip -r $CIRCLE_ARTIFACTS/android/c-toxcore.zip * | ||
144 | ## --- Android build --- | ||
145 | # | ||
146 | #test: | ||
147 | # override: | ||
148 | # - make test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 | ||
diff --git a/testing/random_testing.cc b/testing/random_testing.cc index 3e5be731..ecad07d3 100644 --- a/testing/random_testing.cc +++ b/testing/random_testing.cc | |||
@@ -47,19 +47,21 @@ struct Tox_Deleter { | |||
47 | using Tox_Ptr = std::unique_ptr<Tox, Tox_Deleter>; | 47 | using Tox_Ptr = std::unique_ptr<Tox, Tox_Deleter>; |
48 | 48 | ||
49 | struct Local_State { | 49 | struct Local_State { |
50 | Tox_Ptr tox; | ||
51 | |||
52 | uint32_t friends_online = 0; | 50 | uint32_t friends_online = 0; |
53 | uint32_t next_invite = 0; | 51 | uint32_t next_invite = 0; |
54 | 52 | ||
55 | explicit Local_State(Tox_Ptr tox, uint32_t id) : tox(std::move(tox)), id_(id) {} | 53 | explicit Local_State(Tox_Ptr tox, uint32_t id) : tox_(std::move(tox)), id_(id) {} |
56 | 54 | ||
55 | Tox *tox() const { return tox_.get(); } | ||
57 | uint32_t id() const { return id_; } | 56 | uint32_t id() const { return id_; } |
58 | 57 | ||
59 | private: | 58 | private: |
59 | Tox_Ptr tox_; | ||
60 | uint32_t id_; | 60 | uint32_t id_; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | struct Action; | ||
64 | |||
63 | struct Random { | 65 | struct Random { |
64 | std::uniform_int_distribution<> tox_selector; | 66 | std::uniform_int_distribution<> tox_selector; |
65 | std::uniform_int_distribution<> friend_selector; | 67 | std::uniform_int_distribution<> friend_selector; |
@@ -70,7 +72,7 @@ struct Random { | |||
70 | std::vector<size_t> action_weights; | 72 | std::vector<size_t> action_weights; |
71 | std::discrete_distribution<size_t> action_selector; | 73 | std::discrete_distribution<size_t> action_selector; |
72 | 74 | ||
73 | Random(); | 75 | explicit Random(std::vector<Action> const &actions); |
74 | }; | 76 | }; |
75 | 77 | ||
76 | struct Action { | 78 | struct Action { |
@@ -80,100 +82,7 @@ struct Action { | |||
80 | void (*run)(Local_State &state, Random &rnd, std::mt19937 &rng); | 82 | void (*run)(Local_State &state, Random &rnd, std::mt19937 &rng); |
81 | }; | 83 | }; |
82 | 84 | ||
83 | Action const actions[] = { | 85 | std::vector<size_t> get_action_weights(std::vector<Action> const &actions) { |
84 | { | ||
85 | 10, | ||
86 | "creates a new conference", | ||
87 | [](Local_State const &state) { | ||
88 | return tox_conference_get_chatlist_size(state.tox.get()) < MAX_CONFERENCES_PER_USER; | ||
89 | }, | ||
90 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
91 | TOX_ERR_CONFERENCE_NEW err; | ||
92 | tox_conference_new(state.tox.get(), &err); | ||
93 | assert(err == TOX_ERR_CONFERENCE_NEW_OK); | ||
94 | }, | ||
95 | }, | ||
96 | { | ||
97 | 10, | ||
98 | "invites a random friend to a conference", | ||
99 | [](Local_State const &state) { | ||
100 | return tox_conference_get_chatlist_size(state.tox.get()) != 0; | ||
101 | }, | ||
102 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
103 | TOX_ERR_CONFERENCE_INVITE err; | ||
104 | tox_conference_invite( | ||
105 | state.tox.get(), rnd.friend_selector(rng), | ||
106 | state.next_invite % tox_conference_get_chatlist_size(state.tox.get()), &err); | ||
107 | state.next_invite++; | ||
108 | assert(err == TOX_ERR_CONFERENCE_INVITE_OK); | ||
109 | }, | ||
110 | }, | ||
111 | { | ||
112 | 10, | ||
113 | "deletes the last conference", | ||
114 | [](Local_State const &state) { | ||
115 | return tox_conference_get_chatlist_size(state.tox.get()) != 0; | ||
116 | }, | ||
117 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
118 | TOX_ERR_CONFERENCE_DELETE err; | ||
119 | tox_conference_delete(state.tox.get(), | ||
120 | tox_conference_get_chatlist_size(state.tox.get()) - 1, &err); | ||
121 | assert(err == TOX_ERR_CONFERENCE_DELETE_OK); | ||
122 | }, | ||
123 | }, | ||
124 | { | ||
125 | 10, | ||
126 | "sends a message to the last conference", | ||
127 | [](Local_State const &state) { | ||
128 | return tox_conference_get_chatlist_size(state.tox.get()) != 0; | ||
129 | }, | ||
130 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
131 | std::vector<uint8_t> message(rnd.message_length_selector(rng)); | ||
132 | for (uint8_t &byte : message) { | ||
133 | byte = rnd.byte_selector(rng); | ||
134 | } | ||
135 | |||
136 | TOX_ERR_CONFERENCE_SEND_MESSAGE err; | ||
137 | tox_conference_send_message( | ||
138 | state.tox.get(), tox_conference_get_chatlist_size(state.tox.get()) - 1, | ||
139 | TOX_MESSAGE_TYPE_NORMAL, message.data(), message.size(), &err); | ||
140 | if (err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) { | ||
141 | printf(" (OK, length = %u)", (unsigned)message.size()); | ||
142 | } else { | ||
143 | printf(" (FAILED: %u)", err); | ||
144 | } | ||
145 | }, | ||
146 | }, | ||
147 | { | ||
148 | 10, | ||
149 | "changes their name", | ||
150 | [](Local_State const &state) { return true; }, | ||
151 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
152 | std::vector<uint8_t> name(rnd.name_length_selector(rng)); | ||
153 | for (uint8_t &byte : name) { | ||
154 | byte = rnd.byte_selector(rng); | ||
155 | } | ||
156 | |||
157 | TOX_ERR_SET_INFO err; | ||
158 | tox_self_set_name(state.tox.get(), name.data(), name.size(), &err); | ||
159 | assert(err == TOX_ERR_SET_INFO_OK); | ||
160 | |||
161 | printf(" (length = %u)", (unsigned)name.size()); | ||
162 | }, | ||
163 | }, | ||
164 | { | ||
165 | 10, | ||
166 | "sets their name to empty", | ||
167 | [](Local_State const &state) { return true; }, | ||
168 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
169 | TOX_ERR_SET_INFO err; | ||
170 | tox_self_set_name(state.tox.get(), nullptr, 0, &err); | ||
171 | assert(err == TOX_ERR_SET_INFO_OK); | ||
172 | }, | ||
173 | }, | ||
174 | }; | ||
175 | |||
176 | std::vector<size_t> get_action_weights() { | ||
177 | std::vector<size_t> weights; | 86 | std::vector<size_t> weights; |
178 | for (Action const &action : actions) { | 87 | for (Action const &action : actions) { |
179 | weights.push_back(action.weight); | 88 | weights.push_back(action.weight); |
@@ -181,23 +90,30 @@ std::vector<size_t> get_action_weights() { | |||
181 | return weights; | 90 | return weights; |
182 | } | 91 | } |
183 | 92 | ||
184 | Random::Random() | 93 | Random::Random(std::vector<Action> const &actions) |
185 | : tox_selector(0, NUM_TOXES - 1), | 94 | : tox_selector(0, NUM_TOXES - 1), |
186 | friend_selector(0, NUM_TOXES - 2), | 95 | friend_selector(0, NUM_TOXES - 2), |
187 | name_length_selector(0, TOX_MAX_NAME_LENGTH - 1), | 96 | name_length_selector(0, TOX_MAX_NAME_LENGTH - 1), |
188 | message_length_selector(0, TOX_MAX_MESSAGE_LENGTH - 1), | 97 | message_length_selector(0, TOX_MAX_MESSAGE_LENGTH - 1), |
189 | byte_selector(0, 255), | 98 | byte_selector(0, 255), |
190 | action_weights(get_action_weights()), | 99 | action_weights(get_action_weights(actions)), |
191 | action_selector(action_weights.begin(), action_weights.end()) {} | 100 | action_selector(action_weights.begin(), action_weights.end()) {} |
192 | 101 | ||
193 | struct Global_State : std::vector<Local_State> { | 102 | struct Global_State : std::vector<Local_State> { |
194 | // Non-copyable; | 103 | // Non-copyable; |
195 | Global_State(Global_State const &) = delete; | 104 | Global_State(Global_State const &) = delete; |
196 | Global_State(Global_State &&) = default; | 105 | Global_State(Global_State &&) = default; |
197 | Global_State() : action_counter(rnd.action_weights.size()) {} | 106 | explicit Global_State(std::vector<Action> const &actions) |
107 | : actions_(actions), rnd_(actions), action_counter_(actions.size()) {} | ||
108 | |||
109 | Action const &action(size_t id) const { return actions_.at(id); } | ||
110 | Random &rnd() { return rnd_; } | ||
111 | std::vector<unsigned> &action_counter() { return action_counter_; } | ||
198 | 112 | ||
199 | Random rnd; | 113 | private: |
200 | std::vector<unsigned> action_counter; | 114 | std::vector<Action> const &actions_; |
115 | Random rnd_; | ||
116 | std::vector<unsigned> action_counter_; | ||
201 | }; | 117 | }; |
202 | 118 | ||
203 | void handle_friend_connection_status(Tox *tox, uint32_t friend_number, | 119 | void handle_friend_connection_status(Tox *tox, uint32_t friend_number, |
@@ -256,8 +172,8 @@ void handle_conference_peer_list_changed(Tox *tox, uint32_t conference_number, v | |||
256 | } | 172 | } |
257 | } | 173 | } |
258 | 174 | ||
259 | Global_State make_toxes() { | 175 | Global_State make_toxes(std::vector<Action> const &actions) { |
260 | Global_State toxes; | 176 | Global_State toxes(actions); |
261 | 177 | ||
262 | Tox_Options_Ptr options(tox_options_new(nullptr)); | 178 | Tox_Options_Ptr options(tox_options_new(nullptr)); |
263 | tox_options_set_local_discovery_enabled(options.get(), false); | 179 | tox_options_set_local_discovery_enabled(options.get(), false); |
@@ -266,24 +182,24 @@ Global_State make_toxes() { | |||
266 | TOX_ERR_NEW err; | 182 | TOX_ERR_NEW err; |
267 | toxes.emplace_back(Tox_Ptr(tox_new(options.get(), &err)), i); | 183 | toxes.emplace_back(Tox_Ptr(tox_new(options.get(), &err)), i); |
268 | assert(err == TOX_ERR_NEW_OK); | 184 | assert(err == TOX_ERR_NEW_OK); |
269 | assert(toxes.back().tox != nullptr); | 185 | assert(toxes.back().tox() != nullptr); |
270 | 186 | ||
271 | tox_callback_friend_connection_status(toxes.back().tox.get(), handle_friend_connection_status); | 187 | tox_callback_friend_connection_status(toxes.back().tox(), handle_friend_connection_status); |
272 | tox_callback_conference_invite(toxes.back().tox.get(), handle_conference_invite); | 188 | tox_callback_conference_invite(toxes.back().tox(), handle_conference_invite); |
273 | tox_callback_conference_message(toxes.back().tox.get(), handle_conference_message); | 189 | tox_callback_conference_message(toxes.back().tox(), handle_conference_message); |
274 | tox_callback_conference_peer_list_changed(toxes.back().tox.get(), | 190 | tox_callback_conference_peer_list_changed(toxes.back().tox(), |
275 | handle_conference_peer_list_changed); | 191 | handle_conference_peer_list_changed); |
276 | } | 192 | } |
277 | 193 | ||
278 | std::printf("Bootstrapping %u toxes\n", NUM_TOXES); | 194 | std::printf("Bootstrapping %u toxes\n", NUM_TOXES); |
279 | 195 | ||
280 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | 196 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; |
281 | tox_self_get_dht_id(toxes.front().tox.get(), dht_key); | 197 | tox_self_get_dht_id(toxes.front().tox(), dht_key); |
282 | const uint16_t dht_port = tox_self_get_udp_port(toxes.front().tox.get(), nullptr); | 198 | const uint16_t dht_port = tox_self_get_udp_port(toxes.front().tox(), nullptr); |
283 | 199 | ||
284 | for (Local_State const &state : toxes) { | 200 | for (Local_State const &state : toxes) { |
285 | TOX_ERR_BOOTSTRAP err; | 201 | TOX_ERR_BOOTSTRAP err; |
286 | tox_bootstrap(state.tox.get(), "localhost", dht_port, dht_key, &err); | 202 | tox_bootstrap(state.tox(), "localhost", dht_port, dht_key, &err); |
287 | assert(err == TOX_ERR_BOOTSTRAP_OK); | 203 | assert(err == TOX_ERR_BOOTSTRAP_OK); |
288 | } | 204 | } |
289 | 205 | ||
@@ -291,12 +207,12 @@ Global_State make_toxes() { | |||
291 | 207 | ||
292 | for (Local_State const &state1 : toxes) { | 208 | for (Local_State const &state1 : toxes) { |
293 | for (Local_State const &state2 : toxes) { | 209 | for (Local_State const &state2 : toxes) { |
294 | if (state1.tox != state2.tox) { | 210 | if (state1.tox() != state2.tox()) { |
295 | TOX_ERR_FRIEND_ADD err; | 211 | TOX_ERR_FRIEND_ADD err; |
296 | uint8_t key[TOX_PUBLIC_KEY_SIZE]; | 212 | uint8_t key[TOX_PUBLIC_KEY_SIZE]; |
297 | 213 | ||
298 | tox_self_get_public_key(state1.tox.get(), key); | 214 | tox_self_get_public_key(state1.tox(), key); |
299 | tox_friend_add_norequest(state2.tox.get(), key, &err); | 215 | tox_friend_add_norequest(state2.tox(), key, &err); |
300 | assert(err == TOX_ERR_FRIEND_ADD_OK); | 216 | assert(err == TOX_ERR_FRIEND_ADD_OK); |
301 | } | 217 | } |
302 | } | 218 | } |
@@ -316,10 +232,10 @@ bool bootstrap_toxes(Global_State &toxes) { | |||
316 | MAX_BOOTSTRAP_ITERATIONS); | 232 | MAX_BOOTSTRAP_ITERATIONS); |
317 | 233 | ||
318 | for (uint32_t i = 0; i < MAX_BOOTSTRAP_ITERATIONS; i++) { | 234 | for (uint32_t i = 0; i < MAX_BOOTSTRAP_ITERATIONS; i++) { |
319 | c_sleep(tox_iteration_interval(toxes.front().tox.get())); | 235 | c_sleep(tox_iteration_interval(toxes.front().tox())); |
320 | 236 | ||
321 | for (Local_State &state : toxes) { | 237 | for (Local_State &state : toxes) { |
322 | tox_iterate(state.tox.get(), &state); | 238 | tox_iterate(state.tox(), &state); |
323 | } | 239 | } |
324 | 240 | ||
325 | if (all_connected(toxes)) { | 241 | if (all_connected(toxes)) { |
@@ -333,18 +249,18 @@ bool bootstrap_toxes(Global_State &toxes) { | |||
333 | 249 | ||
334 | bool execute_random_action(Global_State &toxes, std::mt19937 &rng) { | 250 | bool execute_random_action(Global_State &toxes, std::mt19937 &rng) { |
335 | // First, choose a random actor. | 251 | // First, choose a random actor. |
336 | Local_State &actor = toxes.at(toxes.rnd.tox_selector(rng)); | 252 | Local_State &actor = toxes.at(toxes.rnd().tox_selector(rng)); |
337 | size_t const action_id = toxes.rnd.action_selector(rng); | 253 | size_t const action_id = toxes.rnd().action_selector(rng); |
338 | Action const &action = actions[action_id]; | 254 | Action const &action = toxes.action(action_id); |
339 | if (!action.can(actor)) { | 255 | if (!action.can(actor)) { |
340 | return false; | 256 | return false; |
341 | } | 257 | } |
342 | 258 | ||
343 | std::printf("Tox #%u %s", actor.id(), action.title); | 259 | std::printf("Tox #%u %s", actor.id(), action.title); |
344 | action.run(actor, toxes.rnd, rng); | 260 | action.run(actor, toxes.rnd(), rng); |
345 | std::printf("\n"); | 261 | std::printf("\n"); |
346 | 262 | ||
347 | toxes.action_counter.at(action_id)++; | 263 | toxes.action_counter().at(action_id)++; |
348 | 264 | ||
349 | return true; | 265 | return true; |
350 | } | 266 | } |
@@ -362,7 +278,92 @@ bool attempt_action(Global_State &toxes, std::mt19937 &rng) { | |||
362 | } // namespace | 278 | } // namespace |
363 | 279 | ||
364 | int main() { | 280 | int main() { |
365 | Global_State toxes = make_toxes(); | 281 | std::vector<Action> const actions = { |
282 | { | ||
283 | 10, "creates a new conference", | ||
284 | [](Local_State const &state) { | ||
285 | return tox_conference_get_chatlist_size(state.tox()) < MAX_CONFERENCES_PER_USER; | ||
286 | }, | ||
287 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
288 | TOX_ERR_CONFERENCE_NEW err; | ||
289 | tox_conference_new(state.tox(), &err); | ||
290 | assert(err == TOX_ERR_CONFERENCE_NEW_OK); | ||
291 | }, | ||
292 | }, | ||
293 | { | ||
294 | 10, "invites a random friend to a conference", | ||
295 | [](Local_State const &state) { | ||
296 | return tox_conference_get_chatlist_size(state.tox()) != 0; | ||
297 | }, | ||
298 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
299 | TOX_ERR_CONFERENCE_INVITE err; | ||
300 | tox_conference_invite(state.tox(), rnd.friend_selector(rng), | ||
301 | state.next_invite % tox_conference_get_chatlist_size(state.tox()), | ||
302 | &err); | ||
303 | state.next_invite++; | ||
304 | assert(err == TOX_ERR_CONFERENCE_INVITE_OK); | ||
305 | }, | ||
306 | }, | ||
307 | { | ||
308 | 10, "deletes the last conference", | ||
309 | [](Local_State const &state) { | ||
310 | return tox_conference_get_chatlist_size(state.tox()) != 0; | ||
311 | }, | ||
312 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
313 | TOX_ERR_CONFERENCE_DELETE err; | ||
314 | tox_conference_delete(state.tox(), tox_conference_get_chatlist_size(state.tox()) - 1, | ||
315 | &err); | ||
316 | assert(err == TOX_ERR_CONFERENCE_DELETE_OK); | ||
317 | }, | ||
318 | }, | ||
319 | { | ||
320 | 10, "sends a message to the last conference", | ||
321 | [](Local_State const &state) { | ||
322 | return tox_conference_get_chatlist_size(state.tox()) != 0; | ||
323 | }, | ||
324 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
325 | std::vector<uint8_t> message(rnd.message_length_selector(rng)); | ||
326 | for (uint8_t &byte : message) { | ||
327 | byte = rnd.byte_selector(rng); | ||
328 | } | ||
329 | |||
330 | TOX_ERR_CONFERENCE_SEND_MESSAGE err; | ||
331 | tox_conference_send_message( | ||
332 | state.tox(), tox_conference_get_chatlist_size(state.tox()) - 1, | ||
333 | TOX_MESSAGE_TYPE_NORMAL, message.data(), message.size(), &err); | ||
334 | if (err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) { | ||
335 | printf(" (OK, length = %u)", (unsigned)message.size()); | ||
336 | } else { | ||
337 | printf(" (FAILED: %u)", err); | ||
338 | } | ||
339 | }, | ||
340 | }, | ||
341 | { | ||
342 | 10, "changes their name", [](Local_State const &state) { return true; }, | ||
343 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
344 | std::vector<uint8_t> name(rnd.name_length_selector(rng)); | ||
345 | for (uint8_t &byte : name) { | ||
346 | byte = rnd.byte_selector(rng); | ||
347 | } | ||
348 | |||
349 | TOX_ERR_SET_INFO err; | ||
350 | tox_self_set_name(state.tox(), name.data(), name.size(), &err); | ||
351 | assert(err == TOX_ERR_SET_INFO_OK); | ||
352 | |||
353 | printf(" (length = %u)", (unsigned)name.size()); | ||
354 | }, | ||
355 | }, | ||
356 | { | ||
357 | 10, "sets their name to empty", [](Local_State const &state) { return true; }, | ||
358 | [](Local_State &state, Random &rnd, std::mt19937 &rng) { | ||
359 | TOX_ERR_SET_INFO err; | ||
360 | tox_self_set_name(state.tox(), nullptr, 0, &err); | ||
361 | assert(err == TOX_ERR_SET_INFO_OK); | ||
362 | }, | ||
363 | }, | ||
364 | }; | ||
365 | |||
366 | Global_State toxes = make_toxes(actions); | ||
366 | 367 | ||
367 | std::mt19937 rng; | 368 | std::mt19937 rng; |
368 | uint32_t action_number; | 369 | uint32_t action_number; |
@@ -383,14 +384,14 @@ int main() { | |||
383 | c_sleep(ITERATION_INTERVAL); | 384 | c_sleep(ITERATION_INTERVAL); |
384 | 385 | ||
385 | for (Local_State &state : toxes) { | 386 | for (Local_State &state : toxes) { |
386 | tox_iterate(state.tox.get(), &state); | 387 | tox_iterate(state.tox(), &state); |
387 | } | 388 | } |
388 | } | 389 | } |
389 | } | 390 | } |
390 | 391 | ||
391 | std::printf("Test execution success: %u actions performed\n", action_number); | 392 | std::printf("Test execution success: %u actions performed\n", action_number); |
392 | std::printf("Per-action statistics:\n"); | 393 | std::printf("Per-action statistics:\n"); |
393 | for (uint32_t i = 0; i < toxes.action_counter.size(); i++) { | 394 | for (uint32_t i = 0; i < toxes.action_counter().size(); i++) { |
394 | std::printf("%u x '%s'\n", toxes.action_counter.at(i), actions[i].title); | 395 | std::printf("%u x '%s'\n", toxes.action_counter().at(i), actions[i].title); |
395 | } | 396 | } |
396 | } | 397 | } |
diff --git a/toxcore/network.c b/toxcore/network.c index 30c3bb6c..2a32a170 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -924,7 +924,7 @@ Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, | |||
924 | int neterror = net_error(); | 924 | int neterror = net_error(); |
925 | const char *strerror = net_new_strerror(neterror); | 925 | const char *strerror = net_new_strerror(neterror); |
926 | LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%d, %s)" : | 926 | LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%d, %s)" : |
927 | "Local multicast group FF02::1 joined successfully", neterror, strerror); | 927 | "Local multicast group FF02::1 joined successfully. (%d, %s)", neterror, strerror); |
928 | net_kill_strerror(strerror); | 928 | net_kill_strerror(strerror); |
929 | } | 929 | } |
930 | 930 | ||