<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126106>126106</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Test LlvmLibcFILETest.SimpleFileOperations fails due to file descriptor assertion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
libc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alanzhao1
</td>
</tr>
</table>
<pre>
Repro steps:
```
$ cmake ../runtimes -GNinja \
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DLLVM_LIBC_FULL_BUILD=ON \
-DLLVM_LIBC_INCLUDE_SCUDO=ON \
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF
$ ninja check-libc
```
Result:
```
[530/2361] Running unit test libc.test.src.stdio.fileop_test.__unit__
FAILED: libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fileop_test.__unit__ /usr/local/google/home/ayzhao/src/llvm-project/build-libc/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fileop_test.__unit__
cd /usr/local/google/home/ayzhao/src/llvm-project/build-libc/libc/test/src/stdio && /usr/local/google/home/ayzhao/src/llvm-project/build-libc/libc/test/src/stdio/libc.test.src.stdio.fileop_test.__unit__.__build__
[==========] Running 3 tests from 1 test suite.
[ RUN ] LlvmLibcFILETest.SimpleFileOperations
/usr/local/google/home/ayzhao/src/llvm-project/libc/test/src/stdio/fileop_test.cpp:34: FAILURE
Expected: __llvm_libc_20_0_0_git::fileno(file)
Which is: 5
To be equal to: 3
Which is: 3
[ FAILED ] LlvmLibcFILETest.SimpleFileOperations
```
Looking at the [code](https://github.com/llvm/llvm-project/blob/16f7e961c600986de7814822fd118f431e0bb433/libc/test/src/stdio/fileop_test.cpp#L32-L34) the test opens a file and assert that its file descriptor is equal to the hardcoded value 3. This seems to be a brittle assertion as it makes assumptions about the test's process environment.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VtGOmzgU_RrnxQoCOxDywAMJ0EbLZKpMsu0-WQZugjsGs9iMtvv1KztpOu1U3Y52VQZpCD733Otzj2241uLcAyQoXKMwm_HJtGpMuOT93y1XwaxSzadkD8OosDYwaERT5Ls78q-3nyKywHXHHwF7HiLFOPVGdKDx_M1O9B85RuEG-SmeZ2X5-x3Ld-m6zNn-uDts7_IHRDNEiBRVjei6Vt0gJIzz0SBCPgfieba5S3_L2fq4LTN2-ONdjmiWQTWdX0A2Hz6wzf3du22Z7xHNasn7MyJrRNYvoS-A31RabtcbVhzL8pIY0ex-94zlC2a725THLGcPm2N2_xVsnn3OwfaHa_0OxR4O6S5Ly_tdzt5vD2_Zje1f49-8f8fSh3RngUXxfeSLHNfUb9N9nl0Cr30kC9y7LtUt1I9z14hv2uune9CTNNfmPx8K1yH1ESkIjQIUZng_9b3oz3jqhcEGtMGW0LNPnh5rT5tGKO8kJKiBubeMWSxjyE-LdFva6lIXhEhhAYgUerQ_XCgixeaOP0IhJGhEip9lx4gUkx5thKq5RKQ4K3WWgEjRqs7-45-s42_ZpHzq5sOoPkJtS6gmIZv5taz_vTrkp3Xza0rEiESIRL9Mj5-VwGPMcTox7G5Esx_dz6xGnc80Po2qw8HFdHoSBrwLE94fd9hdNqqUT10pqrrYlvnBFvAgukG6jt0PMHIjVK_duvhP-vxIkufTr4cB0ZQurOmt_Y_73O0u9sr_GqA20NgxxmwCZmkZ8Zn9Owu3IGlq-XqFSGwfEFndCN63om6xsJs2DpGfHhSuAMOfE5fYKPuWfhdLr8Lhy4J8pXBf7xylUo-2S9xg0wJG4bpWDaAwQyRujbmcKKSwAgvTTpVXq-4q53dcJ1WFSBFEpyWs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