blob: 79b67c779321c279c48433750c0b4c8b49a751c2 [file] [log] [blame]
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Tests for print functions
4 *
5 * Copyright 2020, Heinrich Schuchadt <xypron.glpk@gmx.de>
6 */
7
8#include <common.h>
9#include <command.h>
10#include <display_options.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020012#include <test/lib.h>
13#include <test/test.h>
14#include <test/ut.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static int test_print_freq(struct unit_test_state *uts,
19 uint64_t freq, char *expected)
20{
Simon Glassb6da5592021-03-15 18:11:13 +130021 ut_silence_console(uts);
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020022 console_record_reset_enable();
23 print_freq(freq, ";\n");
Simon Glassb6da5592021-03-15 18:11:13 +130024 ut_unsilence_console(uts);
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020025 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
26 ut_asserteq_str(expected, uts->actual_str);
27 ut_assertok(ut_check_console_end(uts));
Simon Glassb6da5592021-03-15 18:11:13 +130028
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020029 return 0;
30}
31
32static int lib_test_print_freq(struct unit_test_state *uts)
33{
34 ut_assertok(test_print_freq(uts, 321, "321 Hz;"));
35 ut_assertok(test_print_freq(uts, 4321, "4.32 kHz;"));
36 ut_assertok(test_print_freq(uts, 54321, "54.32 kHz;"));
37 ut_assertok(test_print_freq(uts, 654321, "654.32 kHz;"));
38 ut_assertok(test_print_freq(uts, 7654321, "7.66 MHz;"));
39 ut_assertok(test_print_freq(uts, 87654321, "87.66 MHz;"));
40 ut_assertok(test_print_freq(uts, 987654321, "987.66 MHz;"));
41 ut_assertok(test_print_freq(uts, 1987654321, "1.99 GHz;"));
42 ut_assertok(test_print_freq(uts, 54321987654321, "54321.99 GHz;"));
43 return 0;
44}
45
46LIB_TEST(lib_test_print_freq, 0);
47
48static int test_print_size(struct unit_test_state *uts,
49 uint64_t freq, char *expected)
50{
Simon Glassb6da5592021-03-15 18:11:13 +130051 ut_silence_console(uts);
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020052 console_record_reset_enable();
53 print_size(freq, ";\n");
Simon Glassb6da5592021-03-15 18:11:13 +130054 ut_unsilence_console(uts);
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020055 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
56 ut_asserteq_str(expected, uts->actual_str);
57 ut_assertok(ut_check_console_end(uts));
Simon Glassb6da5592021-03-15 18:11:13 +130058
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020059 return 0;
60}
61
62static int lib_test_print_size(struct unit_test_state *uts)
63{
64 ut_assertok(test_print_size(uts, 321, "321 Bytes;"));
65 ut_assertok(test_print_size(uts, 4321, "4.2 KiB;"));
66 ut_assertok(test_print_size(uts, 54321, "53 KiB;"));
67 ut_assertok(test_print_size(uts, 654321, "639 KiB;"));
68 ut_assertok(test_print_size(uts, 7654321, "7.3 MiB;"));
69 ut_assertok(test_print_size(uts, 87654321, "83.6 MiB;"));
70 ut_assertok(test_print_size(uts, 987654321, "941.9 MiB;"));
Pali Rohárd1790182022-09-12 21:02:27 +020071 ut_assertok(test_print_size(uts, 1073689395, "1023.9 MiB;"));
72 ut_assertok(test_print_size(uts, 1073689396, "1 GiB;"));
73 ut_assertok(test_print_size(uts, 1073741824, "1 GiB;"));
Heinrich Schuchardtf52e9252020-10-22 21:45:28 +020074 ut_assertok(test_print_size(uts, 1987654321, "1.9 GiB;"));
75 ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;"));
76 return 0;
77}
78
79LIB_TEST(lib_test_print_size, 0);