CrashTest.h 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2019-2020, Shannon Booth <shannon@serenityos.org>
  4. * Copyright (c) 2021, Brian Gianforaro <bgianf@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/ByteString.h>
  10. #include <AK/Function.h>
  11. #include <AK/Variant.h>
  12. namespace Test {
  13. class Crash {
  14. public:
  15. enum class RunType {
  16. UsingChildProcess,
  17. UsingCurrentProcess,
  18. };
  19. enum class Failure {
  20. DidNotCrash,
  21. UnexpectedError,
  22. };
  23. static constexpr int ANY_SIGNAL = -1;
  24. Crash(ByteString test_type, Function<Crash::Failure()> crash_function, int crash_signal = ANY_SIGNAL);
  25. bool run(RunType run_type = RunType::UsingChildProcess);
  26. private:
  27. using Report = Variant<Failure, int>;
  28. bool do_report(Report report);
  29. ByteString m_type;
  30. Function<Crash::Failure()> m_crash_function;
  31. int m_crash_signal;
  32. };
  33. }