Coverage Report

Created: 2025-06-13 06:09

/src/uWebSockets/fuzzing/AsyncEpollHelloWorld.cpp
Line
Count
Source (jump to first uncovered line)
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
3.30k
void test() {
11
12
3.30k
    {
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
3.30k
        auto app = uWS::App({
16
            /* There are example certificates in uWebSockets.js repo */
17
3.30k
            .key_file_name = "../misc/key.pem",
18
3.30k
            .cert_file_name = "../misc/cert.pem",
19
3.30k
            .passphrase = "1234"
20
24.6k
        }).get("/*", [](auto *res, auto *req) {
21
24.6k
            auto aborted = std::make_shared<bool>();
22
24.6k
            *aborted = false;
23
24.6k
            res->onAborted([aborted]() {
24
7.27k
                *aborted = true;
25
7.27k
            });
26
27
24.6k
            uWS::Loop::get()->defer([res, aborted]() {
28
22.9k
                if (!*aborted) {
29
17.3k
                    res->cork([res, aborted]() {
30
                        // Todo: also test upgrade to websocket here
31
17.3k
                        res->end("Hello async!");
32
17.3k
                    });
33
17.3k
                }
34
22.9k
            });
35
24.6k
        }).listen(9001, [](auto *listenSocket) {
36
3.30k
            listen_socket = listenSocket;
37
3.30k
        });
38
39
3.30k
        app.run();
40
3.30k
    }
41
3.30k
    uWS::Loop::get()->free();
42
3.30k
}
43
44
/* Thus function should shutdown the event-loop and let the test fall through */
45
3.29k
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
3.29k
  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
3.29k
    if (listen_socket) {
56
3.29k
        us_listen_socket_close(0, listen_socket);
57
3.29k
        listen_socket = NULL;
58
3.29k
    }
59
3.29k
}