Exemplo n.º 1
0
void MainWindow::setupBootLoader()
{
    /* I have no idea why I can't give the value directly to SLOT(...) */
    unsigned val = 0;
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    /* Set up the boot loader */
    ui->statusLabel->setText(tr("Configuring bootloader"));
    logger->addLine("Configuring bootloader: moving /boot to appropriate boot partition");
    bc->copyBootFiles();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    logger->addLine("Configuring boot cmdline");
    bc->configureEnvironment();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    logger->addLine("Configuring /etc/fstab");
    bc->configureMounts();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    /* Dump the log */
    logger->addLine("Successful installation. Dumping log and rebooting system");
    dumpLog();
    QTimer::singleShot(0, this, SLOT(val));

    /* Reboot */
    ui->statusLabel->setText(tr("OSMC installed successfully"));
    qApp->processEvents(); /* Force GUI update */
    utils->rebootSystem();
}
Exemplo n.º 2
0
void MainWindow::haltInstall(QString errorMsg)
{
    logger->addLine("Halting Install. Error message was: " + errorMsg);
    ui->statusProgressBar->setMaximum(100);
    ui->statusProgressBar->setValue(0);
    ui->statusLabel->setText(tr("Install failed: ") + errorMsg);
    dumpLog();
}
Exemplo n.º 3
0
Program* build_Program( const char* name, 
                        int n_shaders, Shader* shaders[],
                        int n_attribs, const char* attribs[],
                        int n_uniforms, const char* uniforms[]) {

	GLuint id = glCreateProgram();
	if( !id )
		return NULL;

	pointer pgmbuf = malloc( sizeof(Program) 
	                         + strlen(name)+1 
	                         + n_shaders*sizeof(Shader*) );

	Program* pgm = pgmbuf;
	pgm->id = id;
	pgm->name = pgmbuf + sizeof(Program);
	strcpy( (char*)pgm->name, name );

	// Build
	pgm->n_shaders = n_shaders;
	pgm->shaders = pgmbuf + sizeof(Program) + strlen(name) + 1;

	pgm->log = NULL;

	for( int i=0; i<n_shaders; i++ ) {
		glAttachShader( id, shaders[i]->id ); check_GL_error;
		pgm->shaders[i] = shaders[i];
	}

	for( int i=0; i<n_attribs; i++ )
		glBindAttribLocation( id, i, attribs[i] ); check_GL_error;

	glLinkProgram( id ); check_GL_error;

	// Get the results
	GLint built; glGetProgramiv( id, GL_LINK_STATUS, &built ); check_GL_error;
	pgm->built = GL_TRUE == built ? true : false;

	// Get the log
	fetchLog( pgm );

	// Build the attribute and uniform metadata
	if( GL_TRUE == built ) {

		pgm->attribs  = get_active_attribs( pgm, n_attribs, attribs );
		pgm->uniforms = get_active_uniforms( pgm, n_uniforms, uniforms );
		
	} else {

		debug( "failed to link program '%s':", pgm->name );
		dumpLog( pgm->log, "\t" );

	}

	return pgm;
}
Exemplo n.º 4
0
// ~Game()
// Description: game ends, calculate & dump results to log
Game::~Game(){
    m_objCount--;
    if(m_objCount == 0 && m_objInit){
        m_endTime = cpuTime();
        updateStats();
        dumpLog("open_src_version.log");
    }
    else
        updateStats();
}
Exemplo n.º 5
0
void MainWindow::setupBootLoader()
{
    /* I have no idea why I can't give the value directly to SLOT(...) */
    unsigned val = 0;
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    /* Set up the boot loader */
    ui->statusLabel->setText(tr("Configuring bootloader"));
    if (device->hasBootChanged())
    {
        logger->addLine("Boot changed. Re-mounting the real /boot");
        utils->unmountPartition(device, MNT_BOOT);
        utils->mountPartition(device, MNT_BOOT);
    }
    logger->addLine("Configuring bootloader: moving /boot to appropriate boot partition");
    bc->copyBootFiles();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    logger->addLine("Configuring boot cmdline");
    bc->configureEnvironment();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    logger->addLine("Configuring /etc/fstab");
    bc->configureMounts();
    QTimer::singleShot(0, this, SLOT(val));
    val += 25;
    /* Dump the log */
    logger->addLine("Successful installation. Dumping log and rebooting system");
    dumpLog();
    QTimer::singleShot(0, this, SLOT(val));

    /* Reboot */
    if (utils->getOSMCDev() == "vero2")
    {
        system("/bin/sync");
        ui->statusLabel->setText(tr("OSMC installed successfully"));
        qApp->processEvents(); /* Force GUI update */
    }
    else
    {
        ui->statusLabel->setText(tr("OSMC installed successfully"));
        qApp->processEvents(); /* Force GUI update */
        utils->rebootSystem();
    }
}
Exemplo n.º 6
0
Shader* compile_Shader( shaderType_e type, const char* name, const char* src ) {

	GLuint id = glCreateShader( (GLenum)type );
	if( !id ) 
		return NULL;

	// Compile
	glShaderSource( id, 1, &src, NULL ); check_GL_error;
	if( GL_NO_ERROR != gl_lastError ) {
		glDeleteShader(id); check_GL_error;
		return NULL;
	}
	glCompileShader( id ); check_GL_error;

	// Build up the Shader* object
	pointer shbuf = malloc( sizeof(Shader) + strlen(name) + 1 + strlen(src) + 1 );
	Shader* sh = shbuf;
	sh->id = id;
	sh->type = type;
	sh->name = shbuf + sizeof(Shader); strcpy( sh->name, name );//clone_string(sh, name);
	sh->src = sh->name + strlen(name) + 1; strcpy( sh->src, src );//clone_string(sh, src);
	
	// Get results
	GLint compiled; glGetShaderiv( id, GL_COMPILE_STATUS, &compiled ); check_GL_error;
	sh->compiled = GL_TRUE == compiled ? true : false;

	GLint log_length; glGetShaderiv( id, GL_INFO_LOG_LENGTH, &log_length ); check_GL_error;
	if( log_length > 1 ) {
		sh->log = malloc( log_length );
		glGetShaderInfoLog( id, log_length, NULL, sh->log ); check_GL_error;
	} else
		sh->log = NULL;

	if( !sh->compiled && sh->log ) {

		const char* kind = (shadeVertex == type) ? "vertex" : "fragment";
		warning( "compilation failed for %s shader '%s':", kind, sh->name );
		dumpLog( sh->log, "\t" );

	}
		
	check_GL_error;
	return sh;

}
Exemplo n.º 7
0
Arquivo: errlTest.c Projeto: deece/occ
// Function Specification
//
// Name: errlTestCreateCommitDeleteLog
//
// Description: errlTestCreateCommitDeleteLog
//
// End Function Specification
uint32_t errlTestCreateCommitDeleteLog()
{
    ERRL_DBG("START");
    uint32_t l_rc = 0;

    do
    {
        /****************************************************/
        // Test create log
        errlHndl_t l_handle = NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 512, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        ERRL_DBG("Slots after Creating call home log" );
        ppdumpslot();

        /****************************************************/
        // Test commit log
        errlHndl_t l_handle2 = l_handle;
        commitErrl( &l_handle );
        CHECK_CONDITION( (l_handle == NULL) &&
                         (l_handle2->iv_userDetails.iv_committed == 1), l_rc);

        ERRL_DBG("Slots after Commiting call home log" );
        dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize );
        ppdumpslot();

        /****************************************************/
        // Test delete log
        deleteErrl(&l_handle2);
        CHECK_CONDITION( l_handle2 == NULL, l_rc);

        ERRL_DBG("Slots after delete Log" );
        ppdumpslot();

        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}
bool Log::logR ( long long now , long type , char *msg , bool asterisk ,
		 bool forced ) {

	// filter if we should
	//if ( forced ) goto skipfilter;

	// return true if we should not log this
	if ( ! forced && ! shouldLog ( type , msg ) ) return true;
	// skipfilter:
	// can we log if we're a sig handler? don't take changes
	if ( g_inSigHandler ) 
		return logLater ( now , type , msg , NULL );
	//if ( g_inSigHandler ) return false;
	// get "msg"'s length
	long msgLen = gbstrlen ( msg );

#ifdef PTHREADS
	// lock for threads
	pthread_mutex_lock ( &s_lock );
#endif

	// do a timestamp, too. use the time synced with host #0 because
	// it is easier to debug because all log timestamps are in sync.
	if ( now == 0 ) now = gettimeofdayInMillisecondsGlobalNoCore();

	// . skip all logging if power out, we do not want to screw things up
	// . allow logging for 10 seconds after power out though
	if ( ! g_process.m_powerIsOn && now - g_process.m_powerOffTime >10000){
#ifdef PTHREADS
		pthread_mutex_unlock ( &s_lock );
#endif
		return false;
	}

	//if ( now == 0 ) now  = g_nowApprox;
	// chop off any spaces at the end of the msg.
	while ( is_wspace_a ( msg [ msgLen - 1 ] ) && msgLen > 0 ) msgLen--;
	// get this pid
	pid_t pid = getpidtid();
	// a tmp buffer
	char tt [ MAX_LINE_LEN ];
	char *p    = tt;
	char *pend = tt + MAX_LINE_LEN;
	/*
	// print timestamp, hostid, type
	if ( g_hostdb.m_numHosts <= 999 ) 
		sprintf ( p , "%llu %03li %s ",
			  now , g_hostdb.m_hostId , getTypeString(type) );
	else if ( g_hostdb.m_numHosts <= 9999 ) 
		sprintf ( p , "%llu %04li %s ",
			  now , g_hostdb.m_hostId , getTypeString(type) );
	else if ( g_hostdb.m_numHosts <= 99999 ) 
		sprintf ( p , "%llu %05li %s ",
			  now , g_hostdb.m_hostId , getTypeString(type) );
	*/


	// print timestamp, hostid, type

	if ( m_logTimestamps ) {
		if ( g_hostdb.m_numHosts <= 999 ) 
			sprintf ( p , "%llu %03li ",
				  now , g_hostdb.m_hostId );
		else if ( g_hostdb.m_numHosts <= 9999 ) 
			sprintf ( p , "%llu %04li ",
				  now , g_hostdb.m_hostId );
		else if ( g_hostdb.m_numHosts <= 99999 ) 
			sprintf ( p , "%llu %05li ",
				  now , g_hostdb.m_hostId );
		p += gbstrlen ( p );
	}

	// msg resource
	char *x = msg;
	long cc = 7;
	// the first 7 bytes or up to the : must be ascii
	//while ( p < pend && *x && is_alnum_a(*x) ) { *p++ = *x++; cc--; }
	// space pad
	//while ( cc-- > 0 ) *p++ = ' ';
	// ignore the label for now...
	while ( p < pend && *x && is_alnum_a(*x) ) { x++; cc--; }
	// thread id if in "thread"
	if ( pid != s_pid && s_pid != -1 ) {
		//sprintf ( p , "[%li] " , (long)getpid() );
		sprintf ( p , "[%lu] " , (unsigned long)pid );
		p += gbstrlen ( p );
	}
	// then message itself
	long avail = (MAX_LINE_LEN) - (p - tt) - 1;
	if ( msgLen > avail ) msgLen = avail;
	if ( *x == ':' ) x++;
	if ( *x == ' ' ) x++;
	strncpy ( p , x , avail );
	// capitalize for consistency. no, makes grepping log msgs harder.
	//if ( is_alpha_a(*p) ) *p = to_upper_a(*p);
	p += gbstrlen(p);
	// back up over spaces
	while ( p[-1] == ' ' ) p--;
	// end in period or ? or !
	//if ( p[-1] != '?' && p[-1] != '.' && p[-1] != '!' )
	//	*p++ = '.';
	*p ='\0';
	// the total length, not including the \0
	long tlen = p - tt;

	// call sprintf, but first make sure we have room in m_buf and in
	// the arrays. who know how much room the sprintf is going to need???
	// NOTE: TODO: this is shaky -- fix it!
	if ( m_bufPtr + tlen  >= 1024 * 32 ||  m_numErrors  >= MAX_LOG_MSGS){
		// this sets m_bufPtr to 0
		if ( ! dumpLog ( ) ) {
			fprintf(stderr,"Log::log: could not dump to file!\n");
#ifdef PTHREADS
			pthread_mutex_unlock ( &s_lock );
#endif
			return false;
		}
	}
	// . filter out nasty chars from the message
	// . replace with ~'s
	char cs;
	char *ttp    = tt;
	char *ttpend = tt + tlen;
	for ( ; ttp < ttpend ; ttp += cs ) {
		cs = getUtf8CharSize ( ttp );
		if ( is_binary_utf8 ( ttp ) ) {
			for ( long k = 0 ; k < cs ; k++ ) *ttp++ = '.';
			// careful not to skip the already skipped bytes
			cs = 0;
			continue;
		}
		// convert \n's and \r's to spaces
		if ( *ttp == '\n' ) *ttp = ' ';
		if ( *ttp == '\r' ) *ttp = ' ';
		if ( *ttp == '\t' ) *ttp = ' ';
	}

	if ( m_fd >= 0 ) {
		write ( m_fd , tt , tlen );
		write ( m_fd , "\n", 1 );
	}
	else {
		// print it out for now
		fprintf ( stderr, "%s\n", tt );
	}

	// set the stuff in the array
	m_errorMsg      [m_numErrors] = msg;
	m_errorMsgLen   [m_numErrors] = msgLen;
	m_errorTime     [m_numErrors] = now;
	m_errorType     [m_numErrors] = type;
	// increase the # of errors
	m_numErrors++;

#ifdef PTHREADS
	// unlock for threads
	pthread_mutex_unlock ( &s_lock );
#endif
	return false;
}
Exemplo n.º 9
0
Arquivo: errlTest.c Projeto: deece/occ
// Function Specification
//
// Name: errlTestCallouts
//
// Description: errlTestCallouts
//
// End Function Specification
uint32_t errlTestCallouts()
{
    uint32_t l_rc = 0;
    ERRL_DBG("START");

    do
    {
        errlHndl_t l_handle = NULL;
        ERRL_DBG("--------------------------------\n");

        /****************************************************/
        // Check max callouts
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        ERRL_CALLOUT_PRIORITY l_array[8] = {
                                             ERRL_CALLOUT_PRIORITY_HIGH,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                             ERRL_CALLOUT_PRIORITY_HIGH,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                            };

        ERRL_CALLOUT_TYPE l_type[8] = {
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                       };

        // add 6 (ERRL_MAX_CALLOUTS) callouts
        uint8_t l_index = 0;
        for(l_index = 0; l_index < ERRL_MAX_CALLOUTS; l_index++)
        {
            ERRL_DBG("current callouts %d attempting to add callout # %d with type %d ,priority %d", l_handle->iv_numCallouts, l_index, l_type[l_index], l_array[l_index] );
            addCalloutToErrl(l_handle,l_type[l_index],l_index,l_array[l_index]);
        }
        CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc);

        // add one more callout and it should fail
        addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]);
        CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        deleteErrl( &l_handle );
        ppdumpslot();

        /****************************************************/
        // Check callouts after errl is committed
        // Create log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 32, 0x1, 0x2);
        errlHndl_t l_log = l_handle;
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // Commit log and add callout. But adding callout should fail
        commitErrl( &l_handle );
        addCalloutToErrl(l_handle,l_type[0],0,l_array[0]);
        CHECK_CONDITION( l_log->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc);

        deleteErrl(&l_log);

        /****************************************************/
        // Check addCalloutToErrl for ERRL_SEV_INFORMATIONAL log
        // Create ERRL_SEV_INFORMATIONAL log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL,g_trac_inf, 128, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);
        if(l_handle == INVALID_ERR_HNDL)

        // add one callout and it should fail
        addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]);
        CHECK_CONDITION( l_handle->iv_numCallouts == 0, l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        deleteErrl( &l_handle );
        ppdumpslot();

        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}
Exemplo n.º 10
0
Arquivo: errlTest.c Projeto: deece/occ
// Function Specification
//
// Name: errlTestAddTraceToErrl
//
// Description: errlTestAddTraceToErrl
//
// End Function Specification
uint32_t errlTestAddTraceToErrl()
{
    uint32_t l_rc = 0;
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;
    ERRL_DBG("START");

    do
    {
        // Create one err log
        errlHndl_t l_handle = NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 512, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        errlHndl_t l_handleX = l_handle;
        ERRL_DBG("Slots after Create - 1 slots should be used (one of each");
        ppdumpslot();

        /****************************************************/
        // Test size limit for addTraceToErrl
        // Add "trace" data that exceeds the max size
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, MAX_BUFFER_SIZE, l_handle);
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        commitErrl( &l_handle );
        ERRL_DBG("Slots after Commit -  1 slots should be used/committed");
        ppdumpslot();

        deleteErrl(&l_handleX);
        ERRL_DBG("Slots after delete Log - All slots should be empty");
        ppdumpslot();

        /****************************************************/
        // Test size limit for addTraceToErrl with continuous calls
        // Create log with 512 bytes trace
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        l_handleX = l_handle;
        ppdumpslot();

        // Add 256 bytes of trace (512+256)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 256, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 bytes" );
        ppdumpslot();
        // (header + 256) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc);

        // Add 512 bytes of trace (512+256+512)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 512, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc);

        // Add 1024 bytes of trace (512+256+512+1024), the entry size is more than 2048 now
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 1024, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc);

        commitErrl( &l_handle );
        deleteErrl(&l_handleX);
        ERRL_DBG("Slots should now be empty");
        ppdumpslot();
        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}
Exemplo n.º 11
0
Arquivo: errlTest.c Projeto: deece/occ
// Function Specification
//
// Name: errlTestAddUsrDtlsToErrl
//
// Description: errlTestAddUsrDtlsToErrl
//
// End Function Specification
uint32_t errlTestAddUsrDtlsToErrl()
{
    uint32_t l_rc = 0;
    ERRL_DBG("START");
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;

    do
    {
        // Create three err logs
        errlHndl_t l_handle = NULL;
        errlHndl_t l_handle2 = NULL;
        errlHndl_t l_handle3 = NULL;

        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_UNRECOVERABLE, NULL, 512, 0x1, 0x2);
        l_handle2 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, NULL, 512, 0x1, 0x2);
        l_handle3 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL, NULL, 512, 0x1, 0x2);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        errlHndl_t l_handleX = l_handle;
        errlHndl_t l_handle2X = l_handle2;
        errlHndl_t l_handle3X = l_handle3;
        ERRL_DBG("Slots after Create - 3 slots should be used (one of each");
        ppdumpslot();

        CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) &&
                         (l_handle2 != INVALID_ERR_HNDL) &&
                         (l_handle3 != INVALID_ERR_HNDL), l_rc);

        /****************************************************/
        // Test size limit for addUsrDtlsToErrl
        // Add "user details" data that exceeds the max size for l_handle
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xCC, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_ENTRY_SZ, l_rc);

        // Add "user details" data that exceeds the max size for l_handle2
        l_entrySizeBefore = l_handle2->iv_userDetails.iv_entrySize;
        memset( G_data, 0xDD, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle2, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_CALLHOME_DATA );
        l_entrySizeAfter = l_handle2->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_CALL_HOME_SZ, l_rc);

        // Add "user details" with size 76 for l_handle3
        l_entrySizeBefore = l_handle3->iv_userDetails.iv_entrySize;
        memset( G_data, 0xEE, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle3, G_data, 76, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle3->iv_userDetails.iv_entrySize;
        // (header + 76) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+76), l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize );
        dumpLog( l_handle3, l_handle3->iv_userDetails.iv_entrySize );

        commitErrl( &l_handle );
        commitErrl( &l_handle2 );
        commitErrl( &l_handle3 );
        ERRL_DBG("Slots after Commit -  3 slots should be used/committed");
        ppdumpslot();

        deleteErrl(&l_handleX);
        deleteErrl(&l_handle2X);
        deleteErrl(&l_handle3X);
        CHECK_CONDITION( (l_handleX == NULL) &&
                         (l_handle2X == NULL) &&
                         (l_handle3X == NULL), l_rc);

        ERRL_DBG("Slots after delete Log - All slots should be empty");
        ppdumpslot();

        /****************************************************/
        // Test size limit for addUsrDtlsToErrl with continuous calls
        // Create log with 512 bytes trace
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2);
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        l_handleX = l_handle;
        ppdumpslot();

        // add 256 bytes of "user details" (512+256)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xAA, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 256, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 bytes" );
        ppdumpslot();
        // (header + 256) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc);

        // add 512 bytes of "user details" (512+256+512)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xBB, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 512, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        // (header + 512) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc);

        // add 1024 bytes of "user details" (512+256+512+1024), the entry size is more than 2048 now
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xCC, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 1024, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 +1024 bytes");
        ppdumpslot();
        // (header + 1024) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c

        commitErrl( &l_handle );
        deleteErrl(&l_handleX);
        ERRL_DBG("Slots should now be empty");
        ppdumpslot();
        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: dud3/ELEVATOR
/**
 * Rank is processor number, name is the name of the person toiling away.
 */
void worker(int rank, char* name) {
  srand(time(NULL) + rank);
  
  int workTicks = rand_num(5);
  int currWorkTick = 0;
  int myFloor = rand_num(3);
  int desiredFloor = myFloor;
  int floorOfElevator = 0;
  enum State state = Work;
  int stillWorking = 1;
  int wantstobeWorking = 1;
  int unusedInt;
  
  while (stillWorking) {
    // send whether or not we still have work to do
    MPI_Reduce(&wantstobeWorking, &unusedInt, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); 

    // receive what floor the elevator is on
    MPI_Bcast(&floorOfElevator, 1, MPI_INT, 0, MPI_COMM_WORLD);
    
    // all workers indicated no more work, so we abandon what we were doing
    if (floorOfElevator == -1) {
      stillWorking = 0;

      struct Bucket *curBuck = firstBuck;
      
      int len = 0;
      
      while (curBuck != 0) {
        // printf("%d has a bucket for %s with a content of %d\n", rank, (*curBuck).key, (*curBuck).value);
        
        // We send the key and a value.
        // Here, the value is a magic number: If the value is zero, then all the buckets have been sent.
        MPI_Send(&(curBuck->value), 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        len = strlen(curBuck->key);
        MPI_Send(&len, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        MPI_Send(curBuck->key, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD);

        curBuck = curBuck->next;
      }

      len = 0;
      MPI_Send(&len, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
    }

    if (state == Elevator) {
      dumpLog(1, rank, name, " is on the elevator to floor ", desiredFloor);
      printf("%d is riding the elevator to floor %d\n", rank, desiredFloor);
      
      // are we on the right floor? if so, state becomes work
      if (floorOfElevator == desiredFloor) {
        dumpLog(1, rank, name, " got off the elevator on floor ", desiredFloor);
        printf("%d got off elevator and is now working on floor %d\n", rank, desiredFloor);
        state = Work;
        myFloor = desiredFloor;
      }
    }
    else if (state == Work) {
      // do work

      if (assgn == 2) {

        if (curLine < list->size) {

          // reduce by counting the words on the lines that have been transmitted

          char* thestring;

          dlist_get(&list, curLine, &thestring);
          printf("%d works on: %s", rank, thestring);
          curLine++;
            
          // actually do some work with thestring, e.g. count the words and put them into bins
        
          // go through the string and write each substring into curStr;

          char curStr[] = "012345678901234567890123456789012345678901234567890123456789";
          int inword = 0;
          int curInCurStr = 0;
    
          for (int curInString = 0; thestring[curInString] != '\0'; curInString++) {
            if ((thestring[curInString] == ' ') ||
                (thestring[curInString] == '\t') ||
                (thestring[curInString] == '\n') ||
                (thestring[curInString] == '\r')) {
              if (inword) {
                inword = 0;
            
                // for that, we iterate through all buckets to see if there already is an appropriate one,
                // and if not, then we add a bucket
            
                struct Bucket *curBuck = firstBuck;
                struct Bucket *prvBuck = 0;
            
                while (curBuck != 0) {
                  //printf("%d compares %s to %s\n", rank, curStr, curBuck->key);

                  if (strcmp(curBuck->key, curStr) == 0) {
                    // we increase the value of the current bucket by one
                    curBuck->value = curBuck->value + 1;
                
                    // printf("%d increased a bucket's value for %s\n", rank, curStr);

                    goto foundABucket;
                  }
              
                  prvBuck = curBuck;
                  curBuck = curBuck->next;
                  if (curBuck == prvBuck) {
                    curBuck = 0;
                  }
                }
           
                struct Bucket *addBuck = malloc(sizeof *addBuck);
            
                // printf("%d added a bucket for %s\n", rank, curStr);

                addBuck->key = strdup(curStr);
                addBuck->value = 1;
                addBuck->next = 0;
            
                if (firstBuck == 0) {
                  firstBuck = addBuck;
                } else {
                  prvBuck->next = addBuck;
                }
            
                foundABucket: ;
                curStr[0] = '\0';
                curInCurStr = 0;
              }
            } else {
              inword = 1;
              curStr[curInCurStr] = thestring[curInString];
              curStr[curInCurStr+1] = '\0';
              curInCurStr++;
            }
          }
        } else {
          wantstobeWorking = false;
        }
      }

      currWorkTick++;
      dumpLog(1, rank, name, " did some work on floor ", myFloor);
      printf("%d did some work on floor %d [%d/%d]\n", rank, myFloor, currWorkTick, workTicks);
      
      //receive our next task and wait for the elevator
      if (currWorkTick >= workTicks) {
        dumpLog(1, rank, name, " is done with work on floor ", myFloor);
        printf("%d is done with work on floor %d\n", rank, myFloor);
        currWorkTick = 0;
        workTicks = rand_num(5);
        desiredFloor = myFloor;
        while (desiredFloor == myFloor) {
          desiredFloor = rand_num(3);
        }
        state = Waiting;
      }
    }
    else if (state == Waiting) {
      dumpLog(1, rank, name, " waits before going to floor ", desiredFloor);
      printf("%d is waiting for the elevator to go to floor %d from floor %d\n", rank, desiredFloor, myFloor);
      if (floorOfElevator == myFloor) {
        dumpLog(1, rank, name, " got on the elevator to floor ", desiredFloor);
        printf("%d got on the elevator to go to floor %d\n", rank, desiredFloor);
        state = Elevator;
      }
    }
  }
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: dud3/ELEVATOR
void master(int rank) {
  srand(time(NULL) + rank);
  
  //master manages elevators
  int floor = 1;
  bool up = true;
  int stillWorking = 1;
  
  while (stillWorking) {
    if (up) {
      //going up
      if (floor + 1 <= MAX_FLOOR) {
        floor++;
      }
      else {
        //at max floor, now going down.
        up = false;
        floor--;
      }
    }
    else {
      //going down
      if (floor - 1 >= 1) {
        floor--;
      }
      else {
        //at ground floor, go back up
        up = true;
        floor++;
      }
    }

    int valOne = 1;
    int redResult = 0;
    
    // ask the workers if they still have work to do
    MPI_Reduce(&valOne, &redResult, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
    
    printf("Reduction result is %d\n", redResult);

    // all workers indicated that no work is left for them
    if (redResult == 1) {

      // magic number: abandon work!
      floor = -1;
      
      stillWorking = 0;

      printf("The work is done!\n");
    } else {
      dumpLog(0, 1, "", " now passes floor ", floor);
      printf("Elevator now passes floor %d\n", floor);
    }

    //tell workers what floor we're on
    MPI_Bcast(&floor, 1, MPI_INT, 0, MPI_COMM_WORLD);

    //elevator very fast, only 3 seconds to get in or out
    //also possibly dangerous to occupants.
    sleep(3);
  }
  
  int size;
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  char tarStr[] = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
  MPI_Status status;
  
  for (int i = 1; i < size; i++) {
    int len = 1;
    int val = 1;

    MPI_Recv(&val, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
    while (0 < val) {
      MPI_Recv(&len, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      MPI_Recv(&tarStr, len, MPI_CHAR, i, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      tarStr[len] = '\0';

      struct Bucket *curBuck = firstBuck;
      struct Bucket *prvBuck = 0;
      
      while (curBuck != 0) {
        if (strcmp(curBuck->key, tarStr) == 0) {
          // we increase the value of the current bucket
          curBuck->value = curBuck->value + val;
                
          goto foundABucket;
        }

        prvBuck = curBuck;
        curBuck = curBuck->next;
        if (curBuck == prvBuck) {
          curBuck = 0;
        }
      }

      struct Bucket *addBuck = malloc(sizeof *addBuck);

      addBuck->key = strdup(tarStr);
      addBuck->value = val;
      addBuck->next = 0;

      if (firstBuck == 0) {
        firstBuck = addBuck;
      } else {
        prvBuck->next = addBuck;
      }
            
      foundABucket: ;

      MPI_Recv(&val, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
    }
    
    printf("Root received all the data from process %d.\n", i);
  }

  struct Bucket *cuBuck = firstBuck;
      
  while (cuBuck != 0) {
    printf("%s :: %d\n", (*cuBuck).key, (*cuBuck).value);
    wordCountLog((*cuBuck).key, (*cuBuck).value);
        
    cuBuck = cuBuck->next;
  }
}
Exemplo n.º 14
0
// ~Game()
// Description: game ends, calculate & dump results to log
Game::~Game(){
    if(m_nRound == 100){
        m_endTime = cpuTime();
        dumpLog("open_src_version.log");
    }
}