[PATCH v2] Add new tests for fopen
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Mar 7 18:35:24 GMT 2025
On 02/02/25 10:47, Florian Weimer wrote:
> * Martin Coufal:
>
>> +static void *
>> +threadReadRoutine (void *argv)
>> +{
>> + struct thread_data *my_data;
>> + unsigned char read_buffer;
>> + int ret = 0;
>> + my_data = (struct thread_data *) argv;
>> + /* Wait for all threads to be ready to read. */
>> + xpthread_barrier_wait (&barrier);
>> +
>> + ret =
>> + fread (&read_buffer, sizeof (char), sizeof (read_buffer), my_data->fd);
>> + if (feof (my_data->fd) != 0)
>> + {
>> + clearerr (my_data->fd);
>> + my_data->eof = true;
>> + }
>> + else
>> + {
>> + TEST_COMPARE (ret, 1);
>> + /* Save the read value. */
>> + my_data->value = read_buffer;
>> + }
>
>> + for (int i = 0; i < NUM_THREADS; i++)
>> + {
>> + if (thread_data_array[i].eof)
>> + {
>> + /* EOF was read. */
>> + present_values[NUM_THREADS - 1] = true;
>> + eof_cnt++;
>> + }
>> + else
>> + {
>> + /* The same value shouldn't be read twice. */
>> + TEST_VERIFY (!present_values[thread_data_array[i].value]);
>> + present_values[thread_data_array[i].value] = true;
>> + }
>> + }
>> + /* EOF is read exactly once. */
>> + TEST_COMPARE (eof_cnt, 1);
>
> This test has a race condition: more than one thread can report
> end-of-file because the check for this condition is separate from the
> fread call. It is possible that all threads return from their fread
> calls before feof is called on multiple threads. This test bug is quite
> visible on larger AArch64 systems, for example.
It has failed on unrelated patch as well [1]. Should we revert this?
[1] https://patchwork.sourceware.org/project/glibc/patch/20250306183418.3086902-1-aurelien@aurel32.net/
More information about the Libc-alpha
mailing list