2 * Copyright (C) 2012-2013 ProFUSION embedded systems
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 #include <sys/types.h>
33 #include <shared/util.h>
35 #include "testsuite.h"
44 static struct mod
*modules
;
45 static bool need_init
= true;
47 static void parse_retcodes(struct mod
**_modules
, const char *s
)
63 if (modname
== NULL
|| modname
[0] == '\0')
66 modnamelen
= strcspn(p
, ":");
67 if (modname
[modnamelen
] != ':')
70 p
= modname
+ modnamelen
+ 1;
74 l
= strtol(p
, &end
, 0);
75 if (end
== p
|| *end
!= ':')
81 l
= strtol(p
, &end
, 0);
84 else if (*end
!= '\0')
89 mod
= malloc(sizeof(*mod
) + modnamelen
+ 1);
93 memcpy(mod
->name
, modname
, modnamelen
);
94 mod
->name
[modnamelen
] = '\0';
96 mod
->errcode
= errcode
;
97 mod
->next
= *_modules
;
102 static struct mod
*find_module(struct mod
*_modules
, const char *modname
)
106 for (mod
= _modules
; mod
!= NULL
; mod
= mod
->next
) {
107 if (streq(mod
->name
, modname
))
114 static void init_retcodes(void)
123 s
= getenv(S_TC_DELETE_MODULE_RETCODES
);
125 ERR("TRAP delete_module(): missing export %s?\n",
126 S_TC_DELETE_MODULE_RETCODES
);
129 parse_retcodes(&modules
, s
);
131 for (mod
= modules
; mod
!= NULL
; mod
= mod
->next
) {
132 LOG("Added module to test delete_module:\n");
133 LOG("\tname=%s ret=%d errcode=%d\n",
134 mod
->name
, mod
->ret
, mod
->errcode
);
138 TS_EXPORT
long delete_module(const char *name
, unsigned int flags
);
141 * FIXME: change /sys/module/<modname> to fake-remove a module
143 * Default behavior is to exit successfully. If this is not the intended
144 * behavior, set TESTSUITE_DELETE_MODULE_RETCODES env var.
146 long delete_module(const char *modname
, unsigned int flags
)
151 mod
= find_module(modules
, modname
);
155 errno
= mod
->errcode
;
159 /* the test is going away anyway, but lets keep valgrind happy */
160 void free_resources(void) __attribute__((destructor
));
161 void free_resources(void)
164 struct mod
*mod
= modules
->next
;