Example #1
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] len           A length of the data buffers.
 */
static void spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  len)
{
    // Initalize buffers.
    init_buffers(p_tx_data, p_rx_data, len);

    // Start transfer.
    uint32_t err_code = spi_master_send_recv(SPI_MASTER_HW, p_tx_data, len, p_rx_data, len);
    APP_ERROR_CHECK(err_code);
    nrf_delay_ms(DELAY_MS);
}
int main(void)
{
    signed int stat=0;
    init_buffers();
    init_variables();
    stat = init_signals_terminals_and_pipes();
    if (stat != 0)
        printf("exiting-error in init_signals_terminals_and_pipes\n");

    stat = run_matmult_p();
    return stat;
}
Example #3
0
	bool bsdsock_streambuf::do_connect(const addrinfo_type * addr)
	{
		handle_type sock;
		for (; addr; addr = addr->ai_next)
		{
			// пытаемся создать сокет, если не получилось - это какая-то серьезная ошибка. man 3 socket.
			// исключение EPROTONOSUPPORT, не поддерживаемый protocol family, в этом случае пробуем следующий адрес
			bool res = do_createsocket(sock, addr);
			if (!res)
			{
				if (m_lasterror == std::errc::protocol_not_supported)
					continue;
				else
					return false;
			}

			// выставляем non blocking режим. если не получилось - все очень плохо
			res = do_setnonblocking(sock);
			if (!res)
			{
				::close(sock);
				return false;
			}

			// do_sockconnect публикует sock в m_sockhandle, а также учитывает interrupt сигналы.
			// в случае успеха:
			//   весь объект будет переведен в открытое состояние, вернет true
			// в случае ошибки или вызова interrupt:
			//   вернет false и гарантированно закроет sock, m_sockhandle == -1
			res = do_sockconnect(sock, addr);
			if (res)
			{
				init_buffers(); // from base_type
				return true;
			}

			// возможные коды ошибок для ::connect в man 3 connect
			// в случае ECONNREFUSED, ENETUNREACH, EHOSTUNREACH - имеет смысл попробовать след адрес
			
			auto & cat = m_lasterror.category();
			auto code = m_lasterror.value();

			bool try_next = cat == std::generic_category() &&
				(code == ECONNREFUSED || code == ENETUNREACH || code == EHOSTUNREACH);

			if (try_next)
				continue;
			else
				return false;
		}
		
		return false;
	}
Example #4
0
/**************************
*         INIT           *
**************************/
PluginInfo *goom_init (uint32_t resx, uint32_t resy)
{
    PluginInfo *goomInfo = (PluginInfo*)malloc(sizeof(PluginInfo));

#ifdef VERBOSE
    printf ("GOOM: init (%d, %d);\n", resx, resy);
#endif

    plugin_info_init(goomInfo,4);

    goomInfo->screen.width = resx;
    goomInfo->screen.height = resy;
    goomInfo->screen.size = resx * resy;

    goomInfo->star_fx = flying_star_create();
    goomInfo->star_fx.init(&goomInfo->star_fx, goomInfo);

    goomInfo->zoomFilter_fx = zoomFilterVisualFXWrapper_create ();
    goomInfo->zoomFilter_fx.init(&goomInfo->zoomFilter_fx, goomInfo);

    goomInfo->tentacles_fx = tentacle_fx_create();
    goomInfo->tentacles_fx.init(&goomInfo->tentacles_fx, goomInfo);

    goomInfo->convolve_fx = convolve_create();
    goomInfo->convolve_fx.init(&goomInfo->convolve_fx, goomInfo);

    plugin_info_add_visual (goomInfo, 0, &goomInfo->zoomFilter_fx);
    plugin_info_add_visual (goomInfo, 1, &goomInfo->tentacles_fx);
    plugin_info_add_visual (goomInfo, 2, &goomInfo->star_fx);
    plugin_info_add_visual (goomInfo, 3, &goomInfo->convolve_fx);

    init_buffers(goomInfo, goomInfo->screen.size);
    goomInfo->gRandom = goom_random_init((uintptr_t)goomInfo->pixel);

    goomInfo->cycle = 0;

    goomInfo->ifs_fx = ifs_visualfx_create();
    goomInfo->ifs_fx.init(&goomInfo->ifs_fx, goomInfo);

    goomInfo->gmline1 = goom_lines_init (goomInfo, resx, goomInfo->screen.height,
                                         GML_HLINE, goomInfo->screen.height, GML_BLACK,
                                         GML_CIRCLE, 0.4f * (float) goomInfo->screen.height, GML_VERT);
    goomInfo->gmline2 = goom_lines_init (goomInfo, resx, goomInfo->screen.height,
                                         GML_HLINE, 0, GML_BLACK,
                                         GML_CIRCLE, 0.2f * (float) goomInfo->screen.height, GML_RED);

    gfont_load ();

    /* goom_set_main_script(goomInfo, goomInfo->main_script_str); */

    return goomInfo;
}
Example #5
0
void init() {
  int i=0, j;
  uart_init_hw();
  init_irq();
  updateTemps();
  init_buffers(&fg_buffer);
  #ifdef CBDEBUG
  for (i=0; i < MAX_FG_DEVICES; i++) {
    mprintf("cb[%d]: isEmpty = %d\n", i, cbisEmpty((struct circ_buffer *)&fg_buffer, i));
    mprintf("cb[%d]: isFull = %d\n", i, cbisFull((struct circ_buffer *)&fg_buffer, i));
    mprintf("cb[%d]: getCount = %d\n", i, cbgetCount((struct circ_buffer *)&fg_buffer, i));
  }
  #endif
  scan_scu_bus(&scub, backplane_id, scub_base);
  scan_for_fgs(&scub, &fgs);
  //probe_scu_bus(scub_base, 55, 3, slaves);
  configure_slaves();
  #ifdef FGDEBUG
  mprintf("ID: 0x%08x%08x\n", (int)(scub.unique_id >> 32), (int)scub.unique_id);
  while(scub.slaves[i].unique_id) { /* more slaves in list */
      mprintf("slaves[%d] ID:  0x%08x%08x\n",i, (int)(scub.slaves[i].unique_id>>32), (int)scub.slaves[i].unique_id);
      mprintf("slave macro: 0x%x\n", scub.slaves[i].version);
      mprintf("CID system:  %d\n", scub.slaves[i].cid_sys);
      mprintf("CID group:   %d\n", scub.slaves[i].cid_group);
      mprintf("slot:        %d\n", scub.slaves[i].slot);
      j = 0;
      while(scub.slaves[i].devs[j].version) { /* more fgs in list */
        mprintf("   fg[%d], version 0x%x \n", j, scub.slaves[i].devs[j].version);
        j++;
      }
      i++;
  }
  mprintf("fg_list-------------------\n");
  i = 0;
  while(fgs.devs[i]) {
    mprintf("fgs.devs[%d] 0x%x\n", i, fgs.devs[i]);
    mprintf("fg[%d]: version 0x%x\n", i, fgs.devs[i]->version);
    mprintf("        dev_number 0x%x\n", fgs.devs[i]->dev_number);
    mprintf("        offset 0x%x\n", fgs.devs[i]->offset);
    mprintf("        endvalue 0x%x\n", fgs.devs[i]->endvalue);
    i++;
  }
  #endif
/*  reset_slaves();
  usleep(1000);
  dis_irq();
  usleep(1000000);
  init_irq();
  usleep(1000);
  configure_slaves();
  */
} 
Example #6
0
static bool Device_states_init_buffers(Device_states* dstates, const Connections* conns)
{
    rassert(dstates != NULL);
    rassert(conns != NULL);

    const Device_node* master = Connections_get_master(conns);
    rassert(master != NULL);
    Device_states_reset_node_states(dstates);
    if (!init_buffers(dstates, master))
        return false;

    Device_states_reset_node_states(dstates);
    return init_effect_buffers(dstates, master);
}
/*
 * init_rx_channel: Initialize Rx DMA channel
 */
static int init_rx_channel(BcmEnet_devctrl *pDevCtrl)
{
    BcmEnet_RxDma *rxdma;
    volatile DmaRegs *dmaCtrl = pDevCtrl->dmaCtrl;
    int phy_chan = 0;

    TRACE(("bcm63xxenet: init_rx_channel\n"));

    /* setup the RX DMA channel */
    rxdma = pDevCtrl->rxdma[0];

    /* init rxdma structures */
    rxdma->pktDmaRxInfo.rxDma = &dmaCtrl->chcfg[phy_chan * 2];
    /* Use the enetcore number to identify the interrupt source */
    rxdma->rxIrq = get_rxIrq(pDevCtrl->sw_port_id);

    /* disable the interrupts from device */
    /* channel parameter is not used inside the function for Duna */
    bcmPktDma_BcmHalInterruptDisable(0, rxdma->rxIrq);

    /* Reset the DMA channel */
    dmaCtrl->ctrl_channel_reset = 1 << (phy_chan * 2);
    dmaCtrl->ctrl_channel_reset = 0;

    /* allocate RX BDs */
    if (bcm63xx_alloc_rxdma_bds(pDevCtrl) < 0)
        return -1;

    setup_rxdma_channel(pDevCtrl);
    bcmPktDma_EthInitRxChan(rxdma->pktDmaRxInfo.numRxBds, &rxdma->pktDmaRxInfo);

#if defined(_CONFIG_BCM_BPM)
    enet_rx_set_bpm_alloc_trig(pDevCtrl);
#endif

    /* initialize the receive buffers */
    if (init_buffers(pDevCtrl)) {
        printk(KERN_NOTICE CARDNAME": Low memory.\n");
        uninit_buffers(pDevCtrl);
        return -ENOMEM;
    }
#if defined(_CONFIG_BCM_BPM)
    /* Substitute channel parameter for enetcore number */
    gbpm_resv_rx_buf(GBPM_PORT_ETH, pDevCtrl->vport_id, rxdma->pktDmaRxInfo.numRxBds,
        (rxdma->pktDmaRxInfo.numRxBds * BPM_ENET_ALLOC_TRIG_PCT/100) );
#endif

    return 0;
}
Example #8
0
/*
 * Run performance tests for a number of different sizes and cached/uncached
 * permutations.
 */
static int
perf_test(void)
{
	const unsigned num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
	unsigned i;
	int ret;

	ret = init_buffers();
	if (ret != 0)
		return ret;

#if TEST_VALUE_RANGE != 0
	/* Setup buf_sizes array, if required */
	for (i = 0; i < TEST_VALUE_RANGE; i++)
		buf_sizes[i] = i;
#endif

	/* See function comment */
	do_uncached_write(large_buf_write, 0, small_buf_read, 1, SMALL_BUFFER_SIZE);

	printf("\n** rte_memcpy() - memcpy perf. tests (C = compile-time constant) **\n"
	       "======= ============== ============== ============== ==============\n"
	       "   Size Cache to cache   Cache to mem   Mem to cache     Mem to mem\n"
	       "(bytes)        (ticks)        (ticks)        (ticks)        (ticks)\n"
	       "------- -------------- -------------- -------------- --------------");

	/* Do tests where size is a variable */
	for (i = 0; i < num_buf_sizes; i++) {
		ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
	}
	printf("\n------- -------------- -------------- -------------- --------------");
	/* Do tests where size is a compile-time constant */
	ALL_PERF_TESTS_FOR_SIZE(63U);
	ALL_PERF_TESTS_FOR_SIZE(64U);
	ALL_PERF_TESTS_FOR_SIZE(65U);
	ALL_PERF_TESTS_FOR_SIZE(255U);
	ALL_PERF_TESTS_FOR_SIZE(256U);
	ALL_PERF_TESTS_FOR_SIZE(257U);
	ALL_PERF_TESTS_FOR_SIZE(1023U);
	ALL_PERF_TESTS_FOR_SIZE(1024U);
	ALL_PERF_TESTS_FOR_SIZE(1025U);
	ALL_PERF_TESTS_FOR_SIZE(1518U);

	printf("\n======= ============== ============== ============== ==============\n\n");

	free_buffers();

	return 0;
}
Example #9
0
File: pread02.c Project: kraj/ltp
/*
 * setup() - performs all ONE TIME setup for this test.
 *           Initialize/allocate write buffer.
 *           Call individual setup function.
 */
void setup(void)
{
	int i;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Allocate/Initialize the read/write buffer with known data */
	init_buffers();

	/* Call individual setup functions */
	for (i = 0; Test_cases[i].desc != NULL; i++) {
		Test_cases[i].setupfunc();
	}
}
Example #10
0
void goom_set_resolution (PluginInfo *goomInfo, uint32_t resx, uint32_t resy)
{
    free (goomInfo->pixel);
    free (goomInfo->back);
    free (goomInfo->conv);

    goomInfo->screen.width = resx;
    goomInfo->screen.height = resy;
    goomInfo->screen.size = resx * resy;

    init_buffers(goomInfo, goomInfo->screen.size);

    /* init_ifs (goomInfo, resx, goomInfo->screen.height); */
    goomInfo->ifs_fx.free(&goomInfo->ifs_fx);
    goomInfo->ifs_fx.init(&goomInfo->ifs_fx, goomInfo);

    goom_lines_set_res (goomInfo->gmline1, resx, goomInfo->screen.height);
    goom_lines_set_res (goomInfo->gmline2, resx, goomInfo->screen.height);
}
Example #11
0
/// main: load scene, initialize acceleration, raytraces scene, saves image
int main(int argc, char** argv) {
    parse_args(argc,argv);
    Serializer::read_json(scene, filename_scene);
    if(scene->raytrace_opts) opts = *scene->raytrace_opts;
    if(scene->distribution_opts) disttrace_opts = *scene->distribution_opts;
    if(scene->pathtrace_opts) pathtrace_opts = *scene->pathtrace_opts;

    // command-line options override settings in json
    if(resolution > 0) {
        opts.res = resolution;
        disttrace_opts.res = resolution;
        pathtrace_opts.res = resolution;
    }
    if(samples > 0) {
        opts.samples = samples;
        disttrace_opts.samples = samples;
        pathtrace_opts.samples = samples;
    }

    scene_tesselation_init(scene,false,0,false);
    //scene_animation_snapshot(scene,opts.time);
    sample_lights_init(scene->lights);
    if(opts.cameralights) scene_cameralights_update(scene,opts.cameralights_dir, opts.cameralights_col);
    intersect_scene_accelerate(scene);
    
    auto w = camera_image_width(scene->camera, opts.res);
    auto h = camera_image_height(scene->camera, opts.res);
    image<vec3f> img;
    init_buffers(w, h);
    auto samples = (pathtrace ? pathtrace_opts.samples : (distribution ? disttrace_opts.samples : opts.samples ) );

    // for debug:
    for(auto s = 0; s < samples; s ++) {
        printf("Pass: %02d/%02d\n", s, samples);
        render_pass(img);
        if(progressive && s < samples-1) {
            trace_image_buffer.get_image(img);
            imageio_write_png(filename_image, img, false);
        }
    }
    trace_image_buffer.get_image(img);
    imageio_write_png(filename_image, img, false);
}
Example #12
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] len           A length of the data buffers.
 */
static void spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  len)
{
    // Initalize buffers.
    init_buffers(p_tx_data, p_rx_data, len);
        
    
    // Start transfer.
    
    uint32_t err_code = nrf_drv_spi_transfer(&m_spi_master,
        p_tx_data, len, p_rx_data, len);
    //m_tx_data
    //SEGGER_RTT_printf(0, "\nSent: %s\n", p_tx_data);
    //SEGGER_RTT_printf(0, "\nRecieved: %s\n", p_rx_data);
    
    APP_ERROR_CHECK(err_code);
    //nrf_delay_us(10);
}
Example #13
0
rtems_device_driver frame_buffer_control(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  rtems_libio_ioctl_args_t *args = arg;

  switch (args->command) {
    case FBIOGET_FSCREENINFO:
      args->ioctl_return =
        get_fix_screen_info((struct fb_fix_screeninfo *)args->buffer);
      return RTEMS_SUCCESSFUL;
    case FBIOGET_VSCREENINFO:
      args->ioctl_return =
        get_var_screen_info((struct fb_var_screeninfo *)args->buffer);
      return RTEMS_SUCCESSFUL;
    case FBIOSWAPBUFFERS:
      swap_buffers();
      args->ioctl_return = 0;
      return RTEMS_SUCCESSFUL;
    case FBIOSETBUFFERMODE:
      args->ioctl_return = 0;
      switch ((unsigned int)args->buffer) {
        case FB_SINGLE_BUFFERED:
          init_buffers();
          fb_fix.smem_start = (volatile char *)frontbuffer;
          MM_WRITE(MM_VGA_BASEADDRESS, (unsigned int)frontbuffer);
          return RTEMS_SUCCESSFUL;
        case FB_TRIPLE_BUFFERED:
          fb_fix.smem_start = (volatile char *)backbuffer;
          return RTEMS_SUCCESSFUL;
        default:
          return RTEMS_UNSATISFIED;
      }
    case FBIOSETVIDEOMODE:
      set_video_mode((int)args->buffer);
      return RTEMS_SUCCESSFUL;
    default:
      args->ioctl_return = -1;
      return RTEMS_UNSATISFIED;
  }
}
Example #14
0
rtems_device_driver frame_buffer_initialize(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  rtems_status_code status;

  init_buffers();
  fb_fix.smem_start = (volatile char *)frontbuffer;
  MM_WRITE(MM_VGA_BASEADDRESS, (unsigned int)frontbuffer);

  status = rtems_io_register_name(FRAMEBUFFER_DEVICE_NAME, major, 0);
  if (status != RTEMS_SUCCESSFUL) {
    printk("Error registering frame buffer device!\n");
    rtems_fatal_error_occurred( status );
  }

  return RTEMS_SUCCESSFUL;
}
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutCreateWindow("Triangle");

	// glewInit Must be called after glutInit
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		printf("%S", "Initialize glew failed");
	}

	init_buffers();
	glutDisplayFunc(display);
	glutMainLoop();
	cleanup();

	return 0;
}
Example #16
0
int main(int argc, char **argv)
{


	if (argc <= 1) 
		cmdline_help();

	init_windows();
	init_buffers();

	for (argv++; *argv != NULL ; argv++) 
		current_buf = load_buffer(*argv);
		

	paint_buffer(current_buf);
	statusprintf("%s", current_buf->name);

	refresh();
	input_loop();

}
Example #17
0
/*
 * setup() - performs all ONE TIME setup for this test.
 *
 *  Initialize/allocate write buffer.
 *  Call individual setup function.
 */
void setup()
{
    int i;

    tst_sig(NOFORK, DEF_HANDLER, cleanup);

    /* see the comment in the sighandler() function */
    /* call signal() to trap the signal generated */
    if (signal(SIGXFSZ, sighandler) == SIG_ERR) {
        tst_brkm(TBROK, cleanup, "signal() failed");
    }

    TEST_PAUSE;

    /* Allocate/Initialize the write buffer with known data */
    init_buffers();

    /* Call individual setup functions */
    for (i = 0; Test_cases[i].desc != NULL; i++) {
        Test_cases[i].setupfunc();
    }
}
Example #18
0
/*
 * setup() - performs all ONE TIME setup for this test.
 *           create temporary directory and open it
 */
void setup()
{
	char *cur_dir = NULL;

	/* capture signals */
	tst_sig(FORK, DEF_HANDLER, cleanup);

	/* Pause if that option was specified */
	TEST_PAUSE;

	/* Allocate the read buffer */
	init_buffers();

	/* make a temp directory and cd to it */
	tst_tmpdir();

	/* get the currect directory name */
	if ((cur_dir = getcwd(cur_dir, 0)) == NULL) {
		tst_brkm(TBROK, cleanup, "Couldn't get current directory name");
	}

	sprintf(test_dir, "%s.%d", cur_dir, getpid());

	/*
	 * create a temporary directory
	 */
	if (mkdir(PREAD_TEMPDIR, 0777) != 0) {
		tst_resm(TFAIL, "mkdir() failed to create" " test directory");
		exit(1);
		/* NOTREACHED */
	}

	/* open temporary directory used for test */
	if ((fd1 = open(PREAD_TEMPDIR, O_RDONLY)) < 0) {
		tst_brkm(TBROK, cleanup, "open() on %s Failed, errno=%d : %s",
			 PREAD_TEMPDIR, errno, strerror(errno));
	}

}
Example #19
0
bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
{
   assert(compositor);

   memset(compositor, 0, sizeof(struct vl_compositor));

   compositor->pipe = pipe;

   if (!init_pipe_state(compositor))
      return false;
   if (!init_shaders(compositor)) {
      cleanup_pipe_state(compositor);
      return false;
   }
   if (!init_buffers(compositor)) {
      cleanup_shaders(compositor);
      cleanup_pipe_state(compositor);
      return false;
   }

   return true;
}
Example #20
0
int main(int argc, char** argv) {

    char* mpi_inbuf;
    char* mpi_outbuf;
    char* farc_inbuf;
    char* farc_outbuf;

    MPI_Init(&argc, &argv);

    test_start("unpack(2, hindexed[{(1*MPI_INT, offset=4), (3*MPI_INT, offset=16), (2*MPI_INT, offset=32)}])");
    init_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);

    MPI_Datatype mpitype; 
    int blocklen[3] = {1, 3, 2};
    MPI_Aint disp[3] = {4, 16, 32};

    MPI_Type_create_hindexed(3, blocklen, disp, MPI_INT, &mpitype);
    MPI_Type_commit(&mpitype);

    farc::DDT_Init();
    farc::Datatype* t1 = new farc::PrimitiveDatatype(farc::PrimitiveDatatype::INT);
    farc::Datatype* t2 = new farc::HIndexedDatatype(3, blocklen, disp, t1);
    farc::DDT_Commit(t2);
    farc::DDT_Unpack(farc_inbuf, farc_outbuf, t2, 2);

    int position = 0;
    MPI_Unpack(mpi_inbuf, 20*sizeof(int), &position, mpi_outbuf, 2, mpitype, MPI_COMM_WORLD);

    int res = compare_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
    free_buffers(&mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
    test_result(res);

    MPI_Finalize();

    return 0;

}
Example #21
0
bool GLGSRender::do_method(u32 cmd, u32 arg)
{
	switch (cmd)
	{
	case NV4097_CLEAR_SURFACE:
	{
		if (arg & 0xF3)
		{
			//Only do all this if we have actual work to do
			init_buffers(true);
			synchronize_buffers();
			clear_surface(arg);
		}

		return true;
	}
	case NV4097_TEXTURE_READ_SEMAPHORE_RELEASE:
	case NV4097_BACK_END_WRITE_SEMAPHORE_RELEASE:
		flush_draw_buffers = true;
		return true;
	}

	return false;
}
Example #22
0
static int el_load_map(const char * file_name)
{
	int ret;

	init_map_loading(file_name);
	ret = load_map(file_name, &updat_func);
	if (!ret)
		// don't try to build pathfinder maps etc. when loading 
		// the map failed...
		return ret;


	if (strstr(file_name, "underworld") != NULL)
	{
		skybox_set_type(SKYBOX_UNDERWORLD);
		skybox_update_colors();
	}
	else if (dungeon)
	{
		skybox_set_type(SKYBOX_NONE);
		skybox_update_colors();
	}
	else
	{
		skybox_set_type(SKYBOX_CLOUDY);
		skybox_init_defs(file_name);
	}
	build_path_map();
	init_buffers();
	
	// reset light levels in case we enter or leave an inside map
	new_minute();

	destroy_loading_win();
	return ret;
}
Example #23
0
int main(int argc, char *argv[]) {

	printf("Memmory Allocation...\n");

	fftw_init_threads();

	fftw_plan_with_nthreads(4);

	load_files();

	init_buffers();

	printf("Analysis Process Started...\n");

	analysis();

	printf("Process Finished.\n");

	clean_up_memmory();

	fftw_cleanup_threads();

	return 0;
}
Example #24
0
// Constructor for the class.
brutefir::brutefir(int filter_length,
                   int filter_blocks,
                   int realsize,
                   int channels,
                   int in_format,
                   int out_format,
                   int sampling_rate,
                   bool apply_dither)
    : m_initialized(false), bfconf(NULL), baseptr(NULL), m_convolver(NULL), m_dither(NULL)
{
    bfconf = (struct bfconf_t *) malloc(sizeof(struct bfconf_t));
    memset(bfconf, 0, sizeof(struct bfconf_t));

    if (init_channels(channels, in_format, out_format, sampling_rate, apply_dither) == 0)
    {
        if (init_convolver(filter_length, filter_blocks, realsize) == 0)
        {
            if (init_buffers() == 0)
            {
                reset();
            }
        }
    }
}
Example #25
0
int Engine_init(const char *name, int width, int height) {
  window_width = width;
  window_height = height;

  glfwSetErrorCallback(error_callback);
  if (!glfwInit()) {
    Log("Unable to initialize glfw.");
    return 0;
  }

  window = init_window(name, width, height);
  if (!window) {
    Log("Unable to initialize glfw window.");
    return 0;
  }

  init_shader_program();
  if (!program) {
    Log("Unable to initialize shader program.");
    return 0;
  }

  // Turn on alpha channel for textures.
  glEnable (GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  if (!init_buffers()) {
    Log("Unable to set up buffer objects");
    return 0;
  }
  glfwSetKeyCallback(window, internal_key_callback);

  start_time = glfwGetTime();
  is_running = 1;
  return 1;
}
Example #26
0
int main(int argc, char* argv[])
{
	int ret;
	unsigned int i;

	printf("Trinity v" __stringify(VERSION) "  Dave Jones <*****@*****.**> 2012\n");

#ifdef __x86_64__
	syscalls = syscalls_x86_64;
	max_nr_syscalls = NR_X86_64_SYSCALLS;
#elif __i386__
	syscalls = syscalls_i386;
	max_nr_syscalls = NR_I386_SYSCALLS;
#elif __powerpc__
	syscalls = syscalls_ppc;
#elif __ia64__
	syscalls = syscalls_ia64;
#elif __sparc__
	syscalls = syscalls_sparc;
#else
	syscalls = syscalls_i386;
#endif

	progname = argv[0];

	parse_args(argc, argv);

	if (getuid() == 0) {
		if (dangerous == 1) {
			printf("DANGER: RUNNING AS ROOT.\n");
			printf("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
			printf("or similar which could potentially make this machine unbootable without a firmware reset.\n\n");
			printf("ctrl-c now unless you really know what you are doing.\n");
			for (i = 10; i > 0; i--) {
				printf("Continuing in %d seconds.\r", i);
				(void)fflush(stdout);
				sleep(1);
			}
		} else {
			printf("Don't run as root (or pass --dangerous if you know what you are doing).\n");
			exit(EXIT_FAILURE);
		}
	}

	if (create_shm())
		exit(EXIT_FAILURE);

	if (logging != 0)
		open_logfiles();

	max_nr_syscalls = NR_SYSCALLS;
	for (i = 0; i < max_nr_syscalls; i++)
		syscalls[i].entry->number = i;

	if (desired_group == GROUP_VM) {
		struct syscalltable *newsyscalls;
		int count = 0, j = 0;

		for (i = 0; i < max_nr_syscalls; i++) {
			if (syscalls[i].entry->group == GROUP_VM)
				count++;
		}

		newsyscalls = malloc(count * sizeof(struct syscalltable));
		if (newsyscalls == NULL)
			exit(EXIT_FAILURE);

		for (i = 0; i < max_nr_syscalls; i++) {
			if (syscalls[i].entry->group == GROUP_VM)
				newsyscalls[j++].entry = syscalls[i].entry;
		}

		max_nr_syscalls = count;
		syscalls = newsyscalls;
	}


	if (!do_specific_syscall)
		output("Fuzzing %d syscalls.\n", max_nr_syscalls);

	if (do_specific_syscall == 1)
		find_specific_syscall();

	if (do_specific_proto == 1)
		find_specific_proto();

	if (show_syscall_list == 1) {
		syscall_list();
		exit(EXIT_SUCCESS);
	}

	page_size = getpagesize();

	if (!seed)
		seed_from_tod();
	else
		output("[%d] Random seed: %u (0x%x)\n", getpid(), seed, seed);


	init_buffers();

	mask_signals();

	setup_fds();

	if (check_tainted() != 0) {
		output("Kernel was tainted on startup. Will keep running if trinity causes an oops.\n");
		do_check_tainted = 1;
	}

	/* just in case we're not using the test.sh harness. */
	chmod("tmp/", 0755);
	ret = chdir("tmp/");
	if (!ret) {
		/* nothing right now */
	}

	main_loop();

	printf("\nRan %ld syscalls (%ld retries). Successes: %ld  Failures: %ld\n",
		shm->execcount - 1, shm->retries, shm->successes, shm->failures);

	shmdt(shm);

	destroy_maps();

	for (i = 0; i < socks; i++)
		close(socket_fds[i]);

	if (logging != 0)
		close_logfiles();

	exit(EXIT_SUCCESS);
}
Example #27
0
void GLGSRender::begin()
{
	rsx::thread::begin();

	if (!load_program())
	{
		//no program - no drawing
		return;
	}

	init_buffers();

	u32 color_mask = rsx::method_registers[NV4097_SET_COLOR_MASK];
	bool color_mask_b = !!(color_mask & 0xff);
	bool color_mask_g = !!((color_mask >> 8) & 0xff);
	bool color_mask_r = !!((color_mask >> 16) & 0xff);
	bool color_mask_a = !!((color_mask >> 24) & 0xff);

	__glcheck glColorMask(color_mask_r, color_mask_g, color_mask_b, color_mask_a);
	__glcheck glDepthMask(rsx::method_registers[NV4097_SET_DEPTH_MASK]);
	__glcheck glStencilMask(rsx::method_registers[NV4097_SET_STENCIL_MASK]);

	if (__glcheck enable(rsx::method_registers[NV4097_SET_DEPTH_TEST_ENABLE], GL_DEPTH_TEST))
	{
		__glcheck glDepthFunc(rsx::method_registers[NV4097_SET_DEPTH_FUNC]);
		__glcheck glDepthMask(rsx::method_registers[NV4097_SET_DEPTH_MASK]);
	}

	if (glDepthBoundsEXT && (__glcheck enable(rsx::method_registers[NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE], GL_DEPTH_BOUNDS_TEST_EXT)))
	{
		__glcheck glDepthBoundsEXT((f32&)rsx::method_registers[NV4097_SET_DEPTH_BOUNDS_MIN], (f32&)rsx::method_registers[NV4097_SET_DEPTH_BOUNDS_MAX]);
	}

	__glcheck glDepthRange((f32&)rsx::method_registers[NV4097_SET_CLIP_MIN], (f32&)rsx::method_registers[NV4097_SET_CLIP_MAX]);
	__glcheck enable(rsx::method_registers[NV4097_SET_DITHER_ENABLE], GL_DITHER);

	if (__glcheck enable(rsx::method_registers[NV4097_SET_ALPHA_TEST_ENABLE], GL_ALPHA_TEST))
	{
		//TODO: NV4097_SET_ALPHA_REF must be converted to f32
		//glcheck(glAlphaFunc(rsx::method_registers[NV4097_SET_ALPHA_FUNC], rsx::method_registers[NV4097_SET_ALPHA_REF]));
	}

	if (__glcheck enable(rsx::method_registers[NV4097_SET_BLEND_ENABLE], GL_BLEND))
	{
		u32 sfactor = rsx::method_registers[NV4097_SET_BLEND_FUNC_SFACTOR];
		u32 dfactor = rsx::method_registers[NV4097_SET_BLEND_FUNC_DFACTOR];
		u16 sfactor_rgb = sfactor;
		u16 sfactor_a = sfactor >> 16;
		u16 dfactor_rgb = dfactor;
		u16 dfactor_a = dfactor >> 16;

		__glcheck glBlendFuncSeparate(sfactor_rgb, dfactor_rgb, sfactor_a, dfactor_a);

		if (m_surface.color_format == rsx::surface_color_format::w16z16y16x16) //TODO: check another color formats
		{
			u32 blend_color = rsx::method_registers[NV4097_SET_BLEND_COLOR];
			u32 blend_color2 = rsx::method_registers[NV4097_SET_BLEND_COLOR2];

			u16 blend_color_r = blend_color;
			u16 blend_color_g = blend_color >> 16;
			u16 blend_color_b = blend_color2;
			u16 blend_color_a = blend_color2 >> 16;

			__glcheck glBlendColor(blend_color_r / 65535.f, blend_color_g / 65535.f, blend_color_b / 65535.f, blend_color_a / 65535.f);
		}
Example #28
0
File: main.c Project: coliv/ed
int main( const int argc, const char * const argv[] )
  {
  int argind;
  bool loose = false;
  const struct ap_Option options[] =
    {
    { 'G', "traditional",       ap_no  },
    { 'h', "help",              ap_no  },
    { 'l', "loose-exit-status", ap_no  },
    { 'p', "prompt",            ap_yes },
    { 'r', "restricted",        ap_no  },
    { 's', "quiet",             ap_no  },
    { 's', "silent",            ap_no  },
    { 'v', "verbose",           ap_no  },
    { 'V', "version",           ap_no  },
    {  0 ,  0,                  ap_no } };

  struct Arg_parser parser;

  if( !ap_init( &parser, argc, argv, options, 0 ) )
    { show_error( "Memory exhausted.", 0, false ); return 1; }
  if( ap_error( &parser ) )				/* bad option */
    { show_error( ap_error( &parser ), 0, true ); return 1; }
  invocation_name = argv[0];

  for( argind = 0; argind < ap_arguments( &parser ); ++argind )
    {
    const int code = ap_code( &parser, argind );
    const char * const arg = ap_argument( &parser, argind );
    if( !code ) break;					/* no more options */
    switch( code )
      {
      case 'G': traditional_ = true; break;	/* backward compatibility */
      case 'h': show_help(); return 0;
      case 'l': loose = true; break;
      case 'p': set_prompt( arg ); break;
      case 'r': restricted_ = true; break;
      case 's': scripted_ = true; break;
      case 'v': set_verbose(); break;
      case 'V': show_version(); return 0;
      default : show_error( "internal error: uncaught option.", 0, false );
                return 3;
      }
    } /* end process options */
  setlocale( LC_ALL, "" );
  if( !init_buffers() ) return 1;

  while( argind < ap_arguments( &parser ) )
    {
    const char * const arg = ap_argument( &parser, argind );
    if( !strcmp( arg, "-" ) ) { scripted_ = true; ++argind; continue; }
    if( may_access_filename( arg ) )
      {
      if( read_file( arg, 0 ) < 0 && is_regular_file( 0 ) )
        return 2;
      else if( arg[0] != '!' ) set_def_filename( arg );
      }
    else
      {
      fputs( "?\n", stderr );
      if( arg[0] ) set_error_msg( "Invalid filename" );
      if( is_regular_file( 0 ) ) return 2;
      }
    break;
    }
  ap_free( &parser );

  return main_loop( loose );
  }
Example #29
0
netplay_t *netplay_new(const char *server, uint16_t port,
      unsigned frames, const struct retro_callbacks *cb,
      bool spectate,
      const char *nick)
{
   unsigned i;
   if (frames > UDP_FRAME_PACKETS)
      frames = UDP_FRAME_PACKETS;

   netplay_t *handle = (netplay_t*)calloc(1, sizeof(*handle));
   if (!handle)
      return NULL;

   handle->fd = -1;
   handle->udp_fd = -1;
   handle->cbs = *cb;
   handle->port = server ? 0 : 1;
   handle->spectate = spectate;
   handle->spectate_client = server != NULL;
   strlcpy(handle->nick, nick, sizeof(handle->nick));

   if (!init_socket(handle, server, port))
   {
      free(handle);
      return NULL;
   }

   if (spectate)
   {
      if (server)
      {
         if (!get_info_spectate(handle))
            goto error;
      }

      for (i = 0; i < MAX_SPECTATORS; i++)
         handle->spectate_fds[i] = -1;
   }
   else
   {
      if (server)
      {
         if (!send_info(handle))
            goto error;
      }
      else
      {
         if (!get_info(handle))
            goto error;
      }

      handle->buffer_size = frames + 1;

      init_buffers(handle);
      handle->has_connection = true;
   }

   return handle;

error:
   if (handle->fd >= 0)
      close(handle->fd);
   if (handle->udp_fd >= 0)
      close(handle->udp_fd);

   free(handle);
   return NULL;
}
Example #30
0
static void test_communication(void)
{
    int ret;

    WSADATA wsa_data;
    SOCKET sock;
    struct hostent *host;
    struct sockaddr_in addr;

    SECURITY_STATUS status;
    ULONG attrs;

    SCHANNEL_CRED cred;
    CredHandle cred_handle;
    CtxtHandle context;
    SecPkgCredentials_NamesA names;
    SecPkgContext_StreamSizes sizes;
    SecPkgContext_ConnectionInfo conn_info;
    CERT_CONTEXT *cert;

    SecBufferDesc buffers[2];
    SecBuffer *buf;
    unsigned buf_size = 4000;
    unsigned char *data;
    unsigned data_size;

    if (!pAcquireCredentialsHandleA || !pFreeCredentialsHandle ||
        !pInitializeSecurityContextA || !pDeleteSecurityContext ||
        !pQueryContextAttributesA || !pDecryptMessage || !pEncryptMessage)
    {
        skip("Required secur32 functions not available\n");
        return;
    }

    /* Create a socket and connect to www.winehq.org */
    ret = WSAStartup(0x0202, &wsa_data);
    if (ret)
    {
        skip("Can't init winsock 2.2\n");
        return;
    }

    host = gethostbyname("www.winehq.org");
    if (!host)
    {
        skip("Can't resolve www.winehq.org\n");
        return;
    }

    addr.sin_family = host->h_addrtype;
    addr.sin_addr = *(struct in_addr *)host->h_addr_list[0];
    addr.sin_port = htons(443);
    sock = socket(host->h_addrtype, SOCK_STREAM, 0);
    if (sock == SOCKET_ERROR)
    {
        skip("Can't create socket\n");
        return;
    }

    ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
    if (ret == SOCKET_ERROR)
    {
        skip("Can't connect to www.winehq.org\n");
        return;
    }

    /* Create client credentials */
    init_cred(&cred);
    cred.grbitEnabledProtocols = SP_PROT_TLS1_CLIENT;
    cred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS|SCH_CRED_MANUAL_CRED_VALIDATION;

    status = pAcquireCredentialsHandleA(NULL, (SEC_CHAR *)UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL,
        &cred, NULL, NULL, &cred_handle, NULL);
    ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", status);
    if (status != SEC_E_OK) return;

    /* Initialize the connection */
    init_buffers(&buffers[0], 4, buf_size);
    init_buffers(&buffers[1], 4, buf_size);

    buffers[0].pBuffers[0].BufferType = SECBUFFER_TOKEN;
    status = pInitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost",
        ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
        0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL);
    ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status);

    buffers[1].cBuffers = 1;
    buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN;
    buffers[0].pBuffers[0].cbBuffer = 1;
    memset(buffers[1].pBuffers[0].pvBuffer, 0xfa, buf_size);
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
todo_wine
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
todo_wine
    ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n");

    buffers[1].cBuffers = 1;
    buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN;
    buffers[0].pBuffers[0].cbBuffer = 1;
    memset(buffers[1].pBuffers[0].pvBuffer, 0, buf_size);
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);
todo_wine
    ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n");

    buffers[0].pBuffers[0].cbBuffer = 0;
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
todo_wine
    ok(status == SEC_E_INSUFFICIENT_MEMORY || status == SEC_E_INVALID_TOKEN,
       "Expected SEC_E_INSUFFICIENT_MEMORY or SEC_E_INVALID_TOKEN, got %08x\n", status);

    buffers[0].pBuffers[0].cbBuffer = buf_size;

    status = pInitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL);
    ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status);

    buf = &buffers[0].pBuffers[0];
    send(sock, buf->pvBuffer, buf->cbBuffer, 0);
    buf->cbBuffer = buf_size;

    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, NULL, 0, NULL, &buffers[0], &attrs, NULL);
    ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
    ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
    ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");

    buffers[1].cBuffers = 4;
    buffers[1].pBuffers[0].cbBuffer = 0;

    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
    ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
    ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
    ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");

    buf = &buffers[1].pBuffers[0];
    buf->cbBuffer = buf_size;
    ret = receive_data(sock, buf);
    if (ret == -1)
        return;

    buffers[1].pBuffers[0].cbBuffer = 4;
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
    ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
    ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
    ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");

    buffers[1].pBuffers[0].cbBuffer = 5;
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
    ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status);
    ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n");
    ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n");

    buffers[1].pBuffers[0].cbBuffer = ret;
    status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
    buffers[1].pBuffers[0].cbBuffer = buf_size;
    while (status == SEC_I_CONTINUE_NEEDED)
    {
        buf = &buffers[0].pBuffers[0];
        send(sock, buf->pvBuffer, buf->cbBuffer, 0);
        buf->cbBuffer = buf_size;

        buf = &buffers[1].pBuffers[0];
        ret = receive_data(sock, buf);
        if (ret == -1)
            return;

        buf->BufferType = SECBUFFER_TOKEN;

        status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost",
            ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM,
            0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL);
        buffers[1].pBuffers[0].cbBuffer = buf_size;
    }

    ok(status == SEC_E_OK || broken(status == SEC_E_INVALID_TOKEN) /* WinNT */,
        "InitializeSecurityContext failed: %08x\n", status);
    if(status != SEC_E_OK) {
        win_skip("Handshake failed\n");
        return;
    }

    status = pQueryCredentialsAttributesA(&cred_handle, SECPKG_CRED_ATTR_NAMES, &names);
    ok(status == SEC_E_NO_CREDENTIALS || status == SEC_E_UNSUPPORTED_FUNCTION /* before Vista */, "expected SEC_E_NO_CREDENTIALS, got %08x\n", status);

    status = pQueryContextAttributesA(&context, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (void*)&cert);
    ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_REMOTE_CERT_CONTEXT) failed: %08x\n", status);
    if(status == SEC_E_OK) {
        test_remote_cert(cert);
        CertFreeCertificateContext(cert);
    }

    status = pQueryContextAttributesA(&context, SECPKG_ATTR_CONNECTION_INFO, (void*)&conn_info);
    ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_CONNECTION_INFO) failed: %08x\n", status);
    if(status == SEC_E_OK) {
        ok(conn_info.dwCipherStrength >= 128, "conn_info.dwCipherStrength = %d\n", conn_info.dwCipherStrength);
        ok(conn_info.dwHashStrength >= 128, "conn_info.dwHashStrength = %d\n", conn_info.dwHashStrength);
    }

    status = pQueryContextAttributesA(&context, SECPKG_ATTR_STREAM_SIZES, &sizes);
    ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_STREAM_SIZES) failed: %08x\n", status);

    reset_buffers(&buffers[0]);

    /* Send a simple request so we get data for testing DecryptMessage */
    buf = &buffers[0].pBuffers[0];
    data = buf->pvBuffer;
    buf->BufferType = SECBUFFER_STREAM_HEADER;
    buf->cbBuffer = sizes.cbHeader;
    ++buf;
    buf->BufferType = SECBUFFER_DATA;
    buf->pvBuffer = data + sizes.cbHeader;
    buf->cbBuffer = sizeof(http_request) - 1;
    memcpy(buf->pvBuffer, http_request, sizeof(http_request) - 1);
    ++buf;
    buf->BufferType = SECBUFFER_STREAM_TRAILER;
    buf->pvBuffer = data + sizes.cbHeader + sizeof(http_request) -1;
    buf->cbBuffer = sizes.cbTrailer;

    status = pEncryptMessage(&context, 0, &buffers[0], 0);
    ok(status == SEC_E_OK, "EncryptMessage failed: %08x\n", status);
    if (status != SEC_E_OK)
        return;

    buf = &buffers[0].pBuffers[0];
    send(sock, buf->pvBuffer, buffers[0].pBuffers[0].cbBuffer + buffers[0].pBuffers[1].cbBuffer + buffers[0].pBuffers[2].cbBuffer, 0);

    reset_buffers(&buffers[0]);
    buf->cbBuffer = buf_size;
    data_size = receive_data(sock, buf);

    /* Too few buffers */
    --buffers[0].cBuffers;
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);

    /* No data buffer */
    ++buffers[0].cBuffers;
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);

    /* Two data buffers */
    buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA;
    buffers[0].pBuffers[1].BufferType = SECBUFFER_DATA;
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);

    /* Too few empty buffers */
    buffers[0].pBuffers[1].BufferType = SECBUFFER_EXTRA;
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status);

    /* Incomplete data */
    buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY;
    buffers[0].pBuffers[0].cbBuffer = (data[3]<<8) | data[4];
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_INCOMPLETE_MESSAGE, "Expected SEC_E_INCOMPLETE_MESSAGE, got %08x\n", status);
    ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_MISSING, "Expected first buffer to be SECBUFFER_MISSING\n");
    ok(buffers[0].pBuffers[0].cbBuffer == 5, "Expected first buffer to be a five bytes\n");

    buffers[0].pBuffers[0].cbBuffer = data_size;
    buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA;
    buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY;
    status = pDecryptMessage(&context, &buffers[0], 0, NULL);
    ok(status == SEC_E_OK, "DecryptMessage failed: %08x\n", status);
    if (status == SEC_E_OK)
    {
        ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_STREAM_HEADER, "Expected first buffer to be SECBUFFER_STREAM_HEADER\n");
        ok(buffers[0].pBuffers[1].BufferType == SECBUFFER_DATA, "Expected second buffer to be SECBUFFER_DATA\n");
        ok(buffers[0].pBuffers[2].BufferType == SECBUFFER_STREAM_TRAILER, "Expected third buffer to be SECBUFFER_STREAM_TRAILER\n");

        data = buffers[0].pBuffers[1].pvBuffer;
        data[buffers[0].pBuffers[1].cbBuffer] = 0;
    }

    pDeleteSecurityContext(&context);
    pFreeCredentialsHandle(&cred_handle);

    free_buffers(&buffers[0]);
    free_buffers(&buffers[1]);

    closesocket(sock);
}