summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibTest/CrashTest.h
blob: be0817eef063c56f6f20563df3d55a35f50182d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2019-2020, Shannon Booth <shannon.ml.booth@gmail.com>
 * Copyright (c) 2021, Brian Gianforaro <bgianf@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/Variant.h>

namespace Test {

class Crash {
public:
    enum class RunType {
        UsingChildProcess,
        UsingCurrentProcess,
    };

    enum class Failure {
        DidNotCrash,
        UnexpectedError,
    };

    static constexpr int ANY_SIGNAL = -1;

    Crash(DeprecatedString test_type, Function<Crash::Failure()> crash_function, int crash_signal = ANY_SIGNAL);

    bool run(RunType run_type = RunType::UsingChildProcess);

private:
    using Report = Variant<Failure, int>;
    bool do_report(Report report);

    DeprecatedString m_type;
    Function<Crash::Failure()> m_crash_function;
    int m_crash_signal;
};

}