Beispiel #1
0
int main(int argc, char * argv[]) 
{       
        // Build the AST used by ROSE
        project = frontend(argc,argv);
        
        /*convertToOMPNormalForm(project, project);
        
        // Run internal consistancy tests on AST
        AstTests::runAllTests(project); 
        
        Rose_STL_Container<SgNode*> functions = NodeQuery::querySubTree(project, V_SgFunctionDefinition);
        for (Rose_STL_Container<SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) {
                SgFunctionDefinition* func = isSgFunctionDefinition(*i);
                ROSE_ASSERT(func);
        
                printf("func = %s\n", func->unparseToString().c_str());
                
                // output the CFG to a file
                ofstream fileCFG;
                fileCFG.open((func->get_declaration()->get_name().getString()+"_cfg.dot").c_str());
                cout << "    writing to file "<<(func->get_declaration()->get_name().getString()+"_cfg.dot")<<"\n";
                cfgToDot(fileCFG, func->get_declaration()->get_name(), func->cfgForBeginning());
                fileCFG.close();
        }
        
        backend(project);*/
        
        //generatePDF ( *project );
        
        // find a declaration for foo()
        Rose_STL_Container<SgNode*> funcDecls = NodeQuery::querySubTree(project, V_SgFunctionDeclaration);      
        for(Rose_STL_Container<SgNode*>::iterator it = funcDecls.begin(); it!=funcDecls.end(); it++)
        {
                SgFunctionDeclaration* decl = isSgFunctionDeclaration(*it); ROSE_ASSERT(decl);
                if(decl->get_name().getString() == "foo")
                {
                        fooDecl = decl;
                        break;
                }
        }
        if(!fooDecl) { printf("ERROR: could not find declaration of function foo()!\n"); numFails++; }
        
        testParsing();
                
        convertToOMPNormalForm(project, project);
        
        testOMPForSensitiveInsertion();
        
        AstTests::runAllTests(project);
        
        insertTopBottomOmpDirectives(project, ompUtils::omp_critical, true, &fooCallStmtCreate);
        insertTopBottomOmpDirectives(project, ompUtils::omp_single, false, &fooCallStmtCreate);
        
        // Run internal consistancy tests on AST
        //
        
        // Generate the CFGs of all the functions to ensure that all CFG data is good
        Rose_STL_Container<SgNode*> functions = NodeQuery::querySubTree(project, V_SgFunctionDefinition);
        for (Rose_STL_Container<SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) {
                SgFunctionDefinition* func = isSgFunctionDefinition(*i);
                ROSE_ASSERT(func);
        
                printf("func = %s\n", func->unparseToString().c_str());
                
                // output the CFG to a file
                ofstream fileCFG;
                fileCFG.open((func->get_declaration()->get_name().getString()+"_cfg.dot").c_str());
                cout << "    writing to file "<<(func->get_declaration()->get_name().getString()+"_cfg.dot")<<"\n";
                cfgToDot(fileCFG, func->get_declaration()->get_name(), func->cfgForBeginning());
                fileCFG.close();
        }
        
        backend(project);
        system("diff rose_test_example.c test_example.valid_rose_output.c > selfTest.out");
        struct stat file;
   stat("selfTest.out",&file);
        if(file.st_size!=0)
        {
                printf("Error: found differences between rose_test_example.c and the canonical test_example.valid_rose_output.c! Details in selfTest.out.\n");
                numFails++;
        }
        
        if(numFails==0) 
                cout << "PASSED\n";
        else
                cout << "FAILED!\n";
}
void testLogicExpressions(void) {
	printf("*************************************************** testLogicExpressions\r\n");

	testParsing();

	LECalculator c;

	LEElement value1;
	value1.init(LE_NUMERIC_VALUE, 123.0);
	c.add(&value1);

	assertEqualsM("123", 123.0, c.getValue(0, NULL));

	LEElement value2;
	value2.init(LE_NUMERIC_VALUE, 321.0);
	c.add(&value2);

	LEElement value3;
	value3.init(LE_OPERATOR_AND);
	c.add(&value3);
	assertEqualsM("123 and 321", 1.0, c.getValue(0, NULL));

	/**
	 * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0)
	 * fuel_pump = time_since_boot 4 less rpm 0 > OR
	 */

	c.reset();

	LEElement thepool[TEST_POOL_SIZE];
	LEElementPool pool(thepool, TEST_POOL_SIZE);
	LEElement *e = pool.next();
	e->init(LE_METHOD_TIME_SINCE_BOOT);

	e = pool.next();
	e->init(LE_NUMERIC_VALUE, 4);

	e = pool.next();
	e->init(LE_OPERATOR_LESS);

	e = pool.next();
	e->init(LE_METHOD_RPM);

	e = pool.next();
	e->init(LE_NUMERIC_VALUE, 0);

	e = pool.next();
	e->init(LE_OPERATOR_MORE);

	e = pool.next();
	e->init(LE_OPERATOR_OR);

	pool.reset();
	LEElement *element;
	element = pool.parseExpression("fan no_such_method");
	assertTrueM("NULL expected", element == NULL);


	/**
	 * fan = (not fan && coolant > 90) OR (fan && coolant > 85)
	 * fan = fan NOT coolant 90 AND more fan coolant 85 more AND OR
	 */


	mockFan = 0;
	mockCoolant = 100;

	testExpression("coolant", 100);
	testExpression("fan", 0);
	testExpression("fan not", 1);
	testExpression("coolant 90 >", 1);
	testExpression("fan not coolant 90 > and", 1);

	testExpression("100 200 1 if", 200);
	testExpression("10 99 max", 99);

	testExpression2(123, "10 self max", 123);

	testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1);
	{
		LEElement thepool[TEST_POOL_SIZE];
		LEElementPool pool(thepool, TEST_POOL_SIZE);
		LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR");
		assertTrueM("Not NULL expected", element != NULL);
		LECalculator c;
		assertEqualsM("that expression", 1, c.getValue2(0, element, NULL));

		assertEquals(12, c.currentCalculationLogPosition);
		assertEquals(102, c.calcLogAction[0]);
		assertEquals(0, c.calcLogValue[0]);
	}

	testExpression("coolant", 100);
	testExpression("fan_off_setting", 0);
	testExpression("coolant fan_off_setting >", 1);

	testExpression("0 1 &", 0);
	testExpression("0 1 |", 1);

	testExpression("0 1 >", 0);

	testExpression(FAN_CONTROL_LOGIC, 1);

	mockRpm = 900;
	testExpression(FUEL_PUMP_LOGIC, 1);

}