xref: /aosp_15_r20/external/skia/tests/OverAlignedTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/core/SkTypes.h"
9 #include "include/private/base/SkAlign.h"
10 #include "include/private/base/SkMalloc.h"
11 #include "src/base/SkRandom.h"
12 #include "tests/Test.h"
13 #include <stdint.h>
14 
15 // Clang seems to think only 32-bit alignment is guaranteed on 32-bit x86 Android.
16 // See https://reviews.llvm.org/D8357
17 // This is why we have disabled -Wover-aligned there (we allocate 8-byte aligned structs in Ganesh).
DEF_TEST(OverAligned,r)18 DEF_TEST(OverAligned, r) {
19     SkRandom rand;
20     // Let's test that assertion.  We think it really should be providing 8-byte alignment.
21     for (int i = 0; i < 1000; i++) {
22         void* p = sk_malloc_throw(rand.nextRangeU(0,100));
23         REPORTER_ASSERT(r, SkIsAlign8((uintptr_t)p));
24         sk_free(p);
25     }
26 }
27