Exemple #1
0
char test_reset_countdowns(void) {
    char result = 0;

    float secs[] = {0, 0};
    T_CALLBACK callbacks[] = {set_value_to_1, set_value_to_2};

    reset_all_countdowns();
    print_test_beauty(__FUNCTION__);

    value = 0;
    if (!(prepare_countdowns(2, secs, callbacks, NULL))) {
        printf("Setting the countdowns failed!\n");
        failure_message(__FUNCTION__);
        return 1;
    }
    run_countdown();
    result |= compare_dec(value, 0, "PRE Callback execution");
    CONCAT_EXP(TIMER, _COMPA_vect)();
    result |= compare_dec(value, 1, "Callback execution 1");
    reset_all_countdowns();
    CONCAT_EXP(TIMER, _COMPA_vect)();
    result |= compare_dec(value, 1, "Callback execution 2");

    if (result != 0) {
        failure_message(__FUNCTION__);
    } else {
        success_message(__FUNCTION__);
    }
    return result;
}
Exemple #2
0
void run_test(
  int test_return_value,
  char* test_name,
  int test_count
) {
	test_return_value == 1 ?
	  failure_message(test_name, test_count) :
	  success_message(test_name, test_count);
}
Exemple #3
0
char test_countdown_preparation(void) {
    int i;
    char buf[1000];
    char result = 0;

    float seconds[4];
    int expected[4][2];

    float fail_zeros[11] = {0};

    for (i = 0; i < 4; i++) {
        seconds[i] = (MAX_SECONDS - 1) / 3 * i;
        expected[i][0] = (int)(seconds[i] / SECONDS_PER_OVERFLOW);
        expected[i][1] =
            (int)(seconds[i] - (expected[i][0] * SECONDS_PER_OVERFLOW)) /
            SECONDS_PER_TICK;
    }

    T_CALLBACK cb[] = {sei, sei};
    T_CALLBACK cb_zeros[11] = {NULL};

    print_test_beauty(__FUNCTION__);

    if ((prepare_countdowns(11, fail_zeros, cb_zeros, NULL))) {
        printf("Countdown preparation did not abort on too many countdowns!\n");
        failure_message(__FUNCTION__);
        return 1;
    }

    if (!(prepare_countdowns(4, seconds, cb, NULL))) {
        printf("Setting the countdowns failed!\n");
        failure_message(__FUNCTION__);
        return 1;
    }

    for (i = 0; i < 4; i++) {
        sprintf(buf, "Overflow calc for %f", seconds[i]);
        result |= compare_dec(_CT_O._cd_ovfs[i], expected[i][0], buf);
        sprintf(buf, "Tick calc for %f", seconds[i]);
        result |= compare_dec(_CT_O._cd_ticks[i], expected[i][1], buf);
        ;
    }
    if (result != 0) {
        failure_message(__FUNCTION__);
    } else {
        success_message(__FUNCTION__);
    }
    return result;
}
Exemple #4
0
char test_non_isr_callback_combination(void) {
    char result = 0;
    T_CALLBACK cur_cb;

    float secs[] = {0, 0, 0};
    T_CALLBACK callbacks[] = {set_value_to_1, set_value_to_2, set_value_to_3};
    uint8_t in_isr[] = {1, 0, 1};

    reset_all_countdowns();
    print_test_beauty(__FUNCTION__);

    value = 0;
    if (!(prepare_countdowns(3, secs, callbacks, in_isr))) {
        printf("Setting the countdowns failed!\n");
        failure_message(__FUNCTION__);
        return 1;
    }

    run_countdown();

    result |= compare_dec(value, 0, "PRE Callback execution");
    CONCAT_EXP(TIMER, _COMPA_vect)();
    compare_cb(get_current_callback(), NULL, "Available callback 1");
    result |= compare_dec(value, 1, "Callback execution 1");

    CONCAT_EXP(TIMER, _COMPA_vect)();
    result |= compare_dec(value, 1, "Callback execution 2");

    cur_cb = get_current_callback();
    result |= compare_cb(cur_cb, set_value_to_2, "Available callback 2");
    (*cur_cb)();
    result |= compare_dec(value, 2, "NON-ISR Callback execution 2");

    CONCAT_EXP(TIMER, _COMPA_vect)();
    compare_cb(get_current_callback(), NULL, "Available callback 3");
    result |= compare_dec(value, 3, "Callback execution 3");

    if (result != 0) {
        failure_message(__FUNCTION__);
    } else {
        success_message(__FUNCTION__);
    }
    return result;
}
Exemple #5
0
char test_failure_on_exceeding(void) {
    char result = 0;
    float seconds = MAX_SECONDS + 1;

    print_test_beauty(__FUNCTION__);

    if ((prepare_single_countdown(seconds, sei, 0))) {
        printf(
            "Countdown preparation did not abort while exceeding "
            "MAX_SECONDS!\n");
        failure_message(__FUNCTION__);
        return 1;
    }

    if (result != 0) {
        failure_message(__FUNCTION__);
    } else {
        success_message(__FUNCTION__);
    }
    return result;
}
Exemple #6
0
//------------------------------------------------------------------------------
int autorun(int argc, char** argv)
{
    // Parse command line arguments.
    struct option options[] = {
        { "help",       no_argument,    nullptr, 'h' },
        { "allusers",   no_argument,    nullptr, 'a' },
        {}
    };

    str<MAX_PATH> clink_path;

    int i;
    int ret = 0;
    while ((i = getopt_long(argc, argv, "ha", options, nullptr)) != -1)
    {
        switch (i)
        {
        case 'a':
            g_all_users = 1;
            break;

        case 'h':
            print_help();
            return 0;

        default:
            return 0;
        }
    }

    dispatch_func_t* function = nullptr;

    // Find out what to do by parsing the verb.
    if (optind < argc)
    {
        if (!strcmp(argv[optind], "install"))
            function = install_autorun;
        else if (!strcmp(argv[optind], "uninstall"))
            function = uninstall_autorun;
        else if (!strcmp(argv[optind], "set"))
            function = set_autorun_value;
        else if (!strcmp(argv[optind], "show"))
            return show_autorun();
    }

    // Get path where clink is installed (assumed to be where this executable is)
    if (function == install_autorun)
    {
        clink_path << _pgmptr;
        clink_path.truncate(clink_path.last_of('\\'));
    }

    // Collect the remainder of the command line.
    if (function == install_autorun || function == set_autorun_value)
    {
        for (i = optind + 1; i < argc; ++i)
        {
            g_clink_args << argv[i];
            if (i < argc - 1)
                g_clink_args << " ";
        }
    }

    // If we can't continue any further then warn the user.
    if (function == nullptr)
    {
        puts("ERROR: Invalid arguments. Run 'clink autorun --help' for info.");
        return 0;
    }

    // Do the magic.
    if (!check_registry_access())
    {
        puts("You must have administator rights to access cmd.exe's autorun");
        return 0;
    }

    const char* arg = clink_path.c_str();
    arg = *arg ? arg : g_clink_args.c_str();
    ret = dispatch(function, arg);

    // Provide the user with some feedback.
    if (ret == 1)
    {
        const char* msg = nullptr;

        if (function == install_autorun)
            msg = "Clink successfully installed to run when cmd.exe starts";
        else if (function == uninstall_autorun)
            msg = "Clink's autorun entry has been removed";
        else if (function == set_autorun_value)
            msg = "Cmd.exe's AutoRun registry key set successfully";

        if (msg != nullptr)
            success_message(msg);
    }

    return ret;
}