Skip to content

Commit 5e45947

Browse files
committed
test: Split the main function in crt-test to a couple smaller functions
This speeds up compilation with LLVM a little bit.
1 parent 0f79bd9 commit 5e45947

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

test/crt-test.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,8 @@ double int_to_double(uint64_t i) {
205205
return u.d;
206206
}
207207

208-
int main(int argc, char* argv[]) {
209-
// The plain "NAN" constant in MSVC is negative, while it is positive
210-
// in other environments.
211-
double pNAN = int_to_double(0x7ff8000000000000ULL);
212-
double nNAN = int_to_double(0xfff8000000000000ULL);
213208

209+
void test_strings() {
214210
char buf[200];
215211
int i;
216212
uint64_t myconst = 0xbaadf00dcafe;
@@ -455,7 +451,9 @@ int main(int argc, char* argv[]) {
455451
}
456452
tests++;
457453
#endif
454+
}
458455

456+
void test_parse_numbers() {
459457
#ifdef _WIN32
460458
_set_invalid_parameter_handler(invalid_parameter);
461459
#endif
@@ -529,7 +527,9 @@ int main(int argc, char* argv[]) {
529527
TEST_STRTOD_64B_RANGE(strtold, );
530528
TEST_STRTOD_64B_RANGE(wcstold, L);
531529
#endif
530+
}
532531

532+
void test_environment() {
533533
int env_ok = 0;
534534
putenv("CRT_TEST_VAR=1");
535535
for (char **ptr = environ; *ptr; ptr++)
@@ -550,6 +550,15 @@ int main(int argc, char* argv[]) {
550550
printf("Variable updated by putenv not found found in environ\n");
551551
}
552552
tests++;
553+
}
554+
555+
void test_math() {
556+
// The plain "NAN" constant in MSVC is negative, while it is positive
557+
// in other environments.
558+
double pNAN = int_to_double(0x7ff8000000000000ULL);
559+
double nNAN = int_to_double(0xfff8000000000000ULL);
560+
561+
int i;
553562

554563
#define TEST_FLOOR(floor) \
555564
TEST_FLT(floor(F(3.9)), 3.0); \
@@ -1700,7 +1709,9 @@ int main(int argc, char* argv[]) {
17001709
TEST_FLT_NAN(_chgsignl(F(NAN)), -F(NAN));
17011710
TEST_FLT_NAN(_chgsignl(-F(NAN)), F(NAN));
17021711
#endif
1712+
}
17031713

1714+
void test_compiler_helpers() {
17041715
TEST_INT(L(7) / L(7), 1); // __rt_sdiv
17051716
TEST_INT(L(-7) / L(7), -1); // __rt_sdiv
17061717
TEST_INT(L(-7) / L(-7), 1); // __rt_sdiv
@@ -1889,7 +1900,9 @@ int main(int argc, char* argv[]) {
18891900
TEST_FLT((float)(__uint128_t)ULL(17293822569102704640), 17293822569102704640.0);
18901901
TEST_FLT((long double)(__uint128_t)ULL(17293822569102704640), 17293822569102704640.0);
18911902
#endif
1903+
}
18921904

1905+
void test_win32_intrinsics() {
18931906
#ifdef _WIN32
18941907
long value = 0;
18951908
__int64 ret;
@@ -2092,7 +2105,15 @@ int main(int argc, char* argv[]) {
20922105
TEST_FUNC(_BitScanReverse64(&idx, ULL(0x8000000000000000)), idx, 63, 1);
20932106
#endif
20942107
#endif
2108+
}
20952109

2110+
int main(int argc, char* argv[]) {
2111+
test_strings();
2112+
test_parse_numbers();
2113+
test_environment();
2114+
test_math();
2115+
test_compiler_helpers();
2116+
test_win32_intrinsics();
20962117
printf("%d tests, %d failures\n", tests, fails);
20972118
return fails > 0;
20982119
}

0 commit comments

Comments
 (0)