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, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <sys/types.h>
34 #include "testsuite.h"
43 static struct mod
*modules
;
44 static bool need_init
= true;
46 static void parse_retcodes(struct mod
*_modules
, const char *s
)
62 if (modname
== NULL
|| modname
[0] == '\0')
65 modnamelen
= strcspn(s
, ":");
66 if (modname
[modnamelen
] != ':')
69 p
= modname
+ modnamelen
+ 1;
73 l
= strtol(p
, &end
, 0);
74 if (end
== p
|| *end
!= ':')
79 l
= strtol(p
, &end
, 0);
82 else if (*end
!= '\0')
87 mod
= malloc(sizeof(*mod
) + modnamelen
+ 1);
91 memcpy(mod
->name
, modname
, modnamelen
);
92 mod
->name
[modnamelen
] = '\0';
94 mod
->errcode
= errcode
;
100 static struct mod
*find_module(struct mod
*_modules
, const char *modname
)
104 for (mod
= _modules
; mod
!= NULL
; mod
= mod
->next
) {
105 if (strcmp(mod
->name
, modname
))
112 static void init_retcodes(void)
120 s
= getenv(S_TC_DELETE_MODULE_RETCODES
);
122 fprintf(stderr
, "TRAP delete_module(): missing export %s?\n",
123 S_TC_DELETE_MODULE_RETCODES
);
126 parse_retcodes(modules
, s
);
129 TS_EXPORT
long delete_module(const char *name
, unsigned int flags
);
132 * FIXME: change /sys/module/<modname> to fake-remove a module
134 * Default behavior is to exit successfully. If this is not the intended
135 * behavior, set TESTSUITE_DELETE_MODULE_RETCODES env var.
137 long delete_module(const char *modname
, unsigned int flags
)
142 mod
= find_module(modules
, modname
);
146 errno
= mod
->errcode
;
150 /* the test is going away anyway, but lets keep valgrind happy */
151 void free_resources(void) __attribute__((destructor
));
152 void free_resources(void)
155 struct mod
*mod
= modules
->next
;