577 lines · plain
1add_custom_target(libc_stdio_unittests)2 3add_libc_test(4 fileop_test5 SUITE6 libc_stdio_unittests7 SRCS8 fileop_test.cpp9 DEPENDS10 libc.include.stdio11 libc.src.errno.errno12 libc.src.stdio.clearerr13 libc.src.stdio.fclose14 libc.src.stdio.feof15 libc.src.stdio.ferror16 libc.src.stdio.fflush17 libc.src.stdio.fileno18 libc.src.stdio.fopen19 libc.src.stdio.fputs20 libc.src.stdio.fread21 libc.src.stdio.fseek22 libc.src.stdio.fwrite23 libc.test.UnitTest.ErrnoCheckingTest24)25 26add_libc_test(27 ungetc_test28 SUITE29 libc_stdio_unittests30 SRCS31 ungetc_test.cpp32 DEPENDS33 libc.include.stdio34 libc.src.stdio.fclose35 libc.src.stdio.fopen36 libc.src.stdio.fread37 libc.src.stdio.fseek38 libc.src.stdio.fwrite39 libc.src.stdio.ungetc40)41 42add_libc_test(43 setbuf_test44 SUITE45 libc_stdio_unittests46 SRCS47 setbuf_test.cpp48 DEPENDS49 libc.include.stdio50 libc.src.stdio.fclose51 libc.src.stdio.fopen52 libc.src.stdio.fread53 libc.src.stdio.fwrite54 libc.src.stdio.setbuf55 libc.src.stdio.ungetc56)57 58add_libc_test(59 setvbuf_test60 SUITE61 libc_stdio_unittests62 SRCS63 setvbuf_test.cpp64 DEPENDS65 libc.include.stdio66 libc.src.errno.errno67 libc.src.stdio.fclose68 libc.src.stdio.fopen69 libc.src.stdio.fread70 libc.src.stdio.fwrite71 libc.src.stdio.setvbuf72 libc.test.UnitTest.ErrnoCheckingTest73)74 75add_libc_test(76 unlocked_fileop_test77 SUITE78 libc_stdio_unittests79 SRCS80 unlocked_fileop_test.cpp81 DEPENDS82 libc.include.stdio83 libc.src.errno.errno84 libc.src.stdio.clearerr_unlocked85 libc.src.stdio.fclose86 libc.src.stdio.feof_unlocked87 libc.src.stdio.ferror_unlocked88 libc.src.stdio.flockfile89 libc.src.stdio.fopen90 libc.src.stdio.fread_unlocked91 libc.src.stdio.funlockfile92 libc.src.stdio.fwrite_unlocked93 libc.test.UnitTest.ErrnoCheckingTest94)95 96add_libc_test(97 fopencookie_test98 SUITE99 libc_stdio_unittests100 SRCS101 fopencookie_test.cpp102 DEPENDS103 libc.include.stdio104 libc.hdr.types.size_t105 libc.src.errno.errno106 libc.src.stdio.clearerr107 libc.src.stdio.fclose108 libc.src.stdio.feof109 libc.src.stdio.ferror110 libc.src.stdio.fflush111 libc.src.stdio.fopencookie112 libc.src.stdio.fread113 libc.src.stdio.fseek114 libc.src.stdio.fwrite115 libc.test.UnitTest.ErrnoCheckingTest116 LINK_LIBRARIES117 LibcMemoryHelpers118)119 120if(LIBC_CONF_PRINTF_DISABLE_FLOAT)121 list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")122endif()123if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_DYADIC_FLOAT OR124 LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_FLOAT320)125 list(APPEND sprintf_test_copts "-DLIBC_COPT_FLOAT_TO_STR_REDUCED_PRECISION")126endif()127if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)128 list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")129endif()130if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)131 list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")132endif()133if(LIBC_CONF_PRINTF_DISABLE_FIXED_POINT)134 list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_FIXED_POINT")135endif()136if(LIBC_CONF_PRINTF_DISABLE_STRERROR)137 list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_STRERROR")138endif()139 140add_fp_unittest(141 sprintf_test142 UNIT_TEST_ONLY143 SUITE144 libc_stdio_unittests145 SRCS146 sprintf_test.cpp147 DEPENDS148 libc.src.stdio.sprintf149 libc.src.__support.FPUtil.fp_bits150 libc.include.inttypes151 COMPILE_OPTIONS152 ${sprintf_test_copts}153)154 155add_libc_test(156 snprintf_test157 SUITE158 libc_stdio_unittests159 SRCS160 snprintf_test.cpp161 DEPENDS162 libc.src.stdio.snprintf163)164 165if(LLVM_LIBC_FULL_BUILD)166 # In fullbuild mode, fprintf's tests use the internal FILE for other functions.167 list(APPEND fprintf_test_deps168 libc.src.stdio.fclose169 libc.src.stdio.ferror170 libc.src.stdio.fopen171 libc.src.stdio.fread172 )173 # This is to be used for tests which write to libc's platform streams174 # under full build but write to system-lib's streams otherwise.175 set(hermetic_test_only HERMETIC_TEST_ONLY)176else()177# Else in overlay mode they use the system's FILE.178 set(use_system_file "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")179endif()180 181add_libc_test(182 fprintf_test183 SUITE184 libc_stdio_unittests185 SRCS186 fprintf_test.cpp187 DEPENDS188 libc.src.stdio.fprintf189 libc.test.UnitTest.ErrnoCheckingTest190 libc.test.UnitTest.ErrnoSetterMatcher191 libc.src.__support.macros.properties.architectures192 ${fprintf_test_deps}193 COMPILE_OPTIONS194 ${use_system_file}195)196 197add_libc_test(198 printf_test199 ${hermetic_test_only}200 SUITE201 libc_stdio_unittests202 SRCS203 printf_test.cpp204 DEPENDS205 libc.src.stdio.printf206)207 208add_libc_test(209 asprintf_test210 SUITE211 libc_stdio_unittests212 SRCS213 asprintf_test.cpp214 DEPENDS215 libc.src.stdio.asprintf216 libc.src.string.memset217 libc.include.stdlib218 libc.src.stdio.sprintf219 )220 221add_fp_unittest(222 vsprintf_test223 UNIT_TEST_ONLY224 SUITE225 libc_stdio_unittests226 SRCS227 vsprintf_test.cpp228 DEPENDS229 libc.src.stdio.vsprintf230)231 232add_libc_test(233 vsnprintf_test234 SUITE235 libc_stdio_unittests236 SRCS237 vsnprintf_test.cpp238 DEPENDS239 libc.src.stdio.vsnprintf240)241 242add_libc_test(243 vfprintf_test244 SUITE245 libc_stdio_unittests246 SRCS247 vfprintf_test.cpp248 DEPENDS249 libc.src.stdio.vfprintf250 ${fprintf_test_deps}251 COMPILE_OPTIONS252 ${use_system_file}253)254 255add_libc_test(256 vprintf_test257 ${hermetic_test_only}258 SUITE259 libc_stdio_unittests260 SRCS261 vprintf_test.cpp262 DEPENDS263 libc.src.stdio.vprintf264)265 266add_libc_test(267 vasprintf_test268 SUITE269 libc_stdio_unittests270 SRCS271 vasprintf_test.cpp272 DEPENDS273 libc.src.stdio.vasprintf274 libc.src.string.memset275 libc.include.stdlib276 )277 278if(LLVM_LIBC_FULL_BUILD)279 # In fullbuild mode, fscanf's tests use the internal FILE for other functions.280 list(APPEND fscanf_test_deps281 libc.src.stdio.fclose282 libc.src.stdio.ferror283 libc.src.stdio.fopen284 libc.src.stdio.fwrite285 )286endif()287 288# FIXME: These tests currently fail on AMDGPU due to an optimization bug in the289# `amdgpu-attributor` pass. Disable until that's fixed.290if(NOT LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)291 add_libc_test(292 fscanf_test293 SUITE294 libc_stdio_unittests295 SRCS296 fscanf_test.cpp297 DEPENDS298 libc.src.stdio.fscanf299 ${fscanf_test_deps}300 libc.src.__support.CPP.string_view301 COMPILE_OPTIONS302 ${use_system_file}303 )304 305 add_libc_test(306 vfscanf_test307 SUITE308 libc_stdio_unittests309 SRCS310 vfscanf_test.cpp311 DEPENDS312 libc.src.stdio.vfscanf313 ${fscanf_test_deps}314 libc.src.__support.CPP.string_view315 COMPILE_OPTIONS316 ${use_system_file}317 )318endif()319 320if(LIBC_CONF_SCANF_DISABLE_FLOAT)321 list(APPEND sscanf_test_copts "-DLIBC_COPT_SCANF_DISABLE_FLOAT")322endif()323if(LIBC_CONF_SCANF_DISABLE_INDEX_MODE)324 list(APPEND sscanf_test_copts "-DLIBC_COPT_SCANF_DISABLE_INDEX_MODE")325endif()326 327add_libc_test(328 sscanf_test329 SUITE330 libc_stdio_unittests331 SRCS332 sscanf_test.cpp333 DEPENDS334 libc.src.stdio.sscanf335 LINK_LIBRARIES336 LibcFPTestHelpers337 COMPILE_OPTIONS338 ${sscanf_test_copts}339)340 341add_libc_test(342 vsscanf_test343 SUITE344 libc_stdio_unittests345 SRCS346 vsscanf_test.cpp347 DEPENDS348 libc.src.stdio.vsscanf349 LINK_LIBRARIES350 LibcFPTestHelpers351 COMPILE_OPTIONS352 ${sscanf_test_copts}353)354 355add_libc_test(356 puts_test357 HERMETIC_TEST_ONLY # writes to libc's stdout358 SUITE359 libc_stdio_unittests360 SRCS361 puts_test.cpp362 DEPENDS363 libc.src.stdio.puts364)365 366add_libc_test(367 perror_test368 HERMETIC_TEST_ONLY # writes to libc's stderr369 SUITE370 libc_stdio_unittests371 SRCS372 perror_test.cpp373 DEPENDS374 libc.src.stdio.perror375 libc.src.errno.errno376)377 378add_libc_test(379 fputs_test380 HERMETIC_TEST_ONLY # writes to libc's stdout and stderr381 SUITE382 libc_stdio_unittests383 SRCS384 fputs_test.cpp385 DEPENDS386 libc.src.stdio.fputs387 libc.src.stdio.stdout388 libc.src.stdio.stderr389)390 391add_libc_test(392 fputc_test393 HERMETIC_TEST_ONLY # writes to libc's stdout and stderr394 SUITE395 libc_stdio_unittests396 SRCS397 fputc_test.cpp398 DEPENDS399 libc.src.stdio.fputc400 libc.src.stdio.putchar401 libc.src.stdio.stdout402 libc.src.stdio.stderr403)404 405add_libc_test(406 fopen_test407 SUITE408 libc_stdio_unittests409 SRCS410 fopen_test.cpp411 DEPENDS412 libc.src.stdio.fread413 libc.src.stdio.fwrite414 libc.src.stdio.fclose415 libc.src.stdio.fopen416)417 418add_libc_test(419 putc_test420 SUITE421 libc_stdio_unittests422 SRCS423 putc_test.cpp424 DEPENDS425 libc.src.stdio.putc426 libc.src.stdio.fclose427 libc.src.stdio.ferror428 libc.src.stdio.fopen429 libc.src.stdio.fread430)431 432if(${LIBC_TARGET_OS} STREQUAL "linux")433 add_libc_test(434 remove_test435 SUITE436 libc_stdio_unittests437 SRCS438 remove_test.cpp439 DEPENDS440 libc.include.unistd441 libc.src.errno.errno442 libc.src.fcntl.open443 libc.src.stdio.remove444 libc.src.sys.stat.mkdirat445 libc.src.unistd.access446 libc.src.unistd.close447 libc.test.UnitTest.ErrnoCheckingTest448 )449 450 add_libc_test(451 rename_test452 SUITE453 libc_stdio_unittests454 SRCS455 rename_test.cpp456 DEPENDS457 libc.src.errno.errno458 libc.src.fcntl.open459 libc.src.stdio.rename460 libc.src.unistd.access461 libc.src.unistd.close462 libc.test.UnitTest.ErrnoCheckingTest463 libc.test.UnitTest.ErrnoSetterMatcher464 )465 466 add_libc_test(467 fdopen_test468 SUITE469 libc_stdio_unittests470 SRCS471 fdopen_test.cpp472 DEPENDS473 libc.src.fcntl.open474 libc.src.stdio.fclose475 libc.src.stdio.fdopen476 libc.src.stdio.fgets477 libc.src.stdio.fputs478 libc.src.unistd.close479 libc.test.UnitTest.ErrnoCheckingTest480 libc.test.UnitTest.ErrnoSetterMatcher481 )482endif()483 484add_libc_test(485 fgetc_test486 SUITE487 libc_stdio_unittests488 SRCS489 fgetc_test.cpp490 DEPENDS491 libc.include.stdio492 libc.src.errno.errno493 libc.src.stdio.fclose494 libc.src.stdio.feof495 libc.src.stdio.ferror496 libc.src.stdio.fgetc497 libc.src.stdio.fopen498 libc.src.stdio.fwrite499 libc.src.stdio.getc500 libc.test.UnitTest.ErrnoCheckingTest501 libc.test.UnitTest.ErrnoSetterMatcher502)503 504add_libc_test(505 fgetc_unlocked_test506 SUITE507 libc_stdio_unittests508 SRCS509 fgetc_unlocked_test.cpp510 DEPENDS511 libc.include.stdio512 libc.src.errno.errno513 libc.src.stdio.fclose514 libc.src.stdio.ferror515 libc.src.stdio.ferror_unlocked516 libc.src.stdio.feof517 libc.src.stdio.feof_unlocked518 libc.src.stdio.fgetc_unlocked519 libc.src.stdio.flockfile520 libc.src.stdio.fopen521 libc.src.stdio.funlockfile522 libc.src.stdio.fwrite523 libc.src.stdio.getc_unlocked524 libc.test.UnitTest.ErrnoCheckingTest525 libc.test.UnitTest.ErrnoSetterMatcher526)527 528add_libc_test(529 fgets_test530 SUITE531 libc_stdio_unittests532 SRCS533 fgets_test.cpp534 DEPENDS535 libc.include.stdio536 libc.src.errno.errno537 libc.src.stdio.fclose538 libc.src.stdio.feof539 libc.src.stdio.ferror540 libc.src.stdio.fgets541 libc.src.stdio.fopen542 libc.src.stdio.fwrite543 libc.test.UnitTest.ErrnoCheckingTest544 libc.test.UnitTest.ErrnoSetterMatcher545)546 547add_libc_test(548 ftell_test549 SUITE550 libc_stdio_unittests551 SRCS552 ftell_test.cpp553 DEPENDS554 libc.include.stdio555 libc.src.stdio.fclose556 libc.src.stdio.fflush557 libc.src.stdio.fopen558 libc.src.stdio.fread559 libc.src.stdio.fseek560 libc.src.stdio.ftell561 libc.src.stdio.fseeko562 libc.src.stdio.ftello563 libc.src.stdio.fwrite564 libc.src.stdio.setvbuf565)566 567# Create an output directory for any temporary test files.568file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testdata)569 570if(LIBC_TARGET_OS_IS_GPU)571 return()572endif()573 574add_subdirectory(printf_core)575add_subdirectory(scanf_core)576add_subdirectory(testdata)577