1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker *
4*8d67ca89SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*8d67ca89SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*8d67ca89SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*8d67ca89SAndroid Build Coastguard Worker *
8*8d67ca89SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*8d67ca89SAndroid Build Coastguard Worker *
10*8d67ca89SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*8d67ca89SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*8d67ca89SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8d67ca89SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*8d67ca89SAndroid Build Coastguard Worker * limitations under the License.
15*8d67ca89SAndroid Build Coastguard Worker */
16*8d67ca89SAndroid Build Coastguard Worker
17*8d67ca89SAndroid Build Coastguard Worker #include <gtest/gtest.h>
18*8d67ca89SAndroid Build Coastguard Worker
19*8d67ca89SAndroid Build Coastguard Worker #include <stdint.h>
20*8d67ca89SAndroid Build Coastguard Worker
21*8d67ca89SAndroid Build Coastguard Worker static const char* record[4] = {};
22*8d67ca89SAndroid Build Coastguard Worker static int idx = 0;
23*8d67ca89SAndroid Build Coastguard Worker
prio1000()24*8d67ca89SAndroid Build Coastguard Worker __attribute__((constructor(1000))) static void prio1000() {
25*8d67ca89SAndroid Build Coastguard Worker record[idx++] = "prio1000";
26*8d67ca89SAndroid Build Coastguard Worker }
27*8d67ca89SAndroid Build Coastguard Worker
prio1()28*8d67ca89SAndroid Build Coastguard Worker __attribute__((constructor(1))) static void prio1() {
29*8d67ca89SAndroid Build Coastguard Worker record[idx++] = "prio1";
30*8d67ca89SAndroid Build Coastguard Worker }
31*8d67ca89SAndroid Build Coastguard Worker
noprio()32*8d67ca89SAndroid Build Coastguard Worker __attribute__((constructor)) static void noprio() {
33*8d67ca89SAndroid Build Coastguard Worker record[idx++] = "noprio";
34*8d67ca89SAndroid Build Coastguard Worker }
35*8d67ca89SAndroid Build Coastguard Worker
TEST(prio_ctor,order)36*8d67ca89SAndroid Build Coastguard Worker TEST(prio_ctor, order) {
37*8d67ca89SAndroid Build Coastguard Worker EXPECT_EQ(idx, 3);
38*8d67ca89SAndroid Build Coastguard Worker EXPECT_STREQ(record[0], "prio1");
39*8d67ca89SAndroid Build Coastguard Worker EXPECT_STREQ(record[1], "prio1000");
40*8d67ca89SAndroid Build Coastguard Worker EXPECT_STREQ(record[2], "noprio");
41*8d67ca89SAndroid Build Coastguard Worker }
42