Coverage Report

Created: 2024-01-26 01:52

/work/auto_tests/overflow_sendq_test.c
Line
Count
Source
1
/* Try to overflow the net_crypto packet buffer.
2
 */
3
4
#include <stdint.h>
5
6
#include "auto_test_support.h"
7
8
40.0k
#define NUM_MSGS 40000
9
10
static void net_crypto_overflow_test(AutoTox *autotoxes)
11
1
{
12
1
    const uint8_t message[] = {0};
13
1
    bool errored = false;
14
15
40.0k
    for (uint32_t i = 0; i < NUM_MSGS; i++) {
16
40.0k
        Tox_Err_Friend_Send_Message err;
17
40.0k
        tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof message, &err);
18
19
40.0k
        if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
20
7.23k
            errored = true;
21
7.23k
        }
22
23
40.0k
        if (errored) {
24
            // As soon as we get the first error, we expect the same error (SENDQ)
25
            // every time we try to send.
26
7.23k
            ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ,
27
7.23k
                          "expected SENDQ error on message %u, but got %d", i, err);
28
32.7k
        } else {
29
32.7k
            ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK,
30
32.7k
                          "failed to send message number %u: %d", i, err);
31
32.7k
        }
32
40.0k
    }
33
34
1
    ck_assert_msg(errored, "expected SENDQ error at some point (increase NUM_MSGS?)");
35
1
}
36
37
int main(void)
38
721
{
39
721
    setvbuf(stdout, nullptr, _IONBF, 0);
40
41
721
    Run_Auto_Options options = default_run_auto_options();
42
721
    options.graph = GRAPH_LINEAR;
43
721
    run_auto_test(nullptr, 2, net_crypto_overflow_test, 0, &options);
44
45
721
    return 0;
46
721
}