From 5556b5fe41173107a67dbe875fbd916a46e52a02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 23 Feb 2014 03:13:54 +0100 Subject: core: clean up some confusing regarding SI decimal and IEC binary suffixes for sizes According to Wikipedia it is customary to specify hardware metrics and transfer speeds to the basis 1000 (SI decimal), while software metrics and physical volatile memory (RAM) sizes to the basis 1024 (IEC binary). So far we specified everything in IEC, let's fix that and be more true to what's otherwise customary. Since we don't want to parse "Mi" instead of "M" we document each time what the context used is. --- src/test/test-util.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/test') diff --git a/src/test/test-util.c b/src/test/test-util.c index 1ac4a1edd1..b718206e86 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -435,42 +435,42 @@ static void test_protect_errno(void) { assert(errno == 12); } -static void test_parse_bytes(void) { +static void test_parse_size(void) { off_t bytes; - assert_se(parse_bytes("111", &bytes) == 0); + assert_se(parse_size("111", 1024, &bytes) == 0); assert_se(bytes == 111); - assert_se(parse_bytes(" 112 B", &bytes) == 0); + assert_se(parse_size(" 112 B", 1024, &bytes) == 0); assert_se(bytes == 112); - assert_se(parse_bytes("3 K", &bytes) == 0); + assert_se(parse_size("3 K", 1024, &bytes) == 0); assert_se(bytes == 3*1024); - assert_se(parse_bytes(" 4 M 11K", &bytes) == 0); + assert_se(parse_size(" 4 M 11K", 1024, &bytes) == 0); assert_se(bytes == 4*1024*1024 + 11 * 1024); - assert_se(parse_bytes("3B3G", &bytes) == 0); + assert_se(parse_size("3B3G", 1024, &bytes) == 0); assert_se(bytes == 3ULL*1024*1024*1024 + 3); - assert_se(parse_bytes("3B3G4T", &bytes) == 0); + assert_se(parse_size("3B3G4T", 1024, &bytes) == 0); assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3); - assert_se(parse_bytes("12P", &bytes) == 0); + assert_se(parse_size("12P", 1024, &bytes) == 0); assert_se(bytes == 12ULL * 1024*1024*1024*1024*1024); - assert_se(parse_bytes("3E 2P", &bytes) == 0); + assert_se(parse_size("3E 2P", 1024, &bytes) == 0); assert_se(bytes == (3 * 1024 + 2ULL) * 1024*1024*1024*1024*1024); - assert_se(parse_bytes("12X", &bytes) == -EINVAL); + assert_se(parse_size("12X", 1024, &bytes) == -EINVAL); - assert_se(parse_bytes("1024E", &bytes) == -ERANGE); - assert_se(parse_bytes("-1", &bytes) == -ERANGE); - assert_se(parse_bytes("-1024E", &bytes) == -ERANGE); + assert_se(parse_size("1024E", 1024, &bytes) == -ERANGE); + assert_se(parse_size("-1", 1024, &bytes) == -ERANGE); + assert_se(parse_size("-1024E", 1024, &bytes) == -ERANGE); - assert_se(parse_bytes("-1024P", &bytes) == -ERANGE); + assert_se(parse_size("-1024P", 1024, &bytes) == -ERANGE); - assert_se(parse_bytes("-10B 20K", &bytes) == -ERANGE); + assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE); } static void test_strextend(void) { @@ -617,7 +617,7 @@ int main(int argc, char *argv[]) { test_u64log2(); test_get_process_comm(); test_protect_errno(); - test_parse_bytes(); + test_parse_size(); test_strextend(); test_strrep(); test_split_pair(); -- cgit v1.2.3-54-g00ecf