Esempio n. 1
0
void test_local_bus__measure_write_and_then_read_data_rate(unsigned short int should_do_write_test, unsigned short int should_do_read_test) {
	unsigned long int number_of_writes = 0, number_of_reads = 0, number_of_errors = 0, number_of_loops = 0;
	unsigned short int value;
	srand(time(NULL));
//	clock_t start_writing, done_writing, start_reading, done_reading;
	unsigned long int i, j;
	if (1) {
		for (i=0; i<BIG_ARRAY_SIZE; i++) {
			array[i] = pseudo_random(0x0, 0xff);
		}
		if (should_do_write_test) {
//			start_writing = clock();
			gettimeofday(&start1, NULL);
			for (i=0; i<BIG_ARRAY_SIZE; i++) {
				j = pseudo_random(ARRAY_PARTIAL_RANGE__FIRST, ARRAY_PARTIAL_RANGE__LAST);
				FINESSE_CSR_WR(slot, j, array[i]);
				number_of_writes++;
			}
//			done_writing = clock();
			gettimeofday(&end1, NULL);
			timeval_subtract(&result1, &end1, &start1);
//			float seconds_for_write = ((float) (done_writing - start_writing)) / CLOCKS_PER_SEC;
			float seconds_for_write = result1.tv_sec + result1.tv_usec / 1000000.0;
			if (seconds_for_write) {
				float kilobytes_per_second_write = 1.0e-3 * number_of_writes / seconds_for_write;
				printf("%d bytes in %4.1f seconds = %4.0f kbytes/s (write)\n", number_of_writes, seconds_for_write, kilobytes_per_second_write);
			}
			number_of_writes = 0;
		}
		if (should_do_read_test) {
//			start_reading = clock();
			gettimeofday(&start2, NULL);
			for (i=0; i<BIG_ARRAY_SIZE; i++) {
				j = pseudo_random(ARRAY_PARTIAL_RANGE__FIRST, ARRAY_PARTIAL_RANGE__LAST);
				FINESSE_CSR(slot, j);
				number_of_reads++;
			}
//			done_reading = clock();
			gettimeofday(&end2, NULL);
			timeval_subtract(&result2, &end2, &start2);
//			float seconds_for_read  = ((float) (done_reading - start_reading)) / CLOCKS_PER_SEC;
			float seconds_for_read = result2.tv_sec + result2.tv_usec / 1000000.0;
			if (seconds_for_read) {
				float kilobytes_per_second_read  = 1.0e-3 * number_of_reads / seconds_for_read;
				printf("%d bytes in %4.1f seconds = %4.0f kbytes/s (read)\n", number_of_reads, seconds_for_read, kilobytes_per_second_read);
			}
			number_of_reads = 0;
		}
	}
}
Esempio n. 2
0
static double get_pseudorandom_double( void)
{
   static uint64_t rval = 1;
   const double two_to_the_53rd_power = 9007199254740992.0;

   rval = pseudo_random( rval);
   return (int64_t)(rval >> 11) * (1.0 / two_to_the_53rd_power);
}
Esempio n. 3
0
// the following function ran for 135,112,000,000 transfers with 0 errors with the
// copper local bus DSP_FIN revC firmware that was in use on 2010-07-07
// it worked flawlessly with the same firmware the next day for 22,808,000,000 transfers
void test_local_bus__measure_write_and_then_read_data_rate__interleaved__single(void) {
	unsigned long int number_of_writes = 0, number_of_reads = 0, number_of_errors = 0, number_of_loops = 0;
	static unsigned long int millions_of_transfers = 0, number_of_transfers = 0;
	unsigned short int value;
	srand(time(NULL));
//	clock_t start, done;
	unsigned long int i, j;
	if (1) {
		for (i=0; i<BIG_ARRAY_SIZE; i++) {
			array[i] = pseudo_random(0x0, 0xff);
		}
//			start = clock();
			gettimeofday(&start1, NULL);
			for (i=0; i<BIG_ARRAY_SIZE; i++) {
				j = pseudo_random(ARRAY_PARTIAL_RANGE__FIRST, ARRAY_PARTIAL_RANGE__LAST);
				FINESSE_CSR_WR(slot, j, array[i]);
				value = FINESSE_CSR(slot, j);
				if (j == 0x57 || j == 0x63 || j >= 0x7a) {
				} else {
					if (value != array[i]) {
						printf("value at [0x%02x]: 0x%02x != 0x%02x (%d errors in %d M transfers)\n", j, value, array[i], number_of_errors, millions_of_transfers);
						number_of_errors++;
					}
				}
				number_of_writes++;
				number_of_reads++;
				number_of_transfers++;
			}
//			done = clock();
			gettimeofday(&end1, NULL);
			timeval_subtract(&result1, &end1, &start1);
			unsigned long int m = (number_of_transfers - (number_of_transfers % 1000000)) / 1000000;
			number_of_transfers -= 1000000 * m;
			millions_of_transfers += m;
//			float seconds = ((float) (done - start)) / CLOCKS_PER_SEC;
			timeval_subtract(&result1, &end1, &start1);
			float seconds = result1.tv_sec + result1.tv_usec / 1000000.0;
			if (seconds) {
				float kilobytes_per_second = 1.0e-3 * number_of_writes / seconds;
				printf("%d bytes in %4.1f seconds = %4.0f kbytes/s (write, then read) (%d errors in %d M transfers) [single]\n", number_of_writes, seconds, kilobytes_per_second, number_of_errors, millions_of_transfers);
			number_of_writes = 0;
			number_of_reads = 0;
			}
	}
}
Esempio n. 4
0
int main(void) {
  unsigned char *r, *hex_char;

  r = pseudo_random(32);

  hex_char = bin_to_hex(r, 32);

  return 0;
}
Esempio n. 5
0
File: bbt.c Progetto: AlexMioMio/gcc
void
gfc_insert_bbt (void *root, void *new_node, compare_fn compare)
{
  gfc_bbt **r, *n;

  r = (gfc_bbt **) root;
  n = (gfc_bbt *) new_node;
  n->priority = pseudo_random ();
  *r = insert (n, *r, compare);
}
Esempio n. 6
0
void test_local_bus__write_and_then_read__blocky(void) {
	unsigned long int number_of_writes = 0, number_of_reads = 0, number_of_errors = 0, number_of_loops = 0;
	static unsigned long int millions_of_transfers = 0, number_of_transfers = 0;
	unsigned short int value;
	srand(time(NULL));
//	clock_t start, done;
	unsigned long int i, j, k;
	if (1) {
		for (i=0; i<ARRAY_PARTIAL_RANGE__LENGTH; i++) {
			array[i] = pseudo_random(0x0, 0xff);
		}
//		start = clock();
		gettimeofday(&start1, NULL);	
//		unsigned long i_max = BIG_ARRAY_SIZE / ARRAY_PARTIAL_RANGE__LENGTH;
//		for (i=0; i<i_max; i++) {
			for (j=ARRAY_PARTIAL_RANGE__FIRST; j<=ARRAY_PARTIAL_RANGE__LAST; j++) {
				k = j - ARRAY_PARTIAL_RANGE__FIRST;
//				printf("writing 0x%02x to address 0x%02x\n", array[k], j);
				FINESSE_CSR_WR(slot, j, array[k]);
				number_of_writes++;
			}
			number_of_transfers++;
			for (j=ARRAY_PARTIAL_RANGE__LAST; j>=ARRAY_PARTIAL_RANGE__FIRST; j--) {
//			for (j=ARRAY_PARTIAL_RANGE__FIRST; j<=ARRAY_PARTIAL_RANGE__LAST; j++) {
				k = j - ARRAY_PARTIAL_RANGE__FIRST;
				value = FINESSE_CSR(slot, j);
//				printf("read 0x%02x from address 0x%02x\n", value, j);
				number_of_reads++;
//				printf("address 0x%02x: 0x%02x (written); 0x%02x (read back)\n", j, array[k], value);
				if (j == 0x57 || j == 0x63 || j >= 0x7a) {
//					printf("address 0x%02x: 0x%02x (written); 0x%02x (read back)\n", j, array[k], value);
				} else {
					if (value != array[k]) {
						number_of_errors++;
						printf("value at [0x%02x]: 0x%02x != 0x%02x (%d errors in %d transfers)\n", j, value, array[k], number_of_errors, number_of_transfers);
					}
				}
			}
//		}
//		done = clock();
		gettimeofday(&end1, NULL);	
		unsigned long int m = (number_of_transfers - (number_of_transfers % 1000000)) / 1000000;
		number_of_transfers -= 1000000 * m;
		millions_of_transfers += m;
//		float seconds = ((float) (done - start)) / CLOCKS_PER_SEC;
		timeval_subtract(&result1, &end1, &start1);
		float seconds = result1.tv_sec + result1.tv_usec / 1000000.0;
		if (seconds) {
			float kilobytes_per_second = 1.0e-3 * number_of_writes / seconds;
//			printf("%d bytes in %4.1f seconds = %4.0f kbytes/s (write, then read) (%d errors in %d M transfers)\n", number_of_writes, seconds, kilobytes_per_second, number_of_errors, millions_of_transfers);
		}
		number_of_writes = 0;
		number_of_reads = 0;
	}
}
Esempio n. 7
0
void hosts::do_fetch(fetch_handler handler)
{
    if (buffer_.empty())
    {
        handler(error::not_found, address());
        return;
    }

    // Randomly select an address from the buffer.
    const auto index = static_cast<size_t>(pseudo_random() % buffer_.size());
    handler(error::success, buffer_[index]);
}
Esempio n. 8
0
code hosts::fetch(address& out) const
{
    ///////////////////////////////////////////////////////////////////////////
    // Critical Section
    shared_lock lock(mutex_);

    if (stopped_)
        return error::service_stopped;

    if (buffer_.empty())
        return error::not_found;

    // Randomly select an address from the buffer.
    const auto random = pseudo_random(0, buffer_.size() - 1);
    const auto index = static_cast<size_t>(random);
    out = buffer_[index];
    return error::success;
    ///////////////////////////////////////////////////////////////////////////
}
Esempio n. 9
0
/*
 * Main entry point of program.<br>
 *  -speed       Test the speed of operations in cycles and per second.<br>
 *  -sha3_224    Test the SHA-3 224 hash algorithm.<br>
 *  -sha3_256    Test the SHA-3_256 hash algorithm.<br>
 *  -sha3_384    Test the SHA-3 384 hash algorithm.<br>
 *  -sha3_512    Test the SHA-3_512 hash algorithm.<br>
 *  -sha224      Test the SHA224 hash algorithm.<br>
 *  -sha256      Test the SHA256 hash algorithm.<br>
 *  -sha384      Test the SHA384 hash algorithm.<br>
 *  -sha512      Test the SHA512 hash algorithm.<br>
 *  -sha512_224  Test the SHA512-224 hash algorithm.<br>
 *  -sha512_256  Test the SHA512-256 hash algorithm.<br>
 *  -blake2b     Test the BLAKE2b hash algorithm with 512 bits of output.<br>
 *  -blake2s     Test the BLAKE2s hash algorithm with 256 bits of output.<br>
 *  -int         Test internal implementations only.<br>
 *  -verify      Test the speed of verification rather than signing.<br>
 *
 * @param [in] argc  The count of command line arguments.
 * @param [in] argv  The command line arguments.
 * @return  0 on success.<br>
 *          1 on test failure.
 */
int main(int argc, char *argv[])
{
    int ret = 0;
    int speed = 0;
    int verify = 0;
    int which = 0;
    int flags = 0;
    int i;
    MAC_ID alg_id;

    while (--argc)
    {
        argv++;
        alg_id = -1;

        if (strcmp(*argv, "-speed") == 0)
            speed = 1;
        else if (strcmp(*argv, "-sha3_224") == 0)
            alg_id = MAC_ID_SHA3_224;
        else if (strcmp(*argv, "-sha3_256") == 0)
            alg_id = MAC_ID_SHA3_256;
        else if (strcmp(*argv, "-sha3_384") == 0)
            alg_id = MAC_ID_SHA3_384;
        else if (strcmp(*argv, "-sha3_512") == 0)
            alg_id = MAC_ID_SHA3_512;
        else if (strcmp(*argv, "-sha224") == 0)
            alg_id = MAC_ID_SHA224;
        else if (strcmp(*argv, "-sha256") == 0)
            alg_id = MAC_ID_SHA256;
        else if (strcmp(*argv, "-sha384") == 0)
            alg_id = MAC_ID_SHA384;
        else if (strcmp(*argv, "-sha512") == 0)
            alg_id = MAC_ID_SHA512;
        else if (strcmp(*argv, "-sha512_224") == 0)
            alg_id = MAC_ID_SHA512_224;
        else if (strcmp(*argv, "-sha512_256") == 0)
            alg_id = MAC_ID_SHA512_256;
        else if (strcmp(*argv, "-blake2b") == 0)
            alg_id = MAC_ID_BLAKE2B_512;
        else if (strcmp(*argv, "-blake2s") == 0)
            alg_id = MAC_ID_BLAKE2S_256;
        else if (strcmp(*argv, "-sha1") == 0)
            alg_id = MAC_ID_SHA1;
        else if (strcmp(*argv, "-int") == 0)
            flags = MAC_METH_FLAG_INTERNAL;
        else if (strcmp(*argv, "-verify") == 0)
            verify = 1;

        if (alg_id != -1)
        {
            for (i=0; i<NUM_ID; i++)
            {
                if (id[i] == alg_id)
                    which |= 1 << i;
            }
        }
    }

    if (speed)
    {
        calc_cps();
        pseudo_random(msg, sizeof(msg));
    }

    for (i=0; i<NUM_ID; i++)
    {
        if ((which == 0) || ((which & (1 << i)) != 0))
            ret |= test_mac(id[i], flags, speed, verify);
    }

    return (ret != 0);
}