Skip to content
Snippets Groups Projects
Commit 5e9b5b0f authored by Yang Bai's avatar Yang Bai Committed by Pekka Enberg
Browse files

tests: Allow specify test names to testrunner


Allow specify test names to testrunner such as testrunner.so tst-foo1.so
tst-foo2.so to run tst-foo1 and tst-foo2 only in the order they are
specified. This does not change the default behavior that
cmdline=testrunner.so will run all tests under /tests dir.

This change can help developer to run the only test cases they need
quickly to verify new feature or find possible regressions.

Signed-off-by: default avatarYang Bai <hamo.by@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 9fa59ae9
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,6 @@
* BSD license as described in the LICENSE file in the top-level directory.
*/
#include <sys/stat.h>
#include <dirent.h>
#include <dlfcn.h>
......@@ -15,6 +14,8 @@
#include <unistd.h>
#include <limits.h>
#define TESTDIR "/tests"
extern void dlclose_by_path_np(const char* filename);
static unsigned nr_tests, nr_failures;
......@@ -42,41 +43,60 @@ void load_test(char *path, char *argv0)
dlclose_by_path_np(path);
}
int main(int argc, char **argv)
int check_path(char *path)
{
#define TESTDIR "/tests"
DIR *dir = opendir(TESTDIR);
char path[PATH_MAX];
struct dirent *d;
struct stat st;
if (stat(path, &st) < 0) {
printf("failed to stat %s\n", path);
return 0;
}
if (!dir) {
perror("failed to open testdir");
return EXIT_FAILURE;
if (!S_ISREG(st.st_mode)) {
printf("ignoring %s, not a regular file\n", path);
return 0;
}
return 1;
}
int main(int argc, char **argv)
{
char path[PATH_MAX];
while ((d = readdir(dir))) {
if (strcmp(d->d_name, ".") == 0 ||
strcmp(d->d_name, "..") == 0)
continue;
if (argc == 1) {
DIR *dir = opendir(TESTDIR);
struct dirent *d;
snprintf(path, PATH_MAX, "%s/%s", TESTDIR, d->d_name);
if (stat(path, &st) < 0) {
printf("failed to stat %s\n", path);
continue;
if (!dir) {
perror("failed to open testdir");
return EXIT_FAILURE;
}
if (!S_ISREG(st.st_mode)) {
printf("ignoring %s, not a regular file\n", path);
continue;
while ((d = readdir(dir))) {
if (strcmp(d->d_name, ".") == 0 ||
strcmp(d->d_name, "..") == 0)
continue;
snprintf(path, PATH_MAX, "%s/%s", TESTDIR, d->d_name);
if (!check_path(path))
continue;
load_test(path, d->d_name);
}
load_test(path, d->d_name);
}
if (closedir(dir) < 0) {
perror("failed to close testdir");
return EXIT_FAILURE;
if (closedir(dir) < 0) {
perror("failed to close testdir");
return EXIT_FAILURE;
}
} else {
for (int i = 1; i < argc; i++) {
snprintf(path, PATH_MAX, "%s/%s", TESTDIR, argv[i]);
if (!check_path(path))
continue;
load_test(path, argv[i]);
}
}
printf("All tests complete - %d/%d failures\n", nr_failures, nr_tests);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment