1e66f31c5Sopenharmony_ci/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2e66f31c5Sopenharmony_ci * 3e66f31c5Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 4e66f31c5Sopenharmony_ci * of this software and associated documentation files (the "Software"), to 5e66f31c5Sopenharmony_ci * deal in the Software without restriction, including without limitation the 6e66f31c5Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7e66f31c5Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 8e66f31c5Sopenharmony_ci * furnished to do so, subject to the following conditions: 9e66f31c5Sopenharmony_ci * 10e66f31c5Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 11e66f31c5Sopenharmony_ci * all copies or substantial portions of the Software. 12e66f31c5Sopenharmony_ci * 13e66f31c5Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14e66f31c5Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15e66f31c5Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16e66f31c5Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17e66f31c5Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18e66f31c5Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19e66f31c5Sopenharmony_ci * IN THE SOFTWARE. 20e66f31c5Sopenharmony_ci */ 21e66f31c5Sopenharmony_ci 22e66f31c5Sopenharmony_ci#include "uv.h" 23e66f31c5Sopenharmony_ci#include "task.h" 24e66f31c5Sopenharmony_ci#include <string.h> 25e66f31c5Sopenharmony_ci 26e66f31c5Sopenharmony_cistatic uv_async_t async_handle; 27e66f31c5Sopenharmony_cistatic uv_check_t check_handle; 28e66f31c5Sopenharmony_cistatic int check_cb_called; 29e66f31c5Sopenharmony_cistatic uv_thread_t thread; 30e66f31c5Sopenharmony_ci 31e66f31c5Sopenharmony_ci 32e66f31c5Sopenharmony_cistatic void thread_cb(void* dummy) { 33e66f31c5Sopenharmony_ci (void) &dummy; 34e66f31c5Sopenharmony_ci uv_async_send(&async_handle); 35e66f31c5Sopenharmony_ci} 36e66f31c5Sopenharmony_ci 37e66f31c5Sopenharmony_ci 38e66f31c5Sopenharmony_cistatic void check_cb(uv_check_t* handle) { 39e66f31c5Sopenharmony_ci ASSERT_OK(check_cb_called); 40e66f31c5Sopenharmony_ci uv_close((uv_handle_t*) &async_handle, NULL); 41e66f31c5Sopenharmony_ci uv_close((uv_handle_t*) &check_handle, NULL); 42e66f31c5Sopenharmony_ci check_cb_called++; 43e66f31c5Sopenharmony_ci} 44e66f31c5Sopenharmony_ci 45e66f31c5Sopenharmony_ci 46e66f31c5Sopenharmony_ciTEST_IMPL(async_null_cb) { 47e66f31c5Sopenharmony_ci /* 48e66f31c5Sopenharmony_ci * Fill async_handle with garbage values. 49e66f31c5Sopenharmony_ci * uv_async_init() should properly initialize struct fields regardless of 50e66f31c5Sopenharmony_ci * initial values. 51e66f31c5Sopenharmony_ci * This is added to verify paddings between fields do not affect behavior. 52e66f31c5Sopenharmony_ci */ 53e66f31c5Sopenharmony_ci memset(&async_handle, 0xff, sizeof(async_handle)); 54e66f31c5Sopenharmony_ci 55e66f31c5Sopenharmony_ci ASSERT_OK(uv_async_init(uv_default_loop(), &async_handle, NULL)); 56e66f31c5Sopenharmony_ci ASSERT_OK(uv_check_init(uv_default_loop(), &check_handle)); 57e66f31c5Sopenharmony_ci ASSERT_OK(uv_check_start(&check_handle, check_cb)); 58e66f31c5Sopenharmony_ci ASSERT_OK(uv_thread_create(&thread, thread_cb, NULL)); 59e66f31c5Sopenharmony_ci ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 60e66f31c5Sopenharmony_ci ASSERT_OK(uv_thread_join(&thread)); 61e66f31c5Sopenharmony_ci ASSERT_EQ(1, check_cb_called); 62e66f31c5Sopenharmony_ci MAKE_VALGRIND_HAPPY(uv_default_loop()); 63e66f31c5Sopenharmony_ci return 0; 64e66f31c5Sopenharmony_ci} 65