Index: uspace/app/tester/Makefile
===================================================================
--- uspace/app/tester/Makefile	(revision 1be7bee8078be21f432895af4f51f96ea24ceda6)
+++ uspace/app/tester/Makefile	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -66,5 +66,7 @@
 	mm/pager1.c \
 	hw/serial/serial1.c \
-	chardev/chardev1.c
+	chardev/chardev1.c \
+	proc/dummy_task.c \
+	proc/task_wait.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/tester/proc/dummy_task.c
===================================================================
--- uspace/app/tester/proc/dummy_task.c	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
+++ uspace/app/tester/proc/dummy_task.c	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015 Michal Koutny
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <str.h>
+#include <task.h>
+
+#include "../tester.h"
+#include "common.h"
+
+typedef void (* behavior_func_t)(void);
+
+typedef struct {
+	const char *name;
+	task_behavior_t behavior;
+	behavior_func_t func;
+} behavior_item_t;
+
+static const char *err = NULL;
+
+static void dummy_fail(void)
+{
+	behavior_func_t func = NULL;
+	func();
+}
+
+static void dummy_bypass(void)
+{
+	__SYSCALL1(SYS_TASK_EXIT, false);
+}
+
+static void dummy_daemon(void)
+{
+	task_retval(EOK);
+	async_manager();
+}
+
+static void dummy_job_fail(void)
+{
+	err = "Intended error";
+}
+
+static void dummy_job_ok(void)
+{
+	err = NULL;
+}
+
+static behavior_item_t behaviors[] = {
+	{ STR_FAIL,     BEHAVIOR_FAIL,     &dummy_fail },
+	{ STR_BYPASS,   BEHAVIOR_BYPASS,   &dummy_bypass },
+	{ STR_DAEMON,   BEHAVIOR_DAEMON,   &dummy_daemon },
+	{ STR_JOB_FAIL, BEHAVIOR_JOB_FAIL, &dummy_job_fail },
+	{ STR_JOB_OK,   BEHAVIOR_JOB_OK,   &dummy_job_ok },
+	{ NULL,         BEHAVIOR_JOB_OK,   NULL }
+};
+
+const char *test_proc_dummy_task(void)
+{
+	const char *name = (test_argc == 0) ? STR_JOB_OK : test_argv[0];
+
+	for (behavior_item_t *it = behaviors; it->name != NULL; ++it) {
+		if (str_cmp(name, it->name) != 0) {
+			continue;
+		}
+		it->func();
+	}
+
+	return err;
+}
Index: uspace/app/tester/proc/dummy_task.def
===================================================================
--- uspace/app/tester/proc/dummy_task.def	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
+++ uspace/app/tester/proc/dummy_task.def	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -0,0 +1,6 @@
+{
+	"proc_dummy_task",
+	"Dummy task",
+	&test_proc_dummy_task,
+	true
+},
Index: uspace/app/tester/proc/task_wait.c
===================================================================
--- uspace/app/tester/proc/task_wait.c	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
+++ uspace/app/tester/proc/task_wait.c	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2015 Michal Koutny
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <task.h>
+
+#include "../tester.h"
+#include "common.h"
+
+#define DUMMY_TASK     "/root/app/tester"
+#define DUMMY_TASK_ARG "proc_dummy_task"
+
+#define S(x) #x
+#define S_(x) S(x)
+#define S__LINE__ S_(__LINE__)
+
+#define TASSERT(expr) \
+	do { \
+		if (!(expr)) \
+			return "Failed " #expr " " __FILE__ ":" S__LINE__ ; \
+	} while (0)
+
+static int dummy_task_spawn(task_id_t *task_id, task_wait_t *wait,
+    const char *behavior)
+{
+	return task_spawnl(task_id, wait,
+	    DUMMY_TASK, DUMMY_TASK, DUMMY_TASK_ARG, behavior,
+	    NULL);
+}
+
+const char *test_proc_task_wait(void)
+{
+	const char *err = NULL;
+
+	int rc;
+	task_id_t tid;
+	task_wait_t wait;
+	int retval;
+	task_exit_t texit;
+
+	TPRINTF("11 match");
+
+	task_wait_set(&wait, TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	TASSERT(texit == TASK_EXIT_UNEXPECTED);
+	TPRINTF("OK");
+	/* ---- */
+	
+	TPRINTF("12 lost wait");
+
+	task_wait_set(&wait, TASK_WAIT_RETVAL);
+	rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EINVAL);
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("13 partial match");
+
+	task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_BYPASS);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	TASSERT(texit == TASK_EXIT_UNEXPECTED);
+	/* retval is undefined */
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("21 ignore retval");
+
+	task_wait_set(&wait, TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	TASSERT(texit == TASK_EXIT_NORMAL);
+	/* retval is unknown */
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("22 good match");
+
+	task_wait_set(&wait, TASK_WAIT_RETVAL);
+	rc = dummy_task_spawn(&tid, &wait, STR_DAEMON);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	/* exit is not expected */
+	TASSERT(retval == EOK);
+	task_kill(tid); /* Terminate daemon */
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("23 partial match (non-exited task)");
+
+	// TODO should update wait for synchronized exit waiting
+	task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_DAEMON);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	/* exit is not expected */
+	TASSERT(retval == EOK);
+	task_kill(tid); /* Terminate daemon */
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("31 on exit return");
+
+	task_wait_set(&wait, TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	TASSERT(texit == TASK_EXIT_NORMAL);
+	/* retval is unknown */
+	TPRINTF("OK");
+	/* ---- */
+
+
+	TPRINTF("32 keep retval until exit");
+
+	task_wait_set(&wait, TASK_WAIT_RETVAL);
+	rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	/* exit is unknown */
+	TASSERT(retval == EOK);
+	/* check task already exited */
+	rc = task_kill(tid);
+	TASSERT(rc == ENOENT);
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("33 double good match");
+
+	task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
+	rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
+	TASSERT(rc == EOK);
+
+	rc = task_wait(&wait, &texit, &retval);
+	TASSERT(rc == EOK);
+	TASSERT(texit == TASK_EXIT_NORMAL);
+	TASSERT(retval == EOK);
+	TPRINTF("OK");
+	/* ---- */
+
+	TPRINTF("All task waiting tests finished");
+
+
+
+	return err;
+}
Index: uspace/app/tester/proc/task_wait.def
===================================================================
--- uspace/app/tester/proc/task_wait.def	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
+++ uspace/app/tester/proc/task_wait.def	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -0,0 +1,6 @@
+{
+	"proc_task_wait",
+	"Task wait API",
+	&test_proc_task_wait,
+	true
+},
Index: uspace/app/tester/tester.c
===================================================================
--- uspace/app/tester/tester.c	(revision 1be7bee8078be21f432895af4f51f96ea24ceda6)
+++ uspace/app/tester/tester.c	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -78,5 +78,7 @@
 #include "hw/serial/serial1.def"
 #include "chardev/chardev1.def"
-	{ NULL, NULL, NULL, false }
+#include "proc/dummy_task.def"
+#include "proc/task_wait.def"
+	{NULL, NULL, NULL, false}
 };
 
Index: uspace/app/tester/tester.h
===================================================================
--- uspace/app/tester/tester.h	(revision 1be7bee8078be21f432895af4f51f96ea24ceda6)
+++ uspace/app/tester/tester.h	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -111,4 +111,6 @@
 extern const char *test_devman2(void);
 extern const char *test_chardev1(void);
+extern const char *test_proc_dummy_task(void);
+extern const char *test_proc_task_wait(void);
 
 extern test_t tests[];
Index: uspace/lib/c/include/task.h
===================================================================
--- uspace/lib/c/include/task.h	(revision 1be7bee8078be21f432895af4f51f96ea24ceda6)
+++ uspace/lib/c/include/task.h	(revision 70d28e8d1b2259d26ca6a608797be694ef1b5a15)
@@ -51,4 +51,8 @@
 } task_wait_t;
 
+static inline void task_wait_set(task_wait_t *wait, int flags)
+{
+	wait->flags = flags;
+}
 
 extern task_id_t task_get_id(void);
