Blame test/test-async-null-cb.c

Packit b5b901
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Packit b5b901
 *
Packit b5b901
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
 * of this software and associated documentation files (the "Software"), to
Packit b5b901
 * deal in the Software without restriction, including without limitation the
Packit b5b901
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
 * sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
 * furnished to do so, subject to the following conditions:
Packit b5b901
 *
Packit b5b901
 * The above copyright notice and this permission notice shall be included in
Packit b5b901
 * all copies or substantial portions of the Software.
Packit b5b901
 *
Packit b5b901
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
 * IN THE SOFTWARE.
Packit b5b901
 */
Packit b5b901
Packit b5b901
#include "uv.h"
Packit b5b901
#include "task.h"
Packit b5b901
#include <string.h>
Packit b5b901
Packit b5b901
static uv_async_t async_handle;
Packit b5b901
static uv_check_t check_handle;
Packit b5b901
static int check_cb_called;
Packit b5b901
static uv_thread_t thread;
Packit b5b901
Packit b5b901
Packit b5b901
static void thread_cb(void* dummy) {
Packit b5b901
  (void) &dummy;
Packit b5b901
  uv_async_send(&async_handle);
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
static void check_cb(uv_check_t* handle) {
Packit b5b901
  ASSERT(check_cb_called == 0);
Packit b5b901
  uv_close((uv_handle_t*) &async_handle, NULL);
Packit b5b901
  uv_close((uv_handle_t*) &check_handle, NULL);
Packit b5b901
  check_cb_called++;
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
TEST_IMPL(async_null_cb) {
Packit b5b901
  /*
Packit b5b901
   * Fill async_handle with garbage values.
Packit b5b901
   * uv_async_init() should properly initialize struct fields regardless of
Packit b5b901
   * initial values.
Packit b5b901
   * This is added to verify paddings between fields do not affect behavior.
Packit b5b901
   */
Packit b5b901
  memset(&async_handle, 0xff, sizeof(async_handle));
Packit b5b901
Packit b5b901
  ASSERT(0 == uv_async_init(uv_default_loop(), &async_handle, NULL));
Packit b5b901
  ASSERT(0 == uv_check_init(uv_default_loop(), &check_handle));
Packit b5b901
  ASSERT(0 == uv_check_start(&check_handle, check_cb));
Packit b5b901
  ASSERT(0 == uv_thread_create(&thread, thread_cb, NULL));
Packit b5b901
  ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
Packit b5b901
  ASSERT(0 == uv_thread_join(&thread));
Packit b5b901
  ASSERT(1 == check_cb_called);
Packit b5b901
  MAKE_VALGRIND_HAPPY();
Packit b5b901
  return 0;
Packit b5b901
}