xref: /aosp_15_r20/external/executorch/test/utils/alignment_test.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <executorch/test/utils/alignment.h>
10 
11 #include <gtest/gtest-spi.h>
12 #include <gtest/gtest.h>
13 
14 using namespace ::testing;
15 
16 // The wrappers use the matcher and the underlying helper function, so testing
17 // them gives full coverage.
18 
TEST(AlignmentTest,ExpectWrapper)19 TEST(AlignmentTest, ExpectWrapper) {
20   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x1000);
21   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x100);
22   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x10);
23   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x8);
24   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x4);
25   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x2);
26   EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x1);
27   EXPECT_NONFATAL_FAILURE(
28       EXPECT_ALIGNED(reinterpret_cast<void*>(0xfff1001), 0x10), "");
29   EXPECT_NONFATAL_FAILURE(
30       EXPECT_ALIGNED(reinterpret_cast<void*>(0xfffffff), 0x10), "");
31 }
32 
TEST(AlignmentTest,AssertWrapper)33 TEST(AlignmentTest, AssertWrapper) {
34   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x1000);
35   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x100);
36   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x10);
37   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x8);
38   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x4);
39   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x2);
40   ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1000), 0x1);
41   EXPECT_FATAL_FAILURE(
42       ASSERT_ALIGNED(reinterpret_cast<void*>(0xfff1001), 0x10), "");
43   EXPECT_FATAL_FAILURE(
44       ASSERT_ALIGNED(reinterpret_cast<void*>(0xfffffff), 0x10), "");
45 }
46