blob: cd7f3f85769682fe8da73570d2f47adaab25055d [file] [log] [blame]
Heinrich Schuchardtdcc8ab72020-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
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +02008#include <command.h>
9#include <display_options.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020011#include <test/lib.h>
12#include <test/test.h>
13#include <test/ut.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static int test_print_freq(struct unit_test_state *uts,
18 uint64_t freq, char *expected)
19{
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020020 print_freq(freq, ";\n");
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020021 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
22 ut_asserteq_str(expected, uts->actual_str);
Simon Glassc579bd42024-08-22 07:58:03 -060023 ut_assert_console_end();
Simon Glass4d294a72021-03-15 18:11:13 +130024
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020025 return 0;
26}
27
28static int lib_test_print_freq(struct unit_test_state *uts)
29{
30 ut_assertok(test_print_freq(uts, 321, "321 Hz;"));
31 ut_assertok(test_print_freq(uts, 4321, "4.32 kHz;"));
32 ut_assertok(test_print_freq(uts, 54321, "54.32 kHz;"));
33 ut_assertok(test_print_freq(uts, 654321, "654.32 kHz;"));
34 ut_assertok(test_print_freq(uts, 7654321, "7.66 MHz;"));
35 ut_assertok(test_print_freq(uts, 87654321, "87.66 MHz;"));
36 ut_assertok(test_print_freq(uts, 987654321, "987.66 MHz;"));
37 ut_assertok(test_print_freq(uts, 1987654321, "1.99 GHz;"));
38 ut_assertok(test_print_freq(uts, 54321987654321, "54321.99 GHz;"));
39 return 0;
40}
Simon Glasscbb230e2024-08-22 07:58:02 -060041LIB_TEST(lib_test_print_freq, UTF_CONSOLE);
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020042
43static int test_print_size(struct unit_test_state *uts,
44 uint64_t freq, char *expected)
45{
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020046 print_size(freq, ";\n");
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020047 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
48 ut_asserteq_str(expected, uts->actual_str);
Simon Glassc579bd42024-08-22 07:58:03 -060049 ut_assert_console_end();
Simon Glass4d294a72021-03-15 18:11:13 +130050
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020051 return 0;
52}
53
54static int lib_test_print_size(struct unit_test_state *uts)
55{
56 ut_assertok(test_print_size(uts, 321, "321 Bytes;"));
57 ut_assertok(test_print_size(uts, 4321, "4.2 KiB;"));
58 ut_assertok(test_print_size(uts, 54321, "53 KiB;"));
59 ut_assertok(test_print_size(uts, 654321, "639 KiB;"));
60 ut_assertok(test_print_size(uts, 7654321, "7.3 MiB;"));
61 ut_assertok(test_print_size(uts, 87654321, "83.6 MiB;"));
62 ut_assertok(test_print_size(uts, 987654321, "941.9 MiB;"));
Pali Rohárc14fad52022-09-12 21:02:27 +020063 ut_assertok(test_print_size(uts, 1073689395, "1023.9 MiB;"));
64 ut_assertok(test_print_size(uts, 1073689396, "1 GiB;"));
65 ut_assertok(test_print_size(uts, 1073741824, "1 GiB;"));
Heinrich Schuchardtdcc8ab72020-10-22 21:45:28 +020066 ut_assertok(test_print_size(uts, 1987654321, "1.9 GiB;"));
67 ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;"));
68 return 0;
69}
Simon Glasscbb230e2024-08-22 07:58:02 -060070LIB_TEST(lib_test_print_size, UTF_CONSOLE);