Beispiel #1
0
// Leosam 08/08: What are the arguments?
int
main (int argc, char **argv)
{

	// Command line parsing
	int input_val = 1000;	// Value serving as an input relatad to the SNR
	int max_num_ofdm_sym = 64;	// Index of the last frame for the channel estimation
	int be_verbose = 0;	// Operate in verbose mode
	int index;
	int c;
	unsigned int rx_energy[NB_ANTENNAS], n0_energy[NB_ANTENNAS];

	if (argc == 1)
	{
		error ();
		exit (-1);
	}

	while ((c = getopt (argc, argv, "hVv:n:")) != -1)
	{
		switch (c)
		{
		case 'h':
			help ();
			exit (1);
		case 'V':
			be_verbose = 1;
			break;
		case 'v':
			input_val = atoi (optarg);
			break;
			return 1;
		case 'n':
			max_num_ofdm_sym = atoi (optarg);
			break;
			return 1;
		default:
			error ();
			exit (-1);
		}
	}

	//
	// Initialization stuff
	//

	int i, ii, j, ret, delay, l;
	short seed[3];

	// Leosam 08/08: What is this amps?
	double amps[8] = { 1.0, .8, .4, .2, .1, .05, .025, .01 };
	struct complex ch[NB_ANTENNAS * NB_ANTENNAS][10 + (int) (1 + 2 * BW * Td)];
	struct complex rx_tmp, tx, n, phase;

	char *chbch_pdu;
	int chbch_size;
	int extension;
	unsigned char dummy_mac_pdu[120];

#ifdef USER_MODE
  char fname[40], vname[40];
#endif // USER_MODE

	if (be_verbose)
		printf ("Allocating memory for PHY_VARS\n");

	// Memory allocation for PHY and MAC structures
	PHY_vars = malloc (sizeof (PHY_VARS));
	PHY_config = malloc (sizeof (PHY_CONFIG));
	mac_xface = malloc (sizeof (MAC_xface));

	// Loading of the configuration data
	if ((config = fopen ("config.cfg", "r")) == NULL)	// this can be configured
	{
		if (be_verbose)
			printf ("[Main USER] The openair configuration file <config.cfg> could not be found!\n");
		exit (0);
	}

	if ((scenario = fopen ("scenario.scn", "r")) == NULL)
	{
		if (be_verbose)
			printf ("[Main USER] The openair scenario file <scenario.scn> could not be found!\n");
		exit (0);
	}

	if (be_verbose)
		printf ("Opened configuration files\n");

	reconfigure_MACPHY (scenario);

	if (be_verbose)
		dump_config ();

	//  Leosam 08/08: This is repeated bellow. Is it necessary?
	mac_xface->is_cluster_head = 0;

	// Initialize the PHY and MAC variables
	phy_init (NB_ANTENNAS_TX);
	if (be_verbose)
		printf ("Initialized PHY variables\n");


	// Fill MAC PDU buffer for CHBCH
	seed[0] = (short) time (NULL);
	seed[1] = (short) time (NULL);
	seed[2] = (short) time (NULL);
	seed48 (&seed[0]);

	randominit ();

	/*
	 * for (i=0;i<mac_xface->mac_tch->bch_tx[0].size-4;i++) {
	 * mac_xface->mac_tch->bch_tx[0].data[i] = i;//(u8)lrand48();
	 * }
	 * 
	 * 
	 * printf("Filled CHBCH PDU with random data\n");
	 * 
	 * // Generate one CHBCH
	 * phy_generate_chbch(0);
	 * 
	 */

	//
	//  Preparation for the TX procedure
	// 

	// Creation of the CHBCH
	chbch_size = (NUMBER_OF_CARRIERS_PER_GROUP * (NUMBER_OF_CHBCH_SYMBOLS) * 16) >> 3;
	if (be_verbose)
		printf ("chbch_size = %d\n", chbch_size);
	chbch_pdu = malloc (chbch_size);

	for (i = 0; i < chbch_size - 4; i++)
	{
		chbch_pdu[i] = i;
	}

	if (be_verbose)
		printf ("Filled CHBCH PDU (%d bytes) with data\n", chbch_size);

	// Leosam 08/08: O.o
	delay = 1032;
	//	delay = 0;

	// Generation of the CHBCH
	phy_generate_chbch (0, 1, NB_ANTENNAS_TX, chbch_pdu);

	// Generation of the pilot symbols
	for (i = 16; i < max_num_ofdm_sym; i++)
	{
		phy_generate_sch (0, i, 0xFFFF, 1, NB_ANTENNAS_TX);
	}
	
	mac_xface->is_cluster_head = 0;
	
	if (be_verbose)
	{
		for (ii=0; ii<NB_ANTENNAS; ii++)
		{
			sprintf (fname, "txsig%d.m", ii);
			sprintf (vname, "txs%d", ii);

			write_output (fname, vname,
										(s16 *) PHY_vars->tx_vars[ii].TX_DMA_BUFFER,
										NUMBER_OF_SYMBOLS_PER_FRAME * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES, 1, 1);
		}
	}


	// generate channels
	if (be_verbose)
		printf ("Generating MIMO Channels\n");

	phase.r = 0;
	phase.i = 0;
	
	printf("Phase pointer %0x\n",&phase);

	for (i = 0; i < NB_ANTENNAS; i++)
	{
		for (j = 0; j < NB_ANTENNAS; j++)
		{
			random_channel (amps, Td, 8, BW, ch[j + (i * NB_ANTENNAS)],0.0,&phase);
		}
	}

	if (be_verbose)
		printf ("chbch_pdu %x (%d)\n", PHY_vars->chbch_data[0].demod_pdu, chbch_size);

	if (be_verbose)
	{
		for (l = 0; l < (1 + 2 * BW * Td); l++)
		{
			printf ("(%f,%f)\n", ch[0][l]);
		}
	}

	//
	// TX procedure
	//

	// Transmission 
	//
	//////////////////////////
	
	// Foreach symbol
	for (i = 0; i < (max_num_ofdm_sym) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++)
	{
		// Foreach RX antenna
		for (ii = 0; ii < NB_ANTENNAS; ii++)
		{
			rx_tmp.r = 0;
			rx_tmp.i = 0;
			n.r = gaussdouble (0.0, 10.0);
			n.i = gaussdouble (0.0, 10.0);
			
			// Foreach TX antenna
			for (j = 0; j < NB_ANTENNAS; j++)
			{
				
				// Foreach symbol
				for (l = 0; l < (1 + 2 * BW * Td); l++)
				{

					tx.r = (double) (((s16 *) & PHY_vars->tx_vars[j].
							  TX_DMA_BUFFER[0 *
									OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES])
							 [2 * (i - l)]) / sqrt (1.0 * input_val);
					tx.i = (double) (((s16 *) & PHY_vars->tx_vars[j].
							  TX_DMA_BUFFER[0 *
									OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES])
							 [1 +
							  (2 * (i - l))]) / sqrt (1.0 * input_val);

					rx_tmp.r +=
						(tx.r * ch[j + (ii * NB_ANTENNAS)][l].r) -
						(tx.i * ch[j + (ii * NB_ANTENNAS)][l].i);
					rx_tmp.i +=
						(tx.i * ch[j + (ii * NB_ANTENNAS)][l].r) +
						(tx.r * ch[j + (ii * NB_ANTENNAS)][l].i);

				}
			}
 
			((s16 *) & PHY_vars->rx_vars[ii].
			 RX_DMA_BUFFER[delay + (0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)])[2 * i] =
					(short) (rx_tmp.r + n.r);
			((s16 *) & PHY_vars->rx_vars[ii].
			 RX_DMA_BUFFER[delay + (0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)])[1 +
											(2 * i)] =
					(short) (rx_tmp.i + n.i);
		}
	}

	if (be_verbose)
	{
		for (ii=0; ii<NB_ANTENNAS; ii++)
		{
			sprintf (fname, "rxsig%d.m", ii);
			sprintf (vname, "rxs%d", ii);

			write_output (fname, vname,
			      (s16 *) PHY_vars->rx_vars[ii].RX_DMA_BUFFER,
						NUMBER_OF_SYMBOLS_PER_FRAME * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES, 1, 1);
		}
	}

	//
	// RX procedure
	//  

	if (be_verbose)
		printf ("Starting RX\n");

	// Sync
	phy_synch_time (PHY_vars->rx_vars[0].RX_DMA_BUFFER,
			&sync_pos, 
			FRAME_LENGTH_COMPLEX_SAMPLES, 
			768, 
			CHSCH, 
			0);

	// Forcing sync to 0 since were running offline
	if (be_verbose)
		msg ("sync_pos = %d\n", sync_pos);
	PHY_vars->rx_vars[0].offset = 0;	//sync_pos;
	
	// estamte the signal and noise energy
	for (ii=0; ii < NB_ANTENNAS; ii++)
	{
		rx_energy[ii] = signal_energy((int *)&PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH],
																	OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
		n0_energy[ii] = signal_energy((int *)&PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH + 
																	(NUMBER_OF_CHSCH_SYMBOLS+NUMBER_OF_CHBCH_SYMBOLS+1) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES],
																	OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
		//msg("CYCLIC_PREFIX_LENGTH=%d, NUMBER_OF_CHSCH_SYMBOLS=%d, NUMBER_OF_CHBCH_SYMBOLS=%d, OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES=%d\n", CYCLIC_PREFIX_LENGTH, NUMBER_OF_CHSCH_SYMBOLS, NUMBER_OF_CHBCH_SYMBOLS, OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
		msg("symbol = %d\n", PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH + 
				(NUMBER_OF_CHSCH_SYMBOLS+NUMBER_OF_CHBCH_SYMBOLS) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES]);
		msg("SNR Ant %d = %d / %d \n", ii, rx_energy[ii], n0_energy[ii]);
	}	

	// CHBCH channel estimation
	phy_channel_estimation_top(PHY_vars->rx_vars[0].offset,0,0,0,NB_ANTENNAS,0);
	//phy_channel_estimation_top (PHY_vars->rx_vars[0].offset, 0, 0, 0);

	phy_decode_chbch (0, &dummy_mac_pdu[0], NB_ANTENNAS, NB_ANTENNAS_TX, 120);

	if (be_verbose)
	{
		for (i = 0; i < chbch_size; i++)
		{
			msg ("Data %x : %x\n", i, PHY_vars->chbch_data[0].demod_pdu[i]);
		}
	}
	
	printf("PERROR_SHIFT: %d\n", PERROR_SHIFT);
	
	//
	// Channel estimation procedure
	//
// 	for (i = 0; i < max_num_ofdm_sym; i++)
// 	{
// 		phy_channel_estimation_top(PHY_vars->rx_vars[0].offset,i,0,0,1);
// 	}
	  
	phy_channel_est_emos(16, 16, max_num_ofdm_sym-1, TRUE, 0);

	phy_cleanup ();
	if (be_verbose)
		printf ("Exiting\n");

}
Beispiel #2
0
int main(int argc, char *argv[])
{
    int x, i, j, k, p, ONEDIREC, len;
    int (*sl_func)();
    time_t t;
    char num[10];
    unsigned short int s;
    char *pp;
    char *c[D51PATTERNS][D51HIGHT+1];

    for (i = 1; i < argc; ++i) {
	if (*argv[i] == '-') {
	    option(argv[i] + 1);
	}
    }
    time(&t);
    s = (unsigned short int)t;
    seed48(&s);
#ifdef DEBUG
    PASSNUM = 3;
    ONEDIREC = 1;
    WAIT_TIME = (USLEEP_ARG0_TYPE)100;
    signal(SIGINT, end_proc);
#else
    if (INTR == 0) {
        signal(SIGINT, SIG_IGN);
    }
    PASSNUM = (int)(drand48() * 20.0) + 10;
    if (drand48() > 0.5) {
      ONEDIREC = 1;
    } else {
      ONEDIREC = 0;
    }
    WAIT_TIME = (USLEEP_ARG0_TYPE)(drand48() * 50000.0);
#endif
    ALL_LENGTH = (3 * D51LENGTH + (PASSLENGTH * (PASSNUM - 1)) + LPASSLENGTH);

    initscr();
    noecho();
#ifdef DEBUG
    printf("%d,%d\n\r", COLS, LINES);
    printf("Hit any key\n\r");
    fflush(stdout);
    getc(stdin);
#endif
    leaveok(stdscr, TRUE);
    scrollok(stdscr, FALSE);
    curs_set(0);

    DIREC = RTOL;
    p = 3 * COLS / 10;
    pp = calloc((COLS + ALL_LENGTH + 10) * (D51HIGHT + 1) * (D51PATTERNS + 1), 1);

    for (j = 0; j < D51PATTERNS; ++j) {
      for (i = 0; i <= D51HIGHT; ++i) {
	c[j][i] = pp + (COLS + ALL_LENGTH + 2) * i + (COLS + ALL_LENGTH + 1) * (D51HIGHT + 1) * j;
	for (k = 0; k < COLS; ++k) {
	  strcat(c[j][i], " ");
	}
	strncat(c[j][i], d51[j][i], 53);
	strncat(c[j][i], coal[i], 29);
	strncat(c[j][i], d51[j][i], 53);
	strncat(c[j][i], coal[i], 29);
	strncat(c[j][i], d51[j][i], 53);
	strncat(c[j][i], coal[i], 29);
	for (k = 0; k < PASSNUM - 1; ++k) {
	  strncat(c[j][i], coach[i], 88);
	  if ( i == 3 ) {
	    len = sprintf(num, "%d", k + 1);
	    strncpy(c[j][i] + COLS + 254 + (PASSLENGTH * k), num, len);
	  }
	}
	strncat(c[j][i], lcoach[i], 89);
	if ( i == 3 ) {
	  len = sprintf(num, "%d", k + 1);
	  strncpy(c[j][i] + COLS + 254 + (PASSLENGTH * k), num, len);
	}
      }
    }
    if (FLY != 1) {
      begin_gate(p);
    }
    if (LOGO == 0) {
      sl_func = add_D51_coach;
    } else {
      sl_func = add_sl;
    }
    for (x = COLS - 1; ; --x) {
        if ((*sl_func)(x, c) == ERR) break;
        if (FLY != 1) {
          if (add_cross(p) == ERR) break;
        }
	refresh();
	usleep((USLEEP_ARG0_TYPE)WAIT_TIME);
    }
    if (FLY != 1 && LOGO == 0 && ONEDIREC == 1) {
      x_gate(p);
      for (x = 0; ; ++x) {
        if (add_D51_coach_r(x) == ERR) break;
        if (add_cross(p) == ERR) break;
        refresh();
        usleep((USLEEP_ARG0_TYPE)WAIT_TIME);
      }
    }
    if (FLY != 1) {
      end_gate(p);
    }
    mvcur(0, COLS - 1, LINES - 1, 0);
    curs_set(0);
    endwin();

    return 0;
}
int
main (void)
{
  unsigned short int xs[3] = { 0x0001, 0x0012, 0x0123 };
  unsigned short int lxs[7];
  unsigned short int *xsp;
  int result = 0;
  long int l;
  double d;
  double e;

  /* Test srand48.  */
  srand48 (0x98765432);
  /* Get the values of the internal Xi array.  */
  xsp = seed48 (xs);
  if (xsp[0] != 0x330e || xsp[1] != 0x5432 || xsp[2] != 0x9876)
    {
      puts ("srand48(0x98765432) didn't set correct value");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x330e, 0x5432, 0x9876);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }
  /* Put the values back.  */
  memcpy (xs, xsp, sizeof (xs));
  (void) seed48 (xs);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x2fed1413l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2fed1413l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xa28c1003l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xa28c1003l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x585fcfb7l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x585fcfb7l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x9e88f474l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x9e88f474l, l);
      result = 1;
    }

  /* Test seed48.  The previous call should have install the values in
     the initialization of `xs' above.  */
  xs[0] = 0x1234;
  xs[1] = 0x5678;
  xs[2] = 0x9012;
  xsp = seed48 (xs);
  if (xsp[0] != 0x62f2 || xsp[1] != 0xf474 || xsp[2] != 0x9e88)
    {
      puts ("seed48() did not install the values correctly");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x62f2, 0xf474, 0x9e88);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }

  /* Test lrand48 and mrand48.  We continue from the seed established
     above.  */
  l = lrand48 ();
  if (l != 0x017e48b5l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x017e48b5l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xeb7a1fa3l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xeb7a1fa3l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x6b6a3f95l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6b6a3f95l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x175c0d6fl)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x175c0d6fl, l);
      result = 1;
    }

  /* Test lcong48.  */
  lxs[0] = 0x4567;
  lxs[1] = 0x6789;
  lxs[2] = 0x8901;
  lxs[3] = 0x0123;
  lxs[4] = 0x2345;
  lxs[5] = 0x1111;
  lxs[6] = 0x2222;
  lcong48 (lxs);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x6df63d66l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6df63d66l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x2f92c8e1l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2f92c8e1l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x3b4869ffl)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x3b4869ffl, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x5cd4cc3el)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x5cd4cc3el, l);
      result = 1;
    }

  /* Check whether srand48() restores the A and C parameters.  */
  srand48 (0x98765432);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x2fed1413l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2fed1413l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xa28c1003l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xa28c1003l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x585fcfb7l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x585fcfb7l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x9e88f474l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x9e88f474l, l);
      result = 1;
    }

  /* And again to see whether seed48() does the same.  */
  lcong48 (lxs);

  /* See whether lxs wasn't modified.  */
  l = lrand48 ();
  if (l != 0x6df63d66l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6df63d66l, l);
      result = 1;
    }

  /* Test seed48.  The previous call should have install the values in
     the initialization of `xs' above.  */
  xs[0] = 0x1234;
  xs[1] = 0x5678;
  xs[2] = 0x9012;
  xsp = seed48 (xs);
  if (xsp[0] != 0x0637 || xsp[1] != 0x7acd || xsp[2] != 0xdbec)
    {
      puts ("seed48() did not install the values correctly");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x0637, 0x7acd, 0xdbec);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }

  /* Test lrand48 and mrand48.  We continue from the seed established
     above.  */
  l = lrand48 ();
  if (l != 0x017e48b5l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x017e48b5l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xeb7a1fa3l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xeb7a1fa3l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x6b6a3f95l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6b6a3f95l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x175c0d6fl)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x175c0d6fl, l);
      result = 1;
    }

  /* Test drand48.  */
  d = drand48 ();
  if (d != 0.0908832261858485424)
    {
      printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.0908832261858485424,
	      DECIMAL_DIG, d);
      result = 1;
    }

  d = drand48 ();
  if (d != 0.943149381730059133133)
    {
      printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.943149381730059133133,
	      DECIMAL_DIG, d);
      result = 1;
    }

  /* Now the functions which get the Xis passed.  */
  xs[0] = 0x3849;
  xs[1] = 0x5061;
  xs[2] = 0x7283;

  l = nrand48 (xs);
  if (l != 0x1efe61a1l)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x1efe61a1l, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0xf568c7a0l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xf568c7a0l, l);
      result = 1;
    }

  l = nrand48 (xs);
  if (l != 0x2a5e57fel)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2a5e57fel, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x71a779a8l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x71a779a8l, l);
      result = 1;
    }

  /* Test whether the global A and C are used.  */
  lcong48 (lxs);

  l = nrand48 (xs);
  if (l != 0x32beee9fl)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x32beee9fl, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x7bddf3bal)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x7bddf3bal, l);
      result = 1;
    }

  l = nrand48 (xs);
  if (l != 0x85bdf28l)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x85bdf28l, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x7b433e47l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x7b433e47l, l);
      result = 1;
    }

  /* Test erand48.  Also compare with the drand48 results.  */
  (void) seed48 (xs);

  d = drand48 ();
  e = erand48 (xs);
  if (d != e)
    {
      printf ("\
drand48() and erand48 in lines %d and %d produce different results\n",
	      __LINE__ - 6, __LINE__ - 5);
      printf ("  drand48() = %g, erand48() = %g\n", d, e);
      result = 1;
    }
  else if (e != 0.640650904452755298735)
    {
      printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.640650904452755298735,
	      DECIMAL_DIG, e);
      result = 1;

    }

  d = drand48 ();
  e = erand48 (xs);
  if (d != e)
    {
      printf ("\
drand48() and erand48 in lines %d and %d produce different results\n",
	      __LINE__ - 6, __LINE__ - 5);
      printf ("  drand48() = %g, erand48() = %g\n", d, e);
      result = 1;
    }
  else if (e != 0.115372323508150742555)
    {
      printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.0115372323508150742555,
	      DECIMAL_DIG, e);
      result = 1;

    }

  return result;
}
Beispiel #4
0
void runFailure() {
    seed48(NULL);
}
int main()
{
  Debug(libcw_do.on());
  Debug(dc::notice.on());
  Debug(libcw_do.set_ostream(&std::cout));
  Debug(list_channels_on(libcw_do));

  unsigned short seed16v[3] = { 0x1234, 0xfedc, 0x7091 };

  for (int k = 0;; ++k)
  {
	std::cout << "Loop: " << k << "; SEED: " << std::hex << seed16v[0] << ", " << seed16v[1] << ", " << seed16v[2] << std::dec << std::endl;
	++LLFrameTimer::sFrameCount;

	seed48(seed16v);
	seed16v[0] = lrand48() & 0xffff;
	seed16v[1] = lrand48() & 0xffff;
	seed16v[2] = lrand48() & 0xffff;

	TestsuiteClient<synckeytype_test1a> client1a[number_of_clients_per_syncgroup];
	TestsuiteClient<synckeytype_test1b> client1b[number_of_clients_per_syncgroup];
	TestsuiteClient<synckeytype_test2a> client2a[number_of_clients_per_syncgroup];
	TestsuiteClient<synckeytype_test2b> client2b[number_of_clients_per_syncgroup];
	client1ap = client1a;
	client1bp = client1b;
	client2ap = client2a;
	client2bp = client2b;

	for (int i = 0; i < number_of_clients_per_syncgroup; ++i)
	{
	  client1a[i].setIndex(i);
	  client1b[i].setIndex(i);
	  client2a[i].setIndex(i);
	  client2b[i].setIndex(i);
	}

	for (int j = 0; j < 1000000; ++j)
	{
	  innerloop_count += 1;

#ifdef DEBUG_SYNCOUTPUT
	  Dout(dc::notice, "Innerloop: " << j);
#endif
	  unsigned long r = lrand48();
	  synckeytype_t keytype = (r & 1) ? ((r & 2) ? synckeytype_test1a : synckeytype_test1b) : ((r & 2) ? synckeytype_test2a : synckeytype_test2b);
	  r >>= 2;
	  int cl = (r & 255) % number_of_clients_per_syncgroup;
	  r >>= 8;
	  switch (keytype)
	  {
		case synckeytype_test1a:
		  client1a[cl].change_state(r);
		  break;
		case synckeytype_test1b:
		  client1b[cl].change_state(r);
		  break;
		case synckeytype_test2a:
		  client2a[cl].change_state(r);
		  break;
		case synckeytype_test2b:
		  client2b[cl].change_state(r);
		  break;
	  }
	}
  }
}