Exemple #1
0
void grpc_passthru_endpoint_create(grpc_endpoint **client,
                                   grpc_endpoint **server,
                                   grpc_resource_quota *resource_quota) {
    passthru_endpoint *m = gpr_malloc(sizeof(*m));
    m->halves = 2;
    m->shutdown = 0;
    half_init(&m->client, m, resource_quota, "client");
    half_init(&m->server, m, resource_quota, "server");
    gpr_mu_init(&m->mu);
    *client = &m->client.base;
    *server = &m->server.base;
}
Exemple #2
0
void grpc_passthru_endpoint_create(grpc_endpoint **client,
                                   grpc_endpoint **server,
                                   grpc_resource_quota *resource_quota,
                                   grpc_passthru_endpoint_stats *stats) {
  passthru_endpoint *m = (passthru_endpoint *)gpr_malloc(sizeof(*m));
  m->halves = 2;
  m->shutdown = 0;
  m->stats = stats == NULL ? &m->dummy_stats : stats;
  memset(m->stats, 0, sizeof(*m->stats));
  half_init(&m->client, m, resource_quota, "client");
  half_init(&m->server, m, resource_quota, "server");
  gpr_mu_init(&m->mu);
  *client = &m->client.base;
  *server = &m->server.base;
}
Exemple #3
0
bool test_max_alc_1_byte( void ) {
	bool rslt = true;
	uint32_t c = 0;
	size_t max_sz;
	
	half_init();

	max_sz = find_max_block();

	// Allocate 1 bytes until no half_aloc returns NULL

	while ( half_alloc( 1 ) != NULL ) {
		c++;
	}

	#ifdef DO_PRINT
		printf( "Only %d 1-Byte block can be allocated within %d addressable Bytes.\n", c, max_sz );
	#endif

	if ( c == 0 || !(max_sz >= smlst_blk_sz * c  || smlst_blk_sz * c >= lrgst_blk_sz) ) {
		#ifdef DO_PRINT
			printf( "32 * %d = %d is not equal to the maximum allocable block which is %d\n", c, c*32 , max_sz );
		#endif

		rslt = false;
	}

	return rslt;
}
Exemple #4
0
void hp98035_io_card::device_reset()
{
	hp9845_io_card_device::device_reset();
	install_readwrite_handler(read16_delegate(FUNC(hp98035_io_card::reg_r) , this) , write16_delegate(FUNC(hp98035_io_card::reg_w) , this));

	m_idr_full = false;
	m_idr = 0;
	m_odr = 0;
	m_ibuffer_ptr = 0;
	m_obuffer_len = 0;
	m_obuffer_ptr = 0;
	sts_w(true);
	set_flg(true);

	// Set real time from the real world
	system_time systime;
	machine().base_datetime(systime);
	m_msec = 0;
	m_sec = systime.local_time.second;
	m_min = systime.local_time.minute;
	m_hrs = systime.local_time.hour;
	m_dom = systime.local_time.mday;
	m_mon = systime.local_time.month + 1;

	attotime period(attotime::from_msec(1));
	m_msec_timer->adjust(period , 0 , period);

	half_init();
}
bool test_static_alc_free( void ) {
	bool rslt = true;
	uint32_t max_sz;
	void *ptr_1, *ptr_2, *ptr_3, *ptr_4, *ptr_5, *ptr_6;
	
	half_init();

	max_sz = find_max_block();

	ptr_1 = half_alloc(1 << 5 + 1);
	if (ptr_1 == NULL) return false;

	ptr_2 = half_alloc(1 << 9 - 1);
	if (ptr_2 == NULL) return false;

	ptr_3 = half_alloc(1 << 5 + 1);
	if (ptr_3 == NULL) return false;

	ptr_4 = half_alloc(1 << 10);
	if (ptr_4 == NULL) return false;

	ptr_5 = half_alloc(12345);
	if (ptr_5 == NULL) return false;

	half_free(ptr_1);

	ptr_6 = half_alloc(1);
	if (ptr_6 == NULL) return false;

	half_free(ptr_3);

	half_free(ptr_4);

	ptr_1 = half_alloc(1 << 9);
	if (ptr_1 == NULL) return false;

	half_free(ptr_6);

	half_free(ptr_1);

	half_free(ptr_2);

	half_free(ptr_5);

	// Check wether all allocated memory blocks are freed.
	ptr_1 = half_alloc(max_sz);

	if ( ptr_1 == NULL ) {
		rslt = false;
		printf("Memory is defraged.\n");
	} else {
		half_free(ptr_1);
	}

	return rslt;
}
Exemple #6
0
bool test_alc_free_max( void ) {
	bool rslt = true;
	uint32_t blk_sz;
	void* ptr;

	half_init();
	blk_sz = find_max_block();
	ptr = half_alloc( blk_sz );

	if ( ptr == NULL ) {
		rslt = false;
	}
	
	return rslt;
}
bool test_max_alc( void ) {
	bool rslt = true;
	uint32_t blk_sz, max_blk_sz;
	
	half_init();

	blk_sz = find_max_block();
	printf("blk_sz = %d", blk_sz);
	max_blk_sz = 0x01 << lrgst_blk;

	if ( ((int)max_blk_sz - (int)blk_sz) / max_blk_sz > 1 ) {
		// The algorithm wasted more than 1% of memory.
		rslt = false;
	}
	
	return rslt;
}
Exemple #8
0
void hp98035_io_card_device::device_reset()
{
	hp9845_io_card_device::device_reset();

	m_idr_full = false;
	m_idr = 0;
	m_odr = 0;
	sts_w(true);
	set_flg(true);

	attotime period(attotime::from_msec(1));
	m_msec_timer->adjust(period , 0 , period);

	period = attotime::from_hz(DIGIT_MUX_FREQ);
	m_clock_timer->adjust(period , 0 , period);

	half_init();
}
Exemple #9
0
void hp98035_io_card::device_reset()
{
	hp9845_io_card_device::device_reset();
	install_readwrite_handler(read16_delegate(FUNC(hp98035_io_card::reg_r) , this) , write16_delegate(FUNC(hp98035_io_card::reg_w) , this));

	m_idr_full = false;
	m_idr = 0;
	m_odr = 0;
	sts_w(true);
	set_flg(true);

	attotime period(attotime::from_msec(1));
	m_msec_timer->adjust(period , 0 , period);

	period = attotime::from_hz(DIGIT_MUX_FREQ);
	m_clock_timer->adjust(period , 0 , period);

	half_init();
}
Exemple #10
0
bool test_rndm_alc_free( void ) {
	bool rslt = true;
	size_t line = 0, max_sz, blks_sz, alc_rec, tbf, blk_sz;
	int i;
	block_t blks[RNDM_TESTS << 1];
	block_t blk;
	void *ptr_1;

	blks_sz = 0;

	half_init();

	max_sz = find_max_block();
	
	// 'alc_rec' stores how many times 'half_alloc' successfully returns a requested block.
	alc_rec = 0;

	// Allocating random memory blocks
	for ( i = 0; i < RNDM_TESTS; ++i ) {

		// Making a new memory block and storing its pointer in the array 
		size_t blk_sz = get_random_block_size();
		block_t blk;
		blk.ptr = half_alloc(blk_sz);
		blk.len = blk_sz;

		if ( blk.ptr != 0 ) {
			blks[blks_sz] = blk;
			++blks_sz;
			alc_rec++;

			#ifdef DO_PRINT
				printf( "%i)The allocated %d Byte block starts from %d \n", ++line, blk.len, blk.ptr );
			#endif
		}
	}

	// Checking any violation
	if ( is_violated(find_violation(blks, blks_sz)) ) {
		return false;
	}
	
	// Free almost half of the allocation blocks
	for ( i = 0; i < RNDM_TESTS >> 1 ; ++i ) {
		if ( (rand() % 2) && (blks_sz > 0) ) {
			// Free a random block
			tbf = rand() % blks_sz;	// To be freed idex
			half_free(blks[tbf].ptr);

			#ifdef DO_PRINT
				printf( "%i)The %d Byte block starting from %d is free1\n", ++line, blks[tbf].len, blks[tbf].ptr );
			#endif

			--blks_sz;
			blks[tbf] = blks[blks_sz];

		} else {
			blk_sz = get_random_block_size();
			blk.ptr = half_alloc(blk_sz);
			blk.len = blk_sz;

			if ( blk.ptr != 0 ) {
				blks[blks_sz] = blk;
				++blks_sz;
				alc_rec++;

				#ifdef DO_PRINT
					printf( "%i)The allocated %d Byte block starts from %d \n", ++line, blk.len, blk.ptr );
				#endif
			}
		}
	}
	
	// Checking any violation
	if ( is_violated( find_violation( blks, blks_sz ) ) ) {
		return false;
	}


	for ( i = blks_sz - 1; i >= 0; --i ) {
		half_free(blks[i].ptr);
		--blks_sz;

		#ifdef DO_PRINT
			printf( "%i)The %d Byte block starting from %d is free2\n", ++line, blks[i].len, blks[i].ptr );
		#endif
	}

	// All allocated memories have to be freed now.

	#ifdef DO_PRINT
		printf("%d random blocks are allocated and freed without any violation.\n", alc_rec);
	#endif

	ptr_1 = half_alloc(max_sz);

	if ( ptr_1 == NULL ) {
		rslt = false;

		#ifdef DO_PRINT
			printf( "Memory is defraged.\n" );
		#endif
	} else {
		half_free( ptr_1 );
	}

	return rslt;
}
Exemple #11
0
bool test_static_alc_free_violation( void ) {
	bool rslt = true;
	size_t max_sz, blks_sz;
	block_t blks[5];
	void* ptr_1;
	
	half_init();
	max_sz = find_max_block();

	blks_sz = 0;

	alloc_blk_in_arr( blks, &blks_sz, (1 << 5) + 1 );
	alloc_blk_in_arr( blks, &blks_sz, (1 << 9) - 1 );
	alloc_blk_in_arr( blks, &blks_sz, (1 << 5) + 1 );
	alloc_blk_in_arr( blks, &blks_sz, (1 << 10)    );
	alloc_blk_in_arr( blks, &blks_sz, 12345        );

	if ( blks_sz == 0 ) {
		#ifdef DO_PRINT
			printf( "Failure on allocating any memory block. The memory access violation is irrelevant.\n" );
		#endif

		return false;
	}

	// Checking any violation
	if ( is_violated( find_violation( blks, blks_sz ) ) ) {
		return false;
	}

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	alloc_blk_in_arr(blks, &blks_sz, (1 << 9));

	// Checking any violation
	if ( is_violated(find_violation(blks, blks_sz)) ) {
		return false;
	}

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	--blks_sz;
	half_free(blks[blks_sz].ptr);

	// Check wether all allocated memory blocks are freed.
	ptr_1 = half_alloc(max_sz);

	if ( ptr_1 == NULL ) {
		rslt = false;

		#ifdef DO_PRINT
			printf( "Memory is defraged.\n" );
		#endif
	} else {
		half_free( ptr_1 );
	}

	return rslt;
}
Exemple #12
0
void hp98035_io_card::process_ibuffer(void)
{
	m_ibuffer[ m_ibuffer_ptr ] = '\0';
	const uint8_t *p = &m_ibuffer[ 0 ];

	clear_obuffer();

	bool get_out = false;

	while (*p != '\0' && !get_out) {
		std::ostringstream out;
		uint8_t datetime[ 5 ];
		unsigned unit_no;

		switch (*p++) {
		case 'A':
			// Halt all timer units
			for (timer_unit_t& unit : m_units) {
				unit.deactivate();
			}
			m_inten = false;
			m_intflag = false;
			update_irq();
			break;

		case 'B':
			// Warm reset
			half_init();
			get_out = true;
			break;

		case 'E':
			// Read and clear errors
			set_obuffer(m_error);
			m_error = 0;
			break;

		case 'F':
			// Activate all timer units
			for (timer_unit_t& unit : m_units) {
				if (unit.m_port) {
					unit.adv_state(true);
				}
			}
			break;

		case 'R':
			// Read time
			// Assume US format of dates
			util::stream_format(out , "%02u:%02u:%02u:%02u:%02u" , m_mon , m_dom , m_hrs , m_min , m_sec);
			set_obuffer(out.str().c_str());
			break;

		case 'S':
			// Set time
			if (parse_datetime(p , datetime)) {
				// Cannot set time when there's one or more active output units
				if (std::any_of(std::begin(m_units) , std::end(m_units) , [](const timer_unit_t& u) { return u.m_state != UNIT_IDLE && !u.m_input; })) {
					set_error(ERR_MASK_CANT_EXEC);
				} else {
					m_msec = 0;
					m_sec = datetime[ 4 ];
					if (datetime[ 3 ] != EMPTY_FIELD) {
						m_min = datetime[ 3 ];
						if (datetime[ 2 ] != EMPTY_FIELD) {
							m_hrs = datetime[ 2 ];
							if (datetime[ 1 ] != EMPTY_FIELD) {
								m_dom = datetime[ 1 ];
								if (datetime[ 0 ] != EMPTY_FIELD) {
									m_mon = datetime[ 0 ];
								}
							}
						}
					}
				}
			} else {
				set_error(ERR_MASK_WRONG_INS);
				get_out = true;
			}
			break;

		case 'T':
			// Read triggered outputs
			set_obuffer(m_triggered);
			m_triggered = 0;
			break;

		case 'U':
			// Control timer units
			if (parse_unit_no(p , unit_no)) {
				get_out = parse_unit_command(p , unit_no);
			} else {
				set_error(ERR_MASK_WRONG_INS);
				get_out = true;
			}
			break;

		case 'W':
			// Read unserviced interrupts
			set_obuffer(m_lost_irq);
			m_lost_irq = 0;
			break;

		default:
			set_error(ERR_MASK_WRONG_INS);
			get_out = true;
			break;
		}
	}

	m_ibuffer_ptr = 0;
}