Exemple #1
0
/**
 * The entry function for a Pumbaa application.
 */
int main()
{
    int stack_dummy;
    int res;

    /* Start the system. */
    sys_start();

    std_printf(sys_get_info());
    std_printf(FSTR("\r\n"));

    /* Initialize the thread module. */
#if MICROPY_PY_THREAD == 1
    module_thread_init();
#endif
    
    stack_top_p = (char*)&stack_dummy;
    mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
    gc_init(heap, heap + sizeof(heap));
    mp_init();

    /* Initialize the keyboard interrupt object. */
    MP_STATE_VM(keyboard_interrupt_obj) =
        mp_obj_new_exception(&mp_type_KeyboardInterrupt);

    /* Initialize sys.path and sys.argv. */
    mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
    mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);

    /* 1. Execute the file main.py. */
    std_printf(FSTR("Executing file 'main.py'.\r\n"));
    res = pyexec_file("main.py");
    print_exit_message(res, "File 'main.py'");

    /* 2. Execute the frozen module main.py. */
    std_printf(FSTR("Executing frozen module 'main.py'.\r\n"));
    res = pyexec_frozen_module("main.py");
    print_exit_message(res, "Frozen module 'main.py'");

#if CONFIG_PUMBAA_MAIN_FRIENDLY_REPL == 1
    /* 3. Execute the interactive shell. */
    res = pyexec_friendly_repl();
    print_exit_message(res, "Interactive shell");
#endif

    return (res != 1);
}
int main ()
{
	int notpassed = 0;
	int passed = 0;
	
	struct array array1;
	
	check (init_array (&array1))
	
	test (add_element (&array1, 1), NO_ERRORS)
	
	test (add_element (&array1, 8), NO_ERRORS)
	
	test (change_element(&array1, 12, 33), WRITE_TO_UNALLOCATED_MEMORY)
	
	test (change_element(&array1, 1, 33), NO_ERRORS)
	
	test (add_element (&array1, 41), NO_ERRORS)
	
	test (add_element (&array1, 3), NO_ERRORS)
	
	test (add_element (&array1, 9), NO_ERRORS)
	
	
	test (elements_sum (&array1), NO_ERRORS)
	
	test (add_element (&array1, 13), NO_ERRORS)
	
	test (verbose_full_print (&array1), NO_ERRORS)
	
	test (remove_element (&array1, 4), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (find_element(&array1, 120), ELEMENT_NOT_FOUND)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_element(&array1, 40), GARBAGE_READ)
	
	test (zero_array   (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	printf ("datalen = %i, memlen = %i\n", get_datalen (&array1), get_memlen (&array1));
	
	for (int i = 0; i < 305; i ++)
		check (add_element (&array1, 41)); 
	
	printf ("Passed %i, not passed %i.\n", passed, notpassed);
	
	test (delete_array (&array1), NO_ERRORS)
	
	print_exit_message ();
	
	return 0;
}
Exemple #3
0
//terminates with error code 1, printing message
void (Error)(const char *func, const unsigned line, const char *fmt,...)
{
	va_list arglist;

	int leader = snprintf(exit_message, sizeof(exit_message), "%s:%u: error: ", func, line);
	va_start(arglist,fmt);
	vsnprintf(exit_message+leader,sizeof(exit_message)-leader,fmt,arglist);
	va_end(arglist);

	Int3();

	/*if (!err_initialized)*/ print_exit_message();
	abort();
}
Exemple #4
0
//terminates with error code 1, printing message
void Error(const char *fmt,...)
{
	char exit_message[MAX_MSG_LEN]="Error: "; // don't put the new line in for dialog output
	va_list arglist;

	va_start(arglist,fmt);
	vsprintf(exit_message+strlen(exit_message),fmt,arglist);
	va_end(arglist);

	Int3();

	print_exit_message(exit_message);

	exit(1);
}
Exemple #5
0
Fichier : error.c Projet : btb/d1x
//terminates with error code 1, printing message
void Error(char *fmt,...)
{
	va_list arglist;

	strcpy(exit_message,"\nError: ");

	va_start(arglist,fmt);
	vsprintf(exit_message+strlen(exit_message),fmt,arglist);
	va_end(arglist);

	puts(exit_message);
	if (!err_initialized) print_exit_message();

#ifndef NDEBUG
	Int3();
#endif
	exit(1);
}
Exemple #6
0
//------------------------------------------------------------------------------
//terminates with error code 1, printing message
void _CDECL_ Error (char *fmt,...)
{
	va_list arglist;

#ifndef _DEBUG
strcpy (szExitMsg, TXT_TITLE_ERROR); // don't put the new line in for dialog output
#else
sprintf (szExitMsg, "\n%s", TXT_TITLE_ERROR);
#endif
va_start (arglist,fmt);
vsprintf (szExitMsg + strlen (szExitMsg), fmt, arglist);
va_end(arglist);
LogErr ("ERROR: %s\n", szExitMsg);
D2MsgBox (szExitMsg, MB_ICONERROR);
Int3();
if (!err_initialized) 
	print_exit_message();
#ifndef _DEBUG
exit (1);
#endif
}
Exemple #7
0
//------------------------------------------------------------------------------
//terminates with error code 1, printing message
void _CDECL_ Error (const char *fmt,...)
{
	va_list arglist;

#if !DBG
strcpy (szExitMsg, TXT_TITLE_ERROR); // don't put the new line in for dialog output
#else
sprintf (szExitMsg, "\n%s", TXT_TITLE_ERROR);
#endif
va_start (arglist,fmt);
vsprintf (szExitMsg + strlen (szExitMsg), fmt, arglist);
va_end(arglist);
PrintLog ("ERROR: %s\n", szExitMsg);
gameStates.app.bShowError = 1;
D2MsgBox (szExitMsg, MB_ICONERROR);
gameStates.app.bShowError = 0;
Int3();
if (!err_initialized) 
	print_exit_message();
#if !DBG
exit (1);
#endif
}
Exemple #8
0
int main(int argc, char * argv[]){
  //parse options
  int opt, ret;
  while ((opt = getopt(argc, argv, "ht:")) != -1){
    switch (opt){
    case 't':
      timelimit = atoi(optarg);
      if (timelimit <= 0){
        fprintf(stderr, "Timelimit must be a positive integer!\n");
        print_exit_message(RET_INTERNAL_ERROR);
        exit(RET_INTERNAL_ERROR);
      }
      break;
    case 'h':
      usage(argc, argv);
      exit(RET_INTERNAL_ERROR);
      break;
    case '?':
      usage(argc, argv);
      exit(RET_INTERNAL_ERROR);
      break;
    }
  }
  if (argc - optind < 3){
    fprintf(stderr, "FATAL ERROR: wrong number of parameters.\n");
    usage(argc, argv);
    exit(RET_INTERNAL_ERROR);
  }

  argc -= optind;
  argv += optind;

  sprintf(executable_name, "a%d.out", getpid());
  sprintf(output_file, "output%d.tmp", getpid());

  sprintf(buffer, "gcc -O1 %s -o %s", argv[2], executable_name);
  ret = system(buffer);
  if (ret == -1){
    fprintf(stderr, "FATAL ERROR: Cannot invoke gcc compiler. Panic!\n");
    exit(RET_INTERNAL_ERROR);
  }
  ret = WEXITSTATUS(ret);
  if (ret != 0){
    print_exit_message(RET_COMPILE_ERROR);
    exit(RET_COMPILE_ERROR);
  }

  sprintf(buffer, "./jaula -t %d %s %s %s > /dev/null 2> /dev/null", timelimit, argv[0], output_file, executable_name);
  ret = system(buffer);

  if (ret == -1){
    fprintf(stderr, "FATAL ERROR: Cannot execute program. Panic!\n");
    exit(RET_INTERNAL_ERROR);
  }

  ret = WEXITSTATUS(ret);
  if (ret == RET_TIMELIMIT_EXCEEDED){
    print_exit_message(RET_TIMELIMIT_EXCEEDED);
    remove(output_file);
    remove(executable_name);
    exit(RET_TIMELIMIT_EXCEEDED);
  }

  if (ret == RET_RUNTIME_ERROR){
    print_exit_message(RET_RUNTIME_ERROR);
    remove(output_file);
    remove(executable_name);
    exit(RET_RUNTIME_ERROR);
  }

  sprintf(buffer, "diff %s %s > /dev/null\n", argv[1], output_file);
  ret = system(buffer);
  if (ret == -1){
    fprintf(stderr, "FATAL ERROR: Cannot compare files. Panic!\n");
    exit(RET_INTERNAL_ERROR);
  }
  ret = WEXITSTATUS(ret);
  if(ret == 0){
    print_exit_message(RET_ACCEPTED);
    remove(output_file);
    remove(executable_name);
    exit(RET_ACCEPTED);
  }


  sprintf(buffer, "diff -q -i -b -B -w %s %s > /dev/null\n", argv[1], output_file);
  ret = system(buffer);

  if (ret == -1){
    fprintf(stderr, "FATAL ERROR: Cannot compare files. Panic!\n");
    exit(RET_INTERNAL_ERROR);
  }
  ret = WEXITSTATUS(ret);
  if(ret == 0){
    print_exit_message(RET_PRESENTATION_ERROR);
    remove(output_file);
    remove(executable_name);
    exit(RET_PRESENTATION_ERROR);
  }

  print_exit_message(RET_WRONG_ANSWER);
  remove(output_file);
  remove(executable_name);
  exit(RET_WRONG_ANSWER);
}
Exemple #9
0
int main(int argc, char * argv[]){
  //parse options
  int opt;
  while ((opt = getopt(argc, argv, "ht:")) != -1){
    switch (opt){
    case 't':
      timelimit = atoi(optarg);
      if (timelimit <= 0){
        fprintf(stderr, "ERROR: Timelimit must be a positive integer (received %s)!\n", optarg);
        exit(RET_INTERNAL_ERROR);
      }
      break;
    case 'h':
      usage(argc, argv);
      exit(RET_INTERNAL_ERROR);
      break;
    case '?':
      usage(argc, argv);
      exit(RET_INTERNAL_ERROR);
      break;
    }
  }

  if (argc - optind < 3){
    fprintf(stderr, "FATAL ERROR: wrong number of parameters.\n");
    usage(argc, argv);
    exit(RET_INTERNAL_ERROR);
  }

  children_pid = fork();
  if (children_pid == -1){
    fprintf(stdout, "ERROR forking sub-process. Panic!\n");
    print_exit_message(RET_INTERNAL_ERROR);
    exit(RET_INTERNAL_ERROR);
  }

  if (children_pid != 0){
    /* parent process */
    signal(SIGALRM, timeout_handler);
    alarm(timelimit);
    printf("Time limit is %d seconds\n", timelimit);

    int status;
    wait(&status);
    /* if we get here, the subprocess ended within the time-limit. Disable the alarm. */
    alarm(0);

    struct rusage usage;
    getrusage(RUSAGE_CHILDREN, &usage);
    double used_time =
      usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1000000.0 +
      usage.ru_stime.tv_sec + usage.ru_stime.tv_usec / 1000000.0;

    printf("Running time: %lf\n", used_time);
    if (WIFEXITED(status)){
      fprintf(stdout, "Subprocess ended SUCCESSFULLY and returned %d\n", WEXITSTATUS(status));
      print_exit_message(RET_SUCCESS);
      exit(RET_SUCCESS);
    }else if (WIFSIGNALED(status)){
      if (WTERMSIG(status) == SIGUSR1){
        fprintf(stdout, "Couldn't execute program.\n");
        print_exit_message(RET_INTERNAL_ERROR);
        exit(RET_INTERNAL_ERROR);
      }else{
        fprintf(stdout, "Subprocess ended ABNORMALLY with signal code %d\n", WTERMSIG(status));
        print_exit_message(RET_RUNTIME_ERROR);
        exit(RET_RUNTIME_ERROR);
      }
    }else{
      fprintf(stdout, "Unrecognized ending situation.\n");
      print_exit_message(RET_RUNTIME_ERROR);
      exit(RET_RUNTIME_ERROR);
    }
  }else{
    /* child process */
    argc -= optind;
    argv += optind;

    if (freopen(argv[0], "r", stdin) == NULL){
      fprintf(stderr, "FATAL ERROR: Cannot open input file %s: %s\n", argv[0], strerror(errno));
      raise(SIGUSR1);
    }
    if (freopen(argv[1], "w", stdout) == NULL){
      fprintf(stderr, "FATAL ERROR: Cannot open output file: %s\n", argv[1], strerror(errno));
      raise(SIGUSR1);
    }

    /* attempt to exec the child process */
    if (execv(argv[2], argv + 2) == -1){
      fprintf(stderr, "FATAL ERROR: Cannot execute program %s: %s\n", argv[2], strerror(errno));
    }
    raise(SIGUSR1);
  }
  /* This is limbo, should never get here */
  exit(RET_INTERNAL_ERROR);
}
Exemple #10
0
void timeout_handler(int sig){
  fprintf(stdout, "Subprocess timed out after %d seconds\n", timelimit);
  kill(children_pid, SIGKILL);
  print_exit_message(RET_TIMELIMIT_EXCEEDED);
  exit(RET_TIMELIMIT_EXCEEDED);
}