mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Create unit test framework for subprocesses
This commit is contained in:
parent
263711965f
commit
c5659b93f8
10 changed files with 279 additions and 77 deletions
|
@ -17,33 +17,27 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/pledge.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define SPAWN(METHOD) \
|
||||
{ \
|
||||
int ws, pid; \
|
||||
ASSERT_NE(-1, (pid = METHOD())); \
|
||||
if (!pid) {
|
||||
|
||||
#define EXITS(rc) \
|
||||
_Exit(0); \
|
||||
} \
|
||||
ASSERT_NE(-1, wait(&ws)); \
|
||||
ASSERT_TRUE(WIFEXITED(ws)); \
|
||||
ASSERT_EQ(rc, WEXITSTATUS(ws)); \
|
||||
}
|
||||
|
||||
#define TERMS(sig) \
|
||||
_Exit(0); \
|
||||
} \
|
||||
ASSERT_NE(-1, wait(&ws)); \
|
||||
ASSERT_TRUE(WIFSIGNALED(ws)); \
|
||||
ASSERT_EQ(sig, WTERMSIG(ws)); \
|
||||
}
|
||||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void CheckPlatform(void) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (__is_linux_2_6_23()) return;
|
||||
kprintf("skipping openbsd_test\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void SetUp(void) {
|
||||
CheckPlatform();
|
||||
}
|
||||
|
||||
TEST(pledge, promisedSyscallsCanBeCalled_ieEnosysIsIgnored) {
|
||||
SPAWN(fork);
|
||||
EXPECT_SYS(0, 0, pledge("stdio", 0));
|
||||
|
|
|
@ -29,30 +29,9 @@
|
|||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define SPAWN(METHOD) \
|
||||
{ \
|
||||
int ws, pid; \
|
||||
ASSERT_NE(-1, (pid = METHOD())); \
|
||||
if (!pid) {
|
||||
|
||||
#define EXITS(rc) \
|
||||
_Exit(0); \
|
||||
} \
|
||||
ASSERT_NE(-1, wait(&ws)); \
|
||||
ASSERT_TRUE(WIFEXITED(ws)); \
|
||||
ASSERT_EQ(rc, WEXITSTATUS(ws)); \
|
||||
}
|
||||
|
||||
#define TERMS(sig) \
|
||||
_Exit(0); \
|
||||
} \
|
||||
ASSERT_NE(-1, wait(&ws)); \
|
||||
ASSERT_TRUE(WIFSIGNALED(ws)); \
|
||||
ASSERT_EQ(sig, WTERMSIG(ws)); \
|
||||
}
|
||||
|
||||
void SetUp(void) {
|
||||
if (!__is_linux_2_6_23() && !IsOpenbsd()) exit(0);
|
||||
}
|
||||
|
|
|
@ -103,6 +103,9 @@ o/$(MODE)/test/libc/calls/poll_test.com.runs: \
|
|||
o/$(MODE)/test/libc/calls/fcntl_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
o/$(MODE)/test/libc/calls/openbsd_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc unveil
|
||||
|
||||
# TODO(jart): Update nointernet() to allow AF_INET6
|
||||
o/$(MODE)/test/libc/calls/pledge_test.com.runs: \
|
||||
private .INTERNET = 1
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/thread/spawn.h"
|
||||
#include "libc/x/x.h"
|
||||
|
@ -47,20 +48,6 @@ STATIC_YOINK("zip_uri_support");
|
|||
|
||||
#define EACCES_OR_ENOENT (IsOpenbsd() ? ENOENT : EACCES)
|
||||
|
||||
#define SPAWN(METHOD) \
|
||||
{ \
|
||||
int ws, pid; \
|
||||
ASSERT_NE(-1, (pid = METHOD())); \
|
||||
if (!pid) {
|
||||
|
||||
#define EXITS(rc) \
|
||||
_Exit(0); \
|
||||
} \
|
||||
ASSERT_NE(-1, wait(&ws)); \
|
||||
ASSERT_TRUE(WIFEXITED(ws)); \
|
||||
ASSERT_EQ(rc, WEXITSTATUS(ws)); \
|
||||
}
|
||||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
struct stat st;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue