Re: [PATCH v2 2/2] selftests/nolibc: add testcase for pipe
From: Thomas Weißschuh
Date: Tue Aug 01 2023 - 10:46:27 EST
Aug 1, 2023 14:23:22 Yuan Tan <tanyuan@xxxxxxxxxxx>:
>>> Would this be fine?
>>>
>>> static int test_pipe(void)
>>> {
>>> const char *const msg = "hello, nolibc";
>>> int pipefd[2];
>>> char buf[32];
>>> ssize_t len;
>>>
>>> if (pipe(pipefd) == -1)
>>> return 1;
>>>
>>> write(pipefd[1], msg, strlen(msg));
>>> close(pipefd[1]);
>>> len = read(pipefd[0], buf, sizeof(buf));
>>> close(pipefd[0]);
>>>
>>> if (len != strlen(msg))
>>> return 1;
>>>
>>> return !!memcmp(buf, msg, len);
>>> }
>>
>> Looks good!
>>
>> The return value of write() could also be validated but given we
>> validate the return value from read() it shouldn't make a difference.
>>
>> (Also the manual manipulation of "buf" is gone that necessitated the
>> check in v1 of the series)
>>
>
> I am sorry that I didn't catch your last sentence.
>
> Did you mean this piece of code does not need any further modifications
> right?
Yes, for me this is great!
Sorry for being unclear.