xref: /openbsd-src/regress/lib/csu/init_priority/init_priority_test.cc (revision 4a08560fec3d048dc92bd89a9bed5ecee2df248e)
1*4a08560fSkettenis /* $OpenBSD: init_priority_test.cc,v 1.4 2013/08/01 21:26:30 kettenis Exp $ */
2476cbaa3Smatthew 
3476cbaa3Smatthew #include <cassert>
4*4a08560fSkettenis #include <cstdio>
5476cbaa3Smatthew 
6476cbaa3Smatthew namespace {
7476cbaa3Smatthew const int kNumTests = 10;
8476cbaa3Smatthew int counter = 0;
9476cbaa3Smatthew int log[kNumTests];
10476cbaa3Smatthew 
11476cbaa3Smatthew struct Test {
12476cbaa3Smatthew 	Test(int x);
13476cbaa3Smatthew };
14476cbaa3Smatthew 
Test(int x)15476cbaa3Smatthew Test::Test(int x)
16476cbaa3Smatthew {
17476cbaa3Smatthew 	if (counter < kNumTests)
18476cbaa3Smatthew 		log[counter] = x;
19*4a08560fSkettenis 	fprintf(stderr, "%d\n", x);
20476cbaa3Smatthew 	counter++;
21476cbaa3Smatthew }
22476cbaa3Smatthew 
237494a4c9Smiod #if __GNUC__ < 4
24ed451371Smiod #define TEST(n) Test test_##n (n) __attribute__((init_priority (n)))
25ed451371Smiod #else
26ed451371Smiod #define TEST(n) Test test_##n __attribute__((init_priority (n))) (n)
27ed451371Smiod #endif
28476cbaa3Smatthew TEST(12597);
29476cbaa3Smatthew TEST(20840);
30476cbaa3Smatthew TEST(31319);
31476cbaa3Smatthew TEST(17071);
32476cbaa3Smatthew TEST(47220);
33476cbaa3Smatthew TEST(40956);
34476cbaa3Smatthew TEST(28373);
35476cbaa3Smatthew TEST(8742);
36476cbaa3Smatthew TEST(14117);
37476cbaa3Smatthew TEST(6407);
38476cbaa3Smatthew #undef TEST
39476cbaa3Smatthew }
40476cbaa3Smatthew 
41476cbaa3Smatthew int
main()42476cbaa3Smatthew main()
43476cbaa3Smatthew {
44476cbaa3Smatthew 	int i;
45476cbaa3Smatthew 
46476cbaa3Smatthew 	assert(counter == kNumTests);
47476cbaa3Smatthew 	for (i = 1; i < kNumTests; i++)
48476cbaa3Smatthew 		assert(log[i] >= log[i - 1]);
49476cbaa3Smatthew 
50476cbaa3Smatthew 	return (0);
51476cbaa3Smatthew }
52