Coverage Report

Created: 2025-10-14 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uWebSockets/fuzzing/AsyncEpollHelloWorld.cpp
Line
Count
Source
1
/* We rely on wrapped syscalls */
2
#include "libEpollFuzzer/epoll_fuzzer.h"
3
4
#include "App.h"
5
6
/* We keep this one for teardown later on */
7
struct us_listen_socket_t *listen_socket;
8
9
/* This test is run by libEpollFuzzer */
10
8.97k
void test() {
11
12
8.97k
    {
13
        /* Keep in mind that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support.
14
        * You may swap to using uWS:App() if you don't need SSL */
15
8.97k
        auto app = uWS::App({
16
            /* There are example certificates in uWebSockets.js repo */
17
8.97k
            .key_file_name = "../misc/key.pem",
18
8.97k
            .cert_file_name = "../misc/cert.pem",
19
8.97k
            .passphrase = "1234"
20
19.8k
        }).get("/*", [](auto *res, auto *req) {
21
19.8k
            auto aborted = std::make_shared<bool>();
22
19.8k
            *aborted = false;
23
19.8k
            res->onAborted([aborted]() {
24
3.53k
                *aborted = true;
25
3.53k
            });
26
27
19.8k
            uWS::Loop::get()->defer([res, aborted]() {
28
19.0k
                if (!*aborted) {
29
16.2k
                    res->cork([res, aborted]() {
30
                        // Todo: also test upgrade to websocket here
31
16.2k
                        res->end("Hello async!");
32
16.2k
                    });
33
16.2k
                }
34
19.0k
            });
35
19.8k
        }).listen(9001, [](auto *listenSocket) {
36
3.21k
            listen_socket = listenSocket;
37
3.21k
        });
38
39
8.97k
        app.run();
40
8.97k
    }
41
8.97k
    uWS::Loop::get()->free();
42
8.97k
}
43
44
/* Thus function should shutdown the event-loop and let the test fall through */
45
15.8k
void teardown() {
46
  /* If we are called twice there's a bug (it potentially could if
47
   * all open sockets cannot be error-closed in one epoll_wait call).
48
   * But we only allow 1k FDs and we have a buffer of 1024 from epoll_wait */
49
15.8k
  if (!listen_socket) {
50
0
    exit(-1);
51
0
  }
52
53
  /* We might have open sockets still, and these will be error-closed by epoll_wait */
54
  // us_socket_context_close - close all open sockets created with this socket context
55
15.8k
    if (listen_socket) {
56
15.8k
        us_listen_socket_close(0, listen_socket);
57
        listen_socket = NULL;
58
15.8k
    }
59
15.8k
}