Exemplo n.º 1
0
bool ClusterManager::ReleaseResourceOnMachine(const string& machine, const ClassAd& resource){
    string data;
    int32_t version;
    if(!ZKMasterI::Instance()->Get("/cluster" + machine + "/status", data, version)){
         return false;
    }
    if(data != "ONLINE") {
        return false;
    }
    if(!ZKMasterI::Instance()->Get("/cluster" + machine + "/resource", data, version)){
        return false;
    }

    ClassAdParser parser;
    ClassAd* classad_ptr = parser.ParseClassAd(data);

    //
    int32_t total_vcpu, total_memory, requried_vcpu, required_memory;
    if(!classad_ptr->EvaluateAttrInt("memory", total_memory) ||
       !classad_ptr->EvaluateAttrInt("vcpu", total_vcpu) ||
       !resource.EvaluateAttrInt("memory", required_memory) ||
       !resource.EvaluateAttrInt("vcpu", requried_vcpu)) {
        return false;
    }
   
    stringstream ss;
    ss << "[ vcpu = " << total_vcpu + requried_vcpu << "; memory = " << total_memory + required_memory << " ]"; 
    
    if(!ZKMasterI::Instance()->Set("/cluster" + machine + "/resource", ss.str(), version)){
        return false;
    }
    return true; 
}
Exemplo n.º 2
0
int32_t main(int argc, char* argv[]){
    string         classad_string = "[ATTR_JOB_ID = 1; b = \"Cardini\"]";
    string         str = "[ ATTR_JOB_ID = 18; ATTR_TASK_ID = 1; ATTR_VMHB_CPU = 0.000000; ATTR_VMHB_MEMORY = 0.456332; ATTR_VMHB_BYTES_IN = 170008; ATTR_VMHB_BYTES_OUT = 27905; ATTR_VMHB_STATE = \"APP_RUNNING\" ]";
    //string	str = "[ ATTR_JOB_ID = 2 ]";
    ClassAd        *classad;
    ClassAdParser  parser;
    classad = parser.ParseClassAd(str, true);
    ClassAdPtr ptr(classad);
    printf("%d\n", ptr.use_count());
    int32_t i;
    string state;
    ClassAdPtr ptr2(new ClassAd(*ptr.get()));
    printf("%d\n", ptr.use_count()); 
    // if(!ptr->EvaluateAttrInt(ATTR_JOB_ID, id.job_id))
    if(!ptr->EvaluateAttrString("ATTR_VMHB_STATE",state)) { 
         printf("error\n");
    } 
    //printf("%s\n",state);
    std::cout<<state<<std::endl;
    string printed_classad;
   
    ClassAdXMLUnParser xml_unparser;
    xml_unparser.SetCompactSpacing(false);
    xml_unparser.Unparse(printed_classad, ptr.get());
    printf("%s\n", printed_classad.c_str());

    printed_classad = "";
    ClassAdUnParser unparser;
    unparser.Unparse(printed_classad, ptr.get());
    printf("%s\n", printed_classad.c_str()); 

    return 0;
}
Exemplo n.º 3
0
int main(int, char **)
{
	// First we turn the textual description of the ClassAd into 
	// our internal representation of the ClassAd. 
	ClassAdParser  parser;
	ClassAd        *job_classad, *machine_classad;

	job_classad     = parser.ParseClassAd(job_classad_text, true);
	machine_classad = parser.ParseClassAd(machine_classad_text, true);

	// Next we print out the ClassAds. This requires unparsing them first.
	PrettyPrint  printer;
	string       printed_job_classad, printed_machine_classad;

	printer.Unparse(printed_job_classad, job_classad);
	printer.Unparse(printed_machine_classad, machine_classad);
	cout << "Job ClassAd:\n" << printed_job_classad << endl;
	cout << "Machine ClassAd:\n" << printed_machine_classad << endl;

	// Finally we test that the two ClassAds match. They should. 
	// Note that a MatchClassAd is a ClassAd. You could pretty print it
	// like the other ads above, if you wanted to.
	MatchClassAd  match_ad(job_classad, machine_classad);
	bool          can_evaluate, ads_match;

	can_evaluate = match_ad.EvaluateAttrBool("symmetricMatch", ads_match);
	if (!can_evaluate) {
		cout << "Something is seriously wrong.\n";
	} else if (ads_match) {
		cout << "The ads match, as expected.\n";
	} else {
		cout << "The ads don't match! Something is wrong.\n";
	}
	return 0;
}
Exemplo n.º 4
0
static void read_from_stream_alt(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;

	ifstream stream("tmp.classads.tmp");
	if (!stream) {
		cout << "Can't open temporary ClassAd file.\n";
		exit(1);
	}

	cout << "Reading from ifstream (alt parse).\n";

	*classad_a = new ClassAd;
	*classad_b = new ClassAd;
	classad_c  = new ClassAd;
	parser.ParseClassAd(stream, **classad_a);
	parser.ParseClassAd(stream, **classad_b);
	if (!parser.ParseClassAd(stream, *classad_c)) {
		delete classad_c;
		classad_c = NULL;
	}

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 5
0
static void read_from_file_alt(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;
	FILE *file;

	file = fopen("tmp.classads.tmp", "r");
	if (file == NULL) {
		cout << "Can't open temporary ClassAd file.\n";
		exit(1);
	}

	cout << "Reading from FILE (alt parse).\n";

	*classad_a = new ClassAd;
	*classad_b = new ClassAd;
	classad_c  = new ClassAd;
	parser.ParseClassAd(file, **classad_a);
	parser.ParseClassAd(file, **classad_b);
	if (!parser.ParseClassAd(file, *classad_c)) {
		delete classad_c;
		classad_c = NULL;
	}

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 6
0
ExprTree *ClassAdXMLParser::
ParseExpr(void)
{
	bool             have_token;
	ExprTree         *tree;
	XMLLexer::Token  token;

	// Get start tag
	tree = NULL;
	have_token = lexer.ConsumeToken(&token);
	assert(have_token && token.tag_id == XMLLexer::tagID_Expr);

	// Get text of expression
	have_token = lexer.PeekToken(&token);
	if (have_token && token.token_type == XMLLexer::tokenType_Text) {
		lexer.ConsumeToken(&token);
		ClassAdParser  parser;
		
		tree = parser.ParseExpression(token.text);
	}

    SwallowEndTag(XMLLexer::tagID_Expr);

	return tree;
}
static bool test_non_empty_simple_return() {
	emit_test("Does FlattenAndInline return true when passed a simple "
		"ExprTree on a non-empty ClassAd?");

	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;

	string classad_string = "[a = 1; b = \"Cardini\"]";
	string expr_string = "a";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	bool flattenResult = classad->FlattenAndInline(expr, value, fexpr);
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_retval("TRUE");
	emit_output_actual_header();
	emit_retval(tfstr(flattenResult));
	if(!flattenResult) {
		delete expr; delete fexpr;
		FAIL;
	}
	delete classad; delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 8
0
  classad_expr_tree 
  classad_parse_expr(const char *s_ex)
   {
    ClassAdParser parser;
    ExprTree *et = parser.ParseExpression(s_ex);

    // et == NULL on error.
    return ((classad_expr_tree)et);
   }
Exemplo n.º 9
0
 classad_context 
 classad_parse (char *s_in)
  {
   ClassAd *ad = NULL;
   ClassAdParser parser;
   ad = parser.ParseClassAd(s_in);
 
   // ad == NULL on error.
   return ((classad_context)ad);
  }
Exemplo n.º 10
0
static void test_quoting_bug(void)
{
    ClassAdParser par ;
    string attr = "other.GlueCEStateStatus == \"Production\"";
    if (!par.ParseExpression(attr, true)) {
        cout << "Error in parsing quotes.\n";
    } else {
        cout << "No problem in parsing quotes.\n";
    }
    return;
}
Exemplo n.º 11
0
static bool test_equivalence_partial_multiple() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original ExprTree after multiple "
		"FlattenAndInline calls.");
	
	classad::ClassAd *classad1, *classad2, *classad3;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr1, *fexpr2, *fexpr3;
	
	string classad1_string = "[a = b]";
	string classad2_string = "[b = c]";
	string classad3_string = "[c = d]";
	string expr_string = "a + b - c";
	ClassAdParser parser;
	
	classad1 = parser.ParseClassAd(classad1_string, true);
	classad2 = parser.ParseClassAd(classad2_string, true);
	classad3 = parser.ParseClassAd(classad3_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad1->FlattenAndInline(expr, value, fexpr1);
	classad2->FlattenAndInline(fexpr1, value, fexpr2);
	classad3->FlattenAndInline(fexpr2, value, fexpr3);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr3);
	
	emit_input_header();
	emit_param("ClassAd 1", classad1_string.c_str());
	emit_param("ClassAd 2", classad2_string.c_str());
	emit_param("ClassAd 3", classad3_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "d + d - d");
	emit_param("Flattened and Inlined Expression", "<error:null expr>");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", "'%s'", fexpr_string.c_str());
	if(fexpr_string.compare("d + d - d") != MATCH){
		delete classad1; delete classad2; delete classad3;
		delete expr; delete fexpr1; delete fexpr2; delete fexpr3;
		FAIL;
	}
	delete classad1; delete classad2; delete classad3;
	delete expr; delete fexpr1; delete fexpr2; delete fexpr3;
	PASS;
}
Exemplo n.º 12
0
static void read_from_char(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;
	const char *text = parsing_text.c_str();
	int offset;

	cout << "Reading from C string.\n";

	offset = 0;
	*classad_a = parser.ParseClassAd(text, offset);
	*classad_b = parser.ParseClassAd(text, offset);
	classad_c = parser.ParseClassAd(text, offset);

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 13
0
Task::Task(const TaskInfo& info): m_task_info(info) {
    //要不要处理一下错误情况?
    m_task_info.id = TaskIdentityI::Instance()->GetTaskId();
    m_state = TASK_WAIT;
    m_run_on = "";
    //要不要处理一下错误的情况?
    m_ad.InsertAttr(ATTR_NEED_VCPU, m_task_info.cpu);
    m_ad.InsertAttr(ATTR_NEED_MEMORY, m_task_info.memory);
    ClassAdParser parser;
    //rank的算法, 选择比例最大的
    ExprTree* expr = parser.ParseExpression(EXP_TASK_RANK);
    m_ad.Insert(ATTR_TASK_RANK, expr);
    //requirement
    ExprTree* re_expr = parser.ParseExpression(EXP_TASK_REQUIREMENT);
    m_ad.Insert(ATTR_TASK_REQUIREMENT, re_expr);
    m_ad.InsertAttr(ATTR_VC, m_task_info.vc_name);
}
Exemplo n.º 14
0
static void read_from_string(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;
	int offset;

	cout << "Reading from C++ string.\n";

	offset = 0;
	*classad_a = parser.ParseClassAd(parsing_text, offset);
	*classad_b = parser.ParseClassAd(parsing_text, offset);
	classad_c = parser.ParseClassAd(parsing_text, offset);

	check_parse(*classad_a, *classad_b, classad_c);

	return;
}
Exemplo n.º 15
0
static bool test_equivalence_complex_list() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original complex expression list "
		"ExprTree.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = b; b = 2; c = d;]";
	string expr_string = "{a, b, c, d, true || false, true && false, 10 + a,"
		"10 - a, 10 * a, 10 / a}";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "{ 2,2,d,d,true,false,12,"
		"8,20,5 }");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr_string.compare("{ 2,2,d,d,true,false,12,8,20,5 }") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 16
0
int main(){
    string ad_string = "[a = 1; b = \"Cardini\"]";
    ClassAd ad;
    ClassAdParser parser;

    int val;

    if(!parser.ParseClassAd(ad_string, ad, true)){
       return 1;
    }

    if(ad.EvaluateAttrInt("a", val)) {
        printf("%d\n",val);
    } else {
        printf("error\n");
        return 1;
    }
    return 0;
}
Exemplo n.º 17
0
static bool test_equivalence_partial_complex_boolean() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original complex boolean ExprTree.");
	emit_comment("This expression could be further reduced to 'g'");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = true; b = false; c = a || b; d = a && b; "
		"e = c && !d; f = !c; g = h]";
	string expr_string = "!e && c || g ";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "false || h");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr_string.compare("false || h") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 18
0
static bool test_equivalence_partial_arithmetic_end() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original arithmetic ExprTree with an "
		"inlined value in the end.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = b; b = 1; c = f]";
	string expr_string = "a + b + c";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	string value2_string, fexpr2_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "2 + f");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr_string.compare("2 + f") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 19
0
//Difference between Flatten and FlattenAndInline:
//	Flatten: 6 + a - 5
//	FlattenAndInline: 6 + f - 5
static bool test_equivalence_partial_arithmetic_constants() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original arithmetic ExprTree that has "
		"constants.");
	emit_comment("This expression could be further reduced to '1 + f'");
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = f; b = c; c = 1]";
	string expr_string = "a + b + (c*5) - (25*b/5))";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	string value2_string, fexpr2_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "6 + f - 5");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr_string.compare("6 + f - 5") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 20
0
static bool test_equivalence_nested_loop_classad() {
	emit_test("Test if FlattenAndInline handles a nested classad with a "
		"loop");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = [b = a]]";
	string expr_string = "a";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	classad_string.clear();
	unparser.Unparse(classad_string, classad);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "<error:null expr>");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr == NULL &&  value_string.compare("undefined") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 21
0
static bool test_equivalence_nested_classad() {
	emit_test("Test if the partially flattened and inlined ExprTree is "
		"logically equivalent to the original ExprTree when using a nested "
		"classad.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = [b = c]; c = 1]";
	string expr_string = "a";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = classad->Lookup("a");

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "[ b = 1 ]");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(fexpr_string.compare("[ b = 1 ]") != MATCH){
		delete classad; delete fexpr;
		FAIL;
	}
	delete classad; delete fexpr;
	PASS;
}
Exemplo n.º 22
0
static bool test_equivalence_full_complex_boolean() {
	emit_test("Test if the fully flattened and inlined ExprTree is logically "
		"equivalent to the original complex boolean ExprTree.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = true; b = false; c = a || b; d = a && b; "
		"e = c && !d; f = !c]";
	string expr_string = "e || !c";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "true");
	emit_param("Flattened and Inlined Expression", "<error:null expr>");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(value_string.compare("true") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 23
0
static bool test_equivalence_no_change() {
	emit_test("Test if the flattened and inlined ExprTree is logically "
		"equivalent to the original ExprTree when the flattening and inlining "
		"does nothing.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = 1]";
	string expr_string = "f";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "undefined");
	emit_param("Flattened and Inlined Expression", "f");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(!expr->SameAs(fexpr)){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad; delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 24
0
static void read_from_stream(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;

	ifstream stream("tmp.classads.tmp");
	if (!stream) {
		cout << "Can't open temporary ClassAd file.\n";
		exit(1);
	}

	cout << "Reading from ifstream.\n";

	*classad_a = parser.ParseClassAd(stream);
	*classad_b = parser.ParseClassAd(stream);
	classad_c = parser.ParseClassAd(stream);

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 25
0
static bool test_equivalence_full_arithmetic_constants() {
	emit_test("Test if the fully flattened and inlined ExprTree is logically "
		"equivalent to the original arithmetic ExprTree that has constants.");
	
	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = b; b = c; c = 1]";
	string expr_string = "a + b + (c*5) - (25*b/5))";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string, fexpr_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	unparser.Unparse(fexpr_string, fexpr);
	
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Flattened and Inlined Value", "2");
	emit_param("Flattened and Inlined Expression", "<error:null expr>");
	emit_output_actual_header();
	emit_param("Flattened and Inlined Value", value_string.c_str());
	emit_param("Flattened and Inlined Expression", fexpr_string.c_str());
	if(value_string.compare("2") != MATCH){
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad;	delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 26
0
static void read_from_file(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;
	FILE *file;

	file = fopen("tmp.classads.tmp", "r");
	if (file == NULL) {
		cout << "Can't open temporary ClassAd file.\n";
		exit(1);
	}

	cout << "Reading from FILE.\n";

	*classad_a = parser.ParseClassAd(file);
	*classad_b = parser.ParseClassAd(file);
	classad_c = parser.ParseClassAd(file);

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 27
0
static void read_from_string_alt(ClassAd **classad_a, ClassAd **classad_b)
{
	ClassAdParser parser;
	ClassAd *classad_c;
	int offset;

	cout << "Reading from C++ string (alt parse).\n";

	offset = 0;
	*classad_a = new ClassAd;
	*classad_b = new ClassAd;
	classad_c  = new ClassAd;
	parser.ParseClassAd(parsing_text, **classad_a, offset);
	parser.ParseClassAd(parsing_text, **classad_b, offset);
	if (!parser.ParseClassAd(parsing_text, *classad_c, offset)) {
		delete classad_c;
		classad_c = NULL;
	}

	check_parse(*classad_a, *classad_b, classad_c);
	return;
}
Exemplo n.º 28
0
static bool test_non_empty_simple_value() {
	emit_test("Does FlattenAndInline set the value to be the flattened "
		"simple ExprTree's value on a non-empty ClassAd?");

	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;

	string classad_string = "[a = 1; b = \"Cardini\"]";
	string expr_string = "a";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("Value", "1");
	emit_output_actual_header();
	emit_param("Value", value_string.c_str());
	if(value_string.compare("1")) {
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad; delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 29
0
static bool test_non_empty_simple_flattened_expression() {
	emit_test("Does FlattenAndInline set fexpr to NULL when the simple "
		"ExprTree is flattened to a single value on a non-empty ClassAd?");

	classad::ClassAd *classad;
	classad::ExprTree *expr;
	Value value;
	classad::ExprTree *fexpr;
	
	string classad_string = "[a = 1; b = \"Cardini\"]";
	string expr_string = "a";
	ClassAdParser parser;
	
	classad = parser.ParseClassAd(classad_string, true);
	expr = parser.ParseExpression(expr_string);

	ClassAdUnParser unparser;
	string value_string;
	
	classad->FlattenAndInline(expr, value, fexpr);
	unparser.Unparse(value_string, value);
	emit_input_header();
	emit_param("ClassAd", classad_string.c_str());
	emit_param("ExprTree", expr_string.c_str());
	emit_param("Value", "");
	emit_param("ExprTree", "NULL");
	emit_output_expected_header();
	emit_param("fexpr is NULL", "TRUE");
	emit_output_actual_header();
	emit_param("fexpr is NULL", tfstr(fexpr == NULL));
	if(fexpr != NULL) {
		delete classad; delete expr; delete fexpr;
		FAIL;
	}
	delete classad; delete expr; delete fexpr;
	PASS;
}
Exemplo n.º 30
0
  int
  classad_evaluate_boolean_expr(const char *s_in, const classad_expr_tree t_ex,
                                int *result)
   {
    ClassAd *ad;
    ClassAdParser parser;
    
    if (s_in == NULL || t_ex == NULL || result == NULL) 
      return C_CLASSAD_INVALID_ARG;

    ExprTree *et = (ExprTree *)t_ex;

    ad = parser.ParseClassAd(s_in);
    if (ad == NULL) return C_CLASSAD_PARSE_ERROR;

    int retcod = C_CLASSAD_NO_ERROR;

    Value v;
    et->SetParentScope(ad);
    ad->EvaluateExpr(et, v);
    et->SetParentScope(NULL);

    bool tmp_res;

    if (v.IsBooleanValue( tmp_res ))
     {
      if (tmp_res) *result = 1;
      else         *result = 0;
      retcod = C_CLASSAD_NO_ERROR;
     }
    else retcod = C_CLASSAD_INVALID_VALUE;

    delete ad;  

    return retcod;
   }