• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include <cstddef>
16 
17 #include "pw_build/test_blob.h"
18 #include "pw_unit_test/framework.h"
19 
20 namespace pw::build {
21 namespace {
22 
23 static_assert(test::ns::kFirstBlob0123.size() == 4);
24 static_assert(test::ns::kSecondBlob0123.size() == 4);
25 
TEST(CcBlobLibraryTest,FirstBlobContentsMatch)26 TEST(CcBlobLibraryTest, FirstBlobContentsMatch) {
27   EXPECT_EQ(test::ns::kFirstBlob0123[0], std::byte{0});
28   EXPECT_EQ(test::ns::kFirstBlob0123[1], std::byte{1});
29   EXPECT_EQ(test::ns::kFirstBlob0123[2], std::byte{2});
30   EXPECT_EQ(test::ns::kFirstBlob0123[3], std::byte{3});
31 }
32 
TEST(CcBlobLibraryTest,SecondBlobContentsMatch)33 TEST(CcBlobLibraryTest, SecondBlobContentsMatch) {
34   EXPECT_EQ(test::ns::kSecondBlob0123[0], std::byte{0});
35   EXPECT_EQ(test::ns::kSecondBlob0123[1], std::byte{1});
36   EXPECT_EQ(test::ns::kSecondBlob0123[2], std::byte{2});
37   EXPECT_EQ(test::ns::kSecondBlob0123[3], std::byte{3});
38 }
39 
TEST(CcBlobLibraryTest,FirstBlobAlignedTo512)40 TEST(CcBlobLibraryTest, FirstBlobAlignedTo512) {
41   // This checks that the variable is aligned to 512, but cannot guarantee that
42   // alignas was specified correctly, since it could be aligned to 512 by
43   // coincidence.
44   const uintptr_t addr = reinterpret_cast<uintptr_t>(&test::ns::kFirstBlob0123);
45   constexpr uintptr_t kAlignmentMask = static_cast<uintptr_t>(512 - 1);
46   EXPECT_EQ(addr & kAlignmentMask, 0u);
47 }
48 
49 }  // namespace
50 }  // namespace pw::build
51