this repo has no description
at fixPythonPipStalling 74 lines 1.2 kB view raw
1#include <libproc.h> 2#include <stdio.h> 3#include <unistd.h> 4#include <string.h> 5#include <stdlib.h> 6 7void TEST(const char* name, int r); 8void test1(); 9void test2(); 10void test3(); 11 12int main() 13{ 14 test1(); 15 test2(); 16 test3(); 17 18 return 0; 19} 20 21void TEST(const char* name, int r) 22{ 23 printf("%s: %s\n", name, r ? "[OK]" : "[FAIL]"); 24} 25 26void test1() 27{ 28 char name[1024]; 29 int rv = proc_name(getpid(), name, sizeof name); 30 31 TEST("proc_name() retval", rv != 0); 32 TEST("proc_name() strstr", strstr(name, "libproc") != NULL); 33} 34 35void test2() 36{ 37 pid_t pids[4096]; 38 int rv; 39 int found = 0; 40 41 rv = proc_listpids(PROC_UID_ONLY, getuid(), pids, sizeof pids); 42 TEST("proc_listpids() retval", rv != 0); 43 44 for (int i = 0; i < rv; i++) 45 { 46 if (pids[i] == getpid()) 47 { 48 found = 1; 49 break; 50 } 51 } 52 53 TEST("proc_listpids() PROC_UID_ONLY", found); 54} 55 56void test3() 57{ 58 char testfile[] = "/tmp/testcaseXXXXXX"; 59 FILE* file; 60 pid_t pids[4096]; 61 int rv; 62 int found = 0, i = 0; 63 64 mkstemp(testfile); 65 file = fopen(testfile, "w"); 66 67 rv = proc_listpidspath(PROC_ALL_PIDS, 0, testfile, 0, pids, sizeof pids); 68 TEST("proc_listpidspath retval", rv > 0); 69 TEST("proc_listpidspath pid", pids[0] == getpid()); 70 71 fclose(file); 72 unlink(testfile); 73} 74