예제 #1
0
int 
main (int   argc,
      char *argv[])
{
  run_all_tests ();

  /* Now we rerun all tests, but this time we fool the system into
   * thinking, that the available thread system is not native, but
   * userprovided. */

  g_thread_use_default_impl = FALSE;
  run_all_tests ();
  
  return 0;
}
예제 #2
0
파일: unittester.cpp 프로젝트: mkuitune/orb
int main(int argc, char* argv[])
{
    // Filter tests are run based on input: test names with any matching strings are run.
    // If there is no input, then all tests are run.
    if(argc < 2)
    {
        run_all_tests();
    }
    else
    {
        for(auto& test_set : *g_tests)
        {
            for(auto& test_group : test_set.second)
            {
                bool run = false;
                for(int i = 1; i < argc; ++i){
                    if(test_group.second.names_match(argv[i])) run = true;
                }
                if(run) run_test(test_group.second);
            }
        }
    }

    return 0;
}
예제 #3
0
파일: main.c 프로젝트: penten/skiplist
int main(void) {
    run_all_tests();
    printf("Tests run: %d | Tests passed: %d | Tests failed: %d\n", \
        tests_failed + tests_passed, tests_passed, tests_failed);

    return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: whunmr/circa
int main(int argc, char** argv)
{
    block_test::register_tests();
    building_test::register_tests();
    c_objects_test::register_tests();
    code_iterator_test::register_tests();
    compound_type_test::register_tests();
    control_flow_test::register_tests();
    fakefs::register_tests();
    file::register_tests();
    file_watch::register_tests();
    handle::register_tests();
    importing::register_tests();
    interpreter::register_tests();
    migration::register_tests();
    modules::register_tests();
    names::register_tests();
    native_patch_test::register_tests();
    parser_test::register_tests();
    path_expression_tests::register_tests();
    stateful_code_test::register_tests();
    string_tests::register_tests();
    symbol_test::register_tests();
    tokenizer::register_tests();

    caWorld* world = circa_initialize();

    run_all_tests();

    circa_shutdown(world);
}
예제 #5
0
int main( int argc, char *argv[] )
{
     run_all_tests();

     show_test_results();

     return (tests_pass()) ? EXIT_SUCCESS : EXIT_FAILURE;
}
예제 #6
0
int
main(int argc, char *argv[])
{
    if (ld_insandbox())
        return SANDBOX_MAGIC;

    return (run_all_tests(test_count, all_tests, argc, argv) != PASSED);
}
int main()
{
    g_head_suite = NULL;
    
    REGISTER_TEST_SUITE(md5)
    REGISTER_TEST_SUITE(system_calls)
    
    run_all_tests();
}
예제 #8
0
파일: cmd_line.c 프로젝트: NunyaOS/Nunya
void cmd_line_attempt(const char *line) {
    char line_copy[KEYBOARD_BUFFER_SIZE];
    strcpy(line_copy, line);
    strip_backspace(line_copy); // Get rid of backspace characters

    char *first_word = strtok(line_copy, " ");
    const char *the_rest_mixed_case = line_copy + (strlen(first_word) + 1);
    char the_rest[strlen(the_rest_mixed_case) + 1];
    to_upper(the_rest, the_rest_mixed_case);

    //Ugly case statement alternative
    if (strcmp("echo", first_word) == 0) {
        cmd_line_echo(the_rest);
    } else if (strcmp("test", first_word) == 0) {
        run_all_tests();
    } else if (strcmp("cd", first_word) == 0) {
        cmd_line_cd(the_rest);
    } else if (strcmp("pwd", first_word) == 0) {
        cmd_line_pwd(the_rest);
    } else if (strcmp("ls", first_word) == 0) {
        cmd_line_ls(the_rest);
    } else if (strcmp("cat", first_word) == 0) {
        cmd_line_cat(the_rest);
    } else if (strcmp("memory_demo", first_word) == 0) { // temporary, for debugging
        uint32_t identifier = permissions_capability_create();

        // set the memory
        int difference = get_max_memory() - get_current_memory_usage();
        capability_set_max_memory(identifier, difference);
        run("/BIN/PRINT_EV.NUN", identifier);
        console_printf("Attempting to run a process I don't have memory for.\nExpecting an error message soon...\n");
        run("/BIN/PRINT_OD.NUN", identifier);
        permissions_capability_delete(identifier);
    } else if (strcmp("clock_test", first_word) == 0) { // temporary, for debugging
        uint32_t identifier = permissions_capability_create();
        run("/BIN/TEST_CLO.NUN", identifier);
        permissions_capability_delete(identifier);
    } else if (strcmp("help", first_word) == 0) {   // Leave this as the last case
        cmd_line_help(the_rest);
    } else if (strcmp("window_test", first_word) == 0) {
        console_printf("\f");
        uint32_t identifier = permissions_capability_create();
        run("/BIN/TEST_WIN.NUN", identifier);
        permissions_capability_delete(identifier);
    }
    /*else if () {
     *...
     *}
     */
    else {
        console_printf("%s: command not found\n", first_word);
    }
    memset(line_copy, '\0', KEYBOARD_BUFFER_SIZE);
    return;
}
예제 #9
0
파일: test.c 프로젝트: akhilmd/btech-sem3
int main(int argl, char** argv)
{
    if (check_for_help(argv + 1, argl - 1))
    {
        if (argl == 1)
            run_all_tests();
        else
            run_tests(argv + 1, argl - 1);
    }
    return 0;
}
예제 #10
0
파일: main.c 프로젝트: idea-on-line/picunit
int main() {

#if RUN_TESTS
    run_all_tests();
#endif

    while(1){
        //HERE GOES YOUR MAIN LOOP
    }
    return (EXIT_SUCCESS);
}
예제 #11
0
int 
main (int   argc,
      char *argv[])
{
  /* Only run the test, if threads are enabled and a default thread
     implementation is available */
#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
  g_thread_init (NULL);
  run_all_tests ();

  /* Now we rerun all tests, but this time we fool the system into
   * thinking, that the available thread system is not native, but
   * userprovided. */

  g_thread_use_default_impl = FALSE;
  run_all_tests ();
  
#endif
  return 0;
}
예제 #12
0
int main() {
	char *result = run_all_tests();
	if (result != 0) {
		printf("%s\n", result);
	}
	else {
		printf("ALL TESTS PASSED\n");
	}
	printf("Tests run: %d\n", tests_run);

	return result != 0;
}
예제 #13
0
파일: main.c 프로젝트: Carrigan/stlv
int main()
{
	char *message = 0;

	if(message = run_all_tests()) {
		printf("%s\n", message);
		printf("TESTS FAILED.");
		return 1;
	}

	printf("Tests run: %d\n", tests_run);
	printf("ALL TESTS PASSED.");
	return 0;
}
예제 #14
0
int main(int argc, char **argv) {
	char *result = run_all_tests();
	printf("\n");
	if (result != 0) {
		printf("Not all unit tests passed\n");
	}
	else {
		printf("TEST_MAPS_AND_SETS: ALL UNIT TESTS PASSED\n");
	}
	printf("Tests      passed: %d of %d\n", tests_run - tests_failed, tests_run);
	printf("Assertions passed: %d of %d\n", assertions_run - assertions_failed, assertions_run);

	return result != 0;
}
예제 #15
0
파일: AllTests.c 프로젝트: Lothy/FreeRSC
int
main(void)
{
    a_t a;
    b_t b;

    a.index = 111;
    a.rofl = 222;
    a.test = 333;

    b.test = 333;
    b.index = 111;
    b.rofl = 222;
    TEST_MACRO(&a, 1337);
    TEST_MACRO(&b, 7331);
    testing_init();
    return run_all_tests();
}
예제 #16
0
int main(int argc, char* argv[]) {
    setlocale(LC_ALL, "");

    board_t board;
    RESET_BOARD(board);
    char buffer[256];
    int len;

    hash_init();
    run_all_tests();
    print_board(&board);

    move_t m;
    while (1) {
    top:
        print_board(&board);
        move_t move = 0;
        while (move == 0)
        { 
            printf("enter move> ");
            fgets(buffer, 255, stdin);
            if (!strcmp(buffer, "undo\n")) {
                undo_move(&board, m);            
                goto top;
            } else if (!strcmp(buffer, "exit\n")) {
                return 0;
            }
            len = strlen(buffer);
            if (buffer[len-1] == '\n') buffer[len-1] = '\0';
            move = move_from_text(buffer, &board);
        }
        make_move(&board, move);
        print_board(&board);

        printf("Calculating...\n");
        m = think(&board);
        make_move(&board, m);
        printf("Done calculating...\n");
        print_move(m);
    }
    return 0;
}
예제 #17
0
int main(int argc, char **argv) {
	printf("TEST_JOIN_BUCKET_KEEPER ENTER\n");
	for (int argi = 1; argi < argc; argi++) {
		if (streq(argv[argi], "-v"))
			tjbk_verbose = TRUE;
	}

	char *result = run_all_tests();
	printf("\n");
	if (result != 0) {
		printf("Not all unit tests passed\n");
	}
	else {
		printf("TEST_JOIN_BUCKET_KEEPER: ALL UNIT TESTS PASSED\n");
	}
	printf("Tests      passed: %d of %d\n", tests_run - tests_failed, tests_run);
	printf("Assertions passed: %d of %d\n", assertions_run - assertions_failed, assertions_run);

	return result != 0;
}
예제 #18
0
파일: main.cpp 프로젝트: andyfischer/circa
int main(int argc, char** argv)
{
    hashtable_test::register_tests();

    bytecode_test::register_tests();

#if 0
    block_test::register_tests();
    building_test::register_tests();
    code_iterator_test::register_tests();
    control_flow_test::register_tests();
    compound_type_test::register_tests();
    fakefs_test::register_tests();
    file_test::register_tests();
    file_watch_test::register_tests();
    function_test::register_tests();
    if_block_test::register_tests();
    list_test::register_tests();
    loop_test::register_tests();
    migration_test::register_tests();
    modules_test::register_tests();
    names_test::register_tests();
    native_patch_test::register_tests();
    parser_test::register_tests();
    path_expression_test::register_tests();
    stack_test::register_tests();
    symbol_test::register_tests();
    tagged_value_test::register_tests();
    string_test::register_tests();
    tokenizer_test::register_tests();
    type_test::register_tests();
#endif

    caWorld* world = circa_initialize();

    run_all_tests();

    circa_shutdown(world);
}
예제 #19
0
파일: test_lrec.c 프로젝트: graydon/miller
int main(int argc, char **argv) {
#ifdef MLR_USE_MCHECK
	if (mcheck(NULL) != 0) {
		printf("Could not set up mcheck\n");
		exit(1);
	}
	printf("Set up mcheck\n");
#endif // MLR_USE_MCHECK

	char *result = run_all_tests();
	printf("\n");
	if (result != 0) {
		printf("Not all unit tests passed\n");
	}
	else {
		printf("TEST_LREC: ALL UNIT TESTS PASSED\n");
	}
	printf("Tests      passed: %d of %d\n", tests_run - tests_failed, tests_run);
	printf("Assertions passed: %d of %d\n", assertions_run - assertions_failed, assertions_run);

	return result != 0;
}
예제 #20
0
파일: test-uri.c 프로젝트: GNOME/yelp
int
main (int argc, char **argv)
{
    YelpUri *parent = NULL;
    YelpUri *uri = NULL;

    g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);

    if (argc < 2) {
        g_test_init (&argc, &argv, NULL);
        return run_all_tests (argc, argv);
    }
    else {
        if (argc > 2) {
            parent = yelp_uri_new (argv[1]);
            uri = yelp_uri_new_relative (parent, argv[2]);
        } else {
            uri = yelp_uri_new (argv[1]);
        }
        if (uri) {
            gchar *orig;
            /* We leak orig if argc > 2.  I don't care. */
            if (argc > 2)
                orig = g_strconcat (argv[1], " ", argv[2], NULL);
            else
                orig = argv[1];
            g_signal_connect (uri, "resolved", G_CALLBACK (uri_resolved), orig);
            yelp_uri_resolve (uri);
        }
        if (parent) {
            g_object_unref (parent);
        }
    }

    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);

    return 0;
}
예제 #21
0
int main(void)
{
  const test_table_entry_t test_table[] = {
    TEST_NO_REP(init_cache),
    TEST_NO_REP(test_abort_classification),
    TEST_NO_REP(test_cc_classification),
    TEST_DF_REP(test_tbegin_ntstg_tend),
    TEST_DF_REP(test_tbegin_ntstg_tabort),
    TEST_DF_REP(test_tbegin_aborts),
    TEST_DF_REP(test_tbegin_tdb),
    TEST_DF_REP(test_etnd),
    { (void *)0, 0, 0 }
  };

  {
    int rc;

    rc = run_all_tests(test_table);

    return rc;
  }
}
예제 #22
0
int main( int argc, char *argv[] )
{
     if ( argc < 2 )
     {
          printf( "Must supply a db file name.\n" );

          return EXIT_FAILURE;
     }

     sqlite3_open( argv[1], &db );
     sqlite3_exec( db, "begin", NULL, NULL, NULL );


     run_all_tests( db );

     show_test_results();


     sqlite3_exec( db, "rollback", NULL, NULL, NULL );
     sqlite3_close( db );

     return (tests_pass()) ? EXIT_SUCCESS : EXIT_FAILURE;
}
예제 #23
0
파일: execute.c 프로젝트: mezun7/ejudge
int
main(int argc, char *argv[])
{
  int i, r;

  progname = argv[0];
  for (i = 1; i < argc; i++) {
    r = handle_options(argv[i]);
    if (r == 1) i++;
    if (r > 0) break;
  }
  if (i == argc) fatal("no program to execute");

  if (!(current_dir = os_GetWorkingDir())) fatal("getcwd() failed");

  if (all_tests > 0) {
    if (!test_dir) fatal("--test-dir must be specified in --all-tests mode");
    if (!test_pattern || !*test_pattern) fatal("--test-pattern must be specified in --all-tests mode");
    return run_all_tests(argc - i, argv + i);
  }

  return run_program(argc - i, argv + i, NULL, NULL);
}
예제 #24
0
int main(int argc, char *argv[])
{
    TEST_OSS_ENDPOINT = TEST_OSS_ENDPOINT != NULL ? 
                        TEST_OSS_ENDPOINT : getenv("OSS_TEST_ENDPOINT");
    TEST_ACCESS_KEY_ID = TEST_ACCESS_KEY_ID != NULL ? 
                         TEST_ACCESS_KEY_ID : getenv("OSS_TEST_ACCESS_KEY_ID");
    TEST_ACCESS_KEY_SECRET = TEST_ACCESS_KEY_SECRET != NULL ?
                             TEST_ACCESS_KEY_SECRET : getenv("OSS_TEST_ACCESS_KEY_SECRET");
    TEST_BUCKET_NAME = TEST_BUCKET_NAME != NULL ?
                       TEST_BUCKET_NAME : getenv("OSS_TEST_BUCKET");

    int exit_code;
    if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
        exit(1);
    }

    aos_log_set_level(AOS_LOG_OFF);
    exit_code = run_all_tests(argc, argv);

    //aos_http_io_deinitialize last
    aos_http_io_deinitialize();

    return exit_code;
}
예제 #25
0
파일: dtls-stress.c 프로젝트: intgr/gnutls
int main(int argc, const char* argv[])
{
	int dropMode = 0;
	int serverFinishedPermute = 0;
	int serverHelloPermute = 0;
	int clientFinishedPermute = 0;
	int batch = 0;
	int arg;

	nonblock = 0;
	debug = 0;
	timeout_seconds = 120;
	retransmit_milliseconds = 100;
	full = 0;
	run_to_end = 1;
	job_limit = 1;

#define NEXT_ARG(name) \
	do { \
		if (++arg >= argc) { \
			fprintf(stderr, "No argument for -" #name "\n"); \
			exit(8); \
		} \
	} while (0);
#define FAIL_ARG(name) \
	do { \
		fprintf(stderr, "Invalid argument for -" #name "\n"); \
		exit(8); \
	} while (0);

	for (arg = 1; arg < argc; arg++) {
		if (strcmp("-die", argv[arg]) == 0) {
			run_to_end = 0;
		} else if (strcmp("-batch", argv[arg]) == 0) {
			batch = 1;
		} else if (strcmp("-d", argv[arg]) == 0) {
			char* end;
			int level = strtol(argv[arg+1], &end, 10);
			if (*end == '\0') {
				debug = level;
				arg++;
			} else {
				debug++;
			}
		} else if (strcmp("-nb", argv[arg]) == 0) {
			nonblock = 1;
		} else if (strcmp("-timeout", argv[arg]) == 0) {
			char* end;
			int val;

			NEXT_ARG(timeout);
			val = strtol(argv[arg], &end, 10);
			if (*end == '\0') {
				timeout_seconds = val;
			} else {
				FAIL_ARG(timeout);
			}
		} else if (strcmp("-retransmit", argv[arg]) == 0) {
			char* end;
			int val;

			NEXT_ARG(retransmit);
			val = strtol(argv[arg], &end, 10);
			if (*end == '\0') {
				retransmit_milliseconds = val;
			} else {
				FAIL_ARG(retransmit);
			}
		} else if (strcmp("-j", argv[arg]) == 0) {
			char* end;
			int val;

			NEXT_ARG(timeout);
			val = strtol(argv[arg], &end, 10);
			if (*end == '\0') {
				job_limit = val;
			} else {
				FAIL_ARG(j);
			}
		} else if (strcmp("-full", argv[arg]) == 0) {
			full = 1;
		} else if (strcmp("-shello", argv[arg]) == 0) {
			NEXT_ARG(shello);
			if (!parse_permutation(argv[arg], full ? permutation_names5 : permutation_names3, &serverHelloPermute)) {
				FAIL_ARG(shell);
			}
		} else if (strcmp("-sfinished", argv[arg]) == 0) {
			NEXT_ARG(sfinished);
			if (!parse_permutation(argv[arg], permutation_names2, &serverFinishedPermute)) {
				FAIL_ARG(sfinished);
			}
		} else if (strcmp("-cfinished", argv[arg]) == 0) {
			NEXT_ARG(cfinished);
			if (!parse_permutation(argv[arg], full ? permutation_names5 : permutation_names3, &clientFinishedPermute)) {
				FAIL_ARG(cfinished);
			}
		} else {
			int drop;
			int filter_count = full ? 12 : 8;
			const char** local_filter_names = full ? filter_names_full : filter_names;
			for (drop = 0; drop < filter_count; drop++) {
				if (strcmp(local_filter_names[drop], argv[arg]) == 0) {
					dropMode |= (1 << drop);
					break;
				}
			}
			if (drop == filter_count) {
				fprintf(stderr, "Unknown packet %s\n", argv[arg]);
				exit(8);
			}
		}
	}

	setlinebuf(stdout);
	gnutls_global_init();
	cred_init();
	gnutls_global_set_log_function(logfn);
	gnutls_global_set_audit_log_function(auditfn);
	gnutls_global_set_log_level(debug);

	if (dropMode || serverFinishedPermute || serverHelloPermute || clientFinishedPermute) {
		return run_one_test(dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute);
	} else {
		job_pids = calloc(sizeof(int), job_limit);
		if (batch) {
			return run_tests_from_id_list(job_limit);
		} else {
			return run_all_tests(job_limit);
		}
	}
}
예제 #26
0
파일: runTest.c 프로젝트: Caspinol/khmap
int main(void){
	run_all_tests();
}
예제 #27
0
파일: main.c 프로젝트: jwasham/practice-c
int main(int argc, char* argv[]) {
  run_all_tests();
  run_example();

  return EXIT_SUCCESS;
}
예제 #28
0
파일: main.c 프로젝트: Janesak1977/Espruino
int main(int argc, char **argv) {
  int i;
  for (i=1;i<argc;i++) {
    if (argv[i][0]=='-') {
      // option
      char *a = argv[i];
      if (!strcmp(a,"-h") || !strcmp(a,"--help")) {
        show_help();
        exit(1);
      } else if (!strcmp(a,"-e") || !strcmp(a,"--eval")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        jshInit();
        jsvInit();
        jsiInit(true);
        addNativeFunction("quit", nativeQuit);
        jsvUnLock(jspEvaluate(argv[i+1], false));
        int errCode = handleErrors();
        isRunning = !errCode;
        bool isBusy = true;
        while (isRunning && (jsiHasTimers() || isBusy))
          isBusy = jsiLoop();
        jsiKill();
        jsvKill();
        jshKill();
        exit(errCode);
      } else if (!strcmp(a,"--test")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        bool ok = run_test(argv[i+1]);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-all")) {
        bool ok = run_all_tests();
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-all")) {
        bool ok = run_memory_tests(0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        bool ok = run_memory_test(argv[i+1], 0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-n")) {
        if (i+2>=argc) die("Expecting an extra 2 arguments\n");
        bool ok = run_memory_test(argv[i+1], atoi(argv[i+2]));
        exit(ok ? 0 : 1);
      } else {
        printf("Unknown Argument %s\n", a);
        show_help();
        exit(1);
      }
    }
  }

  if (argc==1) {
    printf("Interactive mode.\n");
  } else if (argc==2) {
    // single file - just run it
    char *buffer = read_file(argv[1]);
    if (!buffer) exit(1);
    // check for '#' as the first char, and if so, skip the first line
    char *cmd = buffer;
    if (cmd[0]=='#') {
      while (cmd[0] && cmd[0]!='\n') cmd++;
      if (cmd[0]=='\n') cmd++;
    }
    jshInit();
    jsvInit();
    jsiInit(false /* do not autoload!!! */);
    addNativeFunction("quit", nativeQuit);
    jsvUnLock(jspEvaluate(cmd, true));
    int errCode = handleErrors();
    free(buffer);
    isRunning = !errCode;
    bool isBusy = true;
    while (isRunning && (jsiHasTimers() || isBusy))
      isBusy = jsiLoop();
    jsiKill();
    jsvKill();
    jshKill();
    exit(errCode);
  } else {
    printf("Unknown arguments!\n");
    show_help();
    exit(1);
  }

  printf("Size of JsVar is now %d bytes\n", (int)sizeof(JsVar));
  printf("Size of JsVarRef is now %d bytes\n", (int)sizeof(JsVarRef));

#ifndef __MINGW32__
  struct sigaction sa;
  sa.sa_handler = sig_handler;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction(SIGINT, &sa, NULL) == -1)
    printf("Adding SIGINT hook failed\n");
  else
    printf("Added SIGINT hook\n");
  if (sigaction(SIGHUP, &sa, NULL) == -1)
    printf("Adding SIGHUP hook failed\n");
  else
    printf("Added SIGHUP hook\n");
  if (sigaction(SIGTERM, &sa, NULL) == -1)
    printf("Adding SIGTERM hook failed\n");
  else
    printf("Added SIGTERM hook\n");
#endif//!__MINGW32__

  jshInit();
  jsvInit();
  jsiInit(true);

  addNativeFunction("quit", nativeQuit);
  addNativeFunction("interrupt", nativeInterrupt);

  while (isRunning) {
    jsiLoop();
  }
  jsiConsolePrint("\n");
  jsiKill();
  jsvGarbageCollect();
  jsvShowAllocated();
  jsvKill();
  jshKill();

  return 0;
}
예제 #29
0
int main (int argc, char *argv[])
{
	int i;
	char *pluginname = NULL;
	char *plugindir = NULL;
	char *configfile = NULL;
	char *objtype = NULL;
	OSyncError *error = NULL;

	if (argc < 2)
		usage (argv[0], 1);

	pluginname = argv[1];
	for (i = 2; i < argc; i++) {
		char *arg = argv[i];
		if (!strcmp (arg, "--config")) {
			configfile = argv[i + 1];
			i++;
			if (!configfile)
				usage (argv[0], 1);
		} else if (!strcmp (arg, "--type")) {
			objtype = argv[i + 1];
			i++;
			if (!objtype)
				usage (argv[0], 1);
		} else if (!strcmp (arg, "--plugindir")) {
			printf("plugindir %s\n", argv[i + 1]);
			plugindir = argv[i + 1];
			i++;
			if (!plugindir)
				usage (argv[0], 1);
		} else if (!strcmp (arg, "--random")) {
			only_random = TRUE;
		} else if (!strcmp (arg, "--help")) {
			usage (argv[0], 0);
		} else {
			usage (argv[0], 1);
		}
	}

	OSyncEnv *env = osync_env_new(NULL);
	osync_env_set_option(env, "LOAD_GROUPS", "FALSE");

	if (plugindir)
		osync_env_set_option(env, "PLUGINS_DIRECTORY", plugindir);

	if (!osync_env_initialize(env, &error)) {
		printf("Unable to initialize environment: %s\n", osync_error_print(&error));
		osync_error_unref(&error);
		return 1;
	}

	char *testdir = g_strdup_printf("%s/plgtest.XXXXXX", g_get_tmp_dir());
	char *result = mkdtemp(testdir);

	if (result == NULL)
	{
		osync_trace(TRACE_EXIT_ERROR, "unable to create temporary dir: %s", g_strerror(errno));
		return 1;
	}

	OSyncGroup *group = osync_group_new(env);
	osync_group_set_name(group, osync_rand_str(8));
	osync_group_set_configdir(group, testdir);
	OSyncMember *member = osync_member_new(group);

	char *config = NULL;
	int size = 0;
	if (configfile) {
		if (!osync_file_read(configfile, &config, &size, &error)) {
			fprintf(stderr, "Unable to read config: %s\n", osync_error_print(&error));
			osync_error_unref(&error);
			return 1;
		}
		osync_member_set_config(member, config, size);
	}

	osync_member_set_pluginname(member, pluginname);

	OSyncMember *file = osync_member_new(group);

	localdir = g_strdup_printf("%s/plgtest.XXXXXX", g_get_tmp_dir());
	result = mkdtemp(localdir);

	if (result == NULL)
	{
		osync_trace(TRACE_EXIT_ERROR, "unable to create temporary dir: %s", g_strerror(errno));
		return 1;
	}

	config = g_strdup_printf("<config><path>%s</path><recursive>0</recursive></config>", localdir);
	osync_member_set_config(file, config, strlen(config) + 1);
	osync_member_set_pluginname(file, "file-sync");

	if (!osync_group_save(group, &error)) {
		printf("Error while creating syncengine: %s\n", osync_error_print(&error));
		osync_error_unref(&error);
		goto error_free_env;
	}

	if (!g_thread_supported ()) g_thread_init (NULL);

	OSyncEngine *engine = osengine_new(group, &error);
	if (!engine) {
		printf("Error while creating syncengine: %s\n", osync_error_print(&error));
		osync_error_unref(&error);
		goto error_free_env;
	}

	if (!osengine_init(engine, &error)) {
		printf("Error while initializing syncengine: %s\n", osync_error_print(&error));
		osync_error_unref(&error);
		goto error_free_engine;
	}

	int count = 0;
	if (only_random) {
		do {
			count++;
			printf("++++++++++++++++++++++++++++++\n");
			printf("Initializing new round #%i!\n", count);

			if (g_random_int_range(0, 5) == 0) {
				int i;
				OSyncFormatEnv *env = osync_group_get_format_env(group);
				for (i = 0; i < osync_conv_num_objtypes(env); i++) {
					if (g_random_int_range(0, 5) == 0) {
						OSyncObjType *type = osync_conv_nth_objtype(env, i);
						osync_group_set_slow_sync(group, osync_objtype_get_name(type), TRUE);
						printf("Requesting slow-sync for: %s\n", osync_objtype_get_name(type));
					}
				}
				osync_conv_env_free(env);
			}

			change_content();

			check_sync(engine, "Random", 1);
		} while (g_random_int_range(0, 3) != 0);

		printf("Finalizing engine\n");
		osengine_finalize(engine);
		osengine_free(engine);

		engine = osengine_new(group, &error);
		if (!engine) {
			printf("Error while creating syncengine: %s\n", osync_error_print(&error));
			osync_error_unref(&error);
			goto error_free_env;
		}

		if (!osengine_init(engine, &error)) {
			printf("Error while initializing syncengine: %s\n", osync_error_print(&error));
			osync_error_unref(&error);
			goto error_free_engine;
		}
	} else {
		register_tests();
		run_all_tests(engine, file, member, objtype);
	}

	printf("\nCompleted successfully\n");
	return 0;

error_free_engine:
	osengine_free(engine);
error_free_env:
	osync_group_free(group);
	osync_env_free(env);
	return 1;
}
예제 #30
0
파일: main.c 프로젝트: JogoJogo/Espruino
int main(int argc, char **argv) {
  int i;
  for (i=1;i<argc;i++) {
    if (argv[i][0]=='-') {
      // option
      char *a = argv[i];
      if (!strcmp(a,"-h") || !strcmp(a,"--help")) {
        show_help();
        exit(1);
      } else if (!strcmp(a,"-e") || !strcmp(a,"--eval")) {
        if (i+1>=argc) die("Expecting an extra argument");
        jshInit();
        jsiInit(true);
        jspAddNativeFunction(jsiGetParser(), "function quit()", nativeQuit);
        jsvUnLock(jspEvaluate(jsiGetParser(), argv[i+1]));
        isRunning = true;
        while (isRunning && jsiHasTimers()) jsiLoop();
        jsiKill();
        jshKill();
        exit(0);
      } else if (!strcmp(a,"--test-all")) {
        bool ok = run_all_tests();
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-all")) {
        bool ok = run_memory_tests(0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem")) {
        if (i+1>=argc) die("Expecting an extra argument");
        bool ok = run_memory_test(argv[i+1], 0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-n")) {
        if (i+2>=argc) die("Expecting an extra 2 arguments");
        bool ok = run_memory_test(argv[i+1], atoi(argv[i+2]));
        exit(ok ? 0 : 1);
      } else {
        printf("Unknown Argument %s\n", a);
        show_help();
        exit(1);
      }
    }
  }

  if (argc==1) {
    printf("Interactive mode.\n");
  } else if (argc==2) {
    char *buffer = read_file(argv[1]);
    jshInit();
    jsiInit(false /* do not autoload!!! */);
    jspAddNativeFunction(jsiGetParser(), "function quit()", nativeQuit);
    jsvUnLock(jspEvaluate(jsiGetParser(), buffer ));
    free(buffer);
    isRunning = true;
    while (isRunning && jsiHasTimers()) jsiLoop();
    jsiKill();
    jshKill();
    exit(0);
  } else {
    printf("Unknown arguments!\n");
    show_help();
    exit(1);
  }

  printf("Size of JsVar is now %d bytes\n", (int)sizeof(JsVar));
  printf("Size of JsVarRef is now %d bytes\n", (int)sizeof(JsVarRef));

  struct sigaction sa;
  sa.sa_handler = sig_handler;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction(SIGINT, &sa, NULL) == -1)
    printf("Adding SIGINT hook failed\n");
  else
    printf("Added SIGINT hook\n");
  if (sigaction(SIGHUP, &sa, NULL) == -1)
    printf("Adding SIGHUP hook failed\n");
  else
    printf("Added SIGHUP hook\n");
  if (sigaction(SIGTERM, &sa, NULL) == -1)
    printf("Adding SIGTERM hook failed\n");
  else
    printf("Added SIGTERM hook\n");

  jshInit();
  jsiInit(true);

  jspAddNativeFunction(jsiGetParser(), "function quit()", nativeQuit);
  jspAddNativeFunction(jsiGetParser(), "function interrupt()", nativeInterrupt);

  while (isRunning) {
    jsiLoop();
  }
  jsiConsolePrint("\n");
  jsiKill();

  jsvShowAllocated();
  jshKill();

  return 0;
}