1 // SPDX-License-Identifier: LGPL-2.1-or-later
3 * Copyright (C) 2012-2013 ProFUSION embedded systems
14 #include <shared/macro.h>
16 #include <libkmod/libkmod.h>
18 #include "testsuite.h"
20 static int test_load_resources(void)
23 const char *null_config
= NULL
;
26 ctx
= kmod_new(NULL
, &null_config
);
30 kmod_set_log_priority(ctx
, 7);
32 err
= kmod_load_resources(ctx
);
34 ERR("could not load libkmod resources: %s\n", strerror(-err
));
42 DEFINE_TEST_WITH_FUNC(
43 test_load_resource1
, test_load_resources
,
45 "test if kmod_load_resources works (recent modprobe on kernel without modules.builtin.modinfo)",
47 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init-load-resources/",
48 [TC_UNAME_R
] = "5.6.0",
51 DEFINE_TEST_WITH_FUNC(
52 test_load_resource2
, test_load_resources
,
54 "test if kmod_load_resources works with empty modules.builtin.aliases.bin (recent depmod on kernel without modules.builtin.modinfo)",
56 [TC_ROOTFS
] = TESTSUITE_ROOTFS
57 "test-init-load-resources-empty-builtin-aliases-bin/",
58 [TC_UNAME_R
] = "5.6.0",
61 static int test_initlib(void)
64 const char *null_config
= NULL
;
66 ctx
= kmod_new(NULL
, &null_config
);
74 DEFINE_TEST(test_initlib
, .description
= "test if libkmod's init function work");
76 static int test_insert(void)
79 struct kmod_module
*mod
;
80 const char *null_config
= NULL
;
83 ctx
= kmod_new(NULL
, &null_config
);
87 err
= kmod_module_new_from_path(ctx
, "/mod-simple.ko", &mod
);
89 ERR("could not create module from path: %s\n", strerror(-err
));
93 err
= kmod_module_insert_module(mod
, 0, NULL
);
95 ERR("could not insert module: %s\n", strerror(-err
));
98 kmod_module_unref(mod
);
103 DEFINE_TEST(test_insert
,
104 .description
= "test if libkmod's insert_module returns ok",
106 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init/",
107 [TC_INIT_MODULE_RETCODES
] = "bla:1:20",
109 .modules_loaded
= "mod_simple");
111 static int test_remove(void)
113 struct kmod_ctx
*ctx
;
114 struct kmod_module
*mod_simple
, *mod_bla
;
115 const char *null_config
= NULL
;
118 ctx
= kmod_new(NULL
, &null_config
);
122 err
= kmod_module_new_from_name(ctx
, "mod-simple", &mod_simple
);
124 ERR("could not create module from name: %s\n", strerror(-err
));
128 err
= kmod_module_new_from_name(ctx
, "bla", &mod_bla
);
130 ERR("could not create module from name: %s\n", strerror(-err
));
134 err
= kmod_module_remove_module(mod_simple
, 0);
136 ERR("could not remove module: %s\n", strerror(-err
));
140 err
= kmod_module_remove_module(mod_bla
, 0);
141 if (err
!= -ENOENT
) {
142 ERR("wrong return code for failure test: %d\n", err
);
146 kmod_module_unref(mod_bla
);
147 kmod_module_unref(mod_simple
);
153 test_remove
, .description
= "test if libkmod's remove_module returns ok",
155 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-remove/",
156 [TC_DELETE_MODULE_RETCODES
] = "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT
),