Coverage Report

Created: 2026-01-17 06:12

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.96k
void test() {
11
12
8.96k
    {
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.96k
        auto app = uWS::App({
16
            /* There are example certificates in uWebSockets.js repo */
17
8.96k
            .key_file_name = "../misc/key.pem",
18
8.96k
            .cert_file_name = "../misc/cert.pem",
19
8.96k
            .passphrase = "1234"
20
26.5k
        }).get("/*", [](auto *res, auto *req) {
21
26.5k
            auto aborted = std::make_shared<bool>();
22
26.5k
            *aborted = false;
23
26.5k
            res->onAborted([aborted]() {
24
5.40k
                *aborted = true;
25
5.40k
            });
26
27
26.5k
            uWS::Loop::get()->defer([res, aborted]() {
28
25.8k
                if (!*aborted) {
29
21.1k
                    res->cork([res, aborted]() {
30
                        // Todo: also test upgrade to websocket here
31
21.1k
                        res->end("Hello async!");
32
21.1k
                    });
33
21.1k
                }
34
25.8k
            });
35
26.5k
        }).listen(9001, [](auto *listenSocket) {
36
3.19k
            listen_socket = listenSocket;
37
3.19k
        });
38
39
8.96k
        app.run();
40
8.96k
    }
41
8.96k
    uWS::Loop::get()->free();
42
8.96k
}
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
}