summaryrefslogtreecommitdiff
path: root/cesar/hal/clk/test/src/test_clk.c
blob: 7644045af9caa4b3721ece51ad6eeb0095264dfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Cesar project {{{
 *
 * Copyright (C) 2012 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/clk/test/src/test_clk.c
 * \brief   Test the clk dynamic configuration.
 * \ingroup hal
 */
#include "common/std.h"
#include "hal/clk/clk.h"

#include "lib/test.h"

uint cyg_hal_system_clock_freq = 0;

bool
hal_clk_str_to_num (uint *num, const char *str);

void
hal_clk_test_case_string_to_int (test_t t)
{
    test_case_begin (t, "Test function conversion");

    test_begin (t, "spc300, mse500 frequency")
    {
        bool ret = false;
        char frequency_mhz_str[][4] = {"147\0", "250\0"};
        uint frequency_mhz = 0;
        uint expected_freq_mhz[] = {147, 250};
        uint i;

        for (i = 0; i < COUNT (frequency_mhz_str); i++)
        {
            ret = hal_clk_str_to_num (&frequency_mhz,
                                         frequency_mhz_str[i]);
            test_fail_unless (ret);
            test_fail_unless (frequency_mhz == expected_freq_mhz[i]);
        }
    }
    test_end;

    test_begin (t, "Error in parameter")
    {
        bool ret = false;
        uint frequency_mhz = 0;
        ret = hal_clk_str_to_num (&frequency_mhz, "\0");
        test_fail_unless (!ret);
        test_fail_unless (frequency_mhz == 0);
    }
    test_end;
}

void
hal_clk_test_suite (test_t t)
{
    test_suite_begin (t, "System clock dynamic configuration");
    hal_clk_test_case_string_to_int (t);
}

int main (int argc, char *argv[])
{
    test_t t;
    test_init (t, argc, argv);
    hal_clk_test_suite (t);
    test_result (t);
    return test_nb_failed (t);
}