• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #include <string.h>
26 
27 #include <gtest/gtest.h>
28 
29 #include <libavb/libavb.h>
30 
31 #include "avb_unittest_util.h"
32 
33 namespace avb {
34 
35 // Subclass BaseAvbToolTest to check for memory leaks.
36 class UtilTest : public BaseAvbToolTest {
37  public:
UtilTest()38   UtilTest() {}
39 };
40 
TEST_F(UtilTest,RSAPublicKeyHeaderByteswap)41 TEST_F(UtilTest, RSAPublicKeyHeaderByteswap) {
42   AvbRSAPublicKeyHeader h;
43   AvbRSAPublicKeyHeader s;
44   uint32_t n32;
45   uint64_t n64;
46 
47   n32 = 0x11223344;
48   n64 = 0x1122334455667788;
49 
50   h.key_num_bits = htobe32(n32);
51   n32++;
52   h.n0inv = htobe32(n32);
53   n32++;
54 
55   EXPECT_NE(0, avb_rsa_public_key_header_validate_and_byteswap(&h, &s));
56 
57   n32 = 0x11223344;
58   n64 = 0x1122334455667788;
59 
60   EXPECT_EQ(n32, s.key_num_bits);
61   n32++;
62   EXPECT_EQ(n32, s.n0inv);
63   n32++;
64 }
65 
TEST_F(UtilTest,FooterByteswap)66 TEST_F(UtilTest, FooterByteswap) {
67   AvbFooter h;
68   AvbFooter s;
69   AvbFooter other;
70   AvbFooter bad;
71   uint64_t n64;
72 
73   n64 = 0x1122334455667788;
74 
75   memcpy(h.magic, AVB_FOOTER_MAGIC, AVB_FOOTER_MAGIC_LEN);
76   h.version_major = htobe32(AVB_FOOTER_VERSION_MAJOR);
77   h.version_minor = htobe32(AVB_FOOTER_VERSION_MINOR);
78   h.original_image_size = htobe64(n64);
79   n64++;
80   h.vbmeta_offset = htobe64(n64);
81   n64++;
82   h.vbmeta_size = htobe64(n64);
83   n64++;
84 
85   EXPECT_NE(0, avb_footer_validate_and_byteswap(&h, &s));
86 
87   n64 = 0x1122334455667788;
88 
89   EXPECT_EQ((uint32_t)AVB_FOOTER_VERSION_MAJOR, s.version_major);
90   EXPECT_EQ((uint32_t)AVB_FOOTER_VERSION_MINOR, s.version_minor);
91   EXPECT_EQ(n64, s.original_image_size);
92   n64++;
93   EXPECT_EQ(n64, s.vbmeta_offset);
94   n64++;
95   EXPECT_EQ(n64, s.vbmeta_size);
96   n64++;
97 
98   // Check that the struct still validates if minor is bigger than
99   // what we expect.
100   other = h;
101   h.version_minor = htobe32(AVB_FOOTER_VERSION_MINOR + 1);
102   EXPECT_NE(0, avb_footer_validate_and_byteswap(&other, &s));
103 
104   // Check for bad magic.
105   bad = h;
106   bad.magic[0] = 'x';
107   EXPECT_EQ(0, avb_footer_validate_and_byteswap(&bad, &s));
108 
109   // Check for bad major version.
110   bad = h;
111   bad.version_major = htobe32(AVB_FOOTER_VERSION_MAJOR + 1);
112   EXPECT_EQ(0, avb_footer_validate_and_byteswap(&bad, &s));
113 }
114 
TEST_F(UtilTest,KernelCmdlineDescriptorByteswap)115 TEST_F(UtilTest, KernelCmdlineDescriptorByteswap) {
116   AvbKernelCmdlineDescriptor h;
117   AvbKernelCmdlineDescriptor s;
118   AvbKernelCmdlineDescriptor bad;
119   uint64_t nbf;
120   uint32_t n32;
121 
122   // Specify 40 bytes of data past the end of the descriptor struct.
123   nbf = 40 + sizeof(AvbKernelCmdlineDescriptor) - sizeof(AvbDescriptor);
124   h.parent_descriptor.num_bytes_following = htobe64(nbf);
125   h.parent_descriptor.tag = htobe64(AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE);
126   h.kernel_cmdline_length = htobe32(40);
127 
128   n32 = 0x11223344;
129   h.flags = htobe32(n32);
130   n32++;
131 
132   EXPECT_NE(0, avb_kernel_cmdline_descriptor_validate_and_byteswap(&h, &s));
133 
134   n32 = 0x11223344;
135   EXPECT_EQ(n32, s.flags);
136   n32++;
137 
138   EXPECT_EQ(AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE, s.parent_descriptor.tag);
139   EXPECT_EQ(nbf, s.parent_descriptor.num_bytes_following);
140   EXPECT_EQ(40UL, s.kernel_cmdline_length);
141 
142   // Check for bad tag.
143   bad = h;
144   bad.parent_descriptor.tag = htobe64(0xf00dd00d);
145   EXPECT_EQ(0, avb_kernel_cmdline_descriptor_validate_and_byteswap(&bad, &s));
146 
147   // Doesn't fit in 41 bytes.
148   bad = h;
149   bad.kernel_cmdline_length = htobe32(41);
150   EXPECT_EQ(0, avb_kernel_cmdline_descriptor_validate_and_byteswap(&bad, &s));
151 }
152 
TEST_F(UtilTest,HashtreeDescriptorByteswap)153 TEST_F(UtilTest, HashtreeDescriptorByteswap) {
154   AvbHashtreeDescriptor h;
155   AvbHashtreeDescriptor s;
156   AvbHashtreeDescriptor bad;
157   uint64_t nbf;
158   uint32_t n32;
159   uint64_t n64;
160 
161   // Specify 44 bytes of data past the end of the descriptor struct.
162   nbf = 44 + sizeof(AvbHashtreeDescriptor) - sizeof(AvbDescriptor);
163   h.parent_descriptor.num_bytes_following = htobe64(nbf);
164   h.parent_descriptor.tag = htobe64(AVB_DESCRIPTOR_TAG_HASHTREE);
165   h.partition_name_len = htobe32(10);
166   h.salt_len = htobe32(10);
167   h.root_digest_len = htobe32(10);
168 
169   n32 = 0x11223344;
170   n64 = 0x1122334455667788;
171 
172   h.dm_verity_version = htobe32(n32);
173   n32++;
174   h.image_size = htobe64(n64);
175   n64++;
176   h.tree_offset = htobe64(n64);
177   n64++;
178   h.tree_size = htobe64(n64);
179   n64++;
180   h.data_block_size = htobe32(n32);
181   n32++;
182   h.hash_block_size = htobe32(n32);
183   n32++;
184   h.fec_num_roots = htobe32(n32);
185   n32++;
186   h.fec_offset = htobe64(n64);
187   n64++;
188   h.fec_size = htobe64(n64);
189   n64++;
190 
191   EXPECT_TRUE(avb_hashtree_descriptor_validate_and_byteswap(&h, &s));
192 
193   n32 = 0x11223344;
194   n64 = 0x1122334455667788;
195 
196   EXPECT_EQ(n32, s.dm_verity_version);
197   n32++;
198   EXPECT_EQ(n64, s.image_size);
199   n64++;
200   EXPECT_EQ(n64, s.tree_offset);
201   n64++;
202   EXPECT_EQ(n64, s.tree_size);
203   n64++;
204   EXPECT_EQ(n32, s.data_block_size);
205   n32++;
206   EXPECT_EQ(n32, s.hash_block_size);
207   n32++;
208   EXPECT_EQ(n32, s.fec_num_roots);
209   n32++;
210   EXPECT_EQ(n64, s.fec_offset);
211   n64++;
212   EXPECT_EQ(n64, s.fec_size);
213   n64++;
214 
215   EXPECT_EQ(AVB_DESCRIPTOR_TAG_HASHTREE, s.parent_descriptor.tag);
216   EXPECT_EQ(nbf, s.parent_descriptor.num_bytes_following);
217   EXPECT_EQ(10UL, s.partition_name_len);
218   EXPECT_EQ(10UL, s.salt_len);
219   EXPECT_EQ(10UL, s.root_digest_len);
220 
221   // Check for bad tag.
222   bad = h;
223   bad.parent_descriptor.tag = htobe64(0xf00dd00d);
224   EXPECT_FALSE(avb_hashtree_descriptor_validate_and_byteswap(&bad, &s));
225 
226   // Doesn't fit in 44 bytes (30 + 10 + 10 = 50).
227   bad = h;
228   bad.partition_name_len = htobe32(30);
229   EXPECT_FALSE(avb_hashtree_descriptor_validate_and_byteswap(&bad, &s));
230 
231   // Doesn't fit in 44 bytes (10 + 30 + 10 = 50).
232   bad = h;
233   bad.salt_len = htobe32(30);
234   EXPECT_FALSE(avb_hashtree_descriptor_validate_and_byteswap(&bad, &s));
235 
236   // Doesn't fit in 44 bytes (10 + 10 + 30 = 50).
237   bad = h;
238   bad.root_digest_len = htobe32(30);
239   EXPECT_FALSE(avb_hashtree_descriptor_validate_and_byteswap(&bad, &s));
240 }
241 
TEST_F(UtilTest,HashDescriptorByteswap)242 TEST_F(UtilTest, HashDescriptorByteswap) {
243   AvbHashDescriptor h;
244   AvbHashDescriptor s;
245   AvbHashDescriptor bad;
246   uint64_t nbf;
247 
248   // Specify 44 bytes of data past the end of the descriptor struct.
249   nbf = 44 + sizeof(AvbHashDescriptor) - sizeof(AvbDescriptor);
250   h.parent_descriptor.num_bytes_following = htobe64(nbf);
251   h.parent_descriptor.tag = htobe64(AVB_DESCRIPTOR_TAG_HASH);
252   h.partition_name_len = htobe32(10);
253   h.salt_len = htobe32(10);
254   h.digest_len = htobe32(10);
255 
256   EXPECT_NE(0, avb_hash_descriptor_validate_and_byteswap(&h, &s));
257 
258   EXPECT_EQ(AVB_DESCRIPTOR_TAG_HASH, s.parent_descriptor.tag);
259   EXPECT_EQ(nbf, s.parent_descriptor.num_bytes_following);
260   EXPECT_EQ(10UL, s.partition_name_len);
261   EXPECT_EQ(10UL, s.salt_len);
262   EXPECT_EQ(10UL, s.digest_len);
263 
264   // Check for bad tag.
265   bad = h;
266   bad.parent_descriptor.tag = htobe64(0xf00dd00d);
267   EXPECT_EQ(0, avb_hash_descriptor_validate_and_byteswap(&bad, &s));
268 
269   // Doesn't fit in 44 bytes (30 + 10 + 10 = 50).
270   bad = h;
271   bad.partition_name_len = htobe32(30);
272   EXPECT_EQ(0, avb_hash_descriptor_validate_and_byteswap(&bad, &s));
273 
274   // Doesn't fit in 44 bytes (10 + 30 + 10 = 50).
275   bad = h;
276   bad.salt_len = htobe32(30);
277   EXPECT_EQ(0, avb_hash_descriptor_validate_and_byteswap(&bad, &s));
278 
279   // Doesn't fit in 44 bytes (10 + 10 + 30 = 50).
280   bad = h;
281   bad.digest_len = htobe32(30);
282   EXPECT_EQ(0, avb_hash_descriptor_validate_and_byteswap(&bad, &s));
283 }
284 
TEST_F(UtilTest,ChainPartitionDescriptorByteswap)285 TEST_F(UtilTest, ChainPartitionDescriptorByteswap) {
286   AvbChainPartitionDescriptor h;
287   AvbChainPartitionDescriptor s;
288   AvbChainPartitionDescriptor bad;
289   uint64_t nbf;
290 
291   // Specify 36 bytes of data past the end of the descriptor struct.
292   nbf = 36 + sizeof(AvbChainPartitionDescriptor) - sizeof(AvbDescriptor);
293   h.parent_descriptor.num_bytes_following = htobe64(nbf);
294   h.parent_descriptor.tag = htobe64(AVB_DESCRIPTOR_TAG_CHAIN_PARTITION);
295   h.rollback_index_location = htobe32(42);
296   h.partition_name_len = htobe32(16);
297   h.public_key_len = htobe32(17);
298 
299   EXPECT_NE(0, avb_chain_partition_descriptor_validate_and_byteswap(&h, &s));
300 
301   EXPECT_EQ(AVB_DESCRIPTOR_TAG_CHAIN_PARTITION, s.parent_descriptor.tag);
302   EXPECT_EQ(nbf, s.parent_descriptor.num_bytes_following);
303   EXPECT_EQ(42UL, s.rollback_index_location);
304   EXPECT_EQ(16UL, s.partition_name_len);
305   EXPECT_EQ(17UL, s.public_key_len);
306 
307   // Check for bad tag.
308   bad = h;
309   bad.parent_descriptor.tag = htobe64(0xf00dd00d);
310   EXPECT_EQ(0, avb_chain_partition_descriptor_validate_and_byteswap(&bad, &s));
311 
312   // Check for bad rollback index slot (must be at least 1).
313   bad = h;
314   bad.rollback_index_location = htobe32(0);
315   EXPECT_EQ(0, avb_chain_partition_descriptor_validate_and_byteswap(&bad, &s));
316 
317   // Doesn't fit in 40 bytes (24 + 17 = 41).
318   bad = h;
319   bad.partition_name_len = htobe32(24);
320   EXPECT_EQ(0, avb_chain_partition_descriptor_validate_and_byteswap(&bad, &s));
321 
322   // Doesn't fit in 40 bytes (16 + 25 = 41).
323   bad = h;
324   bad.public_key_len = htobe32(25);
325   EXPECT_EQ(0, avb_chain_partition_descriptor_validate_and_byteswap(&bad, &s));
326 }
327 
TEST_F(UtilTest,PropertyDescriptorByteswap)328 TEST_F(UtilTest, PropertyDescriptorByteswap) {
329   AvbPropertyDescriptor h;
330   AvbPropertyDescriptor s;
331   AvbPropertyDescriptor bad;
332   uint64_t nbf;
333 
334   // Specify 40 bytes of data past the end of the descriptor struct.
335   nbf = 40 + sizeof(AvbPropertyDescriptor) - sizeof(AvbDescriptor);
336   h.parent_descriptor.num_bytes_following = htobe64(nbf);
337   h.parent_descriptor.tag = htobe64(AVB_DESCRIPTOR_TAG_PROPERTY);
338   h.key_num_bytes = htobe64(16);
339   h.value_num_bytes = htobe64(17);
340 
341   EXPECT_NE(0, avb_property_descriptor_validate_and_byteswap(&h, &s));
342 
343   EXPECT_EQ(AVB_DESCRIPTOR_TAG_PROPERTY, s.parent_descriptor.tag);
344   EXPECT_EQ(nbf, s.parent_descriptor.num_bytes_following);
345   EXPECT_EQ(16UL, s.key_num_bytes);
346   EXPECT_EQ(17UL, s.value_num_bytes);
347 
348   // Check for bad tag.
349   bad = h;
350   bad.parent_descriptor.tag = htobe64(0xf00dd00d);
351   EXPECT_EQ(0, avb_property_descriptor_validate_and_byteswap(&bad, &s));
352 
353   // Doesn't fit in 40 bytes (22 + 17 + 2 = 41).
354   bad = h;
355   bad.key_num_bytes = htobe64(22);
356   EXPECT_EQ(0, avb_property_descriptor_validate_and_byteswap(&bad, &s));
357 
358   // Doesn't fit in 40 bytes (16 + 23 + 2 = 41).
359   bad = h;
360   bad.value_num_bytes = htobe64(23);
361   EXPECT_EQ(0, avb_property_descriptor_validate_and_byteswap(&bad, &s));
362 }
363 
TEST_F(UtilTest,DescriptorByteswap)364 TEST_F(UtilTest, DescriptorByteswap) {
365   AvbDescriptor h;
366   AvbDescriptor s;
367   uint64_t n64;
368 
369   n64 = 0x1122334455667788;
370 
371   h.num_bytes_following = htobe64(n64);
372   n64++;
373   h.tag = htobe64(n64);
374   n64++;
375 
376   EXPECT_NE(0, avb_descriptor_validate_and_byteswap(&h, &s));
377 
378   n64 = 0x1122334455667788;
379 
380   EXPECT_EQ(n64, s.num_bytes_following);
381   n64++;
382   EXPECT_EQ(n64, s.tag);
383   n64++;
384 
385   // Check that we catch if |num_bytes_following| isn't divisble by 8.
386   h.num_bytes_following = htobe64(7);
387   EXPECT_EQ(0, avb_descriptor_validate_and_byteswap(&h, &s));
388 }
389 
TEST_F(UtilTest,SafeAddition)390 TEST_F(UtilTest, SafeAddition) {
391   uint64_t value;
392   uint64_t pow2_60 = 1ULL << 60;
393 
394   value = 2;
395   EXPECT_NE(0, avb_safe_add_to(&value, 5));
396   EXPECT_EQ(7UL, value);
397 
398   /* These should not overflow */
399   value = 1 * pow2_60;
400   EXPECT_NE(0, avb_safe_add_to(&value, 2 * pow2_60));
401   EXPECT_EQ(3 * pow2_60, value);
402   value = 7 * pow2_60;
403   EXPECT_NE(0, avb_safe_add_to(&value, 8 * pow2_60));
404   EXPECT_EQ(15 * pow2_60, value);
405   value = 9 * pow2_60;
406   EXPECT_NE(0, avb_safe_add_to(&value, 3 * pow2_60));
407   EXPECT_EQ(12 * pow2_60, value);
408   value = 0xfffffffffffffffcUL;
409   EXPECT_NE(0, avb_safe_add_to(&value, 2));
410   EXPECT_EQ(0xfffffffffffffffeUL, value);
411 
412   /* These should overflow. */
413   value = 8 * pow2_60;
414   EXPECT_EQ(0, avb_safe_add_to(&value, 8 * pow2_60));
415   value = 0xfffffffffffffffcUL;
416   EXPECT_EQ(0, avb_safe_add_to(&value, 4));
417 }
418 
avb_validate_utf8z(const char * data)419 static int avb_validate_utf8z(const char* data) {
420   return avb_validate_utf8(reinterpret_cast<const uint8_t*>(data),
421                            strlen(data));
422 }
423 
TEST_F(UtilTest,UTF8Validation)424 TEST_F(UtilTest, UTF8Validation) {
425   // These should succeed.
426   EXPECT_NE(0, avb_validate_utf8z("foo bar"));
427   // Encoding of U+00E6 LATIN SMALL LETTER AE: æ
428   EXPECT_NE(0, avb_validate_utf8z("foo \xC3\xA6 bar"));
429   // Encoding of U+20AC EURO SIGN: €
430   EXPECT_NE(0, avb_validate_utf8z("foo \xE2\x82\xAC bar"));
431   // Encoding of U+1F466 BOY: ��
432   EXPECT_NE(0, avb_validate_utf8z("foo \xF0\x9F\x91\xA6 bar"));
433   // All three runes following each other.
434   EXPECT_NE(0, avb_validate_utf8z("\xC3\xA6\xE2\x82\xAC\xF0\x9F\x91\xA6"));
435 
436   // These should fail.
437   EXPECT_EQ(0, avb_validate_utf8z("foo \xF8 bar"));
438   EXPECT_EQ(0, avb_validate_utf8z("\xF8"));
439   // Stops in the middle of Unicode rune.
440   EXPECT_EQ(0, avb_validate_utf8z("foo \xC3"));
441 }
442 
TEST_F(UtilTest,StrConcat)443 TEST_F(UtilTest, StrConcat) {
444   char buf[8];
445 
446   // These should succeed.
447   EXPECT_NE(0, avb_str_concat(buf, sizeof buf, "foo", 3, "bar1", 4));
448 
449   // This should fail: Insufficient space.
450   EXPECT_EQ(0, avb_str_concat(buf, sizeof buf, "foo0", 4, "bar1", 4));
451 }
452 
TEST_F(UtilTest,StrStr)453 TEST_F(UtilTest, StrStr) {
454   const char* haystack = "abc def abcabc";
455 
456   EXPECT_EQ(nullptr, avb_strstr(haystack, "needle"));
457   EXPECT_EQ(haystack, avb_strstr(haystack, "abc"));
458   EXPECT_EQ(haystack + 4, avb_strstr(haystack, "def"));
459   EXPECT_EQ(haystack, avb_strstr(haystack, haystack));
460 }
461 
TEST_F(UtilTest,StrvFindStr)462 TEST_F(UtilTest, StrvFindStr) {
463   const char* strings[] = {"abcabc", "abc", "def", nullptr};
464 
465   EXPECT_EQ(nullptr, avb_strv_find_str(strings, "not there", 9));
466   EXPECT_EQ(strings[1], avb_strv_find_str(strings, "abc", 3));
467   EXPECT_EQ(strings[2], avb_strv_find_str(strings, "def", 3));
468   EXPECT_EQ(strings[0], avb_strv_find_str(strings, "abcabc", 6));
469 }
470 
TEST_F(UtilTest,StrReplace)471 TEST_F(UtilTest, StrReplace) {
472   char* str;
473 
474   str = avb_replace("$(FOO) blah bah $(FOO $(FOO) blah", "$(FOO)", "OK");
475   EXPECT_EQ("OK blah bah $(FOO OK blah", std::string(str));
476   avb_free(str);
477 
478   str = avb_replace("$(FOO)", "$(FOO)", "OK");
479   EXPECT_EQ("OK", std::string(str));
480   avb_free(str);
481 
482   str = avb_replace(" $(FOO)", "$(FOO)", "OK");
483   EXPECT_EQ(" OK", std::string(str));
484   avb_free(str);
485 
486   str = avb_replace("$(FOO) ", "$(FOO)", "OK");
487   EXPECT_EQ("OK ", std::string(str));
488   avb_free(str);
489 
490   str = avb_replace("$(FOO)$(FOO)", "$(FOO)", "LONGSTRING");
491   EXPECT_EQ("LONGSTRINGLONGSTRING", std::string(str));
492   avb_free(str);
493 }
494 
TEST_F(UtilTest,StrDupV)495 TEST_F(UtilTest, StrDupV) {
496   char* str;
497 
498   str = avb_strdupv("x", "y", "z", NULL);
499   EXPECT_EQ("xyz", std::string(str));
500   avb_free(str);
501 
502   str = avb_strdupv("Hello", "World", " XYZ", NULL);
503   EXPECT_EQ("HelloWorld XYZ", std::string(str));
504   avb_free(str);
505 }
506 
TEST_F(UtilTest,Crc32)507 TEST_F(UtilTest, Crc32) {
508   /* Compare with output of crc32(1):
509    *
510    *  $ (echo -n foobar > /tmp/crc32_input); crc32 /tmp/crc32_input
511    *  9ef61f95
512    */
513   EXPECT_EQ(uint32_t(0x9ef61f95), avb_crc32((const uint8_t*)"foobar", 6));
514 }
515 
TEST_F(UtilTest,htobe32)516 TEST_F(UtilTest, htobe32) {
517   EXPECT_EQ(avb_htobe32(0x12345678), htobe32(0x12345678));
518 }
519 
TEST_F(UtilTest,be32toh)520 TEST_F(UtilTest, be32toh) {
521   EXPECT_EQ(avb_be32toh(0x12345678), be32toh(0x12345678));
522 }
523 
TEST_F(UtilTest,htobe64)524 TEST_F(UtilTest, htobe64) {
525   EXPECT_EQ(avb_htobe64(0x123456789abcdef0), htobe64(0x123456789abcdef0));
526 }
527 
TEST_F(UtilTest,be64toh)528 TEST_F(UtilTest, be64toh) {
529   EXPECT_EQ(avb_be64toh(0x123456789abcdef0), be64toh(0x123456789abcdef0));
530 }
531 
TEST_F(UtilTest,Basename)532 TEST_F(UtilTest, Basename) {
533   EXPECT_EQ("foobar.c", std::string(avb_basename("foobar.c")));
534   EXPECT_EQ("foobar.c", std::string(avb_basename("/path/to/foobar.c")));
535   EXPECT_EQ("foobar.c", std::string(avb_basename("a/foobar.c")));
536   EXPECT_EQ("baz.c", std::string(avb_basename("/baz.c")));
537   EXPECT_EQ("some_dir/", std::string(avb_basename("some_dir/")));
538   EXPECT_EQ("some_dir/", std::string(avb_basename("/path/to/some_dir/")));
539   EXPECT_EQ("some_dir/", std::string(avb_basename("a/some_dir/")));
540   EXPECT_EQ("some_dir/", std::string(avb_basename("/some_dir/")));
541   EXPECT_EQ("/", std::string(avb_basename("/")));
542 }
543 
544 }  // namespace avb
545