<div dir="ltr"><div dir="ltr"><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 Sat, Jul 18, 2020 at 12:35 AM Cyril Hrubis <<a href="mailto:chrubis@suse.cz">chrubis@suse.cz</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"><span class="gmail_default" style="font-size:small">...</span><br>
+       /*<br>
+        * Sum rss, swap and size for all elements listed, which should equal<br>
+        * the data returned in the shm_info structure.<br>
+        *<br>
+        * Note that the size has to be rounded up to nearest multiple of page<br>
+        * size.<br>
+        */<br>
+       while (fscanf(f, "%*i %i %*i %i %*i %*i %*i %*i %*i %*i %*i %*i %*i %*i %i %i",<br>
+                     &shmid, &size, &rss, &swap) > 0) {<br>
+               used_ids++;<br>
+               shm_rss += rss/page_size;<br>
+               shm_swp += swap/page_size;<br>
+               shm_tot += (size + page_size - 1) / page_size;<br>
+               if (shmid > shmid_max)<br>
+                       shmid_max = shmid;<br>
+       }<br>
<br>
<span class="gmail_default" style="font-size:small">...</span><br>
<br>
-       tst_exit();<br>
+       if (max_id != shmid_max) {<br>
+               tst_res(TFAIL, "highest shmid = %i, expected %i",<br>
+                       max_id, shmid_max);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">It failed many times on my personal laptop (5.4.19-100.fc30.x86_64).</div></div><div><br></div><div><div class="gmail_default" style="font-size:small">$ cat /proc/sysvipc/shm </div>       key      shmid <span class="gmail_default" style="font-size:small">  </span>perms        size  <span class="gmail_default" style="font-size:small">    </span>cpid  <span class="gmail_default" style="font-size:small">  </span>lpid <span class="gmail_default" style="font-size:small">   </span>nattch   uid <span class="gmail_default" style="font-size:small">  </span>  gid <span class="gmail_default" style="font-size:small">  </span> cuid <span class="gmail_default" style="font-size:small">  </span> cgid      atime    <span class="gmail_default" style="font-size:small">    </span> <span class="gmail_default" style="font-size:small"> </span> dtime     <span class="gmail_default" style="font-size:small">        </span> ctime               rss        swap<br>         0          6 <span class="gmail_default" style="font-size:small">       </span> 1600      524288  <span class="gmail_default" style="font-size:small"> </span>2778  <span class="gmail_default" style="font-size:small"> </span>5447      2 <span class="gmail_default" style="font-size:small">   </span> 1000  1000  1000  1000 1595120306 <span class="gmail_default" style="font-size:small"> </span>1595120306 <span class="gmail_default" style="font-size:small"> </span>1595119412      4096        <span class="gmail_default" style="font-size:small"> </span>0<br>         0          8 <span class="gmail_default" style="font-size:small">       </span> 1600      524288  <span class="gmail_default" style="font-size:small"> </span>1903  <span class="gmail_default" style="font-size:small"> </span>2043      2  <span class="gmail_default" style="font-size:small">   </span>1000  1000  1000  1000 1595119515  <span class="gmail_default" style="font-size:small"> </span>   0 <span class="gmail_default" style="font-size:small">                </span>1595119515    <span class="gmail_default" style="font-size:small"></span> 24576       0<br><br></div><div>$ ./shmctl04 <br>tst_test.c:1245: INFO: Timeout per run is 0h 05m 00s<br>shmctl04.c:119: PASS: SHM_INFO returned valid index 8<br>shmctl04.c:70: PASS: used_ids = 3<br>shmctl04.c:77: PASS: shm_rss = 7<br>shmctl04.c:84: PASS: shm_swp = 0<br>shmctl04.c:91: PASS: shm_tot = 257<br>shmctl04.c:95: FAIL: highest shmid = 8, expected 65537</div><div><br><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">Summary:</div>passed   5<br>failed   1<br>skipped  0<br>warnings 0</div><div><br></div><div><div class="gmail_default" style="font-size:small">After printing the shm_proc during test running, I guess the 'shmid' is not listing in number order sometimes which probably caused that failure.</div><div class="gmail_default" style="font-size:small"><br></div><span class="gmail_default" style="font-size:small"></span>       key      shmid perms                  size  cpid  lpid nattch   uid   gid  cuid  cgid      atime      dtime      ctime                   rss                  swap<br>         0      98306   600                  2048 29586     0      0  1000  1000  1000  1000          0          0 1595144682                     0                     0<br>         0          6  1600                524288  2778 26559      2  1000  1000  1000  1000 1595142041 1595142041 1595119412                  4096                     0<br>         0          8  1600                524288  1903  2043      2  1000  1000  1000  1000 1595119515          0 1595119515                 24576                     0<br><br></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">
+       } else {<br>
+               tst_res(TPASS, "highest shmid = %i", max_id);<br>
+       }<br>
 }<br>
<br>
-/*<br>
- * setup() - performs all the ONE TIME setup for this test.<br>
- */<br>
-void setup(void)<br>
+static void verify_shminfo(void)<br>
 {<br>
+       struct shm_info info;<br>
+       struct shmid_ds ds;<br>
<br>
-       tst_sig(NOFORK, DEF_HANDLER, cleanup);<br>
+       TEST(shmctl(0, SHM_INFO, (struct shmid_ds *)&info));<br>
<br>
-       TEST_PAUSE;<br>
+       if (TST_RET == -1) {<br>
+               tst_res(TFAIL | TTERRNO, "shmctl(0, SHM_INFO, ...)");<br>
+               return;<br>
+       }<br>
<br>
-       /*<br>
-        * Create a temporary directory and cd into it.<br>
-        * This helps to ensure that a unique msgkey is created.<br>
-        * See libs/libltpipc/libipc.c for more information.<br>
-        */<br>
-       tst_tmpdir();<br>
+       TEST(shmctl(TST_RET, <span class="gmail_default" style="font-size:small"></span>SHM_STAT_ANY, &ds));<br></blockquote><div><br></div><span class="gmail_default" style="font-size:small"></span><span class="gmail_default">'</span>SHM_STAT_ANY<span class="gmail_default" style="font-size:small">'</span><span class="gmail_default" style="font-size:small"> is introduced </span><span class="gmail_default"></span>since Linux 4.17<span class="gmail_default" style="font-size:small">. We have to confirm the SUT supporting before we running it.</span></div><div class="gmail_quote"><div> </div><div><div class="gmail_default" style="font-size:small">Also, we'd better define it in "ipcshm.h" to avoid compiling errors with the old distro.</div><br>shmctl04.c: In function 'verify_shminfo':<br>shmctl04.c:114: error: 'SHM_STAT_ANY' undeclared (first use in this function)<br>shmctl04.c:114: error: (Each undeclared identifier is reported only once<br>shmctl04.c:114: error: for each function it appears in.)</div><div><br></div><div>-- <br></div></div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div></div></div>