diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-02-23 03:13:54 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-02-23 03:19:04 +0100 |
commit | 5556b5fe41173107a67dbe875fbd916a46e52a02 (patch) | |
tree | a9ca468b7c030c5c95a87bb35b4f986dedb1bba8 /src/test | |
parent | e342365c27ecae32a7f20ada0b2c623ce22e5ea8 (diff) |
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.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-util.c | 32 |
1 files changed, 16 insertions, 16 deletions
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(); |