2 * Copyright (C) 2012 ProFUSION embedded systems
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include <sys/types.h>
33 #include "testsuite.h"
42 static struct mod
*modules
;
43 static bool need_init
= true;
45 static void parse_retcodes(struct mod
*_modules
, const char *s
)
61 if (modname
== NULL
|| modname
[0] == '\0')
64 modnamelen
= strcspn(s
, ":");
65 if (modname
[modnamelen
] != ':')
68 p
= modname
+ modnamelen
+ 1;
72 l
= strtol(p
, &end
, 0);
73 if (end
== p
|| *end
!= ':')
78 l
= strtol(p
, &end
, 0);
81 else if (*end
!= '\0')
86 mod
= malloc(sizeof(*mod
) + modnamelen
+ 1);
90 memcpy(mod
->name
, modname
, modnamelen
);
91 mod
->name
[modnamelen
] = '\0';
93 mod
->errcode
= errcode
;
99 static struct mod
*find_module(struct mod
*_modules
, const char *modname
)
103 for (mod
= _modules
; mod
!= NULL
; mod
= mod
->next
) {
104 if (strcmp(mod
->name
, modname
))
111 static void init_retcodes(void)
119 s
= getenv(S_TC_DELETE_MODULE_RETCODES
);
121 fprintf(stderr
, "TRAP delete_module(): missing export %s?\n",
122 S_TC_DELETE_MODULE_RETCODES
);
125 parse_retcodes(modules
, s
);
128 TS_EXPORT
long delete_module(const char *name
, unsigned int flags
);
131 * FIXME: change /sys/module/<modname> to fake-remove a module
133 * Default behavior is to exit successfully. If this is not the intended
134 * behavior, set TESTSUITE_DELETE_MODULE_RETCODES env var.
136 long delete_module(const char *modname
, unsigned int flags
)
141 mod
= find_module(modules
, modname
);
145 errno
= mod
->errcode
;
149 /* the test is going away anyway, but lets keep valgrind happy */
150 void free_resources(void) __attribute__((destructor
));
151 void free_resources(void)
154 struct mod
*mod
= modules
->next
;