1 // Copyright 2017 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <unittest/unittest.h> 8 9 #include "crash-list.h" 10 11 __BEGIN_CDECLS 12 13 typedef enum { 14 // The test function returned true and did not have any unregistered crashes. 15 TEST_PASSED, 16 // The test function returned false and did not have any unregistered crashes. 17 TEST_FAILED, 18 // The test function crashed before completion and was registered to crash. 19 TEST_CRASHED 20 // TODO(jocelyndang): add TEST_CRASHED_UNEXPECTEDLY for unregistered crashes - 21 // this should be returned rather than exiting the test process. 22 } test_result_t; 23 24 /** 25 * Runs the test in a separate thread, catching any crashes. 26 * 27 * A crash is expected if the process or thread handle is present in the 28 * crash_list. crash_list_register can be used to register expected crashes, or 29 * via the unittest helper macro REGISTER_CRASH. 30 * 31 * If an unexpected crash occurs, the test will be terminated immediately. 32 * 33 * Returns ZX_OK if setup succeeded, otherwise a negative error value is 34 * returned. If the return value is ZX_OK, test_result will also be populated. 35 */ 36 zx_status_t run_test_with_crash_handler(crash_list_t crash_list, 37 bool (*test_to_run)(void), 38 test_result_t* test_result); 39 40 /** 41 * Runs the function in a separate thread, passing in the given argument. 42 * This will block until the function either crashes or returns. 43 * 44 * Returns ZX_OK if setup succeeded, otherwise a negative error value is 45 * returned. If the return value is ZX_OK, test_result will also be populated. 46 */ 47 zx_status_t run_fn_with_crash_handler(void (*fn_to_run)(void*), void* arg, 48 test_result_t* test_result); 49 50 __END_CDECLS 51