OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Orlov <ivan.orlov0322@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 4/4] lib: tests: Add sbi_console test
Date: Thu, 15 Feb 2024 15:45:20 +0000	[thread overview]
Message-ID: <290c2605-a043-4211-a6d4-65d310c2a1a9@gmail.com> (raw)
In-Reply-To: <20240215-62fcfc1f00c95b950e3127b3@orel>

On 2/15/24 15:13, Andrew Jones wrote:
> On Thu, Feb 15, 2024 at 02:44:15PM +0000, Ivan Orlov wrote:
>> On 2/12/24 18:24, Andrew Jones wrote:
>>> On Thu, Feb 08, 2024 at 09:50:50AM +0000, Ivan Orlov wrote:
> ...
>>>> +static void clear_buf(void)
>>>> +{
>>>> +	pos = 0;
>>>> +	sbi_memset(buf, 0, BUF_LEN);
>>>
>>> I guess buf[0] = '\0' should be sufficient.
>>>
>>
>> Sorry for the late reply, I agree on all of the points you mentioned except
>> this one. The 'puts' test stops me from clearing the buffer by setting the
>> first char to zero:
>>
>> ```
>> PUTS_TEST(test, "Hello,", "Hello,\0OpenSBI!");
>> ```
>>
>> This test checks if 'puts' stops printing after facing \0. 'puts' won't
>> print out the \0 to the buffer after printing "Hello,", so in case of the
>> 'lazy' buffer clearing there might be other characters in buffer after
>> 'Hello,'. In this case, the 'sbi_strcmp' won't stop comparing the strings
>> causing the test to fail (despite the behavior is correct).
>>
>> I reckon that clearing the buffer completely will help avoiding such tricky
>> issues by making the experiment as pure as possible :)
> 
> Since the mock console device is a ring buffer it doesn't guarantee zeros
> will follow the printed strings. I suggest writing tests which only
> confirm the characters printed are in the stream and in the right order,
> but not check for anything console device implementation specific.
> 

Ah, alright, I see. Moreover, this particular test case is just useless 
since it doesn't increase the coverage. So I guess I will just use the 
"lazy" buffer clearing and remove this particular 'PUTS_TEST'. Thanks 
for the clarification!

-- 
Kind regards,
Ivan Orlov



  reply	other threads:[~2024-02-15 15:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  9:50 [PATCH 1/4] docs: Add documentation about tests and SBIUnit Ivan Orlov
2024-02-08  9:50 ` [PATCH 2/4] lib: Add SBIUnit testing macros and functions Ivan Orlov
2024-02-12 17:36   ` Andrew Jones
2024-02-12 22:03     ` Ivan Orlov
2024-02-13 14:00       ` Andrew Jones
2024-02-13 14:55         ` Ivan Orlov
2024-02-08  9:50 ` [PATCH 3/4] lib: tests: Add a test for sbi_bitmap Ivan Orlov
2024-02-12 18:11   ` Andrew Jones
2024-02-08  9:50 ` [PATCH 4/4] lib: tests: Add sbi_console test Ivan Orlov
2024-02-12 18:24   ` Andrew Jones
2024-02-15 14:44     ` Ivan Orlov
2024-02-15 15:13       ` Andrew Jones
2024-02-15 15:45         ` Ivan Orlov [this message]
2024-02-12 17:20 ` [PATCH 1/4] docs: Add documentation about tests and SBIUnit Andrew Jones
2024-02-12 21:48   ` Ivan Orlov
2024-02-13 13:51     ` Andrew Jones
2024-02-13 14:54       ` Ivan Orlov
2024-02-13 15:21         ` Andrew Jones
2024-02-13 15:29           ` Ivan Orlov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=290c2605-a043-4211-a6d4-65d310c2a1a9@gmail.com \
    --to=ivan.orlov0322@gmail.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox