[Spice-devel] [PATCH vd_agent_linux 10/10] Add a test for session_info

Frediano Ziglio fziglio at redhat.com
Tue Nov 3 09:48:34 UTC 2020


From: Frediano Ziglio <freddy77 at gmail.com>

Test from Uri, integrated in test suite.

Signed-off-by: Uri Lublin <uril at redhat.com>
Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>
---
 Makefile.am               | 30 ++++++++++++++++++++
 tests/test-session-info.c | 58 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 tests/test-session-info.c

diff --git a/Makefile.am b/Makefile.am
index 575ba52..f4c65b4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -109,13 +109,43 @@ src_spice_vdagentd_SOURCES =			\
 	src/vdagentd/virtio-port.h		\
 	$(NULL)
 
+tests_test_session_info_CFLAGS =		\
+	$(DBUS_CFLAGS)				\
+	$(LIBSYSTEMD_DAEMON_CFLAGS)		\
+	$(LIBSYSTEMD_LOGIN_CFLAGS)		\
+	$(SPICE_CFLAGS)				\
+	$(GIO2_CFLAGS)				\
+	-I$(srcdir)/src				\
+	-I$(srcdir)/src/vdagentd		\
+	-DUDSCS_NO_SERVER			\
+	$(NULL)
+
+tests_test_session_info_LDADD =			\
+	$(DBUS_LIBS)				\
+	$(LIBSYSTEMD_DAEMON_LIBS)		\
+	$(LIBSYSTEMD_LOGIN_LIBS)		\
+	$(SPICE_LIBS)				\
+	$(GIO2_LIBS)				\
+	$(NULL)
+
+tests_test_session_info_SOURCES =		\
+	$(common_sources)			\
+	src/vdagentd/session-info.h		\
+	tests/test-session-info.c		\
+	$(NULL)
+
+check_PROGRAMS += tests/test-session-info
+
 if HAVE_CONSOLE_KIT
 src_spice_vdagentd_SOURCES += src/vdagentd/console-kit.c
+tests_test_session_info_SOURCES += src/vdagentd/console-kit.c
 else
 if HAVE_LIBSYSTEMD_LOGIN
 src_spice_vdagentd_SOURCES += src/vdagentd/systemd-login.c
+tests_test_session_info_SOURCES += src/vdagentd/systemd-login.c
 else
 src_spice_vdagentd_SOURCES += src/vdagentd/dummy-session-info.c
+tests_test_session_info_SOURCES += src/vdagentd/dummy-session-info.c
 endif
 endif
 
diff --git a/tests/test-session-info.c b/tests/test-session-info.c
new file mode 100644
index 0000000..dae3ec6
--- /dev/null
+++ b/tests/test-session-info.c
@@ -0,0 +1,58 @@
+/*  test-session-info.c  - test session info
+
+    Copyright 2020 Red Hat, Inc.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+
+#undef NDEBUG
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "session-info.h"
+
+int main(int argc, char *argv[])
+{
+    int pid, uid, ck_uid;
+
+    pid = (int)getpid();
+
+    struct session_info *session_info = session_info_create(1);
+    if (session_info == NULL) {
+        return 1;
+    }
+
+    char *session = session_info_session_for_pid(session_info, pid);
+    if (session == NULL) {
+        session_info_destroy(session_info);
+        return 2;
+    }
+    ck_uid = session_info_uid_for_session(session_info, session);
+
+    free(session);
+    session_info_destroy(session_info);
+
+    uid = getuid();
+    printf("MAIN: uid is %d, ck_uid is %d\n", uid, ck_uid);
+
+    if (uid != ck_uid) {
+        fprintf(stderr, "MAIN: uid (%d) does not match console-kit uid %d\n", uid, ck_uid);
+        return 3;
+    }
+
+    return 0;
+}
-- 
2.26.2



More information about the Spice-devel mailing list