]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-process-util.c
Merge pull request #2708 from vcaputo/journal-restore-offline-state-on-error
[thirdparty/systemd.git] / src / test / test-process-util.c
index e4e2efecd50856046b9c88ba51a7e42514f4d959..461631420019bd43f2ceb50fbe394cdfde10d8ad 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/types.h>
+#include <sys/personality.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
-#include "process-util.h"
+#include "alloc-util.h"
+#include "architecture.h"
 #include "log.h"
-#include "util.h"
 #include "macro.h"
-#include "virt.h"
+#include "process-util.h"
+#include "string-util.h"
 #include "terminal-util.h"
+#include "util.h"
+#include "virt.h"
 
 static void test_get_process_comm(void) {
         struct stat st;
@@ -53,7 +57,7 @@ static void test_get_process_comm(void) {
         assert_se(get_process_cmdline(1, 8, false, &d) >= 0);
         log_info("pid1 cmdline truncated: '%s'", d);
 
-        assert_se(get_parent_of_pid(1, &e) >= 0);
+        assert_se(get_process_ppid(1, &e) >= 0);
         log_info("pid1 ppid: "PID_FMT, e);
         assert_se(e == 0);
 
@@ -85,7 +89,7 @@ static void test_get_process_comm(void) {
         assert_se(r >= 0 || r == -EACCES);
         log_info("self strlen(environ): '%zu'", strlen(env));
 
-        if (!detect_container(NULL))
+        if (!detect_container())
                 assert_se(get_ctty_devnr(1, &h) == -ENXIO);
 
         getenv_for_pid(1, "PATH", &i);
@@ -126,6 +130,29 @@ static void test_pid_is_alive(void) {
         assert_se(!pid_is_alive(-1));
 }
 
+static void test_personality(void) {
+
+        assert_se(personality_to_string(PER_LINUX));
+        assert_se(!personality_to_string(PERSONALITY_INVALID));
+
+        assert_se(streq(personality_to_string(PER_LINUX), architecture_to_string(native_architecture())));
+
+        assert_se(personality_from_string(personality_to_string(PER_LINUX)) == PER_LINUX);
+        assert_se(personality_from_string(architecture_to_string(native_architecture())) == PER_LINUX);
+
+#ifdef __x86_64__
+        assert_se(streq_ptr(personality_to_string(PER_LINUX), "x86-64"));
+        assert_se(streq_ptr(personality_to_string(PER_LINUX32), "x86"));
+
+        assert_se(personality_from_string("x86-64") == PER_LINUX);
+        assert_se(personality_from_string("x86") == PER_LINUX32);
+        assert_se(personality_from_string("ia64") == PERSONALITY_INVALID);
+        assert_se(personality_from_string(NULL) == PERSONALITY_INVALID);
+
+        assert_se(personality_from_string(personality_to_string(PER_LINUX32)) == PER_LINUX32);
+#endif
+}
+
 int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
@@ -133,6 +160,7 @@ int main(int argc, char *argv[]) {
         test_get_process_comm();
         test_pid_is_unwaited();
         test_pid_is_alive();
+        test_personality();
 
         return 0;
 }