<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 5, 2020 at 5:19 PM Jan Stancek <<a href="mailto:jstancek@redhat.com">jstancek@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Some PPC KVM guests accumulate about 1 bit of entropy per second while idle<br>
and running getrandom02. Which isn't enough and test sporadically fails on<br>
timeout.<br>
<br>
Adjust the buffer size by looking at entropy_avail. We want to run the test,<br>
even if all entropy is exhausted, but with smaller buffer we don't set<br>
as high expectations on how much entropy is generated within default test time.<br>
<br>
Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>><br>
---<br>
testcases/kernel/syscalls/getrandom/getrandom02.c | 12 ++++++++++--<br>
1 file changed, 10 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/getrandom/getrandom02.c b/testcases/kernel/syscalls/getrandom/getrandom02.c<br>
index ee0193df9897..1384fc5f32c0 100644<br>
--- a/testcases/kernel/syscalls/getrandom/getrandom02.c<br>
+++ b/testcases/kernel/syscalls/getrandom/getrandom02.c<br>
@@ -10,6 +10,8 @@<br>
#include "lapi/syscalls.h"<br>
#include "tst_test.h"<br>
<br>
+#define PROC_ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail"<br>
+<br>
static int modes[] = { 0, GRND_RANDOM, GRND_NONBLOCK,<br>
GRND_RANDOM | GRND_NONBLOCK };<br>
<br>
@@ -37,11 +39,17 @@ static int check_content(unsigned char *buf, int nb)<br>
static void verify_getrandom(unsigned int n)<br>
{<br>
unsigned char buf[256];<br>
+ int bufsize = 64, entropy_avail;<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I'm not sure why here initialize bufsize as 64? can you explain more?</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
- memset(buf, 0, sizeof(buf));<br>
+ if (access(PROC_ENTROPY_AVAIL, F_OK) == 0) {<br>
+ SAFE_FILE_SCANF(PROC_ENTROPY_AVAIL, "%d", &entropy_avail);<br>
+ if (entropy_avail > 256)<br>
+ bufsize = sizeof(buf);<br>
+ }<br>
<br>
+ memset(buf, 0, sizeof(buf));<br>
do {<br>
- TEST(tst_syscall(__NR_getrandom, buf, sizeof(buf), modes[n]));<br>
+ TEST(tst_syscall(__NR_getrandom, buf, bufsize, modes[n]));<br>
} while ((modes[n] & GRND_NONBLOCK) && TST_RET == -1<br>
&& TST_ERR == EAGAIN);<br>
<br>
-- <br>
2.18.1<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>