this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Adding a test suite for libproc

+86
tests/src/bin/i386/10.2/libproc.c.bin

This is a binary file and will not be displayed.

tests/src/bin/i386/10.6/libproc.c.bin

This is a binary file and will not be displayed.

tests/src/bin/i386/10.8/libproc.c.bin

This is a binary file and will not be displayed.

+6
tests/src/bin/i386/libproc.c.stdout
··· 1 + proc_name() retval: [OK] 2 + proc_name() strstr: [OK] 3 + proc_listpids() retval: [OK] 4 + proc_listpids() PROC_UID_ONLY: [OK] 5 + proc_listpidspath retval: [OK] 6 + proc_listpidspath pid: [OK]
tests/src/bin/x86-64/10.2/libproc.c.bin

This is a binary file and will not be displayed.

tests/src/bin/x86-64/10.6/libproc.c.bin

This is a binary file and will not be displayed.

tests/src/bin/x86-64/10.8/libproc.c.bin

This is a binary file and will not be displayed.

+6
tests/src/bin/x86-64/libproc.c.stdout
··· 1 + proc_name() retval: [OK] 2 + proc_name() strstr: [OK] 3 + proc_listpids() retval: [OK] 4 + proc_listpids() PROC_UID_ONLY: [OK] 5 + proc_listpidspath retval: [OK] 6 + proc_listpidspath pid: [OK]
+74
tests/src/libproc.c
··· 1 + #include <libproc.h> 2 + #include <stdio.h> 3 + #include <unistd.h> 4 + #include <string.h> 5 + #include <stdlib.h> 6 + 7 + void TEST(const char* name, int r); 8 + void test1(); 9 + void test2(); 10 + void test3(); 11 + 12 + int main() 13 + { 14 + test1(); 15 + test2(); 16 + test3(); 17 + 18 + return 0; 19 + } 20 + 21 + void TEST(const char* name, int r) 22 + { 23 + printf("%s: %s\n", name, r ? "[OK]" : "[FAIL]"); 24 + } 25 + 26 + void 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 + 35 + void 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 + 56 + void 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 +