1 #include "capsicum-test.h"
12 bool tmpdir_on_tmpfs = false;
13 bool force_mt = false;
14 bool force_nofork = false;
18 std::map<std::string, std::string> tmp_paths;
21 const char *TmpFile(const char *p) {
22 std::string pathname(p);
23 if (tmp_paths.find(pathname) == tmp_paths.end()) {
24 std::string fullname = tmpdir + "/" + pathname;
25 tmp_paths[pathname] = fullname;
27 return tmp_paths[pathname].c_str();
30 char ProcessState(int pid) {
32 // Open the process status file.
34 snprintf(s, sizeof(s), "/proc/%d/status", pid);
35 FILE *f = fopen(s, "r");
36 if (f == NULL) return '\0';
38 // Read the file line by line looking for the state line.
39 const char *prompt = "State:\t";
41 fgets(s, sizeof(s), f);
42 if (!strncmp(s, prompt, strlen(prompt))) {
44 return s[strlen(prompt)];
52 snprintf(buffer, sizeof(buffer), "ps -p %d -o state | grep -v STAT", pid);
53 sig_t original = signal(SIGCHLD, SIG_IGN);
54 FILE* cmd = popen(buffer, "r");
55 usleep(50000); // allow any pending SIGCHLD signals to arrive
56 signal(SIGCHLD, original);
57 int result = fgetc(cmd);
59 // Map FreeBSD codes to Linux codes.
63 case 'D': // disk wait
69 case 'W': // idle interrupt thread
73 case 'L': // waiting to acquire lock
80 typedef std::vector<std::string> TestList;
81 typedef std::map<std::string, TestList*> SkippedTestMap;
82 static SkippedTestMap skipped_tests;
83 void TestSkipped(const char *testcase, const char *test, const std::string& reason) {
84 if (skipped_tests.find(reason) == skipped_tests.end()) {
85 skipped_tests[reason] = new TestList;
87 std::string testname(testcase);
90 skipped_tests[reason]->push_back(testname);
93 void ShowSkippedTests(std::ostream& os) {
94 for (SkippedTestMap::iterator skiplist = skipped_tests.begin();
95 skiplist != skipped_tests.end(); ++skiplist) {
96 os << "Following tests were skipped because: " << skiplist->first << std::endl;
97 for (size_t ii = 0; ii < skiplist->second->size(); ++ii) {
98 const std::string& testname((*skiplist->second)[ii]);
99 os << " " << testname << std::endl;