blob: 4a64742b459050d84dee3b5e0ffaf8f2b4d8b3f1 [file] [log] [blame]
Dan Albertbf18c612015-03-04 10:31:29 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
Colin Cross7da20342021-07-28 11:18:11 -070019#include <ucontext.h> // for NGREG on musl
Dan Albertbf18c612015-03-04 10:31:29 -080020#include <sys/procfs.h>
21
Elliott Hughes8e5fc5b2020-09-03 12:31:07 -070022TEST(sys_procfs, types) {
Dan Albertbf18c612015-03-04 10:31:29 -080023 elf_greg_t reg;
24 memset(&reg, 0, sizeof(reg));
25
26 elf_gregset_t regs;
27 memset(&regs, 0, sizeof(regs));
28
29 elf_fpregset_t fp_regs;
30 memset(&fp_regs, 0, sizeof(fp_regs));
31
32 prgregset_t pr_g_regs;
33 memset(&pr_g_regs, 0, sizeof(pr_g_regs));
34
35 prfpregset_t pr_fp_regs;
36 memset(&pr_fp_regs, 0, sizeof(pr_fp_regs));
37
38 static_assert(sizeof(prgregset_t) == sizeof(elf_gregset_t), "");
39 static_assert(sizeof(prfpregset_t) == sizeof(elf_fpregset_t), "");
40}
Elliott Hughes8e5fc5b2020-09-03 12:31:07 -070041
42TEST(sys_procfs, constants) {
43 // NGREG != ELF_NGREG (https://github.com/android/ndk/issues/1347)
44 static_assert(sizeof(gregset_t) / sizeof(greg_t) == NGREG);
45
46#if defined(__arm__)
47 static_assert(sizeof(user_regs) / sizeof(elf_greg_t) == ELF_NGREG);
48#elif defined(__aarch64__)
49 static_assert(sizeof(user_pt_regs) / sizeof(elf_greg_t) == ELF_NGREG);
50#else
51 static_assert(sizeof(user_regs_struct) / sizeof(elf_greg_t) == ELF_NGREG);
52#endif
53}