forked from Neirth/FreeNOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce TestReporter, LocalTest, ExternalTest and DirectoryScanner …
…classes in libtest. Modified /test/run to use libtest for test discovery and execution. Implemented StdoutReporter which displays TestResults on the standard output.
- Loading branch information
1 parent
c962c66
commit c31df56
Showing
16 changed files
with
357 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <dirent.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
#include <String.h> | ||
#include "ExternalTest.h" | ||
#include "TestSuite.h" | ||
#include "DirectoryScanner.h" | ||
|
||
DirectoryScanner::DirectoryScanner(int argc, char **argv) | ||
{ | ||
m_argc = argc; | ||
m_argv = argv; | ||
} | ||
|
||
int DirectoryScanner::scan(const char *path) | ||
{ | ||
DIR *d; | ||
struct dirent *dent; | ||
char subPath[255]; | ||
|
||
// Attempt to open the target directory. | ||
if (!(d = opendir(path))) | ||
{ | ||
printf("%s: failed to open '%s': %s\r\n", | ||
m_argv[0], path, strerror(errno)); | ||
return EXIT_FAILURE; | ||
} | ||
// Read directory. | ||
while ((dent = readdir(d))) | ||
{ | ||
snprintf(subPath, sizeof(subPath), "%s/%s", path, dent->d_name); | ||
String str = subPath; | ||
|
||
// Check filetype | ||
switch (dent->d_type) | ||
{ | ||
// Directory | ||
case DT_DIR: | ||
if (dent->d_name[0] != '.') | ||
scan(subPath); | ||
break; | ||
|
||
// Regular file | ||
case DT_REG: | ||
if (str.endsWith((const char *)"Test")) | ||
new ExternalTest(subPath); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
// Close it. | ||
closedir(d); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __LIBTEST_DIRECTORYSCANNER_H | ||
#define __LIBTEST_DIRECTORYSCANNER_H | ||
|
||
class DirectoryScanner | ||
{ | ||
public: | ||
|
||
DirectoryScanner(int argc, char **argv); | ||
|
||
int scan(const char *path); | ||
|
||
private: | ||
|
||
int m_argc; | ||
char **m_argv; | ||
}; | ||
|
||
#endif /* __LIBTEST_DIRECTORYSCANNER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
#include <libgen.h> | ||
#include <sys/stat.h> | ||
#include <sys/wait.h> | ||
#include "ExternalTest.h" | ||
|
||
ExternalTest::ExternalTest(const char *name) | ||
: TestInstance(name) | ||
{ | ||
// TODO: perhaps argc/argv? | ||
} | ||
|
||
TestResult ExternalTest::run() | ||
{ | ||
int status; | ||
|
||
#ifdef __HOST__ | ||
char tmp[255]; | ||
|
||
snprintf(tmp, sizeof(tmp), "%s -n", *m_name); | ||
status = system(tmp); | ||
|
||
if (WIFEXITED(status)) | ||
status = WEXITSTATUS(status); | ||
#else | ||
const char *argv[3] = { *m_name, "-n", 0 }; | ||
|
||
pid_t pid = forkexec(*m_name, (const char **) argv); | ||
waitpid(pid, &status, 0); | ||
#endif | ||
|
||
return status == 0 ? OK : FAIL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __LIBTEST_EXTERNALTEST_H | ||
#define __LIBTEST_EXTERNALTEST_H | ||
|
||
#include "TestInstance.h" | ||
|
||
class ExternalTest : public TestInstance | ||
{ | ||
public: | ||
|
||
ExternalTest(const char *name); | ||
|
||
virtual TestResult run(); | ||
}; | ||
|
||
#endif /* __LIBTEST_EXTERNALTEST_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "LocalTest.h" | ||
|
||
LocalTest::LocalTest(const char *name, TestFunction func) | ||
: TestInstance(name) | ||
{ | ||
m_func = func; | ||
} | ||
|
||
TestResult LocalTest::run(void) | ||
{ | ||
return m_func(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __LIBTEST_LOCALTEST_H | ||
#define __LIBTEST_LOCALTEST_H | ||
|
||
#include "TestInstance.h" | ||
|
||
typedef TestResult TestFunction(void); | ||
|
||
class LocalTest : public TestInstance | ||
{ | ||
public: | ||
|
||
LocalTest(const char *name, TestFunction func); | ||
|
||
virtual TestResult run(); | ||
|
||
private: | ||
|
||
TestFunction *m_func; | ||
}; | ||
|
||
#endif /* __LIBTEST_LOCALTEST_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __LIBTEST_TESTINSTANCE_H | ||
#define __LIBTEST_TESTINSTANCE_H | ||
|
||
#include <String.h> | ||
|
||
enum TestResult | ||
{ | ||
OK = 0, | ||
FAIL = 1, | ||
SKIP = 2 | ||
}; | ||
|
||
class TestInstance | ||
{ | ||
public: | ||
|
||
TestInstance(const char *name); | ||
|
||
virtual TestResult run() = 0; | ||
|
||
protected: | ||
|
||
String m_name; | ||
}; | ||
|
||
#endif /* __LIBTEST_TESTINSTANCE_H */ |
Oops, something went wrong.