Ejemplo n.º 1
0
void test_rule_12(){
	std::cout << "12) The guard, of a conditional and a while loop, must be a "
				"boolean expression:\n";

	// If statement
	std::string test_program = "class Program {\n"
									"void method(){\n"
										"if (1) ; else ;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_12);

	test_program = "class Program {\n"
						"void method1(){\n"
						"}\n"
						"void method2(){\n"
							"if (method1()) ; else ;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_12);

	// While statement
	test_program = "class Program {\n"
						"void method(){\n"
							"while (1) ;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_12);

	test_program = "class Program {\n"
						"void method1(){\n"
						"}\n"
						"void method2(){\n"
							"while (method1()) ;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_12);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 2
0
void test_rule_18(){
	std::cout << "18) In a for loop, \"from\" and \"to\" expression must "
					"evaluate to integers:\n";

	std::string test_program = "class Program {\n"
									"void method(){\n"
										"int x;"
										"for x = true , 2 ;"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_18);

	test_program = "class Program {\n"
						"void method(){\n"
							"int x;"
							"for x = 1 , false ;"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_18);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 3
0
void test_rule_19(){
	std::cout << "19) break and continue, only into a loop's body:\n";

	std::string test_program = "class Program {\n"
									"void method(){\n"
										"break;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_19);

	test_program = "class Program {\n"
						"void method(){\n"
							"continue;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_19);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 4
0
void test_rule_20(){
	std::cout << "20) Identifiers have known type:\n";

	// Attributes
	std::string test_program = "class Program {\n"
									"unkownClass x;\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_20);

	// Method's parameters
	test_program = "class Program {\n"
						"void method(unknownClass x){\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_20);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 5
0
void test_rule_8(){
	std::cout << "8) A return statement must have an associated expression only "
				"if the method returns a value:\n";

	std::string test_program = "class Program {\n"
									"void method(){\n"
										"return 1;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_8);

	test_program = "class Program {\n"
						"int method(){\n"
							"return;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_8);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 6
0
void test_rule_17(){
	std::cout << "17) In a -= or += assignment, the location and the expression "
				"assigned must evaluated to integer or float:\n";

	std::string test_program = "class Program {\n"
									"void method(){\n"
										"int x;"
										"x += true;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_17);

	test_program = "class Program {\n"
						"void method(){\n"
							"boolean x;"
							"x += 1;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_17);


	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    execute_test(random_int_arr(7), 7, 1);
    execute_test(random_int_arr(1), 1, 2);
    execute_test(random_int_arr(3), 3, 3);
    execute_test(random_int_arr(2), 2, 4);

    return 0;
}
Ejemplo n.º 8
0
void test_rule_11(){
	std::cout << "11) If the location is an array position, the corresponding "
				 "id must point to an array, and the index must be an integer:\n";

	// Wrong index
	std::string test_program = "class Program {\n"
									"int x[1];\n"
									"void method(){\n"
										"x[true] = 1;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_11);

	test_program = "class Program {\n"
						"int x[1];\n"
						"void method1(){\n"
						"}\n"
						"void method2(){\n"
							"x[method1()] = 1;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_11);

	// Wrong id type
	test_program = "class Program {\n"
						"int x;\n"
						"void method(){\n"
							"x[0] = 1;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_11);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 9
0
void run_test()
{

 int i;

 /*
  * ========================================================================
  * This is where I'm installing the new dh_test_types[].
  * ========================================================================
  */
 if(dtest_num < 0){
   /* printf("dtest_name = %s\n",dtest_name); */
   for(i=0;i<MAXTESTS;i++){
     if(dh_test_types[i]){
       /* printf("Trying %s\n",dh_test_types[i]->sname); */
       if(strncmp(dh_test_types[i]->sname,dtest_name,128)==0){
         dtest_num = i;
	 break;
       }
     }
   }
 }
 if(dtest_num >= 0){
   execute_test(dtest_num);
 } else {
   fprintf(stderr,"Error:  dtest_num = %d.  No test found.\n",dtest_num);
   exit(1);
 }
  
}
Ejemplo n.º 10
0
/*
 * Execute development-time test
 */
bool_t
rcmd_test_1_svc(rcmd_str_listentry_ptr arg1, rcmd_status *result, struct svc_req *rqstp)
{
	int argc = 0;
	char** argv = NULL;

	rcmd_str_listentry* p;
	int k;

	for (p = arg1;  p;  p = p->next)
		argc++;

	argv = (char**) xmalloc(sizeof(char*) * (argc + 1));

	for (k = 0, p = arg1;  p;  p = p->next)
		argv[k++] = p->value;
	argv[k] = NULL;

	result->status = execute_test(argc, argv, &result->message);

	/* XDR does not tolerate NULL string pointers */
	if (result->message == NULL)
		result->message = xstrdup("");

	free_ptr(argv);

	return true;
}
int main(int argc, char *argv[]) {
	printf("Start of %s.\n", argv[0]);
	nthreads = 5, ncores = 5;
	if (SDF_TRUE != internal_testhomedir_init()) {
		return -1;
	} else if (argc > 1) {
		niterator = atoi(argv[1]);
	} else if (argc > 2) {
		ncores = atoi(argv[2]);
		if (ncores > MAX_CORES)
			ncores = MAX_CORES;
	} else if (argc > 3) {
		nthreads = atoi(argv[3]);
		if (nthreads > MAX_FTH_THREAD)
			nthreads = MAX_FTH_THREAD;
	}

	plat_assert_always(niterator > 0);
	plat_assert_always(nthreads > 0);
	plat_assert_always(ncores > 0);

	int ret = execute_test();
	printf("End of %s.\n", argv[0]);

	// plat_log_parse_arg("sdf/shared=debug");
	plat_shmem_alloc_get_stats(&g_end_sm_stats);
	print_sm_stats(g_init_sm_stats, g_end_sm_stats);
	return (ret);
}
Ejemplo n.º 12
0
void test_rule_3(){
	std::cout << "3) Every program has one class with name \"main\", and a "
			"\"main\" method:\n";

	// No main class declared
	std::string test_program = "class Program {}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_3);

	// main class declared, without a \"main\" method
	test_program = "class main {}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_3);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 13
0
int main()
{
    bool allOk = true;
    for(size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) {
        if(!execute_test(&tests[i])) allOk = false;
    }

    return (allOk ? 0 : 1);
}
Ejemplo n.º 14
0
/* executes all tests */
int main (int argc, const char * argv[]) {
	execute_test(&test_add);
	execute_test(&test_addi);
	execute_test(&test_jal);
	execute_test(&test_lui);
	execute_test(&test_lw);
	execute_test(&test_ori);
	execute_test(&test_sub);
	execute_test(&test_sw);
	return 0;
}
Ejemplo n.º 15
0
void test_rule_14(){
	std::cout << "14) eq_op operands must have the same type (int, float or "
			"boolean):\n";

	// Operands of different type
	std::string test_program = "class Program {\n"
									"boolean method(){\n"
										"return 1 == true;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_14);

	test_program = "class Program {\n"
						"boolean method(){\n"
							"return 1 != true;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_14);

	// Operands of the wrong type.
	test_program = "class Program {\n"
						"boolean method(){\n"
							"return \"asd\" != true;\n"
						"}\n"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_14);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 16
0
void test_rule_1(){
	std::cout << "1) An identifier is declared at most once, into a "
			"given scope:\n";
	std::string test_program = "class Program {\n"
										"int x,x;\n"
									"}\n"
									"class main {\n"
										"void main(){\n"
										"}\n"
									"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_1);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 17
0
void test_rule_24(){
	std::cout << "24) Attributes cannot have as type the class where they belong to: \n";

	std::string test_program = "class Program {\n"
									"Program x;"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_24);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 18
0
void test_rule_6(){
	std::cout << "6) If a method call used is used as expression, the"
			"called method must return a result:\n";

	// void method in return expression (same as rule 9)
	std::string test_program = "class Program {\n"
										"void method1(){\n"
										"}"
										"int method2(){\n"
											"return method1();"
										"}"
									"}\n"
									"class main {\n"
										"void main(){\n"
										"}\n"
									"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_9);

	// void method in a conditional's guard (same as rule 12)
	test_program = "class Program {\n"
						"void method1(){\n"
						"}"
						"void method2(){\n"
							"if (method1()) ; else ;\n"
						"}"
					"}\n"
					"class main {\n"
						"void main(){\n"
						"}\n"
					"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_12);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 19
0
void test_rule_23(){
	std::cout << "23) Parameter's identifier and method's name must differ:\n";

	std::string test_program = "class Program {\n"
									"void method(int method){\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_23);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 20
0
void test_rule_2(){
	std::cout << "2) An identifier is declared before it is used:\n";
	std::string test_program = "class Program {\n"
									"void method(){\n"
										"x = 1;"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_2);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 21
0
void test_rule_7(){
	std::cout << "7) String literals only with extern methods:\n";

	std::string test_program = "class Program {\n"
									"boolean method1(string x){\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_7);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 22
0
void test_rule_4(){
	std::cout << "4) In an array declaration, the length must be > 0:\n";

	// Array declaration with length == 0
	std::string test_program = "class Program {\n"
										"int x[0];\n"
									"}\n"
									"class main {\n"
										"void main(){\n"
										"}\n"
									"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_4);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 23
0
int
main(int argc, char *argv[])
{
    printf("Start of %s.\n", argv[0]);
    if (SDF_TRUE != internal_testhomedir_init()) {
        return -1;
    } else if (argc > 1) {
        numBlocks = atoi(argv[1]);
    }

    int ret = execute_test();
    printf("End of %s.\n", argv[0]);
    // plat_log_parse_arg("sdf/shared=debug");
    plat_shmem_alloc_get_stats(&g_end_sm_stats);
    print_sm_stats(g_init_sm_stats, g_end_sm_stats);
    return (ret);
}
Ejemplo n.º 24
0
void test_rule_9(){
	std::cout << "9) The type of the value returned from a method must be the "
				"same than the type of the expression of the return statement:\n";

	std::string test_program = "class Program {\n"
									"boolean method(){\n"
										"return 1;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_9);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 25
0
void test_rule_21(){
	std::cout << "21) Access of attributes only over instances:\n";

	std::string test_program = "class Program {\n"
									"int x,y;\n"
									"void method(){\n"
										"x = y.z;\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_21);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 26
0
void test_rule_22(){
	std::cout << "22) Method call operation over...methods only:\n";

	std::string test_program = "class Program {\n"
									"int x[1];\n"
									"void method(){\n"
										"x();\n"
									"}\n"
								"}\n"
								"class main {\n"
									"void main(){\n"
									"}\n"
								"}\0\0";

	assert(execute_test(test_program) == semantic_analysis::ERROR_22);

	std::cout << "OK.\n" << std::endl;
}
Ejemplo n.º 27
0
int
main(int argc, char ** argv)
{
  GOptionContext *context;
  GError *gerror = NULL;
  int count = 0;

  error = 0;

  gst_init (&argc, &argv);

  GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, GST_DEFAULT_NAME, 0,
      GST_DEFAULT_NAME);

  context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, gst_init_get_option_group () );

  if (!g_option_context_parse (context, &argc, &argv, &gerror) ) {
    GST_ERROR ("option parsing failed: %s\n", gerror->message);
    g_option_context_free (context);
    g_error_free (gerror);
    return 1;
  }

  g_option_context_free (context);

  loop = g_main_loop_new (NULL, TRUE);

  while (count < times && !g_atomic_int_get (&error)) {
    execute_test (count++);
    GST_INFO ("Executed %d times", count);
    if (g_atomic_int_get (&error)) {
      GST_ERROR ("Test terminated with error");
    } else {
      GST_INFO ("Test terminated correctly");
    }
  }

  g_main_loop_unref (loop);

  return error;
}
Ejemplo n.º 28
0
/**
 * Run a test in given context and analyze the results.
 *
 * @param t     test to be run
 * @param tc    test context
 */
static void test_context_run_test(Test *t, TestContext *tc)
{
    int in_fd, out_fd, err_fd;
    char out_file[] = "/tmp/stest-stdout-XXXXXX";
    char err_file[] = "/tmp/stest-stderr-XXXXXX";
    int status = 0;
    char **args = NULL, *mem_file = NULL;

    if (!test_context_prepare_outfiles(out_file, &out_fd, err_file, &err_fd)) {
        test_context_skip(tc, t, "can not open temporary files");
        goto out;
    }
    if ((in_fd = test_get_input_fd(t)) < 0) {
        test_context_skip(tc, t, "can not open input file");
        goto out;
    }
    if ((args = test_context_get_args(tc, t)) == NULL) {
        test_context_skip(tc, t, "can not read arguments");
        goto out;
    }

    if (tc->use_valgrind) {
        mem_file = prepare_for_valgrind(&args);
        if (!mem_file) {
            test_context_skip(tc, t, "can not open memory output file");
            goto out;
        }
    }
    execute_test(in_fd, out_fd, err_fd, args);

    wait(&status);

    test_context_analyze_test_run(tc, t, out_file, err_file, mem_file, status);
out:
    str_array_free(args);

    unlink(out_file);
    unlink(err_file);
    if (mem_file) {
        unlink(mem_file);
        free(mem_file);
    }
}
Ejemplo n.º 29
0
static K run_test(void (*execute_test)(void(s1)(void),void(s2)(void)), int testCount) 
{
	int i;
	K result, kffc[3], kpmc[4];

	for (i = 0 ; i < PMC_COUNT ; i++) 
		pmc_fixed[i] = 0;
	for (i = 0 ; i < FFC_COUNT ; i++) 
		ffc_fixed[i] = 0;

	ioctl(fd, IOCTL_MSR_CMDS, (long long)pmc_reset);
	execute_baseline(testCount, &start_baseline, &stop_baseline);
	pmc_fixed[0] = pmc_read[1].value / testCount;
	pmc_fixed[1] = pmc_read[2].value / testCount;
	pmc_fixed[2] = pmc_read[3].value / testCount;
	pmc_fixed[3] = pmc_read[4].value / testCount;
	ffc_fixed[0] = pmc_read[5].value / testCount;
	ffc_fixed[1] = pmc_read[6].value / testCount;
	ffc_fixed[2] = pmc_read[7].value / testCount;

	for (i = 0 ; i < PMC_COUNT ; i++) 
		kpmc[i] = ktn(KJ, testCount);
	
	for (i = 0 ; i < FFC_COUNT ; i++) 
		kffc[i] = ktn(KJ, testCount);
	
	for (i = 1 ; i < 1 + PMC_COUNT + FFC_COUNT ; i++)
		pmc_read[i].value = 0;
	
	for (i = 0 ; i < testCount ; i++) {
		ioctl(fd, IOCTL_MSR_CMDS, (long long)pmc_reset);
		execute_test(&start_counters, &stop_counters);
		kJ(kpmc[0])[i] = pmc_read[1].value - pmc_fixed[0];
		kJ(kpmc[1])[i] = pmc_read[2].value - pmc_fixed[1];
		kJ(kpmc[2])[i] = pmc_read[3].value - pmc_fixed[2];
		kJ(kpmc[3])[i] = pmc_read[4].value - pmc_fixed[3];
		kJ(kffc[0])[i] = pmc_read[5].value - ffc_fixed[0];
		kJ(kffc[1])[i] = pmc_read[6].value - ffc_fixed[1];
		kJ(kffc[2])[i] = pmc_read[7].value - ffc_fixed[2];
	}
	result = knk(7, kffc[0], kffc[1], kffc[2], kpmc[0], kpmc[1], kpmc[2], kpmc[3]);
	return result;
}
Ejemplo n.º 30
0
void test_checkout_binaryunicode__autocrlf(void)
{
	cl_repo_set_bool(g_repo, "core.autocrlf", true);
	execute_test();
}