Coverage Report

Created: 2026-11-12 07:10

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
4.69k
void test() {
11
12
4.69k
    {
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
4.69k
        auto app = uWS::App({
16
            /* There are example certificates in uWebSockets.js repo */
17
4.69k
            .key_file_name = "../misc/key.pem",
18
4.69k
            .cert_file_name = "../misc/cert.pem",
19
4.69k
            .passphrase = "1234"
20
6.51k
        }).get("/*", [](auto *res, auto *req) {
21
6.51k
            auto aborted = std::make_shared<bool>();
22
6.51k
            *aborted = false;
23
6.51k
            res->onAborted([aborted]() {
24
2.59k
                *aborted = true;
25
2.59k
            });
26
27
6.51k
            uWS::Loop::get()->defer([res, aborted]() {
28
5.96k
                if (!*aborted) {
29
3.91k
                    res->cork([res, aborted]() {
30
                        // Todo: also test upgrade to websocket here
31
3.91k
                        res->end("Hello async!");
32
3.91k
                    });
33
3.91k
                }
34
5.96k
            });
35
6.51k
        }).listen(9001, [](auto *listenSocket) {
36
4.69k
            listen_socket = listenSocket;
37
4.69k
        });
38
39
        /* Publishing without WebSocket contexts must be a no-op */
40
4.69k
        uWS::PreparedMessage preparedMessage = {};
41
4.69k
        if (app.publish("unused", "hi", uWS::TEXT) ||
42
4.69k
            app.publishPrepared("unused", preparedMessage) ||
43
4.69k
            app.numSubscribers("unused")) {
44
0
            exit(-1);
45
0
        }
46
47
4.69k
        app.run();
48
4.69k
    }
49
0
    uWS::Loop::get()->free();
50
4.69k
}
51
52
/* Thus function should shutdown the event-loop and let the test fall through */
53
20.0k
void teardown() {
54
  /* If we are called twice there's a bug (it potentially could if
55
   * all open sockets cannot be error-closed in one epoll_wait call).
56
   * But we only allow 1k FDs and we have a buffer of 1024 from epoll_wait */
57
20.0k
  if (!listen_socket) {
58
0
    exit(-1);
59
0
  }
60
61
  /* We might have open sockets still, and these will be error-closed by epoll_wait */
62
  // us_socket_context_close - close all open sockets created with this socket context
63
20.0k
    if (listen_socket) {
64
20.0k
        us_listen_socket_close(0, listen_socket);
65
        listen_socket = NULL;
66
20.0k
    }
67
20.0k
}