<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-05-20 14:23 GMT+03:00 Pavel Emelyanov <span dir="ltr">&lt;<a href="mailto:xemul@virtuozzo.com" target="_blank">xemul@virtuozzo.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 05/02/2016 06:46 PM, Eugene Batalov wrote:<br>
&gt; From: Kravchenko Dmitrii &lt;<a href="mailto:equivalence1@gmail.com">equivalence1@gmail.com</a>&gt;<br>
&gt;<br>
&gt; This patch implements a simple autotest for new --leave-stopped CRIU<br>
&gt; restorer option. Test creates ps tree then checkpoints it.<br>
&gt; Then test restores ps tree with --leave-stopped option.<br>
&gt; Then test checks that every process in restored ps tree is in<br>
&gt; stopped state.<br>
&gt;<br>
&gt; Signed-off-by: Kravchenko Dmitrii &lt;<a href="mailto:equivalence1@gmail.com">equivalence1@gmail.com</a>&gt;<br>
&gt; Signed-off-by: Eugene Batalov &lt;<a href="mailto:eabatalov89@gmail.com">eabatalov89@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  test/others/leave-stopped/.gitignore      |  3 ++<br>
&gt;  test/others/leave-stopped/Makefile        |  7 +++++<br>
&gt;  test/others/leave-stopped/pstree.c        | 39 +++++++++++++++++++++++++<br>
&gt;  test/others/leave-stopped/run.sh          | 31 ++++++++++++++++++++<br>
&gt;  test/others/leave-stopped/tree_checker.py | 47 +++++++++++++++++++++++++++++++<br>
<br>
</span>Oh :( Is there any chance to have this as a part of zdtm.py suite?<br></blockquote><div><br></div><div>We need to restore the whole ps tree in stopped state so ps tree can&#39;t validate itself after restore.</div><div>I think there should be some file in CRIU test suite where we can add new shell command to run our non-zdtm style test.</div><div>But we haven&#39;t found such a file.</div><div>Do you have such a shell script? Should we implement such a file?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
&gt;  5 files changed, 127 insertions(+)<br>
&gt;  create mode 100644 test/others/leave-stopped/.gitignore<br>
&gt;  create mode 100644 test/others/leave-stopped/Makefile<br>
&gt;  create mode 100644 test/others/leave-stopped/pstree.c<br>
&gt;  create mode 100755 test/others/leave-stopped/run.sh<br>
&gt;  create mode 100755 test/others/leave-stopped/tree_checker.py<br>
&gt;<br>
&gt; diff --git a/test/others/leave-stopped/.gitignore b/test/others/leave-stopped/.gitignore<br>
&gt; new file mode 100644<br>
&gt; index 0000000..f0f7d9e<br>
&gt; --- /dev/null<br>
&gt; +++ b/test/others/leave-stopped/.gitignore<br>
&gt; @@ -0,0 +1,3 @@<br>
&gt; +dump/*<br>
&gt; +nohup.out<br>
&gt; +pstree<br>
&gt; diff --git a/test/others/leave-stopped/Makefile b/test/others/leave-stopped/Makefile<br>
&gt; new file mode 100644<br>
&gt; index 0000000..83e91cc<br>
&gt; --- /dev/null<br>
&gt; +++ b/test/others/leave-stopped/Makefile<br>
&gt; @@ -0,0 +1,7 @@<br>
&gt; +pstree: pstree.c<br>
&gt; +     gcc -pthread -std=c99 $&lt; -o $@<br>
&gt; +<br>
&gt; +clean:<br>
&gt; +     rm -f pstree<br>
&gt; +<br>
&gt; +.PHONY: clean<br>
&gt; diff --git a/test/others/leave-stopped/pstree.c b/test/others/leave-stopped/pstree.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..a6e437c<br>
&gt; --- /dev/null<br>
&gt; +++ b/test/others/leave-stopped/pstree.c<br>
&gt; @@ -0,0 +1,39 @@<br>
&gt; +#include &lt;stdlib.h&gt;<br>
&gt; +#include &lt;unistd.h&gt;<br>
&gt; +#include &lt;limits.h&gt;<br>
&gt; +#include &lt;pthread.h&gt;<br>
&gt; +<br>
&gt; +const size_t THREADS_N = 3;<br>
&gt; +const size_t TREE_HEIGHT = 3;<br>
&gt; +<br>
&gt; +static void *hang(void *arg)<br>
&gt; +{<br>
&gt; +     (void)arg;<br>
&gt; +     while (1)<br>
&gt; +             sleep(UINT_MAX);<br>
&gt; +}<br>
&gt; +<br>
&gt; +static void create_threads(void)<br>
&gt; +{<br>
&gt; +     pthread_t thread;<br>
&gt; +<br>
&gt; +     for (size_t i = 1; i &lt; THREADS_N; i++)<br>
&gt; +             pthread_create(&amp;thread, NULL, hang, NULL);<br>
&gt; +}<br>
&gt; +<br>
&gt; +int main(void)<br>
&gt; +{<br>
&gt; +     /**<br>
&gt; +      * just building full binary tree of processes<br>
&gt; +      */<br>
&gt; +     for (size_t i = 1; i &lt; TREE_HEIGHT; i++) {<br>
&gt; +             if (fork()) {<br>
&gt; +                     if (fork())<br>
&gt; +                             break;<br>
&gt; +             }<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     create_threads();<br>
&gt; +<br>
&gt; +     hang(NULL);<br>
&gt; +}<br>
&gt; diff --git a/test/others/leave-stopped/run.sh b/test/others/leave-stopped/run.sh<br>
&gt; new file mode 100755<br>
&gt; index 0000000..d2f2ec6<br>
&gt; --- /dev/null<br>
&gt; +++ b/test/others/leave-stopped/run.sh<br>
&gt; @@ -0,0 +1,31 @@<br>
&gt; +#!/bin/bash<br>
&gt; +<br>
&gt; +source ../env.sh || exit 1<br>
&gt; +<br>
&gt; +make || { echo &quot;Failed to build&quot;; exit 1; }<br>
&gt; +<br>
&gt; +DDIR=&quot;dump&quot;<br>
&gt; +<br>
&gt; +rm -f nohup.out<br>
&gt; +rm -rf ${DDIR}<br>
&gt; +<br>
&gt; +mkdir ${DDIR}<br>
&gt; +<br>
&gt; +setsid nohup ./pstree &amp;<br>
&gt; +root_pid=$!<br>
&gt; +<br>
&gt; +${CRIU} dump -D ${DDIR} -t ${root_pid} || \<br>
&gt; +     { echo &quot;Failed to dump&quot;; kill -9 -${root_pid}; exit 1; }<br>
&gt; +${CRIU} restore -D ${DDIR} --leave-stopped -d || \<br>
&gt; +     { echo &quot;Failed to restore&quot;; exit 1; }<br>
&gt; +<br>
&gt; +./tree_checker.py ${root_pid}<br>
&gt; +<br>
&gt; +if [ $? -eq 0 ]; then<br>
&gt; +     echo &quot;PASS&quot;<br>
&gt; +     kill -9 -${root_pid}<br>
&gt; +else<br>
&gt; +     echo &quot;FAIL&quot;<br>
&gt; +     kill -9 -${root_pid}<br>
&gt; +     exit 1<br>
&gt; +fi<br>
&gt; diff --git a/test/others/leave-stopped/tree_checker.py b/test/others/leave-stopped/tree_checker.py<br>
&gt; new file mode 100755<br>
&gt; index 0000000..87d45e2<br>
&gt; --- /dev/null<br>
&gt; +++ b/test/others/leave-stopped/tree_checker.py<br>
&gt; @@ -0,0 +1,47 @@<br>
&gt; +#!/usr/bin/python2<br>
&gt; +<br>
&gt; +import os<br>
&gt; +import sys<br>
&gt; +<br>
&gt; +<br>
&gt; +def get_thread_status(thread_dir):<br>
&gt; +     for line in open(os.path.join(thread_dir, &quot;status&quot;)).readlines():<br>
&gt; +             if line.startswith(&quot;State:&quot;):<br>
&gt; +                     return line.split(&quot;:&quot;, 1)[1].strip().split(&#39; &#39;)[0]<br>
&gt; +     return None<br>
&gt; +<br>
&gt; +<br>
&gt; +def is_process_stopped(pid):<br>
&gt; +     tasks_dir = &quot;/proc/{}/task&quot;.format(pid)<br>
&gt; +<br>
&gt; +     for thread_dir in os.listdir(tasks_dir):<br>
&gt; +             thread_status = get_thread_status(os.path.join(tasks_dir, thread_dir))<br>
&gt; +             if not thread_status == &quot;T&quot;:<br>
&gt; +                     return False<br>
&gt; +<br>
&gt; +     thread_status = get_thread_status(&quot;/proc/{}&quot;.format(pid))<br>
&gt; +     if not thread_status == &quot;T&quot;:<br>
&gt; +             return False<br>
&gt; +<br>
&gt; +     return True<br>
&gt; +<br>
&gt; +<br>
&gt; +def check_tree(root_pid):<br>
&gt; +     if not is_process_stopped(root_pid):<br>
&gt; +             print &quot;Process with pid {} is not stopped.&quot;.format(root_pid)<br>
&gt; +             return False<br>
&gt; +<br>
&gt; +     f_children_path = &quot;/proc/{0}/task/{0}/children&quot;.format(root_pid)<br>
&gt; +<br>
&gt; +     with open(f_children_path, &quot;r&quot;) as f_children:<br>
&gt; +             for line in f_children:<br>
&gt; +                     for child_pid in line.strip().split(&quot; &quot;):<br>
&gt; +                             if not check_tree(int(child_pid)):<br>
&gt; +                                     return False<br>
&gt; +<br>
&gt; +     return True<br>
&gt; +<br>
&gt; +<br>
&gt; +if __name__ == &quot;__main__&quot;:<br>
&gt; +     if not check_tree(sys.argv[1]):<br>
&gt; +             sys.exit(1)<br>
&gt;<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Best regards,<br>Eugene Batalov.</div>
</div></div>